Skip to content
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

Add class info to all data #688

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions src/hubbleds/pages/05-class-results-uncertainty/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
from hubbleds.base_component_state import transition_next, transition_previous
from hubbleds.components import UncertaintySlideshow, IdSlider
from hubbleds.tools import * # noqa
from hubbleds.state import LOCAL_STATE, GLOBAL_STATE, StudentMeasurement, get_free_response, get_multiple_choice, mc_callback, fr_callback
from hubbleds.utils import make_summary_data, models_to_glue_data
from hubbleds.state import LOCAL_STATE, GLOBAL_STATE, ClassSummary, StudentMeasurement, get_free_response, get_multiple_choice, mc_callback, fr_callback
from hubbleds.utils import age_in_gyr_simple, create_single_summary, make_summary_data, models_to_glue_data
from hubbleds.viewers.hubble_histogram_viewer import HubbleHistogramView
from hubbleds.viewers.hubble_scatter_viewer import HubbleScatterView
from .component_state import COMPONENT_STATE, Marker
Expand Down Expand Up @@ -137,7 +137,14 @@ def glue_setup() -> Tuple[JupyterApplication, Dict[str, PlotlyBaseView]]:
student_ids.set(ids)
measurements.set(class_measurements)

all_measurements, student_summaries, class_summaries = LOCAL_API.get_all_data(LOCAL_STATE)
all_measurements, student_summaries, class_summaries = LOCAL_API.get_all_data(GLOBAL_STATE, LOCAL_STATE)
if GLOBAL_STATE.value.classroom.class_info is not None:
class_distances = [distance for m in class_measurements if ((distance := m.est_dist_value) is not None and m.velocity_value is not None)]
class_velocities = [velocity for m in class_measurements if (m.est_dist_value is not None and (velocity := m.velocity_value) is not None)]
my_class_h0, my_class_age = create_single_summary(distances=class_distances, velocities=class_velocities)
class_summaries.append(ClassSummary(class_id=GLOBAL_STATE.value.classroom.class_info["id"], hubble_fit_value=my_class_h0, age_value=my_class_age))
all_measurements.extend(class_measurements)

all_meas = Ref(LOCAL_STATE.fields.all_measurements)
all_stu_summaries = Ref(LOCAL_STATE.fields.student_summaries)
all_cls_summaries = Ref(LOCAL_STATE.fields.class_summaries)
Expand Down
4 changes: 3 additions & 1 deletion src/hubbleds/remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
from cosmicds.state import GlobalState, BaseState, GLOBAL_STATE
from solara import Reactive
from solara.toestand import Ref
from functools import cached_property
from cosmicds.logger import setup_logger
from typing import List

Expand Down Expand Up @@ -328,9 +327,12 @@ def get_class_measurements(

def get_all_data(
self,
global_state: Reactive[GlobalState],
local_state: Reactive[LocalState],
) -> tuple[list[StudentMeasurement], list[StudentSummary], list[ClassSummary]]:
url = f"{self.API_URL}/{local_state.value.story_id}/all-data?minimal=True"
if global_state.value.classroom.class_info is not None:
url += f"&class_id={global_state.value.classroom.class_info['id']}"
r = self.request_session.get(url)
res_json = r.json()

Expand Down