Skip to content

Commit

Permalink
ng zone outlines for map
Browse files Browse the repository at this point in the history
  • Loading branch information
braddf committed Nov 22, 2024
1 parent d443516 commit b9057c7
Show file tree
Hide file tree
Showing 2 changed files with 479,881 additions and 26 deletions.
45 changes: 19 additions & 26 deletions apps/nowcasting-app/components/helpers/data.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { components } from "../../types/quartz-api";
import { Map } from "../map";
import { CombinedData, GspDeltaValue, MapFeatureObject } from "../types";
import { Feature, FeatureCollection, Position } from "geojson";
import { Feature, FeatureCollection, GeoJsonProperties, Geometry, Position } from "geojson";
import gspShapeData from "../../data/gsp_regions_20220314.json";
import gspZoneGroupings from "../../data/ng_gsp_zone_groupings.json";
import ngGSPZoneGroupings from "../../data/ng_gsp_zone_groupings.json";
import ngZones from "../../data/ng_zones.json";
import { formatISODateString, getOpacityValueFromPVNormalized, getRoundedPv } from "./utils";
import { get30MinNow } from "./globalState";
import { NationalAggregation, SelectedData } from "../map/types";
Expand Down Expand Up @@ -145,20 +145,17 @@ const mapZoneFeatures: (
gspDeltas
) => {
if (!targetTime) return [];
const newFeatures: Feature[] = Object.entries(gspZoneGroupings).map(([name, gsps]) => {
let gspCoords: Position[][][] = [];
// Loop through ng_zones data and aggregate the forecast and actuals
const newFeatures: Feature[] = features.map((feature) => {
if (!feature.properties?.id) return feature;
if (!ngGSPZoneGroupings[feature.properties.id as keyof typeof ngGSPZoneGroupings])
return feature;
let zoneForecastTotal = 0;
let zoneActualTotal = 0;
let zoneInstalledCapacity = 0;
// Loop through all the GSP IDs in the zone and aggregate the forecast and actuals
gsps.forEach((gsp) => {
const gspShape = gspShapeData.features[gsp - 1];
if (gspShape.geometry.type === "Polygon") {
gspCoords = [...gspCoords, gspShape.geometry.coordinates as Position[][]];
}
if (gspShape.geometry.type === "MultiPolygon") {
gspCoords = [...gspCoords, ...(gspShape.geometry.coordinates as Position[][][])];
}
const gspIds: number[] =
ngGSPZoneGroupings[feature.properties.id as keyof typeof ngGSPZoneGroupings];
gspIds.forEach((gsp: number) => {
zoneForecastTotal +=
gspForecastsDataByTimestamp.find(
(fc) => fc.datetimeUtc.slice(0, 16) === formatISODateString(targetTime)
Expand All @@ -173,21 +170,16 @@ const mapZoneFeatures: (
);
});
return {
id: name,
...feature,
type: "Feature" as "Feature",
properties: setFeatureObjectProps(
{},
{ regionName: name, installedCapacityMw: zoneInstalledCapacity },
feature.properties,
{ regionName: feature.properties.id, installedCapacityMw: zoneInstalledCapacity },
zoneForecastTotal,
zoneActualTotal
),
geometry: {
type: "MultiPolygon",
coordinates: gspCoords
}
};
)
} as Feature<Geometry, GeoJsonProperties>;
});
// console.log("newFeatures", newFeatures);

// TODO Deltas

Expand Down Expand Up @@ -231,12 +223,13 @@ export const generateGeoJsonForecastData: (
gspShapeJson.features,
combinedData,
gspForecastsDataByTimestamp,
targetTime
targetTime,
gspDeltas
);
} else if (aggregation === NationalAggregation.zone) {
console.log("aggregating to zone");
features = mapZoneFeatures(
gspShapeJson.features,
ngZones.features as Feature<Geometry, GeoJsonProperties>[],
combinedData,
gspForecastsDataByTimestamp,
targetTime
Expand Down
Loading

0 comments on commit b9057c7

Please sign in to comment.