forked from Anwesha2003/Anwesha2003
-
Notifications
You must be signed in to change notification settings - Fork 0
/
course.py
94 lines (90 loc) · 3.8 KB
/
course.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
import mysql.connector
import json
import pandas
import matplotlib.pyplot
from collections import Counter
from student import gradeCheck
mydb = mysql.connector.connect(host = "localhost", user = "root", password = "The39clues$", database = "course")
cursorObject = mydb.cursor()
def createCourse(course_id, course_name):
print("Enter students in course: ")
marks_obtained_D = {}
while(True):
student_id = input("Enter student ID (to stop enter STOP): ")
if(student_id.upper() == "STOP"):
break
else:
marks = int(input("Enter marks obtained in course: "))
marks_obtained_D[student_id] = marks
marks_obtained = json.dumps(marks_obtained_D)
sql = "INSERT INTO course (course_id, course_name, marks_obtained) VALUES (%s, %s, %s)"
val = (course_id, course_name, marks_obtained)
cursorObject.execute(sql, val)
mydb.commit()
def checkPerformance(course_id):
cursorObject.execute("SELECT * FROM course")
myresult = cursorObject.fetchall()
check = 0
data = []
for i in range(0, len(myresult)):
if(myresult[i][0] == course_id):
check = 1
student_marks_d = json.loads(myresult[i][2])
student_marks = [(k, v) for k, v in student_marks_d.items()]
mydb1 = mysql.connector.connect(host = "localhost", user = "root", password = "The39clues$", database = "student")
cursorObject1 = mydb1.cursor()
cursorObject1.execute("SELECT * FROM student")
result = cursorObject1.fetchall()
student_ids = []
students = []
student_rolls = []
for j in range(0, len(result)):
student_ids.append(result[j][0])
students.append(result[j][1])
student_rolls.append(result[j][2])
student_datas = [student_ids, students, student_rolls]
for j in range(0, len(student_marks)):
for k in range(0, len(student_datas[0])):
if(student_marks[j][0] == student_datas[0][k]):
print("Student ID: " + student_datas[0][k])
print("Student Name: " + student_datas[1][k])
print("Student Roll Number: " + str(student_datas[2][k]))
print("Marks obtained: " + str(student_marks[j][1]))
print()
data.append([student_datas[0][k],student_datas[1][k],student_datas[1][k],student_datas[2][k],student_marks[j][1]])
if(check == 0):
print("Course does not exist")
return data
def courseStatistics(course_id):
mydb1 = mysql.connector.connect(host = "localhost", user = "root", password = "The39clues$", database = "student")
cursorObject1 = mydb1.cursor()
cursorObject1.execute("SELECT * FROM student")
result = cursorObject1.fetchall()
student_ids = []
for i in range(0, len(result)):
student_ids.append(result[i][0])
cursorObject.execute("SELECT * FROM course")
result = cursorObject.fetchall()
marks = []
course_ids = []
for i in range(0, len(result)):
marks.append(json.loads(result[i][2]))
course_ids.append(result[i][0])
grades = []
for i in range(0, len(student_ids)):
x = None
for j in range(0, len(course_ids)):
temp = marks[j]
if(isinstance(temp.get(student_ids[i]), int)):
if(course_ids[j] == course_id):
x = temp.get(student_ids[i])
if(isinstance(x, int)):
grades.append(gradeCheck(x))
if(len(grades) == 0):
print("Course does not exist")
else:
grades.sort()
letter_counts = Counter(grades)
df = pandas.DataFrame.from_dict(letter_counts, orient='index')
df.plot(kind='bar')
matplotlib.pyplot.show()