-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmethods.py
144 lines (132 loc) · 4.89 KB
/
methods.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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
import json
import datetime as dt
import requests
import random
def userDetails(codeforcesHandle, clearPastProblems):
url = requests.get('https://codeforces.com/api/user.info?handles='+codeforcesHandle)
jsonData = url.json()
data = json.dumps(jsonData)
codeforcesHandle = json.loads(data)
if(codeforcesHandle['status'] != "OK"):
return False
if(clearPastProblems):
completedProblems.clear()
return codeforcesHandle['result'][0]
def convertUnixTime(unixtime):
date = dt.datetime.fromtimestamp(unixtime).strftime('%Y-%m-%d')
time = dt.datetime.fromtimestamp(unixtime).strftime('%H:%M:%S')
date_time_obj = dt.datetime.strptime(date+" "+time, '%Y-%m-%d %H:%M:%S')
time = date_time_obj.time()
time = str((dt.datetime.combine(dt.date(1, 1, 1), time) +
dt.timedelta(hours=5, minutes=30)).time())
return date+" "+time
def convertToHour(secondsTime):
return str(dt.timedelta(seconds=secondsTime))
def contestDetails():
url = requests.get('https://codeforces.com/api/contest.list')
jsonData = url.json()
data = json.dumps(jsonData)
contests = json.loads(data)
contestList = []
count = 0
for contest in contests['result']:
if(contest['phase'] == "FINISHED"):
break
else:
contest['startTimeSeconds'] = convertUnixTime(
contest['startTimeSeconds'])
contest['durationSeconds'] = convertToHour(
contest['durationSeconds'])
contestList.append(contest)
count += 1
contestList = contestList[::-1]
return contestList[0:5]
completedProblems = {}
def getTags(codeforcesHandle, rank):
url = requests.get(
'https://codeforces.com/api/user.status?handle='+codeforcesHandle)
jsonData = url.json()
data = json.dumps(jsonData)
submissions = json.loads(data)
submissions = submissions['result']
visitedProblems = {}
wrongSubmissions = {}
for problem in submissions:
if(problem['verdict'] != 'OK'):
if(problem['problem']['name'] in visitedProblems):
continue
visitedProblems[problem['problem']['name']] = 1
for tags in problem['problem']['tags']:
if(tags not in wrongSubmissions):
wrongSubmissions[tags] = 1
else:
wrongSubmissions[tags] += 1
else:
completedProblems[problem['problem']['name']] = 1
weakTags = {}
minSolvedCount = 0
maxSolvedCount = 35000
if(rank < 1200):
minSolvedCount = 8000
maxSolvedCount = 18000
elif(rank < 1400):
minSolvedCount = 6000
maxSolvedCount = 10000
elif(rank < 1600):
minSolvedCount = 3000
maxSolvedCount = 7000
elif(rank < 1900):
minSolvedCount = 1000
maxSolvedCount = 5000
elif(rank < 2100):
minSolvedCount = 900
maxSolvedCount = 3000
elif(rank < 2400):
minSolvedCount = 500
maxSolvedCount = 1500
elif(rank < 2600):
minSolvedCount = 300
maxSolvedCount = 800
elif(rank < 3000):
minSolvedCount = 100
maxSolvedCount = 700
else:
minSolvedCount = 0
maxSolvedCount = 400
for tags in sorted(wrongSubmissions.items(), key=lambda x: x[1], reverse=True):
weakTags[tags[0]] = getProblems(tags[0], rank, minSolvedCount, maxSolvedCount)
if(len(weakTags) == 6):
break
return weakTags
def getProblems(tag, rank, minSolvedCount, maxSolvedCount):
problems = []
url = requests.get(
'https://codeforces.com/api/problemset.problems?tags='+tag)
jsonData = url.json()
data = json.dumps(jsonData)
allData = json.loads(data)
allProblems = allData['result']['problems']
allproblemStatistics = allData['result']['problemStatistics']
count = 0
lengthOfProblemSet = len(allProblems)
j = 0
alreadySuggested = {}
while(j < lengthOfProblemSet):
j += 1
i = random.randint(0, lengthOfProblemSet-1)
if("points" in allProblems[i] and allProblems[i]['points'] <= 1000):
continue
elif (allProblems[i]['index'] == 'A'):
continue
if tag in allProblems[i]['tags']:
if((allProblems[i]['name'] not in alreadySuggested) and (allProblems[i]['name'] not in completedProblems) and allproblemStatistics[i]['solvedCount'] >= minSolvedCount and allproblemStatistics[i]['solvedCount'] <= maxSolvedCount):
alreadySuggested[allProblems[i]['name']] = 1
tempList = []
tempList.append(allProblems[i]['name'])
tempList.append('https://codeforces.com/problemset/problem/' +
str(allProblems[i]['contestId'])+'/'+allProblems[i]['index'])
problems.append(tempList)
count += 1
if(count == 6):
break
return problems