ladok3 4.18__tar.gz → 4.19__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of ladok3 might be problematic. Click here for more details.

Files changed (33) hide show
  1. {ladok3-4.18 → ladok3-4.19}/PKG-INFO +1 -1
  2. {ladok3-4.18 → ladok3-4.19}/pyproject.toml +1 -1
  3. {ladok3-4.18 → ladok3-4.19}/src/ladok3/report.nw +124 -117
  4. {ladok3-4.18 → ladok3-4.19}/LICENSE +0 -0
  5. {ladok3-4.18 → ladok3-4.19}/README.md +0 -0
  6. {ladok3-4.18 → ladok3-4.19}/doc/Makefile +0 -0
  7. {ladok3-4.18 → ladok3-4.19}/doc/abstract.tex +0 -0
  8. {ladok3-4.18 → ladok3-4.19}/doc/ladok3.tex +0 -0
  9. {ladok3-4.18 → ladok3-4.19}/doc/preamble.tex +0 -0
  10. {ladok3-4.18 → ladok3-4.19}/makefiles/doc.mk +0 -0
  11. {ladok3-4.18 → ladok3-4.19}/makefiles/exam.mk +0 -0
  12. {ladok3-4.18 → ladok3-4.19}/makefiles/haskell.mk +0 -0
  13. {ladok3-4.18 → ladok3-4.19}/makefiles/miun.course.mk +0 -0
  14. {ladok3-4.18 → ladok3-4.19}/makefiles/miun.depend.mk +0 -0
  15. {ladok3-4.18 → ladok3-4.19}/makefiles/miun.docs.mk +0 -0
  16. {ladok3-4.18 → ladok3-4.19}/makefiles/miun.port.mk +0 -0
  17. {ladok3-4.18 → ladok3-4.19}/makefiles/miun.pub.mk +0 -0
  18. {ladok3-4.18 → ladok3-4.19}/makefiles/noweb.mk +0 -0
  19. {ladok3-4.18 → ladok3-4.19}/makefiles/pkg.mk +0 -0
  20. {ladok3-4.18 → ladok3-4.19}/makefiles/portability.mk +0 -0
  21. {ladok3-4.18 → ladok3-4.19}/makefiles/pub.mk +0 -0
  22. {ladok3-4.18 → ladok3-4.19}/makefiles/results.mk +0 -0
  23. {ladok3-4.18 → ladok3-4.19}/makefiles/subdir.mk +0 -0
  24. {ladok3-4.18 → ladok3-4.19}/makefiles/tex.mk +0 -0
  25. {ladok3-4.18 → ladok3-4.19}/makefiles/transform.mk +0 -0
  26. {ladok3-4.18 → ladok3-4.19}/src/ladok3/.gitignore +0 -0
  27. {ladok3-4.18 → ladok3-4.19}/src/ladok3/Makefile +0 -0
  28. {ladok3-4.18 → ladok3-4.19}/src/ladok3/api.nw +0 -0
  29. {ladok3-4.18 → ladok3-4.19}/src/ladok3/cli.nw +0 -0
  30. {ladok3-4.18 → ladok3-4.19}/src/ladok3/data.nw +0 -0
  31. {ladok3-4.18 → ladok3-4.19}/src/ladok3/ladok3.nw +0 -0
  32. {ladok3-4.18 → ladok3-4.19}/src/ladok3/student.nw +0 -0
  33. {ladok3-4.18 → ladok3-4.19}/src/ladok3/undoc.nw +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: ladok3
3
- Version: 4.18
3
+ Version: 4.19
4
4
  Summary: Python wrapper and CLI for the LADOK3 REST API.
5
5
  Home-page: https://github.com/dbosk/ladok3
6
6
  License: MIT
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "ladok3"
3
- version = "4.18"
3
+ version = "4.19"
4
4
  description = "Python wrapper and CLI for the LADOK3 REST API."
5
5
  authors = [
6
6
  "Daniel Bosk <dbosk@kth.se>",
@@ -83,6 +83,110 @@ report_parser.add_argument("-f", "--finalize",
83
83
  @
84
84
 
85
85
 
86
+ \section{Report many results given in standard input}
87
+
88
+ We want to read CSV data from standard input.
89
+ <<report results given in stdin>>=
90
+ data_reader = csv.reader(sys.stdin, delimiter=args.delimiter)
91
+ for course_code, component_code, student_id, grade, date, *graders in data_reader:
92
+ <<report a result read from stdin>>
93
+ @ We need to add an argument for the delimiter.
94
+ <<add many results group arguments>>=
95
+ many_parser.add_argument("-d", "--delimiter",
96
+ default="\t",
97
+ help="The delimiter for the CSV input; "
98
+ "default is a tab character to be compatible with POSIX commands, "
99
+ "use `-d,` or `-d ,` to get comma-separated values.")
100
+ @
101
+
102
+ We also want to handle errors and confirmations.
103
+ When reporting in bulk, we don't want unnecessary errors.
104
+ We also want to have a summary of the changes.
105
+ <<add many results group arguments>>=
106
+ many_parser.add_argument("-v", "--verbose",
107
+ action="count", default=0,
108
+ help="Increases the verbosity of the output: -v will print results that "
109
+ "were reported to standard out. Otherwise only errors are printed.")
110
+ @
111
+
112
+ Then we can actually report the result using the values read from [[stdin]].
113
+ <<report a result read from stdin>>=
114
+ try:
115
+ set_grade(ladok, args,
116
+ student_id, course_code, component_code, grade, date, graders)
117
+ except Exception as err:
118
+ print(f"{course_code} {component_code}={grade} ({date}) {student_id}: "
119
+ f"{err}",
120
+ file=sys.stderr)
121
+ @
122
+
123
+ When we set the grade, there are a few cases that should be handled.
124
+ If the grade isn't attested, we try to change it.
125
+ (This might still fail if the grade is finalized but not attested.)
126
+ If we've selected the verbose option, then we print what we have reported.
127
+
128
+ If the grade was attested, then we check if it's different.
129
+ If it's different, we output this.
130
+ If it's the same, we silently ignore it.
131
+ This is best for bulk reporting, because then we can always try to report for
132
+ all students.
133
+
134
+ We want to report errors as exceptions.
135
+ <<functions>>=
136
+ def set_grade(ladok, args,
137
+ student_id, course_code, component_code, grade, date, graders):
138
+ student = ladok.get_student(student_id)
139
+ <<get [[course]] from [[student]] and [[course_code]]>>
140
+ <<get [[component]] from [[course]] and [[component_code]]>>
141
+
142
+ if not component.attested and component.grade != grade:
143
+ <<ensure [[date]] is a valid date for [[course]]>>
144
+ component.set_grade(grade, date)
145
+ if args.finalize:
146
+ component.finalize(graders)
147
+ if args.verbose:
148
+ print(f"{course_code} {student}: reported "
149
+ f"{component.component} = {component.grade} ({date}) "
150
+ f"by {', '.join(graders)}.")
151
+ elif component.grade != grade:
152
+ raise Exception(f"attested {component.component} "
153
+ f"result {component.grade} ({component.date}) "
154
+ f"is different from {grade} ({date}).")
155
+ @
156
+
157
+ Now we simply want to set those objects up.
158
+ We want to throw exceptions that explain what the problem is if these don't
159
+ exist.
160
+ <<get [[course]] from [[student]] and [[course_code]]>>=
161
+ try:
162
+ course = student.courses(code=course_code)[0]
163
+ except IndexError:
164
+ raise Exception(f"{course_code}: No such course for {student}")
165
+ <<get [[component]] from [[course]] and [[component_code]]>>=
166
+ try:
167
+ component = course.results(component=component_code)[0]
168
+ except IndexError:
169
+ raise Exception(f"{component_code}: no such component for {course_code}")
170
+ @
171
+
172
+ Finally, we want to ensure the date is correct.
173
+ The date must be at the earliest the start of the course.
174
+ The student can't finish any results before the course has started.
175
+ LADOK will not accept that.
176
+ <<ensure [[date]] is a valid date for [[course]]>>=
177
+ if not isinstance(date, datetime.date):
178
+ date = datetime.date.fromisoformat(date)
179
+
180
+ if date < course.start:
181
+ print(f"{course_code} {component_code}={grade} "
182
+ f"({date}) {student}: "
183
+ f"Grade date ({date}) is before "
184
+ f"course start date ({course.start}), "
185
+ f"using course start date instead.")
186
+ date = course.start
187
+ @
188
+
189
+
86
190
  \section{Report a result given on command line}
87
191
 
88
192
  If we've chosen to give one result on the command line, then we'll need the
@@ -91,28 +195,33 @@ following arguments.
91
195
  We start with the course, component code, the student's ID and grade.
92
196
  <<add one result group arguments>>=
93
197
  one_parser.add_argument("course_code", nargs="?",
94
- help="The course code (e.g. DD1315) for which the grade is for"
198
+ help="The course code (e.g. DD1315) for which the grade is for."
95
199
  )
96
200
 
97
201
  one_parser.add_argument("component_code", nargs="?",
98
- help="The component code (e.g. LAB1) for which the grade is for"
202
+ help="The component code (e.g. LAB1) for which the grade is for. "
203
+ "This can be set to the course code (e.g. DD1315) to set the "
204
+ "final grade for the course. But all components must be "
205
+ "certified (attested) before the course grade can be set."
99
206
  )
100
207
 
101
208
  one_parser.add_argument("student_id", nargs="?",
102
- help="Student identifier (personnummer or LADOK ID)"
209
+ help="Student identifier (personnummer or LADOK ID)."
103
210
  )
104
211
 
105
212
  one_parser.add_argument("grade", nargs="?",
106
- help="The grade (e.g. A or P)"
213
+ help="The grade (e.g. A or P)."
107
214
  )
108
- @ We must make them optional like this to make it work with out second
109
- alternative, so we must check ourselves that we got the arguments.
215
+ @ We must make them optional like this to make it work with our second
216
+ alternative (bulk reporting through [[stdin]]), so we must check ourselves that
217
+ we got the arguments.
110
218
  <<check that we got all positional arguments>>=
111
219
  if not (args.course_code and args.component_code and
112
220
  args.student_id and args.grade):
113
221
  print(f"{sys.argv[0]} report: "
114
- "not all positional args given: course_code, component, student, grade",
115
- file=sys.stderr)
222
+ "not all positional args given: "
223
+ "course_code, component, student, grade",
224
+ file=sys.stderr)
116
225
  sys.exit(1)
117
226
  @
118
227
 
@@ -123,7 +232,7 @@ If it's not provided, we let [[argparse]] set it to today's date.
123
232
  <<add one result group arguments>>=
124
233
  one_parser.add_argument("date", nargs="?",
125
234
  help="Date on ISO format (e.g. 2021-03-18), "
126
- f"defaults to today's date ({datetime.date.today()})",
235
+ f"defaults to today's date ({datetime.date.today()}).",
127
236
  type=datetime.date.fromisoformat,
128
237
  default=datetime.date.today()
129
238
  )
@@ -141,115 +250,13 @@ them.
141
250
  <<report results given in args>>=
142
251
  <<check that we got all positional arguments>>
143
252
  try:
144
- student = ladok.get_student(args.student_id)
145
- <<look up [[course]] from [[student]]>>
146
- <<look up [[result]] from [[course]]>>
147
- result.set_grade(args.grade, args.date)
148
- if args.finalize:
149
- result.finalize(args.graders)
253
+ set_grade(ladok, args,
254
+ args.student_id, args.course_code, args.component_code,
255
+ args.grade, args.date, args.graders)
150
256
  except Exception as err:
151
- try:
152
- print(f"{student}: {err}")
153
- except ValueError as verr:
154
- print(f"{verr}: {args.student_id}: {err}")
155
- @ The option [[args.finalize]] is already set above, so we don't need to add
156
- that one here.
157
-
158
- Both looking up the course and the component can yield index errors.
159
- We'd like to distinguish these.
160
- We will catch the exception, the reraise the same exception but with a better
161
- error message.
162
- <<look up [[course]] from [[student]]>>=
163
- try:
164
- course = student.courses(code=args.course_code)[0]
165
- except IndexError:
166
- raise Exception(f"{args.course_code}: No such course for {student}")
167
- <<look up [[result]] from [[course]]>>=
168
- try:
169
- result = course.results(component=args.component_code)[0]
170
- except IndexError:
171
- raise Exception(f"{args.component_code}: "
172
- f"No such component for {args.course_code}")
173
- @
174
-
175
-
176
- \section{Report many results given in standard input}
177
-
178
- We want to read CSV data from standard input.
179
- <<report results given in stdin>>=
180
- data_reader = csv.reader(sys.stdin, delimiter=args.delimiter)
181
- for course_code, component_code, student_id, grade, date, *graders in data_reader:
182
- <<report a result read from stdin>>
183
- @ We need to add an argument for the delimiter.
184
- <<add many results group arguments>>=
185
- many_parser.add_argument("-d", "--delimiter",
186
- default="\t",
187
- help="The delimiter for the CSV input; "
188
- "default is a tab character to be compatible with POSIX commands, "
189
- "use `-d,` or `-d ,` to get comma-separated values.")
190
- @
191
-
192
- We also want to handle errors and confirmations differently.
193
- When reporting in bulk, we don't want unnecessary errors.
194
- We also want to have a summary of the changes.
195
- <<add many results group arguments>>=
196
- many_parser.add_argument("-v", "--verbose",
197
- action="count", default=0,
198
- help="Increases the verbosity of the output: -v will print results that "
199
- "were reported to standard out. Otherwise only errors are printed.")
200
- @
201
-
202
- When we actually report a result, this is similar to how we did it above.
203
- The difference is that we've read the variables from the CSV data in [[stdin]]
204
- instead of from [[args]].
205
- <<report a result read from stdin>>=
206
- try:
207
- student = ladok.get_student(student_id)
208
-
209
- try:
210
- course = student.courses(code=course_code)[0]
211
- except IndexError:
212
- raise Exception(f"{course_code}: No such course for {student}")
213
-
214
- try:
215
- component = course.results(component=component_code)[0]
216
- except IndexError:
217
- raise Exception(f"{component_code}: no such component for {course_code}")
218
-
219
- <<set [[grade]] to [[component]], output if verbose>>
220
- except Exception as err:
221
- try:
222
- print(f"{course_code} {component_code}={grade} ({date}) {student}: {err}",
223
- file=sys.stderr)
224
- except ValueError as verr:
225
- print(f"{verr}: "
226
- f"{course_code} {component_code}={grade} ({date}) {student_id}: {err}",
227
- file=sys.stderr)
228
- @
229
-
230
- Now, when we set the grade, there are a few cases that should be handled.
231
- If the grade isn't attested, we try to change it.
232
- (This might still fail if the grade is finalized but not attested.)
233
- If we've selected the verbose option, then we print what we have reported.
234
-
235
- If the grade was attested, then we check if it's different.
236
- If it's different, we output this.
237
- If it's the same, we silently ignore it.
238
- This is best for bulk reporting, because then we can always try to report for
239
- all students.
240
- <<set [[grade]] to [[component]], output if verbose>>=
241
- if not component.attested and component.grade != grade:
242
- component.set_grade(grade, date)
243
- if args.finalize:
244
- component.finalize(graders)
245
- if args.verbose:
246
- print(f"{course_code} {student}: reported "
247
- f"{component.component} = {component.grade} ({date}) "
248
- f"by {', '.join(graders)}.")
249
- elif component.grade != grade:
250
- print(f"{course_code} {student}: attested {component.component} "
251
- f"result {component.grade} ({component.date}) "
252
- f"is different from {grade} ({date}).")
257
+ print(f"{args.course_code} {args.component_code}={args.grade} ({args.date}) "
258
+ f"{args.student_id}: {err}",
259
+ file=sys.stderr)
253
260
  @
254
261
 
255
262
 
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes