-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprepare_enrolment_methods.py
executable file
·47 lines (32 loc) · 1.27 KB
/
prepare_enrolment_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
#! /usr/bin/env python
"""
Takes a file preprocessed by preprocess_teachers_and_courses.py
Outputs a file ready for importing into Moodle:
Administration du site -> Plugins -> Inscriptions -> Upload enrolment methods
"""
import argparse
import pandas as pd
from lib.io import read_csv, write_csv
from preprocess_teachers_and_courses import COURSE_COHORT, COURSE_SHORTNAME
def to_enrollment_methods(src: pd.DataFrame) -> pd.DataFrame:
src = src[src[COURSE_COHORT].notna()]
res = pd.DataFrame()
# We start with the columns that come from the source, thus creating all rows
res["metacohort"] = src[COURSE_COHORT]
res["shortname"] = src[COURSE_SHORTNAME]
# Now we can set the constant values to the rest of the columns
res["operation"] = "add"
res["method"] = "cohort"
res["disabled"] = 0
res["role"] = "student"
# To help compare different runs of the tool
res.sort_values(by="shortname", inplace=True)
return res
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("preprocessed")
parser.add_argument("output")
args = parser.parse_args()
preprocessed = read_csv(args.preprocessed)
enrollment_methods = to_enrollment_methods(preprocessed)
write_csv(enrollment_methods, args.output)