Skip to content

Commit

Permalink
ignore last marker for all but stage 6
Browse files Browse the repository at this point in the history
  • Loading branch information
johnarban committed Jan 27, 2025
1 parent 739b8da commit 38c5091
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 72 deletions.
18 changes: 4 additions & 14 deletions src/hubbleds/pages/01-spectra-&-velocity/component_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ class VelocityReflection(BaseModel):

class ComponentState(BaseComponentState, BaseState):
current_step: Marker = Marker.mee_gui1
total_steps: int = len(Marker)
stage_id: str = "spectra_&_velocity"
show_example_galaxy: bool = False
selected_galaxy: int = 0
Expand Down Expand Up @@ -116,22 +115,13 @@ class ComponentState(BaseComponentState, BaseState):
velocity_reflection_state: VelocityReflection = VelocityReflection()
reflection_complete: bool = False
show_dop_cal4_values: bool = False

_max_step: int = 0 # not included in model


# computed fields are included in the model when serialized
@computed_field
@property
def max_step(self) -> int:
self._max_step = max(self.current_step.value, self._max_step) # type: ignore
return self._max_step

@computed_field
@property
def progress(self) -> float:
# +1 for zero index, -1 for extra step
return round(100 * (self._max_step + 1) / (self.total_steps - 1))

def total_steps(self) -> int:
# ignore the last marker, which is a dummy marker
return len(Marker) - 1

@field_validator("current_step", mode="before")
def convert_int_to_enum(cls, v: Any) -> Marker:
Expand Down
15 changes: 3 additions & 12 deletions src/hubbleds/pages/03-distance-measurements/component_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ class Marker(enum.Enum, BaseMarker):

class ComponentState(BaseComponentState, BaseState):
current_step: Marker = Marker.ang_siz1
total_steps: int = len(Marker)
stage_id: str = "distance_measurements"

example_angular_sizes_total: int = 0
Expand All @@ -68,19 +67,11 @@ class ComponentState(BaseComponentState, BaseState):
angular_size_line: Optional[float | int] = None
distance_line: Optional[float | int] = None

_max_step: int = 0 # not included in model

# computed fields are included in the model when serialized
@computed_field
@property
def max_step(self) -> int:
self._max_step = max(self.current_step.value, self._max_step) # type: ignore
return self._max_step

@computed_field
@property
def progress(self) -> float:
return round(100 * (self._max_step + 1) / (self.total_steps - 1))
def total_steps(self) -> int:
# ignore the last marker, which is a dummy marker
return len(Marker) - 1


@field_validator("current_step", mode="before")
Expand Down
13 changes: 4 additions & 9 deletions src/hubbleds/pages/04-explore-data/component_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ class HubbleSlideshow(BaseModel):

class ComponentState(BaseComponentState, BaseState):
current_step: Marker = Marker.first()
total_steps: int = len(Marker)
stage_id: str = "explore_data"
show_hubble_slideshow_dialog: bool = False
hubble_slideshow_finished: bool = False
Expand All @@ -56,14 +55,10 @@ class ComponentState(BaseComponentState, BaseState):
# computed fields are included in the model when serialized
@computed_field
@property
def max_step(self) -> int:
self._max_step = max(self.current_step.value, self._max_step) # type: ignore
return self._max_step

@computed_field
@property
def progress(self) -> float:
return round(100 * (self._max_step + 1) / (self.total_steps - 1))
def total_steps(self) -> int:
# ignore the last marker, which is a dummy marker
return len(Marker) - 1



@field_validator("current_step", mode="before")
Expand Down
16 changes: 4 additions & 12 deletions src/hubbleds/pages/05-class-results-uncertainty/component_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ class UncertaintyState(BaseModel):

class ComponentState(BaseComponentState, BaseState):
current_step: Marker = Marker.first()
total_steps: int = len(Marker)
stage_id: str = "class_results_and_uncertainty"
student_low_age: int = 0
student_high_age: int = 0
Expand All @@ -65,19 +64,12 @@ class ComponentState(BaseComponentState, BaseState):
uncertainty_slideshow_finished: bool = False
class_best_fit_clicked: bool = False

_max_step: int = 0 # not included in model

# computed fields are included in the model when serialized
@computed_field
@property
def max_step(self) -> int:
self._max_step = max(self.current_step.value, self._max_step) # type: ignore
return self._max_step

@computed_field
@property
def progress(self) -> float:
return round(100 * (self._max_step + 1) / (self.total_steps - 1))
def total_steps(self) -> int:
# ignore the last marker, which is a dummy marker
return len(Marker) - 1



@field_validator("current_step", mode="before")
Expand Down
9 changes: 0 additions & 9 deletions src/hubbleds/pages/06-prodata/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,15 +289,6 @@ def _on_component_state_loaded(value: bool):
event_mc_callback = lambda event: mc_callback(event, LOCAL_STATE, COMPONENT_STATE),
state_view={'mc_score': get_multiple_choice(LOCAL_STATE, COMPONENT_STATE, 'pro-dat2'), 'score_tag': 'pro-dat2'}
)
ScaffoldAlert(
GUIDELINE_ROOT / "GuidelineProfessionalData3.vue",
event_next_callback=lambda _: transition_next(COMPONENT_STATE),
event_back_callback=lambda _: transition_previous(COMPONENT_STATE),
can_advance=COMPONENT_STATE.value.can_transition(next=True),
show=COMPONENT_STATE.value.is_current_step(Marker.pro_dat3),
event_mc_callback = lambda event: mc_callback(event, LOCAL_STATE, COMPONENT_STATE),
state_view={'mc_score': get_multiple_choice(LOCAL_STATE, COMPONENT_STATE, 'pro-dat3'), 'score_tag': 'pro-dat3'}
)
# ScaffoldAlert(
# GUIDELINE_ROOT / "GuidelineProfessionalData3.vue",
# event_next_callback=lambda _: transition_next(COMPONENT_STATE),
Expand Down
17 changes: 1 addition & 16 deletions src/hubbleds/pages/06-prodata/component_state.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import solara

from pydantic import field_validator, computed_field
from pydantic import field_validator

from cosmicds.state import BaseState
from hubbleds.base_marker import BaseMarker
Expand Down Expand Up @@ -32,7 +32,6 @@ class Marker(enum.Enum, BaseMarker):

class ComponentState(BaseComponentState, BaseState):
current_step: Marker = Marker.pro_dat0
total_steps: int = len(Marker)
stage_id: str = "professional_data"

# TODO: I don't think our_age is used anywhere
Expand All @@ -44,20 +43,6 @@ class ComponentState(BaseComponentState, BaseState):

fit_line_shown: bool = False

_max_step: int = 0 # not included in model

# computed fields are included in the model when serialized
@computed_field
@property
def max_step(self) -> int:
self._max_step = max(self.current_step.value, self._max_step) # type: ignore
return self._max_step

@computed_field
@property
def progress(self) -> float:
return round(100 * (self._max_step + 1) / (self.total_steps - 1))



@field_validator("current_step", mode="before")
Expand Down

0 comments on commit 38c5091

Please sign in to comment.