forked from cyscomvit/cyber-odyssey-webapp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
time_functions.py
101 lines (88 loc) · 2.66 KB
/
time_functions.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
import os
from dotenv import load_dotenv
load_dotenv("cyber-odyssey.env")
def calculate_current_time_left() -> int:
import time, datetime, pytz
event_end_time_ist = (
int(os.getenv("EVENT_END_TIME")) if os.getenv("EVENT_END_TIME") else 1677054600
)
current_time_ist_float = time.mktime(
datetime.datetime.now(pytz.timezone("Asia/Kolkata")).timetuple()
)
time_left = event_end_time_ist - current_time_ist_float
if time_left > 1:
return int(time_left)
return 1
def get_base_value(time_left: int = 0):
# returns base_value and time_diff past that base value
base_value = 900
if time_left >= 3600:
base_value = 3600
elif time_left >= 2700:
base_value = 2700
elif time_left >= 1800:
base_value = 1800
elif time_left >= 900:
base_value = 900
elif time_left >= 600:
base_value = 600
elif time_left >= 300:
base_value = 300
elif time_left >= 100:
base_value = 100
elif 60 >= time_left >= 0:
base_value = 60
return base_value
def get_time_differentiator(time_left: int = 0) -> int:
# returns time_diff past that base value
time_differentiator = 60
if time_left > 3600:
time_differentiator = 200
elif time_left > 2700:
time_differentiator = 120
elif time_left > 1800:
time_differentiator = 90
elif time_left > 900:
time_differentiator = 60
elif time_left > 600:
time_differentiator = 50
elif time_left > 300:
time_differentiator = 40
elif time_left > 100:
time_differentiator = 30
elif 100 > time_left >= 0:
time_differentiator = 3
return time_differentiator
def calculate_points_for_answering(
question_level: str, hints_used: bool, time_left: int = 0
):
if not time_left:
time_left = calculate_current_time_left()
base_value = get_base_value(time_left)
time_differentiator = get_time_differentiator(time_left)
if question_level in ("easy", "start"):
multiplier = 50
elif question_level in ("medium", "ctfe"):
multiplier = 75
elif question_level in ("hard", "ctfm"):
multiplier = 120
else:
multiplier = 0
divider = 1
if hints_used:
divider = 1.5
ratio = multiplier / divider
points_without_time = int(ratio + 1)
points_with_time = int(
abs(((((ratio * (time_left % base_value)) / time_differentiator))) + 1)
)
from icecream import ic
ic(
points_without_time,
points_with_time,
time_left,
time_differentiator,
base_value,
ratio,
)
return points_without_time, points_with_time