Skip to content

Commit

Permalink
fixes the case when the network line extensions are used and coordina…
Browse files Browse the repository at this point in the history
…te for a line are missing

Signed-off-by: Christian Biasuzzi <[email protected]>
  • Loading branch information
CBiasuzzi committed Jul 12, 2024
1 parent 1d83530 commit f8785b9
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 28 deletions.
49 changes: 37 additions & 12 deletions js/networkmapwidget.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
StyledEngineProvider,
} from '@mui/material/styles';
import { Box } from '@mui/system';
import LinearProgress from '@mui/material/LinearProgress';

const INITIAL_ZOOM = 9;
const LABELS_ZOOM_THRESHOLD = 9;
Expand All @@ -28,6 +29,11 @@ const styles = {
zIndex: 2,
},
},
divTemporaryGeoDataLoading: {
position: 'absolute',
width: '100%',
zIndex: 2,
},
};

const darkTheme = createTheme({
Expand Down Expand Up @@ -91,14 +97,29 @@ const render = createRender(() => {
targetSubId === null ? null : { to: targetSubId }
);

const geoData = new GeoData(new Map(), new Map());
geoData.setSubstationPositions(JSON.parse(spos));
geoData.setLinePositions(JSON.parse(lpos));
const [mapDataReady, setMapDataReady] = useState(false);

const mapEquipments = new WidgetMapEquipments(
JSON.parse(smap),
JSON.parse(lmap)
);
const [equipmentData, setEquipmentData] = useState({
gdata: new GeoData(new Map(), new Map()),
edata: new WidgetMapEquipments([], []),
});

useEffect(() => {
let initDataTask = new Promise((resolve, reject) => {
const geoData = new GeoData(new Map(), new Map());
geoData.setSubstationPositions(JSON.parse(spos));
geoData.setLinePositions(JSON.parse(lpos));
const mapEquipments = new WidgetMapEquipments(
JSON.parse(smap),
JSON.parse(lmap)
);
resolve({ gdata: geoData, edata: mapEquipments });
});
initDataTask.then((result) => {
setMapDataReady(true);
setEquipmentData(result);
});
}, []);

useEffect(() => {
const handleContextmenu = (e) => {
Expand Down Expand Up @@ -150,7 +171,7 @@ const render = createRender(() => {

let choiceVoltageLevelsSubstation = null;
if (choiceVoltageLevelsSubstationId) {
choiceVoltageLevelsSubstation = mapEquipments?.getSubstation(
choiceVoltageLevelsSubstation = equipmentData.edata?.getSubstation(
choiceVoltageLevelsSubstationId
);
}
Expand Down Expand Up @@ -199,7 +220,7 @@ const render = createRender(() => {
return (
<Box sx={styles.divNominalVoltageFilter}>
<NominalVoltageFilter
nominalVoltages={mapEquipments.getNominalVoltages()}
nominalVoltages={equipmentData.edata.getNominalVoltages()}
filteredNominalVoltages={filteredNominalVoltages}
onChange={setFilteredNominalVoltages}
/>
Expand All @@ -210,8 +231,8 @@ const render = createRender(() => {
const renderMap = () => (
<NetworkMap
ref={networkMapRef}
mapEquipments={mapEquipments}
geoData={geoData}
mapEquipments={equipmentData.edata}
geoData={equipmentData.gdata}
labelsZoomThreshold={LABELS_ZOOM_THRESHOLD}
arrowsZoomThreshold={ARROWS_ZOOM_THRESHOLD}
initialZoom={INITIAL_ZOOM}
Expand Down Expand Up @@ -254,11 +275,15 @@ const render = createRender(() => {
height: 600,
}}
>
<Box sx={styles.divTemporaryGeoDataLoading}>
{!mapDataReady && <LinearProgress />}
</Box>

{renderMap()}
{choiceVoltageLevelsSubstationId &&
renderVoltageLevelChoice()}

{mapEquipments?.substations?.length > 0 &&
{equipmentData.edata?.substations?.length > 0 &&
renderNominalVoltageFilter()}
</div>
</ThemeProvider>
Expand Down
22 changes: 6 additions & 16 deletions src/pypowsybl_jupyter/networkmapwidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,23 +122,13 @@ def extract_map_data(self, network, display_lines, use_line_extensions):
lines_positions_from_extensions_sorted_df = lines_positions_from_extensions_df.sort_values(by=['id', 'num'])
lines_positions_from_extensions_grouped_df = lines_positions_from_extensions_sorted_df.groupby('id').apply(lambda x: x[['latitude', 'longitude']].to_dict('records'), include_groups=False).to_dict()

for idx, row in lines_positions_df.iterrows():
id_val = row['id']
coordinates = []
if id_val in lines_positions_from_extensions_grouped_df:
coordinates += [{'lat': coord['latitude'], 'lon': coord['longitude']} for coord in lines_positions_from_extensions_grouped_df[id_val]]
lpos.append({'id': id_val, 'coordinates': coordinates})
else:
for _, row in lines_positions_df.iterrows():
entry = {
"id": row['id'],
"coordinates": [
{"lat": row['v1_latitude'], "lon": row['v1_longitude']},
{"lat": row['v2_latitude'], "lon": row['v2_longitude']}
]
}
lpos.append(entry)

id_val = row['id']
coordinates = [{'lat': coord['latitude'], 'lon': coord['longitude']} for coord in lines_positions_from_extensions_grouped_df.get(id_val, [])]
if coordinates:
lpos.append({'id': id_val, 'coordinates': coordinates})

# note that if there are no linePositions for a line, the viewer component draws the lines using the substation positions

for s_id, group in vls_subs_df.groupby('substation_id'):
entry = {
Expand Down

0 comments on commit f8785b9

Please sign in to comment.