From 03a26fbb46435c751784042a85e283917619317f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9E=D0=BB=D1=8C=D0=B3=D0=B0?= Date: Sun, 26 Dec 2021 02:02:33 +0500 Subject: [PATCH 1/4] 2 --- ...20\260\320\264\320\260\321\207\320\260.py" | 116 ++++++++++++++++++ 1 file changed, 116 insertions(+) create mode 100644 "2 \320\267\320\260\320\264\320\260\321\207\320\260.py" diff --git "a/2 \320\267\320\260\320\264\320\260\321\207\320\260.py" "b/2 \320\267\320\260\320\264\320\260\321\207\320\260.py" new file mode 100644 index 0000000..66defc8 --- /dev/null +++ "b/2 \320\267\320\260\320\264\320\260\321\207\320\260.py" @@ -0,0 +1,116 @@ +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"

{i + 1})

" + 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(): + con = sqlite3.connect('works.sqlite') + jobs = list(con.execute(f'select jobTitle from works')) + qualifications = list(con.execute(f'select qualification from works')) + con.close() + res_count = 0 + total = 0 + for (job, qualification) in zip(jobs, qualifications): + total += 1 + if not compare(str(job), str(qualification)) and not compare(str(qualification), str(job)): + res_count += 1 + res = f"

Из {total} людей не совпадают профессия и должность у {res_count}

" + res += f"

Топ 5 образований людей, которые работают менеджерами:

" + res += get_top(jobs, qualifications, "менедж") + res += f"

Топ 5 должностей людей, которые инженеры по диплому:

" + res += get_top(qualifications, jobs, "инжен") + return res + + +def compare(profession, other): + for i in profession.lower().replace('-', ' ').split(): + if i in other.lower(): + return True + return False + + +def get_top(profession, other, prof_name): + result = '' + full_top = top(profession, other, prof_name) + for i in range(5): + result += f"

- {full_top[i][0]} - {full_top[i][1]} чел.

" + return result + + +def top(profession, other, prof_name): + res = [] + for (prof, top_prof) in zip(profession, other): + if str(prof[0]).lower().find(prof_name) != -1: + if str(top_prof[0]).find('None') == -1: + res.append(top_prof[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 From 5427cb87b5fe7b225ae6c2cacfe89a4061109db4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9E=D0=BB=D1=8C=D0=B3=D0=B0?= Date: Sun, 26 Dec 2021 02:02:48 +0500 Subject: [PATCH 2/4] d2 --- templates/d2.html | 22 ++++------------------ 1 file changed, 4 insertions(+), 18 deletions(-) diff --git a/templates/d2.html b/templates/d2.html index da76864..af2ce1b 100644 --- a/templates/d2.html +++ b/templates/d2.html @@ -199,25 +199,11 @@

Резюме

var myChart = new Chart(ctx, { type: 'line', data: { - labels: [ - 'Sunday', - 'Monday', - 'Tuesday', - 'Wednesday', - 'Thursday', - 'Friday', - 'Saturday' - ], + {% autoescape false %} + labels: {{ labels }} + {% endautoescape %} datasets: [{ - data: [ - 15339, - 21345, - 18483, - 24003, - 23489, - 24092, - 12034 - ], + data: {{ data }}, lineTension: 0, backgroundColor: 'transparent', borderColor: '#007bff', From 77bbb557065a32c6c0c4bdf9e733c5df931130fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9E=D0=BB=D1=8C=D0=B3=D0=B0?= Date: Sun, 26 Dec 2021 02:03:00 +0500 Subject: [PATCH 3/4] sqlite --- works.sqlite | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 works.sqlite diff --git a/works.sqlite b/works.sqlite new file mode 100644 index 0000000..e69de29 From cfa3416337ef3836b11a90d90fa52bd8a7d58487 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9E=D0=BB=D1=8C=D0=B3=D0=B0?= Date: Sun, 26 Dec 2021 02:03:13 +0500 Subject: [PATCH 4/4] =?UTF-8?q?=D0=B8=D0=B7=20=D1=82=D0=B5=D0=BE=D1=80?= =?UTF-8?q?=D0=B8=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...20\265\320\276\321\200\320\270\320\270.py" | 67 +++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 "\320\270\320\267 \321\202\320\265\320\276\321\200\320\270\320\270.py" diff --git "a/\320\270\320\267 \321\202\320\265\320\276\321\200\320\270\320\270.py" "b/\320\270\320\267 \321\202\320\265\320\276\321\200\320\270\320\270.py" new file mode 100644 index 0000000..c7a3dfb --- /dev/null +++ "b/\320\270\320\267 \321\202\320\265\320\276\321\200\320\270\320\270.py" @@ -0,0 +1,67 @@ +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__) + + +@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(): + return render_template('d3.html', + cvs=get_cv(), + ) + + +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