Skip to content

Commit

Permalink
enable selection of zones
Browse files Browse the repository at this point in the history
  • Loading branch information
braddf committed Nov 22, 2024
1 parent b9057c7 commit 87afcb4
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 11 deletions.
18 changes: 16 additions & 2 deletions apps/nowcasting-app/components/charts/gsp-pv-remix-chart/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import useGlobalState, { get30MinNow, getNext30MinSlot } from "../../helpers/glo
import Spinner from "../../icons/spinner";
import { ForecastValue } from "../../types";
import React, { FC } from "react";
import { NationalAggregation } from "../../map/types";

// We want to have the ymax of the graph to be related to the capacity of the GspPvRemixChart
// If we use the raw values, the graph looks funny, i.e y major ticks are 0 100 232
Expand Down Expand Up @@ -39,14 +40,24 @@ const GspPvRemixChart: FC<{
visibleLines,
deltaView = false
}) => {
const {
const [nationalAggregationLevel] = useGlobalState("nationalAggregationLevel");
let {
errors,
pvRealDataAfter,
pvRealDataIn,
gspLocationInfo,
gspForecastDataOneGSP,
gspNHourData
} = useGetGspData(gspId);
// TODO – if aggregation is zone, we need to get the data for all GSPs in the zone
if (nationalAggregationLevel === NationalAggregation.zone) {
errors = [];
pvRealDataAfter = [];
pvRealDataIn = [];
gspLocationInfo = [];
gspForecastDataOneGSP = [];
gspNHourData = [];
}
// const gspData = fcAll?.forecasts.find((fc) => fc.location.gspId === gspId);
const gspInstalledCapacity = gspLocationInfo?.[0]?.installedCapacityMw;
const gspName = gspLocationInfo?.[0]?.regionName;
Expand Down Expand Up @@ -112,12 +123,15 @@ const GspPvRemixChart: FC<{
let yMax = gspInstalledCapacity || 100;
yMax = getRoundedTickBoundary(yMax, yMax_levels);

const title =
nationalAggregationLevel === NationalAggregation.GSP ? gspName || "" : String(gspId);

return (
<>
<div className="flex-initial">
<ForecastHeaderGSP
onClose={close}
title={gspName || ""}
title={title}
mwpercent={Math.round(pvPercentage)}
pvTimeOnly={convertISODateStringToLondonTime(latestPvActualDatetime)}
pvValue={Number(latestPvActualInMW)?.toFixed(1)}
Expand Down
5 changes: 3 additions & 2 deletions apps/nowcasting-app/components/helpers/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ const mapGspFeatures: (
const updatedFeatureObj: MapFeatureObject = {
...featureObj,
properties: setFeatureObjectProps(
featureObj.properties,
{ ...featureObj.properties, id: featureObj.properties?.gsp_id },
gspSystemInfo,
selectedFCValue,
selectedActualValueMW
Expand Down Expand Up @@ -171,6 +171,7 @@ const mapZoneFeatures: (
});
return {
...feature,
id: feature.properties.id,
type: "Feature" as "Feature",
properties: setFeatureObjectProps(
feature.properties,
Expand Down Expand Up @@ -215,6 +216,7 @@ export const generateGeoJsonForecastData: (
gspDeltas,
aggregation = NationalAggregation.GSP
) => {
console.log("aggregation", aggregation);
const gspForecastsDataByTimestamp = forecastData || [];
const gspShapeJson = gspShapeData as FeatureCollection;
let features = gspShapeJson.features;
Expand All @@ -236,7 +238,6 @@ export const generateGeoJsonForecastData: (
);
}
const forecastGeoJson = {
...gspShapeData,
type: "FeatureCollection" as "FeatureCollection",
features
};
Expand Down
7 changes: 7 additions & 0 deletions apps/nowcasting-app/components/layout/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { API_PREFIX, getViewTitle } from "../../constant";
import { useLoadDataFromApi } from "../hooks/useLoadDataFromApi";
import { SolarStatus } from "../types";
import useGlobalState from "../helpers/globalState";
import { useEffect } from "react";

interface ILayout {
children: React.ReactNode;
Expand All @@ -12,9 +13,15 @@ interface ILayout {
const Layout = ({ children }: ILayout) => {
const { data: solarStatus } = useLoadDataFromApi<SolarStatus>(`${API_PREFIX}/solar/GB/status`);
const [view] = useGlobalState("view");
const [nationalAggregationLevel] = useGlobalState("nationalAggregationLevel");
const [, setClickedGspId] = useGlobalState("clickedGspId");
const viewTitle = getViewTitle(view);
const pageTitle = view && viewTitle ? `Quartz Solar - ${viewTitle}` : "Quartz Solar";

useEffect(() => {
setClickedGspId(undefined);
}, [nationalAggregationLevel]);

return (
<>
<Head>
Expand Down
7 changes: 5 additions & 2 deletions apps/nowcasting-app/components/map/deltaMap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ const DeltaMap: React.FC<DeltaMapProps> = ({
activeUnit
}) => {
const [selectedISOTime] = useGlobalState("selectedISOTime");
const [nationalAggregationLevel] = useGlobalState("nationalAggregationLevel");

const latestForecastValue = 0;
const isNormalized = activeUnit === ActiveUnit.percentage;
Expand All @@ -67,7 +68,8 @@ const DeltaMap: React.FC<DeltaMapProps> = ({
initForecastData,
selectedISOTime,
combinedData,
gspDeltas
gspDeltas,
nationalAggregationLevel
);

map.addSource("latestPV", {
Expand Down Expand Up @@ -145,7 +147,8 @@ const DeltaMap: React.FC<DeltaMapProps> = ({
initForecastData,
selectedISOTime,
combinedData,
gspDeltas
gspDeltas,
nationalAggregationLevel
);
map.addSource("latestPV", {
type: "geojson",
Expand Down
3 changes: 2 additions & 1 deletion apps/nowcasting-app/components/map/pvLatestMap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,8 @@ const PvLatestMap: React.FC<PvLatestMapProps> = ({
const { forecastGeoJson } = generatedGeoJsonForecastData;
map.addSource("latestPV", {
type: "geojson",
data: forecastGeoJson
data: forecastGeoJson,
promoteId: "id"
});
} else {
source.setData(generatedGeoJsonForecastData.forecastGeoJson);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,44 @@
import { useEffect, useRef } from "react";
import useGlobalState from "../helpers/globalState";
import { NationalAggregation } from "./types";

type UseUpdateMapStateOnClickProps = {
map?: mapboxgl.Map;
isMapReady: boolean;
};
const useUpdateMapStateOnClick = ({ map, isMapReady }: UseUpdateMapStateOnClickProps) => {
const [clickedGspId, setClickedGspId] = useGlobalState("clickedGspId");
const [nationalAggregationLevel] = useGlobalState("nationalAggregationLevel");

const clickedGspIdRef = useRef(clickedGspId);
const isEventRegistertedRef = useRef(false);
useEffect(() => {
if (clickedGspIdRef.current) {
map?.setFeatureState(
{ source: "latestPV", id: clickedGspIdRef.current - 1 },
{
source: "latestPV",
id:
clickedGspId && nationalAggregationLevel === NationalAggregation.GSP
? clickedGspIdRef.current
: clickedGspIdRef.current
},
{ click: false }
);
}

if (clickedGspId) {
console.log("map", map?.getFeatureState({ source: "latestPV", id: clickedGspId }));
clickedGspIdRef.current = clickedGspId;
map?.setFeatureState({ source: "latestPV", id: clickedGspId - 1 }, { click: true });
map?.setFeatureState(
{
source: "latestPV",
id:
nationalAggregationLevel === NationalAggregation.GSP
? Number(clickedGspId)
: clickedGspId
},
{ click: true }
);
} else {
clickedGspIdRef.current = undefined;
}
Expand All @@ -32,8 +50,11 @@ const useUpdateMapStateOnClick = ({ map, isMapReady }: UseUpdateMapStateOnClickP
map.on("click", "latestPV-forecast", (e) => {
const clickedFeature = e.features && e.features[0];
if (clickedFeature) {
const gspId = clickedFeature.properties?.gsp_id;
if (gspId !== clickedGspIdRef.current) setClickedGspId(gspId);
const id =
nationalAggregationLevel === NationalAggregation.GSP
? clickedFeature.properties?.id
: clickedFeature.properties?.id;
if (id !== clickedGspIdRef.current) setClickedGspId(id);
else setClickedGspId(undefined);
}
});
Expand Down

0 comments on commit 87afcb4

Please sign in to comment.