-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCodeforcesDatabase.py
More file actions
74 lines (56 loc) · 2.96 KB
/
CodeforcesDatabase.py
File metadata and controls
74 lines (56 loc) · 2.96 KB
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
import mysql.connector
from database import connectdatabase
#To add the count of each verdict into the database Table
def addToSubmissionsInDb(userId,submissionCount):
#submissionCount = codeforcesScrap.submissionCount
mydb,mycursor = connectdatabase()
try:
#Here usersubmissions consists of count of each verdict of particular userId
insertStatement = f'INSERT INTO usersubmissions VALUES("{userId}",{submissionCount["AcceptedCount"]},{submissionCount["WrongAnswerCount"]},{submissionCount["TimeLimitExceedCount"]},{submissionCount["CompileTimeErrorCount"]},{submissionCount["RuntimeErrorCount"]});'
mycursor.execute(insertStatement)
except:
updateStatement = f'update usersubmissions SET Accepted = {submissionCount["AcceptedCount"]},WrongAnswer = {submissionCount["WrongAnswerCount"]},TimeLimitExceed = {submissionCount["TimeLimitExceedCount"]},CompilationError= {submissionCount["CompileTimeErrorCount"]},RunTimeError= {submissionCount["RuntimeErrorCount"]} where userid="{userId}";'
mycursor.execute(updateStatement)
mydb.commit()
print("addToSubmissionsIntoDb: The submission details are updated")
#Adding the problems of the codeforces into the database
def addToProblemDetails(problemId,problemName,problemLink):
mydb,mycursor = connectdatabase()
#problemDetails consists of all the problems that are available in the codeforces
insertStatement = f'insert ignore into problemDetails values("{problemId}","{problemName}","{problemLink}")'
try:
mycursor.execute(insertStatement)
except:
pass
mydb.commit()
#To add the problem with respective tags as true into databases under particular userId
def addToUserProblemDetails(valuesList):
mydb,mycursor = connectdatabase()
values = f'"{valuesList[0]}","{valuesList[1]}","{valuesList[2]}",'
values = values+",".join(str(x) for x in valuesList[3:])
#userProblemDetails consist of problems submitted by the user
insertStatement = 'insert ignore into userProblemDetails values(%s)' % values
try:
mycursor.execute(insertStatement)
except Exception as msg:
#print("Exception Message(addToUserProblemDetails)",msg)
pass
mydb.commit()
def addToContestDetails(contestid,contestName,contestStartTime):
mydb,mycursor = connectdatabase()
#Here contestDetails Table consists of details about all the contests of codeforces
insertStatement = f'insert ignore into contestDetails values("{contestid}","{contestName}","{contestStartTime}")'
try:
mycursor.execute(insertStatement)
except:
pass
mydb.commit()
def addToUserContestDetails(userid,platform,contestId,contestRank,contestRating,newRating):
mydb,mycursor = connectdatabase()
#userContestDetails Table consists of details about the user participated contests
insertStatement = f'insert into userContestDetails values("{userid}","{platform}","{contestId}",{contestRank},{contestRating},{newRating})'
try:
mycursor.execute(insertStatement)
except:
pass
mydb.commit()