Skip to content

Commit

Permalink
Trying to fix the flow layer for visualization. Needs more work so re…
Browse files Browse the repository at this point in the history
…verted it with commented out code.
  • Loading branch information
abhyshr committed Dec 21, 2024
1 parent de87d9e commit e0e187c
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 47 deletions.
123 changes: 79 additions & 44 deletions viz/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ const countyloaddata = getCountyNodes(data);
data = countyloaddata.updatedata;


var flowdata = ExtractFlowData(data);
const flowdata = ExtractFlowData(data);

const Points = getPoints(data);
const Voltages = Points.map(d => d.value);
Expand Down Expand Up @@ -182,7 +182,7 @@ export default function App({ refdata = data, refflowdata = flowdata, ggdata = g

const [netfiltervalue, setNetFilterValue] = useState([0, 800]);

const [flowfiltervalue, setFlowFilterValue] = useState([0, 800]);
const [flowfiltervalue, setFlowFilterValue] = useState([0, 120]);

const [loadfiltervalue, setLoadFilterValue] = useState([0, countyloaddata.maxPd]);

Expand Down Expand Up @@ -213,26 +213,32 @@ export default function App({ refdata = data, refflowdata = flowdata, ggdata = g
lat: feature.geometry.coordinates[1]
})
} else if (feature.geometry.type === "LineString" && lineNameSelectItems.includes(feature.properties.NAME)) {
var RATE_A;
if(feature.properties.RATE_A == 0) {
RATE_A = 10000;
} else {
RATE_A = feature.properties.RATE_A;
}
var loading = Math.abs(feature.properties.PF / RATE_A)*100;
if (feature.properties.PF > 0) {
const [origin, dest] = feature.properties.NAME.split(' -- ')
flows.push({
origin: origin,
dest: dest,
count: Math.abs(feature.properties.PF)
count: feature.properties.KV,
loading: loading
})
} else {
const [dest, origin] = feature.properties.NAME.split(' -- ')
flows.push({
origin: origin,
dest: dest,
count: Math.abs(feature.properties.PF)
count: feature.properties.KV,
loading: loading
})
}

}

})

} else if (busNameSelectItems.length > 0) {

data.features.forEach(feature => {
Expand All @@ -244,63 +250,80 @@ export default function App({ refdata = data, refflowdata = flowdata, ggdata = g
lat: feature.geometry.coordinates[1]
})
} else if (feature.geometry.type === "LineString" && feature.properties.NAME.split(' -- ').some(r => busNameSelectItems.includes(r))) {
var RATE_A;
if(feature.properties.RATE_A == 0) {
RATE_A = 10000;
} else {
RATE_A = feature.properties.RATE_A;
}

var loading = Math.abs(feature.properties.PF / RATE_A)*100;
if (feature.properties.PF > 0) {
const [origin, dest] = feature.properties.NAME.split(' -- ')
flows.push({
origin: origin,
dest: dest,
count: Math.abs(feature.properties.PF)
count: feature.properties.KV,
loading: loading
})
} else {
const [dest, origin] = feature.properties.NAME.split(' -- ')
flows.push({
origin: origin,
dest: dest,
count: Math.abs(feature.properties.PF)
count: feature.properties.KV,
loading: loading
})
}

}

})
}
else {
else {
data.features.forEach(feature => {
if (feature.geometry.type === "Point" && netfiltervalue[0] <= feature.properties.KVlevels[0] &&
feature.properties.KVlevels[0] <= netfiltervalue[1] &&
flowfiltervalue[0] <= feature.properties.KVlevels[0] &&
feature.properties.KVlevels[0] <= flowfiltervalue[1]) {
feature.properties.KVlevels[0] <= netfiltervalue[1]) {
locations.push({
id: feature.properties.NAME,
name: feature.properties.NAME,
lon: feature.geometry.coordinates[0],
lat: feature.geometry.coordinates[1]
})
} else if (feature.geometry.type === "LineString" && netfiltervalue[0] <= feature.properties.KV &&
feature.properties.KV <= netfiltervalue[1] &&
flowfiltervalue[0] <= feature.properties.KV &&
feature.properties.KV <= flowfiltervalue[1]) {
if (feature.properties.PF > 0) {
const [origin, dest] = feature.properties.NAME.split(' -- ')
flows.push({
origin: origin,
dest: dest,
count: Math.abs(feature.properties.PF)
})
} else {
const [dest, origin] = feature.properties.NAME.split(' -- ')
flows.push({
origin: origin,
dest: dest,
count: Math.abs(feature.properties.PF)
})
}

feature.properties.KV <= netfiltervalue[1]) {
var RATE_A;
if(feature.properties.RATE_A == 0) {
RATE_A = 10000;
} else {
RATE_A = feature.properties.RATE_A;
}
var loading = Math.abs(feature.properties.PF/RATE_A)*100.0;

if(flowfiltervalue[0] <= loading && loading <= flowfiltervalue[1]) {
if (feature.properties.PF > 0) {
const [origin, dest] = feature.properties.NAME.split(' -- ')
flows.push({
origin: origin,
dest: dest,
count: feature.properties.KV,
loading: loading
})
} else {
const [dest, origin] = feature.properties.NAME.split(' -- ')
flows.push({
origin: origin,
dest: dest,
count: feature.properties.KV,
loading: loading
})
}
}
}

})
}
const newflowdata = { locations: locations, flows: flows }
}

const newflowdata = { locations: locations, flows: flows, maxloading: 120 }
setFlowData(newflowdata);
}, [data, netfiltervalue, flowfiltervalue, lineNameSelectItems]);

Expand Down Expand Up @@ -554,16 +577,15 @@ export default function App({ refdata = data, refflowdata = flowdata, ggdata = g
toggleMsgLoader(); // close loading
}, [ouputMes]);



const handleNetLayerChange = (event) => {
setNetLayerActive(event.target.checked);
setNetFilterValue([0, 800]);
};


const handleFlowLayerChange = (event) => {
setFlowLayerActive(event.target.checked);
setFlowLayerActive(event.target.checked);
setFlowFilterValue([0, 120]);
};

const handleLoadLayerChange = (event) => {
Expand Down Expand Up @@ -640,16 +662,29 @@ export default function App({ refdata = data, refflowdata = flowdata, ggdata = g
if (netfiltervalue[0] <= KV && KV <= netfiltervalue[1]) return KV;
}
} else {
/* Line layer */
return data.properties.KV;
if(data.geometry.type == 'LineString') { /* Line layer */
/* Uncomment to activate flow-based filtering
var RATE_A;
if(data.properties.RATE_A == 0) {
RATE_A = 10000;
} else {
RATE_A = data.properties.RATE_A;
}
var loading = Math.abs(data.properties.PF / RATE_A)*100;
if(flowfiltervalue[0] <= loading && loading <= flowfiltervalue[1]) {
return data.properties.KV;
}
*/
return data.properties.KV;
}
}
}

return -1; // This is beyond the range so filter will filter out this data point.
}

function getFlowFilterValue(data) {
console.log(data)

}

function getGenFilterValue(data) {
Expand Down Expand Up @@ -777,7 +812,7 @@ export default function App({ refdata = data, refflowdata = flowdata, ggdata = g

extensions: [new DataFilterExtension({ filtersize: 1 })],
updateTriggers: {
getFilterValue: [netfiltervalue, lineNameSelectItems, busNameSelectItems]
getFilterValue: [netfiltervalue, lineNameSelectItems, busNameSelectItems, flowfiltervalue]
}
}),

Expand Down Expand Up @@ -1293,9 +1328,9 @@ export default function App({ refdata = data, refflowdata = flowdata, ggdata = g
valueLabelDisplay="auto"
onChange={handleFlowRangeFilterChange}
getAriaValueText={valuetext}
step={100}
step={10}
min={0}
max={800}
max={120}
>
</Slider></div>)
}
Expand Down
15 changes: 12 additions & 3 deletions viz/src/dataprocess.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,19 +90,28 @@ function ExtractFlowData(data) {
lat: feature.geometry.coordinates[1]
})
} else if (feature.geometry.type === "LineString") {
var RATE_A;
if(feature.properties.RATE_A == 0) {
RATE_A = 10000;
} else {
RATE_A = feature.properties.RATE_A;
}
var loading = Math.abs(feature.properties.PF / RATE_A)*100;
if (feature.properties.PF > 0) {
const [origin, dest] = feature.properties.NAME.split(' -- ')
flows.push({
origin: origin,
dest: dest,
count: feature.properties.KV
count: feature.properties.KV,
loading: loading
})
} else {
const [dest, origin] = feature.properties.NAME.split(' -- ')
flows.push({
origin: origin,
dest: dest,
count: feature.properties.KV
count: feature.properties.KV,
loading: loading
})
}

Expand All @@ -114,7 +123,7 @@ function ExtractFlowData(data) {
const uniq = new Set(flows.map(e => JSON.stringify(e)));
const res = Array.from(uniq).map(e => JSON.parse(e));
return ({
locations: locations, flows: res
locations: locations, flows: res, maxloading: 120
})

}
Expand Down

0 comments on commit e0e187c

Please sign in to comment.