Commit ac6f230a authored by Wichit Sombat's avatar Wichit Sombat

wrapping up session-2

parent 79e90759
......@@ -33,21 +33,6 @@
"| Declarative | program logic (fourth-gen) | SQL, regex, CSS, Prolog |\n"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"### Textbook: PPICS\n",
"![screenshot](http://mcsp.wartburg.edu/zelle/python/ppics3/cover_small.png)\n",
"> [An Introduction to Computer Science 2nd Edition - John M. Zelle, Ph.D.](http://www.leetupload.com/database/Misc/Papers/Python%20programming%20-%20An%20introduction%20to%20computer%20science%202002.pdf)\n",
"\n",
"> [Slides](http://mcsp.wartburg.edu/zelle/python/ppics3/slides/)"
]
},
{
"cell_type": "markdown",
"metadata": {
......@@ -80,7 +65,7 @@
"### 1. Computers and Programs [Lecture](./01 Computers and Programs.ipynb) [Lab](./01 Computers and Programs Lab.ipynb)\n",
"\n",
"| Lectures | Laboratory |\n",
"|:----------------------------|:------------------------|\n",
"|:---------------------------- |:------------------------|\n",
"| 1. The Universal Machine | 1. Anaconda Installation |\n",
"| 2. Program Power | 2. Python Shell |\n",
"| 3. What is Computer Science? | 3. IPython Shell |\n",
......@@ -364,7 +349,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.1"
"version": "3.5.2"
}
},
"nbformat": 4,
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
import sys
import PyQt5.QtWidgets
app = PyQt5.QtWidgets.QApplication(sys.argv)
w = PyQt5.QtWidgets.QWidget()
w.resize(250, 150)
w.move(300, 300)
w.show()
sys.exit(app.exec_())
import sys
from PyQt5.QtWidgets import QApplication, QWidget
from PyQt5.QtGui import QIcon
class MyWindow(QWidget):
def __init__(self):
super().__init__()
self.setGeometry(300, 300, 300, 220)
self.setWindowTitle('Icon')
self.setWindowIcon(QIcon('csubu.jpg'))
self.show()
if __name__ == '__main__':
app = QApplication(sys.argv)
ex = MyWindow()
sys.exit(app.exec_())
This diff is collapsed.
{
"K": {
"ชื่อ-สกุล": "เกรียงศักดิ์ ตรีประพิณ",
"e-mail": "kriengsak.t@ubu.ac.th",
"picture": "image/K.jpg"
},
"Kai": {
"ชื่อ-สกุล": "ปิยนันท์ พนากานต์",
"e-mail": "piyanan.p@ubu.ac.th",
"picture": "image/Kai.jpg"
},
"Or": {
"ชื่อ-สกุล": "วาสนา เหง้าเกษ",
"e-mail": "wasana.n@ubu.ac.th",
"picture": "image/Or.jpg"
},
"Paul": {
"ชื่อ-สกุล": "วิชิต สมบัติ",
"e-mail": "wichit.s@ubu.ac.th",
"picture": "image/Paul.jpg"
},
"Tom": {
"ชื่อ-สกุล": "ไพชยนต์ คงไชย",
"e-mail": "phaichayon.k@ubu.ac.th",
"picture": "image/Tom.jpg"
},
"Woot": {
"ชื่อ-สกุล": "วราวุฒิ ผ้าเจริญ",
"e-mail": "warawoot.p@ubu.ac.th",
"picture": "image/Woot.jpg"
}
}
{
"base": "EUR",
"date": "2018-01-19",
"source": "https://api.fixer.io/latest",
"rates": {
"AUD": 1.5302,
"BGN": 1.9558,
"BRL": 3.9312,
"CAD": 1.5246,
"CHF": 1.1758,
"CNY": 7.8481,
"CZK": 25.433,
"DKK": 7.4454,
"GBP": 0.88365,
"HKD": 9.5814,
"HRK": 7.4352,
"HUF": 309.2,
"IDR": 16316,
"ILS": 4.1837,
"INR": 78.239,
"JPY": 135.54,
"KRW": 1306.9,
"MXN": 22.816,
"MYR": 4.826,
"NOK": 9.6243,
"NZD": 1.6831,
"PHP": 62.138,
"PLN": 4.1716,
"RON": 4.6594,
"RUB": 69.332,
"SEK": 9.8333,
"SGD": 1.6178,
"THB": 39.069,
"TRY": 4.6557,
"USD": 1.2255,
"ZAR": 14.955
}
}
# Micro-Service Web
## สิ่งที่ต้องติดตั้งก่อน
```sh
pip install -r requirements.txt
```
## วิธี run
```sh
python3 server.py
```
## วิธีเรียกใช้
```sh
http://localhost:5000/info
http://localhost:5000/speakers/txt
http://localhost:5000/speakers/json
http://localhost:5000/height/txt
http://localhost:5000/height/json
http://localhost:5000/pop/txt
http://localhost:5000/pop/json
http://localhost:5000/picture/K
http://localhost:5000/picture/Tom
http://localhost:5000/picture/Woot
```
from flask import Flask, jsonify, send_file #, url_for
import os, json
app = Flask(__name__)
def read(fname):
with open(fname, 'r') as f:
data = f.read()
f.close()
return json.loads(data)
@app.route('/')
def api_root():
return """Welcome I'm a <a href="http://www.python.org">python</a> server that give you data."""
@app.errorhandler(404)
def not_found(a):
return """Error! Ask the right question. <br/> ระบุข้อมูลและรูปแบบให้ถูกต้องด้วย """
@app.route('/<data>/<dataformat>')
def app_data(data, dataformat):
DATA = {
'speakers': ["K","Kai","Or","Paul","Tom","Woot"],
'height': [180,164,165,165,180,170],
'pop': [3.25,3.9,4,3,3.5,3.44],
'popularity': [3.25,3.9,4,3,3.5,3.44]
}
try:
if dataformat in ['txt', 'text', 'TXT']:
return " ".join(DATA[data])
if dataformat in ['json', 'JSON', 'jsn']:
return jsonify(DATA[data])
except: pass
return """Error! Ask the right question. <br/> ระบุข้อมูลและรูปแบบให้ถูกต้องด้วย """
@app.route('/api/<name>')
def api_name(name):
return jsonify(read('api/{}.json'.format(name)))
@app.route('/picture/<speaker>')
def api_image(speaker):
fname = 'image/{}.jpg'.format(speaker)
if os.path.exists(fname):
return send_file(fname, mimetype="image/jpeg")
return """Error! no picture for {}.""".format(speaker)
if __name__ == '__main__':
app.run(host='0.0.0.0', port=5000)
import statistics
line = input('speakers ')
speakers = map(str, line.split(' '))
print(speakers)
line = input('height ')
height = map(int, line.split(' '))
print(statistics.mode(height))
line = input('pop ')
pop = map(float, line.split(' '))
print(statistics.mean(pop))
......@@ -3,7 +3,7 @@ from PyQt5.QtWidgets import QWidget, QPushButton, QLineEdit, QLabel, QGridLayout
from PyQt5.QtGui import QImage, QImageWriter, QPainter, QPen, qRgb, QPixmap
import os
import matplotlib.pyplot as plt
#import matplotlib.pyplot as plt
# Import datasets, classifiers and performance metrics
from sklearn import datasets, svm, metrics
......
......@@ -3,7 +3,7 @@ from PyQt5.QtWidgets import QWidget, QPushButton, QLineEdit, QLabel, QGridLayout
from PyQt5.QtGui import QImage, QImageWriter, QPainter, QPen, qRgb, QPixmap
import os
import matplotlib.pyplot as plt
#import matplotlib.pyplot as plt
# Import datasets, classifiers and performance metrics
from sklearn import datasets, svm, metrics
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment