forked from railbotan/web
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
100 lines (77 loc) · 2.7 KB
/
main.py
File metadata and controls
100 lines (77 loc) · 2.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
from flask import Flask
from flask import render_template
from flask import Response
import sqlite3
import random
import io
from matplotlib.backends.backend_agg import FigureCanvasAgg as FigureCanvas
from matplotlib.figure import Figure
app = Flask(__name__)
def get_cv():
con = sqlite3.connect('works.sqlite')
con.row_factory = dict_factory
res = list(con.execute('select * from works limit 20'))
con.close()
return res
@app.route("/")
def cv_index():
cvs = get_cv()
res = ""
for i, cv in enumerate(cvs):
res += f"<h1>{i + 1})</h1>"
res += f"<p>Желаемая зарплата: {cv['salary']}.</p>"
res += f"<p>Образование: {cv['educationType_id']}.</p>"
return res
@app.route("/dashboard")
def dashboard():
con = sqlite3.connect('works.sqlite')
res = con.execute('SELECT SUBSTR(dateModify, 1, 4), COUNT(*) FROM works WHERE dateModify NOT NULL GROUP BY '
'SUBSTR(dateModify, 1, 4)').fetchall()
con.close()
return render_template('d2.html', cvs=get_cv(), labels=[row[0] for row in res], data=[row[1] for row in res])
@app.route("/statistic")
def statistic():
jobTitles = get_list_field('jobTitle')
qualifications = get_list_field('qualification')
result = ""
count = different_profession(jobTitles, qualifications)
result += f"<p>Из {count[1]} количество людей у которых не совпадает профессия и должность: {count[0]}</p>"
return result
def get_list_field(field):
con = sqlite3.connect('works.sqlite')
res = list(con.execute(f'select {field} from works'))
con.close()
return res
def dict_factory(cursor, row):
d = {}
for idx, col in enumerate(cursor.description):
d[col[0]] = row[idx]
return d
@app.route('/plot.png')
def plot_png():
fig = create_figure()
output = io.BytesIO()
FigureCanvas(fig).print_png(output)
return Response(output.getvalue(), mimetype='image/png')
def create_figure():
fig = Figure()
axis = fig.add_subplot(1, 1, 1)
xs = range(100)
ys = [random.randint(1, 50) for x in xs]
axis.plot(xs, ys)
return fig
def different_profession(field1, field2):
res_count = 0
total = 0
for (f1, f2) in zip(field1, field2):
total += 1
if not find_match(f1[0], f2[0]) and not find_match(f2[0], f1[0]):
res_count += 1
return res_count, total
def find_match(f1, f2):
arr1 = str(f1).lower().replace('-', ' ').split()
for word in arr1:
if word in str(f2).lower():
return True
return False
app.run()