diff --git a/main.py b/main.py new file mode 100644 index 0000000..fee4bd6 --- /dev/null +++ b/main.py @@ -0,0 +1,128 @@ +from flask import Flask +from flask import render_template +from flask import Response +import sqlite3 +import random +import io +from collections import Counter + +from matplotlib.backends.backend_agg import FigureCanvasAgg as FigureCanvas +from matplotlib.figure import Figure + +app = Flask(__name__) + + +@app.route("/") +def cv_index(): + cvs = get_cv() + res = "" + for i, cv in enumerate(cvs): + res += f"
Желаемая зарплата: {cv['salary']}.
" + res += f"Образование: {cv['educationType']}.
" + + 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('jobTitle') + qualifications = get_list('qualification') + res = "" + people_count = count_people(jobTitles, qualifications) + res += f"Из {people_count[1]} людей не совпадают профессия и должность у {people_count[0]}
" + res += f"Топ 5 образований людей, которые работают по профессии менеджер:
" + res += get_top(5, jobTitles, qualifications, "менеджер") + res += f"Топ 5 должностей людей, которые по диплому являются инженерами:
" + res += get_top(5, qualifications, jobTitles, "инженер") + return res + + +def get_top(top_size, column_1, column_2, profession): + res = '' + full_top = top(column_1, column_2, profession) + for i in range(top_size): + res += f"- {full_top[i][0]} - {full_top[i][1]} чел.
" + return res + + +def get_list(column): + con = sqlite3.connect('works.sqlite') + res = list(con.execute(f'select {column} from works')) + con.close() + return res + +def count_people(column_1, column_2): + res_count = 0 + total = 0 + for (c1, c2) in zip(column_1, column_2): + total += 1 + if not find_match(c1[0], c2[0]) and not find_match(c2[0], c1[0]): + res_count += 1 + return res_count, total + + +def find_match(column_1, column_2): + arr1 = str(column_1).lower().replace('-', ' ').split() + for word in arr1: + if word in str(column_2).lower(): + return True + return False + + +def top(column_1, column_2, profession): + res = [] + for (c_1, c_2) in zip(column_1, column_2): + if str(c_1[0]).lower().find(profession[:-2]) != -1: + if str(c_2[0]).find('None') == -1: + res.append(c_2[0]) + + return Counter(res).most_common() + +def dict_factory(cursor, row): + # обертка для преобразования + # полученной строки. (взята из документации) + d = {} + for idx, col in enumerate(cursor.description): + d[col[0]] = row[idx] + return d + + +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('/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 + + +app.run() \ No newline at end of file diff --git a/templates/d2.html b/templates/d2.html index da76864..88e3b1f 100644 --- a/templates/d2.html +++ b/templates/d2.html @@ -199,25 +199,11 @@