Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
exam-scan
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
RWTHmoodle
exam-scan
Commits
6670d2df
Commit
6670d2df
authored
4 years ago
by
Christian Rohlfing
Browse files
Options
Downloads
Patches
Plain Diff
supplementy.py uses moodle utils
parent
18584c4b
No related branches found
No related tags found
1 merge request
!34
Encapsulate parsing student grading info from CSV
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
supplements.py
+17
-20
17 additions, 20 deletions
supplements.py
tests/test_supplements.py
+1
-1
1 addition, 1 deletion
tests/test_supplements.py
with
18 additions
and
21 deletions
supplements.py
+
17
−
20
View file @
6670d2df
...
...
@@ -13,9 +13,9 @@ import os # path listing/manipulation/...
import
time
# keep track of time
import
argparse
# handle command line arguments
import
shutil
# copy
import
csv
# handle CSV files
import
utils.matnum
as
matnum_utils
import
utils.moodle
as
moodle
def
copy_supplements
(
supp_dir
,
supp_files
,
prefixes
,
output_dir
,
dry
=
False
):
...
...
@@ -88,12 +88,17 @@ def main(args):
"
Moodle grading CSV file. Default: ./pdfs
"
)
parser
.
add_argument
(
"
-o
"
,
"
--outfolder
"
,
default
=
"
./supplements_out
"
,
help
=
"
Output folder. Default: ./supplements_out
"
)
parser
.
add_argument
(
"
--csvprefixformat
"
,
default
=
"
{matnum}_{fullname[0]}
"
,
help
=
"
Format of CSV prefix. Available keywords:
"
+
"
{{matnum}}, {{fullname}}, {{lastname}},
"
+
"
{{firstname}}. Default:
'
{{matnum}}_{{fullname[0]}}
'"
)
parser
.
add_argument
(
"
-d
"
,
"
--dry
"
,
action
=
'
store_true
'
,
help
=
"
Flag for dry run
"
)
args
=
parser
.
parse_args
(
args
)
supp_dir
=
args
.
infolder
prefixinfo
=
args
.
prefix
prefixformat
=
args
.
csvprefixformat
output_dir
=
args
.
outfolder
dry
=
args
.
dry
...
...
@@ -114,7 +119,7 @@ def main(args):
# Print status
starttime
=
time
.
time
()
supp_folder
=
os
.
listdir
(
supp_dir
)
supp_files
=
[
_
for
_
in
supp_folder
if
_
.
endswith
(
"
.pdf
"
)]
supp_files
=
[
_
for
_
in
supp_folder
if
_
.
lower
().
endswith
(
"
.pdf
"
)]
print
(
"""
Available supplement PDFs to be copied:
- {}
...
...
@@ -127,7 +132,7 @@ Files in output folder {} will be overwritten during this process.
if
pdf_dir
!=
""
:
# Take prefixes from pdf directory
pdf_folder
=
os
.
listdir
(
pdf_dir
)
pdf_files
=
[
_
for
_
in
pdf_folder
if
_
.
endswith
(
"
.pdf
"
)
and
if
_
.
lower
().
endswith
(
"
.pdf
"
)
and
matnum_utils
.
starts_with_matnum
(
_
)]
prefixes
=
[]
for
pdf_file
in
pdf_files
:
...
...
@@ -135,20 +140,12 @@ Files in output folder {} will be overwritten during this process.
prefixes
.
append
(
prefix
)
else
:
# Take prefixes from CSV file
prefixes
=
[]
# Open CSV file
with
open
(
csvfilename
,
newline
=
''
)
as
csvfile
:
# Loop over all lines in CSV file
reader
=
csv
.
reader
(
csvfile
,
delimiter
=
'
,
'
,
quotechar
=
'"'
)
next
(
reader
)
# skip header CSV line
for
row
in
reader
:
# Parse required fields from CSV line
name
=
row
[
1
]
# [Lastname], [Firstname]
name
=
name
[
0
]
# Take only first letter of lastname
matnum
=
row
[
2
]
# matriculation number (6-digit)
if
not
matnum_utils
.
check_matnum
(
matnum
):
raise
Exception
(
"
Invalid matriculation number found
"
)
prefix
=
matnum
+
"
_
"
+
name
infos
=
moodle
.
extract_info
(
csvfilename
)
for
info
in
infos
:
prefix
=
prefixformat
.
format
(
matnum
=
info
[
'
matnum
'
],
fullname
=
info
[
'
fullname
'
],
lastname
=
info
[
'
lastname
'
],
firstname
=
info
[
'
firstname
'
])
prefixes
.
append
(
prefix
)
# save prefix
# Copy supplements to output dir and prepend prefixes
...
...
This diff is collapsed.
Click to expand it.
tests/test_supplements.py
+
1
−
1
View file @
6670d2df
...
...
@@ -85,7 +85,7 @@ class MainTest(unittest.TestCase):
# Prepare parameter
supp_dir
=
'
./supplements
'
pdf_dir
=
'
./pdfs
'
dpi
=
1
5
0
dpi
=
1
0
0
supp_out_dir
=
os
.
path
.
join
(
self
.
test_dir
,
'
supplements_out
'
)
os
.
mkdir
(
supp_out_dir
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment