forked from mfbutner/CanvasHelpers
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
90 lines (69 loc) · 3.33 KB
/
main.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
from canvasapi import Canvas
import pandas as pd
from makeGroups import makeGroups
from checkValidGroup import invalidGroupDict
from analyzeCode import gradeGroups
from sendCanvasConvo import sendConvo
from canvasapi import Canvas
from canvasapi.canvas_object import CanvasObject
from studentClass import Student
from parseStudent import parse, parseEmails, parsePartnerQuiz
def retrieveCSVfromCanvas(quiz:CanvasObject) :
studentReport = quiz.create_report("student_analysis")
reportProgress = None
# URL of canvas progress object from studentReport
reportProgressURL = studentReport.progress_url
# parse so only the process id remains
reportProgressID = reportProgressURL.removeprefix('https://canvas.ucdavis.edu/api/v1/progress/')
# wait for student report to finish generating while the process has not completed or failed
while reportProgress != 'completed' and reportProgress != 'failed':
reportProgressObj = canvas.get_progress(reportProgressID)
reportProgress = reportProgressObj.workflow_state
print(reportProgress)
studentReportN = quiz.create_report("student_analysis")
url = studentReportN.file["url"]
studentData = pd.read_csv(url)
return studentData
#Get the right class
API_URL = ""
API_KEY = ""
#Macros that will have to change to the appropriate class and survey number
CLASS_ID = 1
QUIZ_ID = 1
QUIZ_ID2 = 1
className = ""
studyGroupNumber = ""
#Get the class data from canvas
canvas = Canvas(API_URL, API_KEY)
canvasClass = canvas.get_course(CLASS_ID)
# Get the right quiz
quiz = canvasClass.get_quiz(QUIZ_ID)
studentReport = quiz.create_report("student_analysis")
reportProgress = None
# URL of canvas progress object from studentReport
reportProgressURL = studentReport.progress_url
# parse so only the process id remains
reportProgressID = reportProgressURL.removeprefix('https://canvas.ucdavis.edu/api/v1/progress/')
# wait for student report to finish generating while the process has not completed or failed
while reportProgress != 'completed' and reportProgress != 'failed':
reportProgressObj = canvas.get_progress(reportProgressID)
reportProgress = reportProgressObj.workflow_state
studentReportN = quiz.create_report("student_analysis")
url = studentReportN.file["url"]
studentData = pd.read_csv(url)
#Parse the student data of those that took the survey
dictStudentTakeSurvey = parse(studentData, CLASS_ID)
#Finds out who did not take survey (also updates the entire class with their school emails)
dictStudentDidNotTakeSurvey = parseEmails(dictStudentTakeSurvey, canvasClass)
#Find the appropriate quiz
quiz2 = canvasClass.get_quiz(QUIZ_ID2)
partnerQuizData = retrieveCSVfromCanvas(quiz2)
parsePartnerQuiz(partnerQuizData ,canvasClass, dictStudentTakeSurvey, dictStudentDidNotTakeSurvey)
#Find the people who were matchedBefore, place it into a dict
matchedBefore = invalidGroupDict(canvas, CLASS_ID)
#Create the groups:
groups = makeGroups(dictStudentTakeSurvey, dictStudentDidNotTakeSurvey, matchedBefore)
#Now that groups are matched, send emails and form groups
#sendConvo(canvas, CLASS_ID, groups, studyGroupNumber)
#Anaylze the groups: how many students with a preference got it?
gradeGroups(groups, matchedBefore)