Skip to content

Commit

Permalink
improves
Browse files Browse the repository at this point in the history
  • Loading branch information
WolfgangFahl committed Jan 17, 2024
1 parent c94ef14 commit a589737
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
16 changes: 13 additions & 3 deletions dcm/dcm_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,12 @@ def get_examples(cls, content_class=CompetenceTree, markup: str = "json") -> dic

@classmethod
def from_definition_string(
cls, name: str, definition_string: str, content_class, markup: str = "json"
cls,
name: str,
definition_string: str,
content_class,
markup: str = "json",
debug:bool = False
) -> Any:
"""
Load a DynamicCompetenceMap or Learner instance from a definition string (either JSON or YAML).
Expand All @@ -575,7 +580,7 @@ def from_definition_string(
definition_string (str): The string content of the definition.
content_class (dataclass_json): The class which will be instantiated with the parsed data.
markup (str): The markup format of the data. Defaults to 'json'. Supported values are 'json' and 'yaml'.
debug(bool): if True supply a JSON dump of the data in /tmp/{name}.json
Returns:
DynamicCompetenceMap: An instance of DynamicCompetenceMap loaded with the parsed data.
Expand All @@ -584,7 +589,12 @@ def from_definition_string(
"""
try:
data = cls.parse_markup(definition_string, markup)
content = content_class.from_dict(data)
if debug:
# Save the parsed data to a JSON file in /tmp directory
debug_file_path = os.path.join('/tmp', f'{name}.json')
with open(debug_file_path, 'w') as debug_file:
json.dump(data, debug_file, indent=2,default=str)
content = content_class.from_dict(data)
if isinstance(content, CompetenceTree):
return DynamicCompetenceMap(content)
else:
Expand Down
2 changes: 1 addition & 1 deletion dcm/dcm_webserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ async def render(self, _click_args=None):
else:
self.learner = item
self.assess(item)
except BaseException as ex:
except Exception as ex:
self.handle_exception(ex, self.do_trace)

def render_dcm(self,
Expand Down
12 changes: 10 additions & 2 deletions tests/test_rwth_aachen_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
CompetenceFacet,
CompetenceLevel,
CompetenceTree,
DynamicCompetenceMap
)

class TestModule(Basetest):
Expand Down Expand Up @@ -149,11 +150,18 @@ def test_master_informatik(self):
# Create the competence tree
competence_tree = self.create_competence_tree(competence_elements, url=url)
# Pretty print the JSON with specified indentation
pretty_json = competence_tree.to_pretty_json()
#pretty_json = competence_tree.to_pretty_json()
yaml_str = competence_tree.to_yaml()
debug = self.debug
# debug=True
debug=True
if debug:
print(yaml_str)
with open("/tmp/rwth_aachen_master_informatik.yaml", "w") as yaml_file:
yaml_file.write(yaml_str)
dcm=DynamicCompetenceMap.from_definition_string(
name="RWTH Aachen Master Informatik",
definition_string=yaml_str,
content_class=CompetenceTree,
markup="yaml",
debug=debug)
self.assertIsNotNone(dcm)

0 comments on commit a589737

Please sign in to comment.