2019-08-04 14:25:44 +00:00
|
|
|
#!/usr/bin/env python
|
|
|
|
# encoding: utf-8
|
|
|
|
|
|
|
|
import click
|
|
|
|
from pathlib import Path
|
|
|
|
import yaml
|
|
|
|
import sys
|
|
|
|
import papermill as pm
|
|
|
|
|
|
|
|
with open("recoconfig.yml", "r") as config:
|
|
|
|
config = yaml.load(config, Loader=yaml.FullLoader)
|
|
|
|
|
|
|
|
|
|
|
|
@click.group()
|
|
|
|
def cli():
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
@cli.command()
|
|
|
|
def print_config():
|
|
|
|
click.echo(config.key())
|
|
|
|
|
|
|
|
|
|
|
|
@cli.command()
|
|
|
|
@click.argument("csv_file")
|
|
|
|
def report(csv_file):
|
|
|
|
csv = Path(csv_file)
|
|
|
|
if not csv.exists():
|
|
|
|
click.echo(f"{csv_file} does not exists")
|
|
|
|
sys.exit(1)
|
|
|
|
if csv.suffix != ".csv":
|
|
|
|
click.echo(f"{csv_file} has to be a csv file")
|
|
|
|
sys.exit(1)
|
|
|
|
|
2019-08-04 14:43:06 +00:00
|
|
|
csv_file = Path(csv_file)
|
2019-08-04 14:54:12 +00:00
|
|
|
tribe_dir = csv_file.parent
|
2019-08-04 14:43:06 +00:00
|
|
|
csv_filename = csv_file.name.split(".")[0]
|
2019-08-04 14:54:12 +00:00
|
|
|
|
2019-08-04 14:43:06 +00:00
|
|
|
assessment = str(csv_filename).split("_")[-1].capitalize()
|
2019-08-04 14:54:12 +00:00
|
|
|
tribe = str(tribe_dir).split("/")[-1]
|
2019-08-04 14:25:44 +00:00
|
|
|
|
|
|
|
template = Path(config["templates"]) / "tpl_evaluation.ipynb"
|
|
|
|
|
2019-08-04 14:54:12 +00:00
|
|
|
dest = Path(config["output"]) / tribe / csv_filename
|
|
|
|
dest.mkdir(parents=True, exist_ok=True)
|
2019-08-04 14:25:44 +00:00
|
|
|
|
2019-08-04 14:54:12 +00:00
|
|
|
click.echo(f"Building {assessment} report")
|
2019-08-04 14:25:44 +00:00
|
|
|
pm.execute_notebook(
|
2019-08-04 14:43:06 +00:00
|
|
|
str(template),
|
2019-08-04 14:54:12 +00:00
|
|
|
str(dest / f"{assessment}.ipynb"),
|
2019-08-04 14:43:06 +00:00
|
|
|
parameters=dict(
|
|
|
|
tribe=tribe, assessment=assessment, csv_file=str(csv_file.absolute())
|
|
|
|
),
|
2019-08-04 14:25:44 +00:00
|
|
|
)
|
|
|
|
|
2019-08-04 14:54:12 +00:00
|
|
|
with open(csv_file.parent / "description.yml") as f:
|
|
|
|
tribe_desc = yaml.load(f, Loader=yaml.FullLoader)
|
|
|
|
|
|
|
|
template = Path(config["templates"]) / "tpl_student.ipynb"
|
|
|
|
dest = Path(config["output"]) / tribe / csv_filename / "students"
|
|
|
|
dest.mkdir(parents=True, exist_ok=True)
|
|
|
|
|
|
|
|
for st in tribe_desc["students"]:
|
|
|
|
click.echo(f"Building {st} report on {assessment}")
|
|
|
|
pm.execute_notebook(
|
|
|
|
str(template),
|
|
|
|
str(dest / f"{st}.ipynb"),
|
|
|
|
parameters=dict(tribe=tribe, student=st, source=str(tribe_dir.absolute())),
|
|
|
|
)
|
|
|
|
|
2019-08-04 14:25:44 +00:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
cli()
|