-
Notifications
You must be signed in to change notification settings - Fork 1
StateManagement
This project uses Redux Toolkit for state management. The implementation follows a slice pattern, with each slice managing a specific domain/aspect of the application's state needed for adjusting the various visualizations.
{
groundTruth: GroundTruthState,
predictions: PredictionsState,
location: LocationState,
filter: FilterState, //Various Settings (date, US State, season, etc.)
nowcastTrends: NowcastTrendsState,
stateThresholds: StateThresholdsState,
historicalGroundTruth: HistoricalGroundTruthState
}
Note
Currently Building Evaluations Page, expect changes here
The application implements a two-phase data loading strategy:
-
Initial Data Loading (
forecasts/page.tsx
)- Loads surveillance data
- Processes model predictions
- Fetches location information
- Retrieves nowcast trends
- Sets up threshold data
- Prepares historical data
-
Store States Inside Redux
- Redux managed
interface FilterState {
selectedStateName: string;
USStateNum: string;
forecastModel: string[];
numOfWeeksAhead: number;
dateStart: Date;
dateEnd: Date;
dateRange: string;
yAxisScale: string;
confidenceInterval: string[];
historicalDataMode: boolean;
seasonOptions: SeasonOption[];
userSelectedRiskLevelModel: string;
userSelectedWeek: Date;
}
Purpose: Filter Slice is for storing what user has chosen for the various options related to how Forecast Visualization Components and Nowcast Visualization Components display.
interface GroundTruthState {
data: DataPoint[];
}
Purpose: Stores actual surveillance data
- Historical hospitalization rates
- Weekly admission data by state
- Used as baseline for model comparisons
interface HistoricalGroundTruthState {
data: HistoricalDataEntry[];
}
Purpose: Maintains historical surveillance data snapshots
- Tracks data revisions over time
- Enables historical comparison views
- Supports model evaluation features
interface LocationState {
data: LocationData[]; // LocationData contains state information and population
}
Purpose: Stores Location Data
interface NowcastTrendsCollection {
allData: NowcastTrendByModel[]; // Trend analysis by model
}
Purpose: Current trend analysis management
- Tracks trend directions (increase/decrease/stable)
- Maintains model-specific trend predictions
- Supports risk level visualizations
interface PredictionsState {
data: ModelPrediction[]; // Forecast data from multiple models
}
Purpose: Model forecast data management
- Stores predictions from multiple models
- Maintains confidence intervals
- Tracks forecast horizons
interface StateThresholdsState {
data: StateThresholds[]; // Risk level thresholds by state
}
Purpose: Risk level threshold management
- Defines risk level boundaries
- State-specific threshold values
- Supports risk assessment visualizations
The application uses centralized data loading patterns in major page components:
// Example from forecasts/page.tsx
useEffect(() => {
fetchForecastData();
fetchLocationData();
fetchNowcastTrendsData();
fetchThresholdsData();
fetchHistoricalGroundTruthData();
}, []);
Custom hooks ensure type safety when accessing the Redux store:
export const useAppDispatch: () => AppDispatch = useDispatch;
export const useAppSelector: TypedUseSelectorHook<RootState> = useSelector;
const selectedState = useAppSelector((state) => state.filter.selectedStateName);
const groundTruthData = useAppSelector((state) => state.groundTruth.data);
const dispatch = useAppDispatch();
dispatch(updateSelectedState({ stateName: "California", stateNum: "06" }));
dispatch(setGroundTruthData(processedData));
- Chart components subscribe to relevant state
- Filter panels dispatch state updates
- Risk level indicators react to state changes
- Page components handle initial data loading
- Error states managed through Redux
- Loading states tracked for UI feedback
Main Pages
Data Pipeline
- Data Pipeline
- Data Transformation Script
- Custom data interface for wrapping processed csv into React Components
- Data Fetching API
Static Components
Visualizations
-
- WIP
Styling