Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spatial Aggregations V2 #4627

Merged
merged 14 commits into from
Oct 10, 2022
Merged
68 changes: 64 additions & 4 deletions config/exchanges.json
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,10 @@
},
"rotation": -140
},
"AT->IT": {
"lonlat": [12.344464, 46.741723],
"rotation": -140
},
"AT->SI": {
"lonlat": [15.014142, 46.613582],
"parsers": {
Expand Down Expand Up @@ -504,6 +508,10 @@
},
"rotation": 180
},
"CH->IT": {
"lonlat": [9.047334, 46.113596],
"rotation": 180
},
"CN->RU-AS": {
"lonlat": [123.275128, 53.541248],
"parsers": {
Expand Down Expand Up @@ -549,6 +557,10 @@
},
"rotation": 135
},
"DE->DK": {
"lonlat": [9.3, 54.9],
"rotation": 0
},
"DE->DK-DK1": {
"capacity": [-2500, 2500],
"lonlat": [9.3, 54.9],
Expand Down Expand Up @@ -617,6 +629,10 @@
},
"rotation": 0
},
"DE->SE": {
"lonlat": [13.552264, 54.925814],
"rotation": 0
},
"DK-BHM->SE-SE4": {
"capacity": [-60, 60],
"lonlat": [14.509682, 55.363057],
Expand Down Expand Up @@ -662,6 +678,10 @@
},
"rotation": 70
},
"DK->SE": {
"lonlat": [11.556268, 56.857802],
"rotation": 70
},
"DK-DK2->SE-SE4": {
"capacity": [-1300, 1700],
"lonlat": [12.704418, 55.952282],
Expand Down Expand Up @@ -760,6 +780,10 @@
},
"rotation": -30
},
"FI->NO": {
"lonlat": [25.35158, 68.862684],
"rotation": -30
},
"FI->RU-1": {
"capacity": [-1460, 320],
"lonlat": [28.378, 60.878],
Expand All @@ -778,6 +802,10 @@
},
"rotation": -90
},
"FI->SE": {
"lonlat": [23.857, 66.921],
"rotation": -90
},
"FI->SE-SE3": {
"capacity": [-1200, 1200],
"lonlat": [19.797, 60.628],
Expand All @@ -804,6 +832,10 @@
},
"rotation": 70
},
"FR->IT": {
"lonlat": [6.9, 44.4],
"rotation": 70
},
"FR-COR->IT-CNO": {
"lonlat": [10.091148, 42.686804],
"parsers": {
Expand Down Expand Up @@ -864,6 +896,10 @@
},
"rotation": 50
},
"GB->NO": {
"lonlat": [2.44819, 57.266334],
"rotation": 50
},
"GE->RU-1": {
"lonlat": [42.822242, 43.158267],
"parsers": {
Expand Down Expand Up @@ -911,6 +947,10 @@
},
"rotation": -90
},
"GR->IT": {
"lonlat": [18.759248, 38.902132],
"rotation": -90
},
"GR->MK": {
"lonlat": [22.011736, 41.160374],
"parsers": {
Expand Down Expand Up @@ -1095,6 +1135,10 @@
},
"rotation": 90
},
"IT->SI": {
"lonlat": [13.596393, 46.105418],
"rotation": 90
},
"IT-SIC->IT-SO": {
"lonlat": [15.65, 38.1],
"parsers": {
Expand All @@ -1112,6 +1156,10 @@
},
"rotation": -160
},
"IT->MT": {
"lonlat": [14.675346, 36.264287],
"rotation": -160
},
"JP-CB->JP-HR": {
"lonlat": [136.85, 36.35],
"parsers": {
Expand Down Expand Up @@ -1230,6 +1278,10 @@
},
"rotation": -90
},
"LT->SE": {
"lonlat": [18.847674, 55.910978],
"rotation": -90
},
"LV->RU-1": {
"capacity": [-970, 970],
"lonlat": [27.7336, 56.87436],
Expand Down Expand Up @@ -1441,6 +1493,10 @@
},
"rotation": -90
},
"NO->SE": {
"lonlat": [14.055, 64.918],
"rotation": 100
},
"NO-NO1->SE-SE3": {
"capacity": [-2095, 2145],
"lonlat": [12.254138, 61.008235],
Expand Down Expand Up @@ -1512,6 +1568,10 @@
},
"rotation": 120
},
"NO->RU-1": {
"lonlat": [30.1437, 69.52],
"rotation": 120
},
"PL->SE-SE4": {
"capacity": [-600, 600],
"lonlat": [15.969256, 55.215172],
Expand Down Expand Up @@ -1583,16 +1643,16 @@
},
"SE-SE1->SE-SE2": {
"capacity": [-3300, 3300],
"lonlat": [17.869, 65.112],
"lonlat": [17.869, 65.469],
"parsers": {
"exchange": "ENTSOE.fetch_exchange",
"exchangeForecast": "ENTSOE.fetch_exchange_forecast"
},
"rotation": 180
"rotation": 205
},
"SE-SE2->SE-SE3": {
"capacity": [-7300, 7300],
"lonlat": [14.804, 61.661],
"lonlat": [14.804, 61.42],
"parsers": {
"exchange": "ENTSOE.fetch_exchange",
"exchangeForecast": "ENTSOE.fetch_exchange_forecast"
Expand All @@ -1601,7 +1661,7 @@
},
"SE-SE3->SE-SE4": {
"capacity": [-2000, 5400],
"lonlat": [14.518, 57.18],
"lonlat": [14.518, 57.78],
"parsers": {
"exchange": "ENTSOE.fetch_exchange",
"exchangeForecast": "ENTSOE.fetch_exchange_forecast"
Expand Down
16 changes: 14 additions & 2 deletions web/geo/generate-exchanges-to-exclude.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,23 @@ const generateExchangesToIgnore = (OUT_PATH, fc) => {
const split = key.split('->');
const zoneOne = split[0].slice(0, 2);
const zoneTwo = split[1].slice(0, 2);
if (zoneOne === zoneTwo && countryKeysToExclude.includes(key.slice(0, 2))) {
if (key.length > 6 && (countryKeysToExclude.includes(zoneOne) || countryKeysToExclude.includes(zoneTwo))) {
return key;
}
});
const exchanges = { exchangesToExclude: unCombinedExchanges };

const countryExchangesWithSubzones = Object.keys(exchangeConfig).filter((key) => {
const split = key.split('->');
const zoneOne = split[0].slice(0, 2);
tonypls marked this conversation as resolved.
Show resolved Hide resolved
const zoneTwo = split[1].slice(0, 2);
if (key.length === 6 && (countryKeysToExclude.includes(zoneOne) || countryKeysToExclude.includes(zoneTwo))) {
return key;
}
});
const exchanges = {
exchangesToExcludeCountryView: unCombinedExchanges,
exchangesToExcludeZoneView: countryExchangesWithSubzones,
};
const existingExchanges = fileExists(OUT_PATH) ? getJSON(OUT_PATH) : {};
if (JSON.stringify(exchanges) === JSON.stringify(existingExchanges)) {
console.log(`No changes to excluded-aggregated-exchanges.json`); // eslint-disable-line no-console
Expand Down
5 changes: 2 additions & 3 deletions web/public/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -127,13 +127,12 @@
"production": "production",
"consumption": "consumption",
"cpinfo": "<b>consumption</b> takes imports and exports into account, <b>production</b> ignores them",
"aggregated": "aggregated",
"detailed": "detailed",
"aggregateinfo": "Countries with missing zone data are unable to be aggregated",
"aggregateinfo": "Countries are aggregated when the annual zone capacity is greater than 90% of the total capacity",
"selectLanguage": "Select language",
"lowCarbDescription": "Includes renewables and nuclear",
"dataIsDelayed": "Data is delayed"
},
"buttons": { "country": "country", "zone": "zone" },
tonypls marked this conversation as resolved.
Show resolved Hide resolved
"misc": {
"maintitle": "Live 24/7 CO₂ emissions of electricity consumption",
"oops": "Oops! We are having trouble reaching the server. We will try again in a few seconds.",
Expand Down
28 changes: 13 additions & 15 deletions web/src/components/settingsmodal.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import {
} from '../hooks/router';
import { LANGUAGE_NAMES } from '../helpers/constants';

import { aggregatedViewFFEnabled } from '../helpers/featureFlags';
import Toggle from './toggle';

import styled from 'styled-components';
Expand Down Expand Up @@ -121,9 +120,8 @@ const SettingsView = () => {
};

const history = useHistory();
const isAggregatedFFEnabled = aggregatedViewFFEnabled();
const toggleAggregates = useAggregatesToggle();
const isAggregated = useAggregatesEnabled() ? 'aggregated' : 'detailed';
const isAggregated = useAggregatesEnabled() ? 'country' : 'zone';

return (
<InfoContainer>
Expand All @@ -137,18 +135,18 @@ const SettingsView = () => {
value={electricityMixMode}
tooltipStyle={{ width: 250, top: 110, zIndex: 99 }}
/>
{isAggregatedFFEnabled && (
<Toggle
infoHTML={__('tooltips.aggregateinfo')}
onChange={(value) => value !== isAggregated && history.push(toggleAggregates)}
options={[
{ value: 'aggregated', label: __('tooltips.aggregated') },
{ value: 'detailed', label: __('tooltips.detailed') },
]}
value={isAggregated}
tooltipStyle={{ width: 250, top: 146, zIndex: 99 }}
/>
)}

<Toggle
infoHTML={__('tooltips.aggregateinfo')}
onChange={(value) => value !== isAggregated && history.push(toggleAggregates)}
options={[
{ value: 'country', label: __('buttons.country') },
{ value: 'zone', label: __('buttons.zone') },
]}
value={isAggregated}
tooltipStyle={{ width: 250, top: 146, zIndex: 99 }}
/>

<SettingsWrapper>
<SettingButton active icon="language" onClick={() => setLanguageSelectOpen(!languageSelectOpen)}>
{__('tooltips.selectLanguage')}
Expand Down
65 changes: 22 additions & 43 deletions web/src/components/zonemap.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { isEmpty } from '../helpers/isEmpty';
import { debounce } from '../helpers/debounce';
import { getCO2IntensityByMode } from '../helpers/zonedata';
import { ZoomControls } from './zoomcontrols';
import { aggregatedViewFFEnabled } from '../helpers/featureFlags';
import { useAggregatesEnabled } from '../hooks/router';

const interactiveLayerIds = ['zones-clickable-layer'];
Expand Down Expand Up @@ -72,7 +71,6 @@ const ZoneMap = ({
};

const isAggregateEnabled = useAggregatesEnabled();
const isAggregatedViewFFEnabled = aggregatedViewFFEnabled();
// Generate two sources (clickable and non-clickable zones), based on the zones data.
// The `sources` object will trigger a whole re-rendering of the map, and will
// thus re-render all zones.
Expand All @@ -81,46 +79,24 @@ const ZoneMap = ({
// We here iterate over the zones list (instead of dict) to keep the iteration
// order stable
const features = zoneValues.map((zone, i) => {
if (isAggregatedViewFFEnabled) {
if (isAggregateEnabled && zone.geography.properties.isAggregatedView) {
const length = (coordinate) => (coordinate ? coordinate.length : 0);
const zoneId = zone.config.countryCode;
return {
type: 'Feature',
geometry: {
...zone.geography.geometry,
coordinates: zone.geography.geometry.coordinates.filter(length), // Remove empty geometries
},
id: i, // assign an integer id so the feature can be updated later on
properties: {
color: undefined,
zoneData: zone[selectedTimeAggregate].overviews,
zoneId,
},
};
}
if (!isAggregateEnabled && !zone.geography.properties.isCombined) {
const length = (coordinate) => (coordinate ? coordinate.length : 0);
const zoneId = zone.config.countryCode;
return {
type: 'Feature',
geometry: {
...zone.geography.geometry,
coordinates: zone.geography.geometry.coordinates.filter(length), // Remove empty geometries
},
id: i, // assign an integer id so the feature can be updated later on
properties: {
color: undefined,
zoneData: zone[selectedTimeAggregate].overviews,
zoneId,
},
};
}
if (!zone.geography.properties.aggregatedView) {
return {};
}
if (isAggregateEnabled && zone.geography.properties.isAggregatedView) {
const length = (coordinate) => (coordinate ? coordinate.length : 0);
const zoneId = zone.config.countryCode;
return {
type: 'Feature',
geometry: {
...zone.geography.geometry,
coordinates: zone.geography.geometry.coordinates.filter(length), // Remove empty geometries
},
id: i, // assign an integer id so the feature can be updated later on
properties: {
color: undefined,
zoneData: zone[selectedTimeAggregate].overviews,
zoneId,
},
};
}
if (!isAggregatedViewFFEnabled) {
if (!isAggregateEnabled && !zone.geography.properties.isCombined) {
Kongkille marked this conversation as resolved.
Show resolved Hide resolved
const length = (coordinate) => (coordinate ? coordinate.length : 0);
const zoneId = zone.config.countryCode;
return {
Expand All @@ -137,6 +113,9 @@ const ZoneMap = ({
},
};
}
if (!zone.geography.properties.aggregatedView) {
return {};
}
});

return {
Expand All @@ -149,7 +128,7 @@ const ZoneMap = ({
// TODO: `zoneValues` will change even in cases where the geometry doesn't change.
// This will cause this memo to re-update although it should only update when the
// geometry changes. This will slow down the map render..
}, [zoneValues, selectedTimeAggregate, isAggregateEnabled, isAggregatedViewFFEnabled]);
}, [zoneValues, selectedTimeAggregate, isAggregateEnabled]);

// Every time the hovered zone changes, update the hover map layer accordingly.
const hoverFilter = useMemo(() => ['==', 'zoneId', hoveredZoneId || ''], [hoveredZoneId]);
Expand Down Expand Up @@ -305,7 +284,7 @@ const ZoneMap = ({
hovering over zoom buttons doesn't fire hover events on the map.
*/}
<Portal node={wrapperRef.current}>
<ZoomControls aggregatedViewFF={isAggregatedViewFFEnabled} />
<ZoomControls />
</Portal>
{/* Layers */}
<Layer id="ocean" type="background" paint={styles.ocean} />
Expand Down
Loading