From d805b253a86cda33dacaf79124fac48a048c0a9a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Kruli=C5=A1?= Date: Thu, 16 May 2024 23:04:45 +0200 Subject: [PATCH] Adding new features (retrieving students by list of IDs and group stats) and preparing release of 0.0.29 --- recodex/api.py | 3 +++ recodex/plugins/groups/cli.py | 19 ++++++++++++++++++- recodex/plugins/users/cli.py | 18 ++++++++++++++++++ setup.py | 2 +- 4 files changed, 40 insertions(+), 2 deletions(-) diff --git a/recodex/api.py b/recodex/api.py index 8a2f295..caf5f25 100644 --- a/recodex/api.py +++ b/recodex/api.py @@ -281,6 +281,9 @@ def set_group_exam_flag(self, group_id, is_exam=True): return self.post("/groups/{}/exam".format(group_id), data={"value": is_exam}) + def get_group_stats(self, group_id): + return self.get("/groups/{}/students/stats".format(group_id)) + # Assignments and related stuff... def get_assignment(self, assignment_id): diff --git a/recodex/plugins/groups/cli.py b/recodex/plugins/groups/cli.py index 59172a8..01fbff6 100644 --- a/recodex/plugins/groups/cli.py +++ b/recodex/plugins/groups/cli.py @@ -79,7 +79,7 @@ def detail(api: ApiClient, group_id, useJson): json.dump(group, sys.stdout, sort_keys=True, indent=4) elif useJson is False: yaml = YAML(typ="safe") - yaml.dump(group, sys.stdout) + yaml.dump(group, sys.stdout) @ cli.command() @@ -202,3 +202,20 @@ def set_exam(api: ApiClient, group_id, unset): """ api.set_group_exam_flag(group_id, not unset) + + +@ cli.command() +@ click.argument("group_id") +@ click.option("--json/--yaml", "useJson", default=False) +@ pass_api_client +def stats(api: ApiClient, group_id, useJson): + """ + Get students information about solution stats (point summaries) + """ + + stats = api.get_group_stats(group_id) + if useJson is True: + json.dump(stats, sys.stdout, sort_keys=True, indent=4) + elif useJson is False: + yaml = YAML(typ="safe") + yaml.dump(stats, sys.stdout) diff --git a/recodex/plugins/users/cli.py b/recodex/plugins/users/cli.py index 9170a4f..d1ee68c 100644 --- a/recodex/plugins/users/cli.py +++ b/recodex/plugins/users/cli.py @@ -43,6 +43,24 @@ def get(api: ApiClient, user_id, useJson): yaml.dump(user, sys.stdout) +@cli.command() +@click.option("--json/--yaml", "useJson", default=True) +@pass_api_client +def get_list(api: ApiClient, useJson): + """ + Get data of multiple users, list of IDs is given on stdin (one ID per line) + """ + ids = map(lambda id: id.strip(), sys.stdin.readlines()) + ids = list(filter(lambda id: id, ids)) + + users = api.get_users_list(ids) + if useJson: + json.dump(users, sys.stdout, sort_keys=True, indent=4) + else: + yaml = YAML(typ="safe") + yaml.dump(users, sys.stdout) + + @cli.command() @click.option("--json/--yaml", "useJson", default=None, help='Default is CSV.') @click.option('--only-active', 'onlyActive', is_flag=True, help='Return full records formated into CSV.') diff --git a/setup.py b/setup.py index 5a3b8bd..5aad9a2 100644 --- a/setup.py +++ b/setup.py @@ -2,7 +2,7 @@ setup( name='recodex-cli', - version='0.0.28', + version='0.0.29', description='ReCodEx CLI', long_description='A command line frontend to the ReCodEx programmer evaluation system', classifiers=[