diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..94f33bf --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml + +# IntellijIdea files +*.iml +.idea +out diff --git a/.idea/.name b/.idea/.name new file mode 100644 index 0000000..a055837 --- /dev/null +++ b/.idea/.name @@ -0,0 +1 @@ +Flask_task.py \ No newline at end of file diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml new file mode 100644 index 0000000..105ce2d --- /dev/null +++ b/.idea/inspectionProfiles/profiles_settings.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..7a85af6 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,7 @@ + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..f589ca3 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Flask_task.py b/Flask_task.py new file mode 100644 index 0000000..3193ba6 --- /dev/null +++ b/Flask_task.py @@ -0,0 +1,101 @@ +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 count_people_diploma_not_match_job(jobTitles, qualification): + result = 0 + total = 0 + for (jt, q) in zip(jobTitles, qualification): + total += 1 + if not does_diploma_match(jt[0], q[0]) and not does_diploma_match(q[0], jt[0]): + result += 1 + return result, total + + +def does_diploma_match(str1, str2): + str_array = str1.lower().replace('-', ' ').split() + for word in str_array: + if word in str2.lower(): + return True + return False + +@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(): + jobTitles = get_list('jobTitle') + qualifications = get_list('qualification') + res = "" + count = count_people_diploma_not_match_job(jobTitles, qualifications) + res += f"

Из {count[1]} людей не совпадают профессия и должность у {count[0]}

" + return res + + +def get_list(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 + + +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/works.sqlite b/works.sqlite new file mode 100644 index 0000000..e69de29