-
Notifications
You must be signed in to change notification settings - Fork 0
/
standard_score.py
38 lines (33 loc) · 1.32 KB
/
standard_score.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
import getopt
import sys
import serialization
def calculate_standard_score(rating, options, birthyear_offset = 1, participation_offset = 1):
df = serialization.load_data()
for (k, v) in options.items():
if k == "Country":
df = df[df[k] == options[k]]
if k == "Birthyear":
df = df.dropna()
df["Birthyear"] = df["Birthyear"].astype(int)
df = df[(df[k] >= options[k] - birthyear_offset) & (df[k] <= options[k] + birthyear_offset)]
if k == "Participation":
df = df[(df[k] >= options[k] - participation_offset) & (df[k] <= options[k] + participation_offset)]
df_rating = df["Rating"]
standard_score = 10 * (rating - df_rating.mean()) / df_rating.std() + 50
return standard_score
def main():
try:
(opts, args) = getopt.getopt(sys.argv[1:], "c:b:p:")
except getopt.GetoptError:
print("usage: %s [-c country] [-b birthyear] [-p participation] [rating]" % sys.argv[0])
option_dict = {}
for (k, v) in opts:
if k == "-c":
option_dict["Country"] = v
elif k == "-b":
option_dict["Birthyear"] = int(v)
elif k == "-p":
option_dict["Participation"] = int(v)
print(calculate_standard_score(int(args[0]), option_dict))
if __name__ == "__main__":
main()