Skip to content

Commit

Permalink
Refactor all 4hr refs to N Hour
Browse files Browse the repository at this point in the history
  • Loading branch information
braddf committed Sep 4, 2024
1 parent 70f4d72 commit 7098aac
Show file tree
Hide file tree
Showing 20 changed files with 103 additions and 132 deletions.
14 changes: 6 additions & 8 deletions apps/nowcasting-app/components/charts/ChartLegend.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,16 @@ import { ChartInfo } from "../../ChartInfo";
import { InfoIcon, LegendLineGraphIcon } from "../icons/icons";
import { FC, useEffect } from "react";
import useGlobalState from "../helpers/globalState";
import { getRounded4HoursAgoString } from "../helpers/utils";
import LegendItem from "./LegendItem";
import { NHR_FORECAST_OPTIONS } from "../../constant";
import { N_HOUR_FORECAST_OPTIONS } from "../../constant";

type ChartLegendProps = {
className?: string;
};
export const ChartLegend: FC<ChartLegendProps> = ({ className }) => {
const [showNhrView] = useGlobalState("show4hView");
const [showNHourView] = useGlobalState("showNHourView");
const [nHourForecast, setNHourForecast] = useGlobalState("nHourForecast");

const fourHoursAgo = getRounded4HoursAgoString();
const legendItemContainerClasses = `flex flex-initial flex-col @sm:gap-1 @6xl:gap-6 @6xl:flex-row ${
className ? ` ${className}` : ""
}`;
Expand Down Expand Up @@ -49,12 +47,12 @@ export const ChartLegend: FC<ChartLegendProps> = ({ className }) => {
{/* label={"OCF Final Forecast"}*/}
{/* dataKey={`PAST_FORECAST`}*/}
{/*/>*/}
{showNhrView && (
{showNHourView && (
<LegendItem
iconClasses={"text-ocf-orange"}
dashStyle={"both"}
label={`OCF ${nHourForecast}hr Forecast`}
dataKey={`NHR_FORECAST`}
dataKey={`N_HOUR_FORECAST`}
/>
)}
</div>
Expand All @@ -67,9 +65,9 @@ export const ChartLegend: FC<ChartLegendProps> = ({ className }) => {
onChange={(e) => setNHourForecast(Number(e.target.value))}
className="text-sm px-2 py-0 rounded-md"
>
{NHR_FORECAST_OPTIONS.map((option) => (
{N_HOUR_FORECAST_OPTIONS.map((option) => (
<option
key={`NHr-select-option-${option}`}
key={`N-hour-select-option-${option}`}
className="text-black bg-white"
value={option}
>
Expand Down
12 changes: 6 additions & 6 deletions apps/nowcasting-app/components/charts/DataLoadingChartStatus.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const DataLoadingChartStatus = <
const isLoadingData =
!loadingState.initialLoadComplete ||
(loadingState.showMessage && !!loadingState.message.length);
const [show4hView] = useGlobalState("show4hView");
const [showNHourView] = useGlobalState("showNHourView");

if (!loadingState || !loadingState.endpointStates || !loadingState.endpointStates.type)
return null;
Expand All @@ -42,7 +42,7 @@ const DataLoadingChartStatus = <
isLoadingData={isLoadingData}
message={loadingState.message}
endpointStates={loadingState.endpointStates}
show4hView={show4hView}
showNHourView={showNHourView}
/>
);
} else if (isEndpointStateType<SitesEndpointStates>(loadingState.endpointStates, "sites")) {
Expand All @@ -51,7 +51,7 @@ const DataLoadingChartStatus = <
message={loadingState.message}
endpointStates={loadingState.endpointStates}
isLoadingData={isLoadingData}
show4hView={show4hView}
showNHourView={showNHourView}
/>
);
}
Expand All @@ -63,13 +63,13 @@ type EndpointStatusListProps<K> = {
isLoadingData: boolean;
message: string;
endpointStates: K;
show4hView: boolean | undefined;
showNHourView: boolean | undefined;
};
const EndpointStatusList = <K extends NationalEndpointStates | SitesEndpointStates>({
isLoadingData,
message,
endpointStates,
show4hView = false
showNHourView = false
}: EndpointStatusListProps<K>) => {
const endpointsArray = Array.from(Object.entries(endpointStates));
return (
Expand All @@ -92,7 +92,7 @@ const EndpointStatusList = <K extends NationalEndpointStates | SitesEndpointStat
{!!endpointsArray.length &&
endpointsArray.map(([key, val]) => {
if (!endpointStates) return null;
if (key === "national4Hour" && !show4hView) return null;
if (key === "nationalNHour" && !showNHourView) return null;
// Filter out "type" key with string state value
if (typeof val === "string") return null;
const state = endpointStates[key as keyof typeof endpointStates];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,7 @@ import { DELTA_BUCKET, MAX_NATIONAL_GENERATION_MW } from "../../../constant";
import ForecastHeader from "../forecast-header";
import useGlobalState, { get30MinSlot } from "../../helpers/globalState";
import useFormatChartData from "../use-format-chart-data";
import {
convertToLocaleDateString,
formatISODateString,
getRounded4HoursAgoString
} from "../../helpers/utils";
import { convertToLocaleDateString, formatISODateString } from "../../helpers/utils";
import GspPvRemixChart from "../gsp-pv-remix-chart";
import { useStopAndResetTime } from "../../hooks/use-and-update-selected-time";
import Spinner from "../../icons/spinner";
Expand Down Expand Up @@ -254,7 +250,7 @@ type DeltaChartProps = {
};
const DeltaChart: FC<DeltaChartProps> = ({ className, combinedData, combinedErrors }) => {
// const [view] = useGlobalState("view");
const [show4hView] = useGlobalState("show4hView");
const [show4hView] = useGlobalState("showNHourView");
const [clickedGspId, setClickedGspId] = useGlobalState("clickedGspId");
const [visibleLines] = useGlobalState("visibleLines");
const [globalZoomArea] = useGlobalState("globalZoomArea");
Expand All @@ -278,7 +274,7 @@ const DeltaChart: FC<DeltaChartProps> = ({ className, combinedData, combinedErro
nationalForecastData,
pvRealDayInData,
pvRealDayAfterData,
national4HourData,
nationalNHourData,
allGspForecastData,
allGspRealData,
gspDeltas
Expand All @@ -287,7 +283,7 @@ const DeltaChart: FC<DeltaChartProps> = ({ className, combinedData, combinedErro
nationalForecastError,
pvRealDayInError,
pvRealDayAfterError,
national4HourError,
nationalNHourError,
allGspForecastError
} = combinedErrors;

Expand All @@ -303,14 +299,14 @@ const DeltaChart: FC<DeltaChartProps> = ({ className, combinedData, combinedErro

const chartData = useFormatChartData({
forecastData: nationalForecastData,
fourHourData: national4HourData,
fourHourData: nationalNHourData,
pvRealDayInData,
pvRealDayAfterData,
timeTrigger: selectedTime,
delta: true
});

// While 4-hour is not available, we default to the latest interval with an Initial Estimate
// While N-hour is not available, we default to the latest interval with an Initial Estimate
// useEffect(() => {
// if (selectedISOTime === get30MinNow() && view === VIEWS.DELTA) {
// setSelectedISOTime(get30MinNow(-60));
Expand All @@ -321,7 +317,7 @@ const DeltaChart: FC<DeltaChartProps> = ({ className, combinedData, combinedErro
nationalForecastError ||
pvRealDayInError ||
pvRealDayAfterError ||
national4HourError ||
nationalNHourError ||
allGspForecastError
)
return <div className={`h-full flex ${className}`}>Failed to load data.</div>;
Expand All @@ -337,7 +333,6 @@ const DeltaChart: FC<DeltaChartProps> = ({ className, combinedData, combinedErro
stopTime();
setSelectedISOTime(time + ":00.000Z");
};
const fourHoursAgo = getRounded4HoursAgoString();

return (
<>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,21 +39,20 @@ const GspPvRemixChart: FC<{
visibleLines,
deltaView = false
}) => {
//when adding 4hour forecast data back in, add gsp4HourData to list in line 27
const {
errors,
pvRealDataAfter,
pvRealDataIn,
gspLocationInfo,
gspForecastDataOneGSP,
gsp4HourData
gspNHourData
} = useGetGspData(gspId);
// const gspData = fcAll?.forecasts.find((fc) => fc.location.gspId === gspId);
const gspInstalledCapacity = gspLocationInfo?.[0]?.installedCapacityMw;
const gspName = gspLocationInfo?.[0]?.regionName;
const chartData = useFormatChartData({
forecastData: gspForecastDataOneGSP,
fourHourData: gsp4HourData,
fourHourData: gspNHourData,
pvRealDayInData: pvRealDataIn,
pvRealDayAfterData: pvRealDataAfter,
timeTrigger: selectedTime,
Expand All @@ -71,7 +70,7 @@ const GspPvRemixChart: FC<{
const pvPercentage = (forecastAtSelectedTime.expectedPowerGenerationNormalized || 0) * 100;

const fourHourForecastAtSelectedTime: ForecastValue =
gsp4HourData?.find((fc) => formatISODateString(fc?.targetTime) === now30min) ||
gspNHourData?.find((fc) => formatISODateString(fc?.targetTime) === now30min) ||
({} as ForecastValue);

//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import useGlobalState from "../../helpers/globalState";
import { useLoadDataFromApi } from "../../hooks/useLoadDataFromApi";

const useGetGspData = (gspId: number) => {
const [show4hView] = useGlobalState("show4hView");
const [show4hView] = useGlobalState("showNHourView");
const [nHourForecast] = useGlobalState("nHourForecast");

const { data: pvRealDataIn, error: pvRealInDat } = useLoadDataFromApi<PvRealData>(
Expand All @@ -26,11 +26,10 @@ const useGetGspData = (gspId: number) => {
`${API_PREFIX}/system/GB/gsp/?gsp_id=${gspId}`
);

const { data: gsp4HourData, error: pv4HourError } = useLoadDataFromApi<ForecastData>(
const nMinuteForecast = nHourForecast * 60;
const { data: gspNHourData, error: pvNHourError } = useLoadDataFromApi<ForecastData>(
show4hView
? `${API_PREFIX}/solar/GB/gsp/${gspId}/forecast?forecast_horizon_minutes=${
nHourForecast * 60
}&historic=true&only_forecast_values=true`
? `${API_PREFIX}/solar/GB/gsp/${gspId}/forecast?forecast_horizon_minutes=${nMinuteForecast}&historic=true&only_forecast_values=true`
: null
);

Expand All @@ -40,9 +39,9 @@ const useGetGspData = (gspId: number) => {
pvRealDayAfter,
gspForecastDataOneGSPError,
gspLocationError,
pv4HourError
pvNHourError
].filter((e) => !!e),
gsp4HourData,
gspNHourData: gspNHourData,
pvRealDataIn,
pvRealDataAfter,
gspForecastDataOneGSP,
Expand Down
8 changes: 4 additions & 4 deletions apps/nowcasting-app/components/charts/pv-remix-chart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const PvRemixChart: FC<{
nationalForecastData,
pvRealDayInData,
pvRealDayAfterData,
national4HourData,
nationalNHourData,
allGspForecastData,
allGspRealData,
gspDeltas
Expand All @@ -42,7 +42,7 @@ const PvRemixChart: FC<{
nationalForecastError,
pvRealDayInError,
pvRealDayAfterError,
national4HourError,
nationalNHourError,
allGspForecastError
} = combinedErrors;

Expand All @@ -60,7 +60,7 @@ const PvRemixChart: FC<{
const chartData = useFormatChartData({
forecastData: nationalForecastData,
probabilisticRangeData: nationalForecastData,
fourHourData: national4HourData,
fourHourData: nationalNHourData,
pvRealDayInData,
pvRealDayAfterData,
timeTrigger: selectedTime
Expand All @@ -70,7 +70,7 @@ const PvRemixChart: FC<{
nationalForecastError ||
pvRealDayInError ||
pvRealDayAfterError ||
national4HourError ||
nationalNHourError ||
allGspForecastError
)
return <div className={`${className}`}>failed to load</div>;
Expand Down
Loading

0 comments on commit 7098aac

Please sign in to comment.