From 8e11d80c1c799d57d9f93c2d87f1edafbf6b1429 Mon Sep 17 00:00:00 2001 From: Wanderer76 Date: Sun, 26 Dec 2021 17:22:54 +0500 Subject: [PATCH] =?UTF-8?q?1=20=D1=87=D0=B0=D1=81=D1=82=D1=8C=20=D0=B4?= =?UTF-8?q?=D0=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.py | 83 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 main.py diff --git a/main.py b/main.py new file mode 100644 index 0000000..0fcf5ee --- /dev/null +++ b/main.py @@ -0,0 +1,83 @@ +import numpy as np +from flask import Flask +from flask import render_template +from flask import Response +import sqlite3 +import random +import io + +from matplotlib import pyplot as plt +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"

{i + 1})

" + res += f"

Желаемая зарплата: {cv['salary']}.

" + res += f"

Образование: {cv['educationType']}.

" + + return res + + +@app.route("/dashboard") +def dashboard(): + res= get_cv() + return render_template('d3.html', + cvs=res, + labels=[i['dateModify'] for i in res], + data=[i['count'] for i in get_count()] + ) + +def dict_factory(cursor, row): + # обертка для преобразования + # полученной строки. (взята из документации) + d = {} + for idx, col in enumerate(cursor.description): + d[col[0]] = row[idx] + return d + +def get_count(): + con = sqlite3.connect('works.sqlite') + con.row_factory = dict_factory + res = list(con.execute("select count(*) as count from works" + " join gender on gender.id = works.gender" + " join education on works.educationType = education.id" + " group by dateModify" + " limit 20;")) + con.close() + return res + +def get_cv(): + con = sqlite3.connect('works.sqlite') + con.row_factory = dict_factory + res = list(con.execute("select * from works" + " join gender on gender.id = works.gender " + "join education on works.educationType = education.id" + " 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