Skip to content

Commit

Permalink
more cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
conbrad committed Aug 7, 2024
1 parent fb85f0c commit f69c923
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 147 deletions.
2 changes: 2 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
"HAINES",
"hourlies",
"HRDPS",
"Indeterminates",
"luxon",
"maxx",
"maxy",
Expand All @@ -94,6 +95,7 @@
"PRECIP",
"PRIMEM",
"PROJCS",
"pydantic",
"RDPS",
"rocketchat",
"sfms",
Expand Down
91 changes: 53 additions & 38 deletions api/app/schemas/morecast_v2.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
""" This module contains pydantic models for Morecast v2"""
"""This module contains pydantic models for Morecast v2"""

from enum import Enum
from typing import List, Optional
Expand All @@ -7,66 +7,74 @@


class ModelChoice(str, Enum):
""" Enumerator for all valid forecasted value types """
GDPS = 'GDPS'
GFS = 'GFS'
HRDPS = 'HRDPS'
NAM = 'NAM'
MANUAL = 'MANUAL'
RDPS = 'RDPS'
"""Enumerator for all valid forecasted value types"""

GDPS = "GDPS"
GFS = "GFS"
HRDPS = "HRDPS"
NAM = "NAM"
MANUAL = "MANUAL"
RDPS = "RDPS"


class WeatherDeterminate(str, Enum):
""" Enumerator for all valid determinate weather sources"""
GDPS = 'GDPS'
GDPS_BIAS = 'GDPS_BIAS'
GFS = 'GFS'
GFS_BIAS = 'GFS_BIAS'
HRDPS = 'HRDPS'
HRDPS_BIAS = 'HRDPS_BIAS'
NAM = 'NAM'
NAM_BIAS = 'NAM_BIAS'
RDPS = 'RDPS'
RDPS_BIAS = 'RDPS_BIAS'
GRASS_CURING_CWFIS = 'Grass_Curing_CWFIS'
"""Enumerator for all valid determinate weather sources"""

GDPS = "GDPS"
GDPS_BIAS = "GDPS_BIAS"
GFS = "GFS"
GFS_BIAS = "GFS_BIAS"
HRDPS = "HRDPS"
HRDPS_BIAS = "HRDPS_BIAS"
NAM = "NAM"
NAM_BIAS = "NAM_BIAS"
RDPS = "RDPS"
RDPS_BIAS = "RDPS_BIAS"
GRASS_CURING_CWFIS = "Grass_Curing_CWFIS"

# non prediction models
FORECAST = 'Forecast'
ACTUAL = 'Actual'
FORECAST = "Forecast"
ACTUAL = "Actual"


class ForecastedTemperature(BaseModel):
""" Forecaster chosen temperature """
"""Forecaster chosen temperature"""

temp: float
choice: ModelChoice


class ForecastedRH(BaseModel):
""" Forecaster chosen rh """
"""Forecaster chosen rh"""

rh: float
choice: ModelChoice


class ForecastedPrecip(BaseModel):
""" Forecaster chosen 24-hour precipitation mm """
"""Forecaster chosen 24-hour precipitation mm"""

precip: float
choice: ModelChoice


class ForecastedWindSpeed(BaseModel):
""" Forecaster chosen wind speed """
"""Forecaster chosen wind speed"""

wind_speed: float
choice: ModelChoice


class ForecastedWindDirection(BaseModel):
""" Forecaster chosen wind direction """
"""Forecaster chosen wind direction"""

wind_direction: float
choice: ModelChoice


class MoreCastForecastInput(BaseModel):
""" Forecasted daily request """
"""Forecasted daily request"""

station_code: int
for_date: int
temp: float
Expand All @@ -78,28 +86,32 @@ class MoreCastForecastInput(BaseModel):


class MoreCastForecastRequest(BaseModel):
""" Incoming daily forecasts to be saved """
token: str # WF1 token
"""Incoming daily forecasts to be saved"""

forecasts: List[MoreCastForecastInput]


class MoreCastForecastOutput(MoreCastForecastInput):
""" Outgoing forecast daily response item """
"""Outgoing forecast daily response item"""

update_timestamp: int


class MorecastForecastResponse(BaseModel):
""" Outgoing forecast daily response """
"""Outgoing forecast daily response"""

forecasts: List[MoreCastForecastOutput]


class ObservedDailiesForStations(BaseModel):
""" Request for observed dailies for stations """
"""Request for observed dailies for stations"""

station_codes: List[int]


class StationDailyFromWF1(BaseModel):
""" Daily weather data (forecast or observed) for a specific station and date retrieved from WF1 API """
"""Daily weather data (forecast or observed) for a specific station and date retrieved from WF1 API"""

created_by: str
forecast_id: str
station_code: int
Expand All @@ -113,12 +125,14 @@ class StationDailyFromWF1(BaseModel):


class StationDailiesResponse(BaseModel):
""" List of StationDailyFromWF1 records as response """
"""List of StationDailyFromWF1 records as response"""

dailies: List[StationDailyFromWF1]


class WeatherIndeterminate(BaseModel):
""" Used to represent a predicted or actual value """
"""Used to represent a predicted or actual value"""

station_code: int
station_name: str
determinate: WeatherDeterminate
Expand Down Expand Up @@ -153,8 +167,9 @@ class WF1ForecastRecordType(BaseModel):


class WF1PostForecast(BaseModel):
""" Used to represent a forecast to be POSTed to WF1 """
archive: str = 'false'
"""Used to represent a forecast to be POSTed to WF1"""

archive: str = "false"
createdBy: Optional[str] = None
id: Optional[str] = None
station: str # station URL
Expand Down
2 changes: 1 addition & 1 deletion web/src/api/moreCast2API.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ describe('moreCast2API', () => {
})
it('should call submit endpoint for forecast submission', async () => {
axios.post = jest.fn().mockResolvedValue({ status: 201 })
const res = await submitMoreCastForecastRecords('testToken', [
const res = await submitMoreCastForecastRecords([
buildMorecast2Forecast('1', 1, 'one', DateTime.fromObject({ year: 2021, month: 1, day: 1 })),
buildMorecast2Forecast('2', 2, 'two', DateTime.fromObject({ year: 2021, month: 1, day: 1 }))
])
Expand Down
3 changes: 0 additions & 3 deletions web/src/api/moreCast2API.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,6 @@ export interface MoreCast2ForecastRecord {
}

export interface MoreCastForecastRequest {
wf1Token: string
forecasts: MoreCast2ForecastRecord[]
}

Expand All @@ -203,14 +202,12 @@ export const marshalMoreCast2ForecastRecords = (forecasts: MoreCast2ForecastRow[
* @returns True if the response is a 201, otherwise false.
*/
export async function submitMoreCastForecastRecords(
token: string,
forecasts: MoreCast2ForecastRow[]
): Promise<{ success: boolean; errorMessage?: string }> {
const forecastRecords = marshalMoreCast2ForecastRecords(forecasts)
const url = `/morecast-v2/forecast`
try {
const { status } = await axios.post<MoreCastForecastRequest>(url, {
token,
forecasts: forecastRecords
})
return { success: status === 201 }
Expand Down
3 changes: 0 additions & 3 deletions web/src/app/rootReducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import percentilesReducer from 'features/percentileCalculator/slices/percentiles
import cHainesModelRunReducer from 'features/cHaines/slices/cHainesModelRunsSlice'
import cHainesPredictionReducer from 'features/cHaines/slices/cHainesPredictionsSlice'
import authReducer from 'features/auth/slices/authenticationSlice'
import wf1AuthReducer from 'features/auth/slices/wf1AuthenticationSlice'
import hfiCalculatorDailiesReducer, { HFICalculatorState } from 'features/hfiCalculator/slices/hfiCalculatorSlice'
import hfiStationsReducer from 'features/hfiCalculator/slices/stationsSlice'
import hfiReadyReducer, { HFIReadyState } from 'features/hfiCalculator/slices/hfiReadySlice'
Expand All @@ -29,7 +28,6 @@ const rootReducer = combineReducers({
cHainesModelRuns: cHainesModelRunReducer,
cHainesPredictions: cHainesPredictionReducer,
authentication: authReducer,
wf1Authentication: wf1AuthReducer,
hfiCalculatorDailies: hfiCalculatorDailiesReducer,
hfiStations: hfiStationsReducer,
hfiReady: hfiReadyReducer,
Expand Down Expand Up @@ -60,7 +58,6 @@ export const selectPercentiles = (state: RootState) => state.percentiles
export const selectCHainesModelRuns = (state: RootState) => state.cHainesModelRuns
export const selectChainesPredictions = (state: RootState) => state.cHainesPredictions
export const selectAuthentication = (state: RootState) => state.authentication
export const selectWf1Authentication = (state: RootState) => state.wf1Authentication
export const selectToken = (state: RootState) => state.authentication.token
export const selectFireBehaviourCalcResult = (state: RootState) => state.fbaCalculatorResults
export const selectHFIStations = (state: RootState) => state.hfiStations
Expand Down
49 changes: 0 additions & 49 deletions web/src/features/auth/slices/wf1AuthenticationSlice.test.ts

This file was deleted.

49 changes: 0 additions & 49 deletions web/src/features/auth/slices/wf1AuthenticationSlice.ts

This file was deleted.

7 changes: 3 additions & 4 deletions web/src/features/moreCast2/components/TabbedDataGrid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import { selectSelectedStations } from 'features/moreCast2/slices/selectedStatio
import { cloneDeep, groupBy, isEqual, isNull, isUndefined } from 'lodash'
import SaveForecastButton from 'features/moreCast2/components/SaveForecastButton'
import { ROLES } from 'features/auth/roles'
import { selectAuthentication, selectWf1Authentication } from 'app/rootReducer'
import { selectAuthentication } from 'app/rootReducer'
import { DateRange } from 'components/dateRangePicker/types'
import MoreCast2Snackbar from 'features/moreCast2/components/MoreCast2Snackbar'
import { isForecastRowPredicate, getRowsToSave, isForecastValid } from 'features/moreCast2/saveForecasts'
Expand Down Expand Up @@ -74,7 +74,6 @@ const TabbedDataGrid = ({ fromTo, setFromTo, fetchWeatherIndeterminates }: Tabbe
const selectedStations = useSelector(selectSelectedStations)
const loading = useSelector(selectWeatherIndeterminatesLoading)
const { roles, isAuthenticated } = useSelector(selectAuthentication)
const { wf1Token } = useSelector(selectWf1Authentication)

// All MoreCast2Rows derived from WeatherIndeterminates in dataSlice.ts. Updates in response to
// a change of station group or date range.
Expand Down Expand Up @@ -449,9 +448,9 @@ const TabbedDataGrid = ({ fromTo, setFromTo, fetchWeatherIndeterminates }: Tabbe
}

const handleSaveClick = async () => {
if (isForecastValid(visibleRows) && !isUndefined(wf1Token)) {
if (isForecastValid(visibleRows)) {
const rowsToSave: MoreCast2ForecastRow[] = getRowsToSave(visibleRows)
const result = await submitMoreCastForecastRecords(wf1Token, rowsToSave)
const result = await submitMoreCastForecastRecords(rowsToSave)
if (result.success) {
setSnackbarMessage(FORECAST_SAVED_MESSAGE)
setSnackbarSeverity('success')
Expand Down

0 comments on commit f69c923

Please sign in to comment.