-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
25e37af
commit d1e261a
Showing
11 changed files
with
1,901 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
""" | ||
Created on 2024-01-24 | ||
Experience API xAPI support module | ||
@author: wf | ||
""" | ||
import json | ||
import sys | ||
|
||
from dcm.dcm_core import Achievement, CompetenceTree, Learner | ||
|
||
|
||
class XAPI: | ||
""" | ||
Experience API xAPI support class | ||
""" | ||
|
||
def __init__(self): | ||
self.xapi_dict = {} | ||
|
||
def warn(self, msg): | ||
print(msg, file=sys.stderr) | ||
pass | ||
|
||
def to_learner(self, competence_tree: CompetenceTree) -> Learner: | ||
""" | ||
Convert xapi_dict to a Learner with Achievements. | ||
Args: | ||
competence_tree (CompetenceTree): The competence tree to align the achievements with. | ||
Returns: | ||
Learner: A learner object with achievements mapped from xapi_dict. | ||
""" | ||
# Assuming each entry in xapi_dict is an xAPI statement relevant to a learning activity | ||
achievements = [] | ||
actor_id = None | ||
learner = None | ||
for entry in self.xapi_dict: | ||
stmt=entry.get("statement") | ||
if stmt: | ||
actor=stmt.get("actor") | ||
if actor: | ||
# Extract necessary information from the xAPI statement | ||
new_actor_id = actor["account"]["name"] | ||
if actor_id is None: | ||
actor_id = new_actor_id | ||
else: | ||
if new_actor_id != actor_id: | ||
self.warn(f"invalid actor_id {new_actor_id} != {actor_id}") | ||
competence_path = stmt["context"]["extensions"][ | ||
"learningObjectMetadata" | ||
]["competencePath"] | ||
score_scaled = stmt["result"]["score"]["scaled"] | ||
timestamp = stmt["timestamp"] | ||
|
||
# Create an Achievement instance | ||
achievement = Achievement( | ||
path=competence_path, | ||
level=int( | ||
score_scaled * competence_tree.total_valid_levels | ||
), # Convert scaled score to level | ||
score=stmt["result"]["score"]["raw"], | ||
date_assessed_iso=timestamp, | ||
) | ||
achievements.append(achievement) | ||
|
||
if actor_id: | ||
# Create a Learner instance with these achievements | ||
learner = Learner(learner_id=actor_id, achievements=achievements) | ||
else: | ||
self.warn("no learner / actor defined") | ||
return learner | ||
|
||
@classmethod | ||
def from_json(cls, json_file_path: str): | ||
xapi = cls() | ||
# Open and read the JSON file | ||
with open(json_file_path, "r") as json_file: | ||
xapi.xapi_dict = json.load(json_file) | ||
return xapi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
{ | ||
"learner_id": "1116e424-b4f9-45a2-acc1-c5d54350daea", | ||
"achievements": [ | ||
{ | ||
"path": "greta_v2_0/BerufspraktischesWissenUndKoennen/BeratungIndividualisierteLernunterstuetzung/Teilnehmendenorientierung", | ||
"level": 3, | ||
"score": 3, | ||
"score_unit": "%", | ||
"evidence": null, | ||
"date_assessed_iso": "2023-09-17T11:03:33.863Z" | ||
}, | ||
{ | ||
"path": "greta_v2_0/BerufspraktischesWissenUndKoennen/BeratungIndividualisierteLernunterstuetzung/Teilnehmendenorientierung", | ||
"level": 3, | ||
"score": 3, | ||
"score_unit": "%", | ||
"evidence": null, | ||
"date_assessed_iso": "2023-09-23T11:03:33.863Z" | ||
}, | ||
{ | ||
"path": "greta_v2_0/BerufspraktischesWissenUndKoennen/BeratungIndividualisierteLernunterstuetzung/Teilnehmendenorientierung", | ||
"level": 3, | ||
"score": 3, | ||
"score_unit": "%", | ||
"evidence": null, | ||
"date_assessed_iso": "2023-09-18T11:03:33.863Z" | ||
}, | ||
{ | ||
"path": "greta_v2_0/ProfessionelleSelbststeuerung/MotivationaleOrientierungen/Selbstwirksamkeitsueberzeugungen", | ||
"level": 3, | ||
"score": 3, | ||
"score_unit": "%", | ||
"evidence": null, | ||
"date_assessed_iso": "2023-09-25T11:03:33.863Z" | ||
}, | ||
{ | ||
"path": "greta_v2_0/ProfessionelleSelbststeuerung/MotivationaleOrientierungen/Selbstwirksamkeitsueberzeugungen", | ||
"level": 3, | ||
"score": 3, | ||
"score_unit": "%", | ||
"evidence": null, | ||
"date_assessed_iso": "2023-09-23T11:03:33.863Z" | ||
}, | ||
{ | ||
"path": "greta_v2_0/BerufspraktischesWissenUndKoennen/DidaktikUndMethodik/RahmenbedingungenUndLernumgebungen", | ||
"level": 3, | ||
"score": 3, | ||
"score_unit": "%", | ||
"evidence": null, | ||
"date_assessed_iso": "2023-09-19T11:03:33.863Z" | ||
}, | ||
{ | ||
"path": "greta_v2_0/BerufspraktischesWissenUndKoennen/DidaktikUndMethodik/RahmenbedingungenUndLernumgebungen", | ||
"level": 3, | ||
"score": 3, | ||
"score_unit": "%", | ||
"evidence": null, | ||
"date_assessed_iso": "2023-09-17T11:03:33.863Z" | ||
}, | ||
{ | ||
"path": "greta_v2_0/BerufspraktischesWissenUndKoennen/DidaktikUndMethodik/Outcomeorientierung", | ||
"level": 3, | ||
"score": 3, | ||
"score_unit": "%", | ||
"evidence": null, | ||
"date_assessed_iso": "2023-09-22T11:03:33.863Z" | ||
}, | ||
{ | ||
"path": "greta_v2_0/BerufspraktischesWissenUndKoennen/DidaktikUndMethodik/Outcomeorientierung", | ||
"level": 3, | ||
"score": 3, | ||
"score_unit": "%", | ||
"evidence": null, | ||
"date_assessed_iso": "2023-09-17T11:03:33.863Z" | ||
}, | ||
{ | ||
"path": "greta_v2_0/BerufspraktischesWissenUndKoennen/DidaktikUndMethodik/LerninhalteUndZiele", | ||
"level": 3, | ||
"score": 3, | ||
"score_unit": "%", | ||
"evidence": null, | ||
"date_assessed_iso": "2023-09-17T11:03:33.863Z" | ||
}, | ||
{ | ||
"path": "greta_v2_0/BerufspraktischesWissenUndKoennen/DidaktikUndMethodik/LerninhalteUndZiele", | ||
"level": 3, | ||
"score": 3, | ||
"score_unit": "%", | ||
"evidence": null, | ||
"date_assessed_iso": "2023-09-18T11:03:33.863Z" | ||
}, | ||
{ | ||
"path": "greta_v2_0/ProfessionelleSelbststeuerung/MotivationaleOrientierungen/Enthusiasmus", | ||
"level": 3, | ||
"score": 3, | ||
"score_unit": "%", | ||
"evidence": null, | ||
"date_assessed_iso": "2023-09-26T11:03:33.863Z" | ||
}, | ||
{ | ||
"path": "greta_v2_0/ProfessionelleSelbststeuerung/MotivationaleOrientierungen/Enthusiasmus", | ||
"level": 3, | ||
"score": 3, | ||
"score_unit": "%", | ||
"evidence": null, | ||
"date_assessed_iso": "2023-09-25T11:03:33.863Z" | ||
} | ||
] | ||
} |
Oops, something went wrong.