Skip to content

Commit

Permalink
fixes #31
Browse files Browse the repository at this point in the history
  • Loading branch information
WolfgangFahl committed Jan 20, 2024
1 parent 86c11e3 commit c73c169
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 3 deletions.
5 changes: 5 additions & 0 deletions dcm/dcm_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,11 @@ def required_keys(cls):
def main_id(self):
main_id = self.learner_id
return main_id

@property
def file_name(self):
file_name=slugify(self.learner_id, lowercase=False, regex_pattern=r"[^\w\s\-]")
return file_name

def add_achievement(self, new_achievement):
self.achievements.append(new_achievement)
Expand Down
41 changes: 38 additions & 3 deletions dcm/dcm_webserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
@author: wf
"""
import os
import uuid
from typing import List, Optional
from urllib.parse import urlparse

Expand Down Expand Up @@ -258,7 +259,7 @@ def render_dcm(
self.assessment = None
self.learner = None
self.dcm = dcm
self.assessment_button.enable()
self.assess_state(True)
dcm_chart = DcmChart(dcm)
svg_markup = dcm_chart.generate_svg_markup(
learner=learner,
Expand Down Expand Up @@ -319,13 +320,19 @@ async def home(self, _client: Client):
icon="query_stats",
handler=self.new_assess,
)
self.assessment_button.disable()
if self.is_local:
self.tool_button(
tooltip="open",
icon="file_open",
handler=self.open_file,
)
self.download_button=self.tool_button(
tooltip="download",
icon="download",
handler=self.download,
)
self.assess_state(False)

with splitter.after:
self.svg_view = ui.html("")
await self.setup_footer()
Expand All @@ -351,7 +358,7 @@ def new_assess(self):
"""
run a new assessment for a new learner
"""
self.learner = Learner(learner_id="?")
self.learner = Learner(learner_id=f"{uuid.uuid4()}")
self.assess_learner(self.dcm, self.learner)

def assess(self, learner: Learner, tree_id: str = None):
Expand All @@ -375,6 +382,34 @@ def assess(self, learner: Learner, tree_id: str = None):
# assess_learner will render ...
# self.render_dcm(dcm,learner=learner)
self.assess_learner(dcm, learner)

def assess_state(self,state:bool):
if state:
self.assessment_button.enable()
else:
self.assessment_button.disable()
if self.learner:
self.download_button.enable()
else:
self.download_button.disable()

async def download(self,_args):
"""
allow downloading the assessment result
"""
try:
with self.container:
if not self.learner:
ui.notify("no active learner assessment")
return
# https://nicegui.io/documentation/download
json_str=self.learner.to_json(indent=2)
json_bytes=json_str.encode()
json_file=f"{self.learner.file_name}.json"
ui.notify(f"downloading {json_file}")
ui.download(json_bytes,json_file)
except Exception as ex:
self.handle_exception(ex, self.do_trace)

async def on_text_mode_change(self, args):
"""
Expand Down

0 comments on commit c73c169

Please sign in to comment.