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.

12 changes: 12 additions & 0 deletions .idea/inspectionProfiles/Project_Default.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/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.

131 changes: 131 additions & 0 deletions code.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
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"<h1>{i + 1})</h1>"
res += f"<p>Желаемая зарплата: {cv['salary']}.</p>"
res += f"<p>Образование: {cv['educationType']}.</p>"

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():
jobs = get_list_field('jobTitle')
qualifications = get_list_field('qualification')
res = ""
people_amount = people_in_first_only(jobs, qualifications)
res += f"<p>Из {people_amount[1]} людей не совпадают профессия и должность у {people_amount[0]}</p>"
res += f"<p>Топ 5 образований людей, которые работают менеджерами:</p>"
res += get_top(5, jobs, qualifications, "менеджер")
res += f"<p>Топ 5 должностей людей, которые по диплому являются инженерами:</p>"
res += get_top(5, qualifications, jobs, "инженер")
return res


def get_top(top_size, field_to_search, field_to_return, str_to_search):
res = ''
full_top = top(field_to_search, field_to_return, str_to_search)
for i in range(top_size):
res += f"<p>- {full_top[i][0]} - {full_top[i][1]} чел.</p>"
return res


def get_list_field(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 = make_figure()
output = io.BytesIO()
FigureCanvas(fig).print_png(output)
return Response(output.getvalue(), mimetype='image/png')


def make_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


def people_in_first_only(field1, field2):
res_count = 0
total = 0
for (f1, f2) in zip(field1, field2):
total += 1
if not get_matches(f1[0], f2[0]) and not get_matches(f2[0], f1[0]):
res_count += 1
return res_count, total


def get_matches(f1, f2):
arr1 = str(f1).lower().replace('-', ' ').split()
for word in arr1:
if word in str(f2).lower():
return True
return False


def top(f_to_search, f_to_return, str_to_search):
res = []
for (f_s, f_r) in zip(f_to_search, f_to_return):
if str(f_s[0]).lower().find(str_to_search[:-2]) != -1:
if str(f_r[0]).find('None') == -1:
res.append(f_r[0])

return Counter(res).most_common()


app.run()
22 changes: 4 additions & 18 deletions templates/d2.html
Original file line number Diff line number Diff line change
Expand Up @@ -199,25 +199,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: {{ data }},
lineTension: 0,
backgroundColor: 'transparent',
borderColor: '#007bff',
Expand Down
Binary file added works.sqlite
Binary file not shown.