Skip to content

Commit

Permalink
some UI fixes and overlay uploads now show tooltip
Browse files Browse the repository at this point in the history
  • Loading branch information
itsMando committed Sep 4, 2024
1 parent f545cc3 commit 290edbf
Show file tree
Hide file tree
Showing 12 changed files with 299 additions and 274 deletions.
2 changes: 1 addition & 1 deletion glimpse/config/appConfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -131,4 +131,4 @@
"zoomView": false
}
}
}
}
51 changes: 4 additions & 47 deletions glimpse/data/demo_examples/customModelExample.json
Original file line number Diff line number Diff line change
@@ -1,67 +1,24 @@
{
"objects":[
"objects": [
{
"name": "load",
"elementType": "node",
"attributes": {
"id": "load_1",
"phases": "AN",
"flags": "DELTMODE",
"nominal_voltage": "241.7771"
}
},
{
"name": "load",
"attributes": {
"id": "load_2",
"phases": "AN",
"flags": "DELTAMOE",
"nominal_voltage": "2401.771"
}
},
{
"name": "node",
"attributes": {
"id": "node_3",
"phases": "AN",
"flags": "DLTAMODE",
"nominal_voltage": "2401.777"
}
},
{
"name": "node",
"attributes": {
"id": "node_4",
"phases": "AN",
"flags": "DELTAMODE",
"nominal_voltage": "2401.771"
}
},
{
"name": "overhead_line",
"elementType": "edge",
"attributes": {
"id": "1-2",
"from": "load_1",
"to": "load_2",
"type": "<tag>"
}
},
{
"name": "overhead_line",
"attributes": {
"id": "3-4",
"from": "node_3",
"to": "node_4",
"type": "<tag>"
}
},
{
"name": "overhead_line",
"attributes": {
"id": "4-1",
"from": "node_4",
"to": "load_1",
"type": "<tag>"
}
}
]
}
}
44 changes: 22 additions & 22 deletions glimpse/data/demo_examples/test.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,61 +24,61 @@
{
"objectType": "G",
"elementType": "node",
"attributes":{
"id":"green_2"
"attributes": {
"id": "green_2"
}
},
{
"objectType": "B",
"elementType": "node",
"attributes":{
"id":"blue_2"
"attributes": {
"id": "blue_2"
}
},
{
"objectType":"M",
"elementType":"edge",
"attributes":{
"objectType": "M",
"elementType": "edge",
"attributes": {
"id": "red_40-green_2",
"from": "red_40",
"to": "green_2"
}
},
{
"objectType":"C",
"elementType":"edge",
"attributes":{
"objectType": "C",
"elementType": "edge",
"attributes": {
"id": "green_2-blue_2",
"from": "green_2",
"to": "blue_2"
}
},
{
"objectType":"Y",
"elementType":"edge",
"attributes":{
"objectType": "Y",
"elementType": "edge",
"attributes": {
"id": "blue_1-green_1",
"from": "blue_1",
"to": "green_1"
}
},
{
"objectType":"M",
"elementType":"edge",
"attributes":{
"objectType": "M",
"elementType": "edge",
"attributes": {
"id": "red_40-blue_2",
"from": "red_40",
"to": "blue_2"
}
},
},
{
"objectType":"Y",
"elementType":"edge",
"attributes":{
"objectType": "Y",
"elementType": "edge",
"attributes": {
"id": "green_2-green_1",
"from": "green_2",
"to": "green_1"
}
}
}
]
}
}
65 changes: 42 additions & 23 deletions glimpse/local-server/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@
from engineio.async_drivers import gevent
from flask_socketio import SocketIO
import networkx as nx
import pprint
import glm
import ntpath
import json

GRAPH = nx.MultiGraph()

# return the file name only
def path_leaf(path: str):
head, tail = ntpath.split(path)
Expand All @@ -25,26 +28,32 @@ def dict2json( glm_dict: dict ):
glm_json = json.dumps( glm_dict, indent = 3 )
return glm_json

def get_nx_graph(file_data: dict):
graph = nx.MultiGraph()
def create_graph(data: dict, set_communities=False):
GRAPH.clear()

for obj in file_data["objects"]:
for obj in data["objects"]:
if obj["elementType"] == "node":
graph.add_node(obj["attributes"]["id"], objectType = obj["objectType"], attributes = obj["attributes"])
GRAPH.add_node(obj["attributes"]["id"], objectType = obj["objectType"], attributes = obj["attributes"])
else:
graph.add_edge(obj["attributes"]["from"], obj["attributes"]["to"], obj["attributes"]["id"])

return graph
GRAPH.add_edge(obj["attributes"]["from"], obj["attributes"]["to"], obj["attributes"]["id"])

if set_communities :
partition = nx.algorithms.community.louvain_communities(G=GRAPH, max_level=5)

community_ids = {node: community_id for community_id, community in enumerate(partition) for node in community}

def get_modularity(graph):
modularity = nx.community.modularity(graph, nx.community.label_propagation_communities(graph))
nx.set_node_attributes(GRAPH, community_ids, "glimpse_community_id")
return nx.get_node_attributes(G=GRAPH, name="glimpse_community_id")

def get_modularity():
modularity = nx.community.modularity(GRAPH, nx.community.label_propagation_communities(GRAPH))
return modularity

# long computation with larger graphs
def get_avg_betweenness_centrality(graph):
def get_avg_betweenness_centrality():
avg = 0
myk = int(graph.number_of_nodes()*0.68)
betweenness_centrality_dict = nx.betweenness_centrality(graph, k=myk)
myk = int(GRAPH.number_of_nodes()*0.68)
betweenness_centrality_dict = nx.betweenness_centrality(GRAPH, k=myk)

for centrality in betweenness_centrality_dict.values():
avg += centrality
Expand All @@ -54,7 +63,8 @@ def get_avg_betweenness_centrality(graph):
#------------------------------ Server ------------------------------#

app = Flask(__name__)
socketio = SocketIO(app, cors_allowed_origins="*", async_mode="gevent")
socketio = SocketIO(app)
# socketio = SocketIO(app, cors_allowed_origins="*", async_mode="gevent")

#------------------------------ Server Routes ------------------------------#
@app.route("/")
Expand All @@ -68,17 +78,26 @@ def glm_to_json():

return dict2json(glm_dict)

@app.route("/getstats", methods=["POST"])
@app.route("/create-nx-graph", methods=["POST"])
def create_nx_graph():
graphData = req.get_json()

if isinstance(graphData, dict):
create_graph(graphData)
return '', 204
elif isinstance(graphData, list):
#index 0 contains the data and index 1 contains a bool value whether to set the community IDs as well
community_ids = create_graph(data=graphData[0], set_communities=graphData[1])
return community_ids

@app.route("/get-stats", methods=["GET"])
def get_stats():
data = req.get_json()
graph = get_nx_graph(data)

summary_stats = {
'#Nodes': graph.number_of_nodes(),
'#Edges': graph.number_of_edges(),
'#ConnectedComponets': nx.number_connected_components(graph),
'modularity': get_modularity(graph),
'avgBetweennessCentrality': get_avg_betweenness_centrality(graph)
'#Nodes': GRAPH.number_of_nodes(),
'#Edges': GRAPH.number_of_edges(),
'#ConnectedComponets': nx.number_connected_components(GRAPH),
'modularity': get_modularity(),
'avgBetweennessCentrality': get_avg_betweenness_centrality()
}

return summary_stats
Expand Down Expand Up @@ -106,4 +125,4 @@ def delete_edge(edgeID):

#------------------------------ Start WebSocket Server ------------------------------#
if __name__ == "__main__":
socketio.run(app, log_output=True)
socketio.run(app, debug=True, log_output=True)
68 changes: 30 additions & 38 deletions glimpse/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ const glm2json = async (filePaths) => {

if (res.ok) {
const output = await res.json();

const valid = checkIncludes(output);

if (!valid) {
return { alert: "One or more include files are missing!" };
}
Expand All @@ -120,20 +120,6 @@ const validateThemeFile = (filepath) => {
}
};

const getGraphStats = async (data) => {
const res = await fetch("http://127.0.0.1:5000/getstats", {
method: "POST",
headers: {
"content-type": "application/json",
},
body: data,
});

if (res.ok) {
return await res.json();
}
};

const sendPlot = () => {
return fs.readFileSync(path.join(__dirname, "figs", "plot.png"));
};
Expand Down Expand Up @@ -346,21 +332,28 @@ const makeWindow = () => {
.items)
if (item.checked) return item.id;
});

ipcMain.handle("getConfig", () => {
return fs.readFileSync(path.join(rootDir, "config", "appConfig.json"), { encoding: "utf-8" });
});

ipcMain.handle("glm2json", (e, paths) => glm2json(paths));
ipcMain.handle("getStats", (e, dataObject) => getGraphStats(dataObject));

ipcMain.handle("getPlot", () => sendPlot());

ipcMain.handle("validate", (e, jsonFilePath) => validateJson(jsonFilePath));

ipcMain.handle("getThemeJsonData", (e, filepath) =>
JSON.parse(fs.readFileSync(path.join(rootDir, "themes", filepath), { encoding: "utf-8" }))
);

ipcMain.handle("read-json-file", (e, filepath) =>
JSON.parse(fs.readFileSync(filepath, { encoding: "utf-8" }))
);
ipcMain.handle("validate-theme", (e, filepath) => validateThemeFile(filepath));

ipcMain.on("json2glm", (e, jsonData) => json2glmFunc(jsonData));

ipcMain.on("exportTheme", (e, themeData) => exportThemeFile(themeData));

mainWindow.loadFile(path.join(__dirname, "renderer", "public", "index.html"));
Expand All @@ -385,28 +378,27 @@ const makeSplashWindow = () => {
};

const initiateServer = () => {
const serverPath = path.join(__dirname, "local-server", "dist", "server.exe");
if (fs.existsSync(serverPath)) {
try {
execFile(serverPath, (error, stdout, stderr) => {
if (error) throw error;
if (stderr) throw stderr;
console.log(stdout);
});
} catch (error) {
console.log(error);
return;
}
} else {
const python = spawn("python", ["./local-server/server.py"]);
python.stdout.on("data", function (data) {
console.log("data: ", data.toString("utf8"));
});

python.stderr.on("data", (data) => {
console.log(`log: ${data}`); // when error
});
}
// const serverPath = path.join(__dirname, "local-server", "dist", "server.exe");
// if (fs.existsSync(serverPath)) {
// try {
// execFile(serverPath, (error, stdout, stderr) => {
// if (error) throw error;
// if (stderr) throw stderr;
// console.log(stdout);
// });
// } catch (error) {
// console.log(error);
// return;
// }
// } else {
// const python = spawn("python", ["./local-server/server.py"]);
// python.stdout.on("data", function (data) {
// console.log("data: ", data.toString("utf8"));
// });
// python.stderr.on("data", (data) => {
// console.log(`log: ${data}`); // when error
// });
// }
};

app.whenReady()
Expand Down
Loading

0 comments on commit 290edbf

Please sign in to comment.