-
Notifications
You must be signed in to change notification settings - Fork 0
/
dbCheck.py
270 lines (250 loc) · 7.71 KB
/
dbCheck.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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
import pymongo
import config
def markAttendance(client, classroomId, rollNo, studentName, loginTime):
try:
print("Marking attendance for " + classroomId)
db = client.jiitclassroom
col = db["attendance"]
data = col.find({'classroomId': classroomId})
if(data.count()): #classroom exists
currentAttendance = data[0]["attendance"].copy()
if(not rollNo in currentAttendance.keys()): #if logging in first time
print("Updating Attendance")
currentAttendance[rollNo] = [studentName,loginTime]
updatedData = { "$set": {
"classroomId": classroomId,
"attendance": currentAttendance
}
}
col.update_one(data[0],updatedData)
else: #if class doesnt exists
print("Creating class and marking attendance for " + classroomId)
data = {"classroomId": classroomId,
"attendance": {
rollNo: [studentName,loginTime]
}
}
col.insert_one(data)
except Exception as e:
print("Could not mark attendance")
print(e)
None
def addMeeting(client, facultyId, classroomId, meetingPassword):
db = client.jiitclassroom
col = db["facultyLogin"]
data = col.find_one({'id': facultyId})
if(data):
if "meetings" in data:
meetings = data["meetings"].copy()
meetingPasswordData = data["meetingPassword"].copy()
meetingPasswordData[str(classroomId)] = meetingPassword
if(str(classroomId) in meetings):
return [False, "Meeting with same ID already Exists"]
meetings.append(str(classroomId))
updatedData = { "$set": {
"id": data["id"],
"meetings": meetings,
"meetingPassword": meetingPasswordData,
"name": data["name"],
"password": data["password"]
}
}
col.update_one(data,updatedData)
meetingPasswordCol = db["meetingPassword"]
meetingPasswordData = {"classroomId": str(classroomId), "meetingPassword": meetingPassword}
meetingPasswordCol.insert_one(meetingPasswordData)
return [True]
else:
return [False, "Some error occurred. Couldn't create meeting."]
def getAllMeetingsOfFaculty(client, facultyId):
db = client.jiitclassroom
col = db["facultyLogin"]
data = col.find_one({'id': facultyId})
if(data):
return data["meetings"]
else:
return False
def getAttendance(client, classroomId):
db = client.jiitclassroom
col = db["attendance"]
meetingData = col.find_one({'classroomId': classroomId})
if(meetingData):
return [True, meetingData["attendance"]]
return [False]
def checkFacultyLogin(client, facultyId, facultyPassword):
db = client.jiitclassroom
col = db["facultyLogin"]
data = col.find_one({'id': facultyId, 'password': facultyPassword})
if(data):
return [True, data]
return [False]
def checkStudentLogin(client, rollNo, password):
db = client.jiitclassroom
col = db["studentLogin"]
data = col.find_one({'rollNo': rollNo, 'password': password})
if(data):
return [True, data['name']]
return [False]
def createAccount(client, facultyName, facultyId, facultyPassword):
db = client.jiitclassroom
col = db["facultyLogin"]
if(col.find_one({'id': facultyId})):
return False
else:
data = {"id": facultyId,
"meetings": [],
"exams": [],
"meetingPassword": {},
"name": facultyName,
"password": facultyPassword
}
col.insert_one(data)
return True
def createStudentAccount(client, studentName, studentRollNo, studentPassword):
db = client.jiitclassroom
col = db["studentLogin"]
if(col.find_one({'rollNo': studentRollNo})):
return False
else:
data = {"rollNo": studentRollNo,
"name": studentName,
"password": studentPassword
}
col.insert_one(data)
return True
def checkIfFacultyExists(client, facultyId):
db = client.jiitclassroom
col = db["facultyLogin"]
data = col.find_one({'id': facultyId})
if(data):
return True
else:
return False
def getSurvey(client, facultyId):
db = client.jiitclassroom
col = db["facultyLogin"]
data = col.find_one({'id': facultyId})
if 'survey' in data:
if(data['survey'] == False):
return False
else:
return True
return False
def setSurvey(client, facultyId):
db = client.jiitclassroom
col = db["facultyLogin"]
data = col.find_one({'id': facultyId})
if(data):
updatedData = { "$set": {
"id": data["id"],
"meetings": data["meetings"],
"name": data["name"],
"password": data["password"],
"survey": True
}
}
col.update_one(data,updatedData)
return True
else:
return False
def setFeatureOpen(client, name):
db = client.jiitclassroom
col = db["featureOpen"]
data = col.find_one({"name" : name})
if not data:
col.insert_one({"name": name})
def getMeetingPassword(client, classroomId):
db = client.jiitclassroom
col = db["meetingPassword"]
data = col.find_one({"classroomId": classroomId})
if(data):
return data["meetingPassword"]
return ""
def getExamDetails(client, examId):
db = client.jiitclassroom
col = db["examDetails"]
data = col.find_one({"examId": examId})
if(data):
return [True, data]
return [False, "Exam ID Doesn't Exist"]
def addExam(client, facultyId, examData):
db = client.jiitclassroom
col = db["facultyLogin"]
data = col.find_one({'id': facultyId})
if(data):
exams = data["exams"].copy()
if(str(examData["examId"]) in data["exams"]):
return [False, "Exam with same Exam ID already exists"]
exams.append(str(examData["examId"]))
updatedData = { "$set": {
"id": data["id"],
"exams": exams,
"meetings": data["meetings"],
"meetingPassword": data["meetingPassword"],
"name": data["name"],
"password": data["password"]
}
}
col.update_one(data,updatedData)
getExamDetailsDb = db["examDetails"]
getExamDetailsDb.insert_one(examData)
examResultsDb = db["examResults"]
examResultsDb.insert_one({
'examId': examData['examId'],
'examResults': {}
})
return [True]
else:
return [False, "Some error occurred. Couldn't create Exam."]
def getExamResults(client, examId):
db = client.jiitclassroom
col = db["examResults"]
examIdData = col.find_one({'examId': examId})
examIdResults = examIdData['examResults']
return examIdResults
def getExamTable(client, facultyId):
db = client.jiitclassroom
col = db["facultyLogin"]
data = col.find_one({'id': facultyId})
if(data):
tableData = []
if "exams" in data:
exams = data["exams"]
for examId in exams:
try:
examData = getExamDetails(client, examId)[1]
givenBy = getExamResults(client, examId)
tableData.append({"examId": examId,
"examName": examData["examName"],
"examDate": examData["examDate"],
"givenBy": len(givenBy)
})
except Exception as e:
print(e)
pass
return tableData
def submitExam(client, studentExamData, examScore):
rollNo = studentExamData['rollNo']
studentName = studentExamData['studentName']
examId = studentExamData['examId']
del studentExamData['rollNo']
del studentExamData['studentName']
del studentExamData['examId']
data = {
'studentName': studentName,
'examData': studentExamData,
'examScore': examScore
}
db = client.jiitclassroom
col = db["examResults"]
examIdData = col.find_one({'examId': examId})
examIdResults = examIdData['examResults']
newExamIdResults = examIdResults.copy()
newExamIdResults[rollNo] = data
updatedData = { "$set": {
"examId": examId,
"examResults": newExamIdResults
}
}
col.update_one(examIdData,updatedData)
return [True]