-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathuser_statistics.py
107 lines (91 loc) · 3.47 KB
/
user_statistics.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
import datetime
from typing import TypedDict
from settings import QuestionThreshold as qt
class StatInformation(TypedDict):
right_answers_amount: str
percentage_completion: str
basic_progress: float
oop_progress: float
pep_progress: float
structures_progress: float
alghorimts_progress: float
git_progress: float
sql_progress: float
def get_right_answers_amount(progress: dict) -> StatInformation:
# Summary progress
right_answers_amount = len([right for right in progress.values() if right])
amount_of_answers = max(progress) - 7
percentage_completion = (
f'{round(100 * right_answers_amount / amount_of_answers, 1)}%'
)
# Patricular progress
basic_amount = qt.BASIC_LAST_QUESTION - qt.BASIC_FIRST_QUESTION
oop_amount = qt.OOP_LAST_QUESTION - qt.OOP_FIRST_QUESTION
pep_amount = qt.PEP8_LAST_QUESTION - qt.PEP8_FIRST_QUESTION
structures_amount = (
qt.STRUCTURES_LAST_QUESTION - qt.STRUCTURES_FIRST_QUESTION
)
alghorimts_amount = (
qt.ALGHORITMS_LAST_QUESTION - qt.ALGHORITMS_FIRST_QUESTION
)
git_amount = qt.GIT_LAST_QUESTION - qt.GIT_FIRST_QUESTION
sql_amount = qt.SQL_LAST_QUESTION - qt.SQL_FIRST_QUESTION
basic_progress = get_paticular_progress(
progress, basic_amount, qt.BASIC_FIRST_QUESTION, qt.BASIC_LAST_QUESTION
)
oop_progress = get_paticular_progress(
progress, oop_amount, qt.OOP_FIRST_QUESTION, qt.OOP_LAST_QUESTION
)
pep_progress = get_paticular_progress(
progress, pep_amount, qt.PEP8_FIRST_QUESTION, qt.PEP8_LAST_QUESTION
)
structures_progress = get_paticular_progress(
progress, structures_amount,
qt.STRUCTURES_FIRST_QUESTION,
qt.STRUCTURES_LAST_QUESTION
)
alghorimts_progress = get_paticular_progress(
progress,
alghorimts_amount,
qt.ALGHORITMS_FIRST_QUESTION,
qt.ALGHORITMS_LAST_QUESTION
)
git_progress = get_paticular_progress(
progress, git_amount, qt.GIT_FIRST_QUESTION, qt.GIT_LAST_QUESTION
)
sql_progress = get_paticular_progress(
progress, sql_amount, qt.SQL_FIRST_QUESTION, qt.SQL_LAST_QUESTION
)
return StatInformation(
right_answers_amount=f'{right_answers_amount} из {amount_of_answers}',
percentage_completion=percentage_completion,
basic_progress=basic_progress,
oop_progress=oop_progress,
pep_progress=pep_progress,
structures_progress=structures_progress,
alghorimts_progress=alghorimts_progress,
git_progress=git_progress,
sql_progress=sql_progress,
)
def get_last_enter_message(date) -> str:
return (
f'{date.day}.{date.month}.{date.year}'
if type(date) is datetime.datetime
else 'не было'
)
def get_paticular_progress(
user_progress: dict, amount_kind: int, from_: int, to_: int) -> float:
return round(
len(
[is_right for question_number, is_right in user_progress.items()
if question_number
in range(from_, to_) and is_right]) / amount_kind, 1
)
def count_interview_duration(start_date, stop_date) -> int:
time_difference = stop_date - start_date
difference_in_seconds = time_difference.total_seconds()
return int(difference_in_seconds)
def convert_seconds_to_hours(seconds: int) -> float:
hours = seconds / 3600
hours_decimal = round(hours, 1)
return hours_decimal