-
Notifications
You must be signed in to change notification settings - Fork 10
WiP: Prototype generic lo blocks module #253
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
bradley-erickson
wants to merge
2
commits into
master
Choose a base branch
from
berickson/20260113-generic-lo-blocks-module
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
| @@ -1 +1 @@ | ||
| 0.1.0+2026.01.26T17.51.31.713Z.b83cda8e.berickson.20260126.blacklist.by.domain | ||
| 0.1.0+2026.01.15T20.46.52.349Z.863d72db.berickson.20260113.generic.lo.blocks.module |
This file contains hidden or 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,12 @@ | ||
| # LO Blocks module | ||
|
|
||
| Common items for how to work with LO Blocks | ||
|
|
||
| ## Reducers | ||
|
|
||
| - **Page last visited**: Sets the time a student last visited a page and provides the most recent visited page | ||
| - **Event type counter**: Counts the events types each student producers per page | ||
| - **Time on task**: Records the time a student has spent on a page | ||
| - **Binned time on task**: Tracks time a student has spent on a page but binned into increments | ||
| - **Event timeline**: Simplified list of events a student has produced on each page | ||
|
|
This file contains hidden or 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 @@ | ||
| 0.1.0+2026.01.15T20.46.52.349Z.863d72db.berickson.20260113.generic.lo.blocks.module |
Empty file.
This file contains hidden or 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,163 @@ | ||
| ''' | ||
| LO Blocks module | ||
|
|
||
| A Learning Observer module for handling LO Block items. | ||
| ''' | ||
| import learning_observer.communication_protocol.query as q | ||
| from learning_observer.communication_protocol.integration import publish_function | ||
| import learning_observer.communication_protocol.util | ||
| from learning_observer.stream_analytics.helpers import KeyField, Scope | ||
|
|
||
| import lo_blocks_module.reducers | ||
|
|
||
| # Name for the module | ||
| NAME = 'LO Blocks module' | ||
|
|
||
| COURSE_ROSTER = q.call('learning_observer.courseroster') | ||
| roster_echo_call = q.call('examples.roster_echo') | ||
|
|
||
| @publish_function('examples.roster_echo') | ||
| def roster_echo(user_id): | ||
| return {'user_id': user_id, 'status': 'ok'} | ||
|
|
||
|
|
||
| EXECUTION_DAG = { | ||
| "execution_dag": { | ||
| "roster": COURSE_ROSTER(runtime=q.parameter("runtime"), course_id=q.parameter("course_id", required=True)), | ||
| "page_last_visited": q.select( | ||
| q.keys( | ||
| "lo_blocks_module.page_last_visited", | ||
| scope_fields={ | ||
| 'student': {'values': q.variable('roster'), 'path': 'user_id'}, | ||
| } | ||
| ), | ||
| fields={'last_visited': 'page'}, | ||
| ), | ||
| "event_type_counter": q.select( | ||
| q.keys( | ||
| "lo_blocks_module.event_type_counter", | ||
| scope_fields={ | ||
| 'student': {'values': q.variable('roster'), 'path': 'user_id'}, | ||
| 'page': {'values': q.variable('page_last_visited'), 'path': 'page'}, | ||
| } | ||
| ), | ||
| fields=q.SelectFields.All, | ||
| ), | ||
| "time_on_task": q.select( | ||
| q.keys( | ||
| "lo_blocks_module.time_on_task", | ||
| scope_fields={ | ||
| 'student': {'values': q.variable('roster'), 'path': 'user_id'}, | ||
| 'page': {'values': q.variable('page_last_visited'), 'path': 'page'}, | ||
| } | ||
| ), | ||
| fields=q.SelectFields.All, | ||
| ), | ||
| "binned_time_on_task": q.select( | ||
| q.keys( | ||
| "lo_blocks_module.binned_time_on_task", | ||
| scope_fields={ | ||
| 'student': {'values': q.variable('roster'), 'path': 'user_id'}, | ||
| 'page': {'values': q.variable('page_last_visited'), 'path': 'page'}, | ||
| } | ||
| ), | ||
| fields=q.SelectFields.All, | ||
| ), | ||
| "event_timeline": q.select( | ||
| q.keys( | ||
| "lo_blocks_module.event_timeline", | ||
| scope_fields={ | ||
| 'student': {'values': q.variable('roster'), 'path': 'user_id'}, | ||
| 'page': {'values': q.variable('page_last_visited'), 'path': 'page'}, | ||
| } | ||
| ), | ||
| fields=q.SelectFields.All, | ||
| ), | ||
| 'roster_map': q.map( | ||
| roster_echo_call, | ||
| values=q.variable('roster'), | ||
| value_path='user_id', | ||
| ), | ||
| }, | ||
| "exports": { | ||
| "page_last_visited": { | ||
| "returns": "page_last_visited", | ||
| "parameters": ["course_id"], | ||
| }, | ||
| "event_type_counter": { | ||
| "returns": "event_type_counter", | ||
| "parameters": ["course_id"], | ||
| }, | ||
| "time_on_task": { | ||
| "returns": "time_on_task", | ||
| "parameters": ["course_id"], | ||
| }, | ||
| "binned_time_on_task": { | ||
| "returns": "binned_time_on_task", | ||
| "parameters": ["course_id"], | ||
| }, | ||
| "event_timeline": { | ||
| "returns": "event_timeline", | ||
| "parameters": ["course_id"], | ||
| }, | ||
| 'roster_map': { | ||
| 'returns': 'roster_map', | ||
| 'parameters': ['course_id'], | ||
| }, | ||
| }, | ||
| } | ||
|
|
||
| ''' | ||
| Add reducers to the module. | ||
| ''' | ||
| REDUCERS = [ | ||
| { | ||
| 'context': 'org.ets.sba', | ||
| 'scope': Scope([KeyField.STUDENT]), | ||
| 'function': lo_blocks_module.reducers.page_last_visited, | ||
| }, | ||
| { | ||
| 'context': 'org.ets.sba', | ||
| 'scope': lo_blocks_module.reducers.page_scope, | ||
| 'function': lo_blocks_module.reducers.event_type_counter, | ||
| }, | ||
| { | ||
| 'context': "org.ets.sba", | ||
| 'scope': lo_blocks_module.reducers.page_scope, | ||
| 'function': lo_blocks_module.reducers.time_on_task, | ||
| 'default': {'saved_ts': 0} | ||
| }, | ||
| { | ||
| 'context': "org.ets.sba", | ||
| 'scope': lo_blocks_module.reducers.page_scope, | ||
| 'function': lo_blocks_module.reducers.binned_time_on_task | ||
| }, | ||
| { | ||
| 'context': "org.ets.sba", | ||
| 'scope': lo_blocks_module.reducers.page_scope, | ||
| 'function': lo_blocks_module.reducers.event_timeline | ||
| }, | ||
| ] | ||
|
|
||
|
|
||
| ''' | ||
| The Course Dashboards are used to populate the modules | ||
| on the home screen. | ||
|
|
||
| Note the icon uses Font Awesome v5 | ||
| ''' | ||
| COURSE_DASHBOARDS = [{ | ||
| 'name': NAME, | ||
| 'url': "/lo_blocks_module/dashboard/", | ||
| "icon": { | ||
| "type": "fas", | ||
| "icon": "fa-play-circle" | ||
| } | ||
| }] | ||
|
|
||
| ''' | ||
| Next js dashboards | ||
| ''' | ||
| NEXTJS_PAGES = [ | ||
| # {'path': 'dashboard/'}, | ||
| ] | ||
This file contains hidden or 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,81 @@ | ||
| ''' | ||
| This file defines reducers we wish to add to the incoming event | ||
| pipeline. The `learning_observer.stream_analytics` package includes | ||
| helper functions for Scoping the and setting the null state. | ||
| ''' | ||
| import learning_observer.stream_analytics.time_on_task | ||
| from learning_observer.stream_analytics.helpers import student_event_reducer, kvs_pipeline, Scope, KeyField, EventField | ||
|
|
||
| page_scope = Scope([KeyField.STUDENT, EventField('page')]) | ||
|
|
||
| @student_event_reducer(null_state={}) | ||
| async def page_last_visited(event, internal_state): | ||
| page = event['client'].get('page') | ||
| if not page: | ||
| return False, False | ||
| internal_state[page] = event['server']['time'] | ||
| internal_state['last_visited'] = page | ||
| return internal_state, internal_state | ||
|
|
||
|
|
||
| @kvs_pipeline(scope=page_scope, null_state={}) | ||
| async def event_type_counter(event, internal_state): | ||
| ''' | ||
| An example of a per-student event counter | ||
| ''' | ||
| event_type = event['client']['event'] | ||
| if 'counts' not in internal_state: | ||
| internal_state['counts'] = {} | ||
| if event_type not in internal_state['counts']: | ||
| internal_state['counts'][event_type] = 0 | ||
| internal_state['counts'][event_type] += 1 | ||
|
|
||
| return internal_state, internal_state | ||
|
|
||
|
|
||
| @kvs_pipeline(scope=page_scope) | ||
| async def time_on_task(event, internal_state): | ||
| internal_state = learning_observer.stream_analytics.time_on_task.apply_time_on_task( | ||
| internal_state, | ||
| event['server']['time'], | ||
| 60 | ||
| ) | ||
| return internal_state, internal_state | ||
|
|
||
|
|
||
| @kvs_pipeline(scope=page_scope) | ||
| async def binned_time_on_task(event, internal_state): | ||
| internal_state = learning_observer.stream_analytics.time_on_task.apply_binned_time_on_task( | ||
| internal_state, | ||
| event['server']['time'], | ||
| 60, | ||
| 600 | ||
| ) | ||
| return internal_state, internal_state | ||
|
|
||
|
|
||
| @kvs_pipeline(scope=page_scope, null_state={"events": []}) | ||
| async def event_timeline(event, internal_state): | ||
| """ | ||
| Collect a per-student timeline of events for later playback in dashboards. | ||
| """ | ||
| client = event.get("client", {}) | ||
| event_type = client.get("event") | ||
| metadata = client.get("metadata", {}) | ||
| timestamp = metadata.get("iso_ts") | ||
|
|
||
| # Capture useful payload fields if present | ||
| entry = { | ||
| "event": event_type, | ||
| "timestamp": timestamp, | ||
| "id": client.get("id"), | ||
| "scope": client.get("scope"), | ||
| } | ||
|
|
||
| # Add common payload values if they exist on the event | ||
| for key in ("value", "submitCount", "correct", "message", "showAnswer"): | ||
| if key in client: | ||
| entry[key] = client[key] | ||
|
|
||
| internal_state.setdefault("events", []).append(entry) | ||
| return internal_state, internal_state |
This file contains hidden or 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,3 @@ | ||
| [build-system] | ||
| requires = ["setuptools>=42", "wheel"] | ||
| build-backend = "setuptools.build_meta" |
This file contains hidden or 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,14 @@ | ||
| [metadata] | ||
| name = LO Blocks module | ||
| version = file:VERSION | ||
| description = This is a generic module for understanding how write and read from reducers for the LO Blocks framework. | ||
|
|
||
| [options] | ||
| packages = lo_blocks_module | ||
|
|
||
| [options.package_data] | ||
| lo_blocks_module = assets/* | ||
|
|
||
| [options.entry_points] | ||
| lo_modules = | ||
| lo_blocks_module = lo_blocks_module.module |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
q.keyscall here passesscope_fields, but the KEYS handler (hack_handle_keysinlearning_observer/communication_protocol/executor.py) only acceptsSTUDENTS,STUDENTS_path,RESOURCES, andRESOURCES_path. When this DAG executes,dispatch_nodecalls the handler with**node, so the unexpectedscope_fieldskeyword raises aTypeErrorand the module’s exports never resolve. Use the supported STUDENTS/RESOURCES parameters (as in other modules) or update the handler to acceptscope_fieldsbefore shipping this module.Useful? React with 👍 / 👎.