Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/inspectionProfiles/profiles_settings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/web.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file added 1g.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added 2g.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
119 changes: 119 additions & 0 deletions Main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
import os
import sqlite3
import pandas as pd
import numpy as np
from matplotlib import pyplot as plt

from flask import Flask
from flask import render_template
from flask import Response
import io
from matplotlib.backends.backend_agg import FigureCanvasAgg as FigureCanvas
from matplotlib.figure import Figure

con = sqlite3.connect("task.sqlite")
cursor = con.cursor()

cursor.execute("drop table if exists works")
cursor.execute("create table works("
"ID integer primary key AUTOINCREMENT,"
"salary integer,"
"educationType text,"
"jobTitle text,"
"qualification text,"
"gender text,"
"dateModify text,"
"skills text,"
"otherInfo text"
");")
con.commit()

data = pd.read_csv("works.csv")
data.to_sql('works', con, if_exists="append", index = None)
con.commit()


a = cursor.execute("select substring(dateModify, 1, 4) as 'year', count(*) as 'c' from works group by year").fetchall()
labels = list(map(lambda x: x[0], a))
values = list(map(lambda x: x[1], a))
mensCount = cursor.execute("select count(*) from works where gender = 'Мужской'").fetchall()[0][0]
womensCount = cursor.execute("select count(*) from works where gender = 'Женский'").fetchall()[0][0]

# 1ый график
'''cursor.execute("select salary from works where gender = 'Мужской'")
men = list(map(lambda row: row[0],cursor.fetchall()))
cursor.execute("select salary from works where gender = 'Женский'")
women = [row[0] for row in cursor.fetchall()]
pers = np.linspace(0.1, 1, 10)
a = np.quantile(men, pers)
b = np.quantile(women, pers)
plt.plot(pers, a, color="b")
plt.plot(pers, b, color="r")
plt.xlabel("Перцентили")
plt.ylabel("Зарплата")
plt.show()'''

# 2ой график
'''cursor.execute("select educationType, avg(salary) as 'av' from works where gender='Мужской' group by educationType")
men = list(map(lambda row: row[1],cursor.fetchall()))[1:5]
print(men)
cursor.execute("select educationType, avg(salary) as 'av' from works where gender='Женский' group by educationType")
women = list(map(lambda row: row[1],cursor.fetchall()))[1:5]
print(women)
index = np.arange(4)
bw = 0.3
plt.bar(index, men, bw, color='b')
plt.bar(index+bw, women, bw, color='r')
plt.xticks(index+0.5*bw,['Высшее','Неоконченное высшее','Среднее','Проффессиональное'])
plt.show()'''


app = Flask(__name__, static_folder="C:\\Users\\Иван\\Documents\\pRep\\web")


@app.route("/")
def cv_index():
return render_template('myPage.html', count=sum(values), mensCount=mensCount, womensCount=womensCount)


@app.route("/dashboard")
def dashboard():
return render_template('d3.html',
cvs=get_cv(), labels=labels[1:4], values=values[1:4],
)


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('task.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 = [2000, 2001, 2002]
ys = [300, 50, 70]
axis.plot(xs, ys)
return fig

app.run()
Binary file added task.sqlite
Binary file not shown.
22 changes: 4 additions & 18 deletions templates/d3.html
Original file line number Diff line number Diff line change
Expand Up @@ -200,25 +200,11 @@ <h2>Резюме</h2>
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: {{values}},
lineTension: 0,
backgroundColor: 'transparent',
borderColor: '#007bff',
Expand Down
15 changes: 15 additions & 0 deletions templates/myPage.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<h1> Статистика </h1>
<p>1) Количество резюме: {{count}}.</p>
<p>2) Количество мужчин: {{mensCount}}.</p>
<p>3) Количество женщин: {{womensCount}}.</p>
<img src="{{ url_for('static', filename = '1g.png') }}">
<img src="{{ url_for('static', filename = '2g.png') }}">
</body>
</html>
Loading