Skip to content

Commit

Permalink
little fix for distributions plots
Browse files Browse the repository at this point in the history
  • Loading branch information
mishadr committed Oct 30, 2024
1 parent 5e8b943 commit d81b188
Show file tree
Hide file tree
Showing 3 changed files with 135 additions and 132 deletions.
24 changes: 23 additions & 1 deletion experiments/user_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,31 @@ def simgnn():
print("len =", len(gen_dataset))


def nx_to_ptg_converter():
from aux.utils import GRAPHS_DIR
from base.dataset_converter import networkx_to_ptg
from base.datasets_processing import DatasetManager
import networkx as nx

nx_path = GRAPHS_DIR / 'networkx-graphs' / 'input' / 'reply_graph.edgelist'
nx_graph = nx.read_edgelist(nx_path)
nx_graph = nx.to_undirected(nx_graph)
ptg_graph = networkx_to_ptg(nx_graph)
if ptg_graph.x is None:
ptg_graph.x = torch.zeros((ptg_graph.num_nodes, 1))
if ptg_graph.y is None:
ptg_graph.y = torch.zeros(ptg_graph.num_nodes)
ptg_graph.y[0] = 1
ptg_dataset = UserLocalDataset('test_dataset_single', [ptg_graph])
gen_dataset = DatasetManager.register_torch_geometric_local(ptg_dataset)
print(len(gen_dataset))


if __name__ == '__main__':

# local()
converted_local()
# converted_local()
# api()
# simgnn()

nx_to_ptg_converter()
17 changes: 9 additions & 8 deletions web_interface/main_multi.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import json
import logging
import multiprocessing
import time
from multiprocessing import Pipe
from threading import Thread

from flask import Flask, render_template, request
from flask_socketio import SocketIO, emit
Expand All @@ -30,12 +28,15 @@ def worker_process(process_id, conn, sid):
client = FrontendClient(sid)
# client.socket.socket.send('hello from subprocess')

def report(process_id):
while True:
print(f"Process {process_id} is working...")
time.sleep(1)

Thread(target=report, args=(process_id,)).start()
# import time
# from threading import Thread
#
# def report(process_id):
# while True:
# print(f"Process {process_id} is working...")
# time.sleep(1)
#
# Thread(target=report, args=(process_id,)).start()

while True:
command = conn.recv() # This blocks until a command is received
Expand Down
226 changes: 103 additions & 123 deletions web_interface/static/js/presentation/right_panel/panelDatasetView.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,80 +47,70 @@ class PanelDatasetView extends PanelView {
$ddDiv.append($button)
$button.click(async () => {
$button.prop("disabled", true)
await $.ajax({
type: 'POST',
url: '/dataset',
let data = await Controller.ajaxRequest('/dataset', {get: "stat",stat: st})
// console.log(data)
$ddDiv.empty()
let scale = 'linear'
let type = 'bar'
if (Object.keys(data).length > 20) {
scale = 'logarithmic'
type = 'scatter'
delete data[0]
}
let $canvas = $("<canvas></canvas>").css("height", "300px")
$ddDiv.append($canvas)
const ctx = $canvas[0].getContext('2d')
new Chart(ctx, {
type: type,
data: {
get: "stat",
stat: st,
datasets: [{
label: lbl,
data: data,
backgroundColor: 'rgb(52, 132, 246, 0.6)',
// borderColor: borderColor,
borderWidth: 1,
barPercentage: 1,
categoryPercentage: 1,
borderRadius: 0,
}]
},
success: function (data) {
data = JSON_parse(data)
// console.log(data)
$ddDiv.empty()
let scale = 'linear'
let type = 'bar'
if (Object.keys(data).length > 20) {
scale = 'logarithmic'
type = 'scatter'
delete data[0]
}
let $canvas = $("<canvas></canvas>").css("height", "300px")
$ddDiv.append($canvas)
const ctx = $canvas[0].getContext('2d')
new Chart(ctx, {
type: type,
data: {
datasets: [{
label: lbl,
data: data,
backgroundColor: 'rgb(52, 132, 246, 0.6)',
// borderColor: borderColor,
borderWidth: 1,
barPercentage: 1,
categoryPercentage: 1,
borderRadius: 0,
}]
options: {
// responsive: false,
// maintainAspectRatio: true,
// aspectRatio: 3,
scales: {
x: {
type: scale,
beginAtZero: false,
// offset: false,
// grid: {
// offset: false
// },
ticks: {stepSize: 1},
title: {
display: true,
text: oX,
font: {size: 14}
}
},
options: {
// responsive: false,
// maintainAspectRatio: true,
// aspectRatio: 3,
scales: {
x: {
type: scale,
beginAtZero: false,
// offset: false,
// grid: {
// offset: false
// },
ticks: {stepSize: 1},
title: {
display: true,
text: oX,
font: {size: 14}
}
},
y: {
type: scale,
suggestedMin: 1,
title: {
display: true,
text: oY,
font: {size: 14}
}
}
},
plugins: {
title: {
display: true,
text: name,
font: {size: 16}
},
legend: {display: false},
y: {
type: scale,
suggestedMin: 1,
title: {
display: true,
text: oY,
font: {size: 14}
}
}
})
},
plugins: {
title: {
display: true,
text: name,
font: {size: 16}
},
legend: {display: false},
}
}
})
})
Expand Down Expand Up @@ -222,64 +212,54 @@ class PanelDatasetView extends PanelView {
$acDiv.append($button1)
$button1.click(async () => {
$button1.prop("disabled", true)
await $.ajax({
type: 'POST',
url: '/dataset',
data: {
get: "stat",
stat: "attr_corr",
},
success: function (data) {
data = JSON_parse(data)
let attrs = data['attributes']
let correlations = data['correlations']
$acDiv.empty()
$acDiv.append(name1 + ':<br>')
let data = Controller.ajaxRequest('/dataset', {get: "stat", stat: "attr_corr"})

// Adds mouse listener for all elements which shows a tip with given text
let $tip = $("<span></span>").addClass("tooltip-text")
$acDiv.append($tip)
let _addTip = (element, text) => {
element.onmousemove = (e) => {
$tip.show()
$tip.css("left", e.pageX + 10)
$tip.css("top", e.pageY + 15)
$tip.html(text)
}
element.onmouseout = (e) => {
$tip.hide()
}
}
let attrs = data['attributes']
let correlations = data['correlations']
$acDiv.empty()
$acDiv.append(name1 + ':<br>')

// SVG with table
let count = attrs.length
let size = Math.min(30, Math.floor(300 / count))
let svg = document.createElementNS("http://www.w3.org/2000/svg", "svg");
let $svg = $(svg)
.css("background-color", "#e7e7e7")
// .css("flex-shrink", "0")
.css("margin", "5px")
.css("width", (count * size) + "px")
.css("height", (count * size) + "px")
$acDiv.append($svg)
for (let j = 0; j < count; j++) {
for (let i = 0; i < count; i++) {
let rect = document.createElementNS("http://www.w3.org/2000/svg", "rect")
rect.setAttribute('x', size * i)
rect.setAttribute('y', size * j)
rect.setAttribute('width', size)
rect.setAttribute('height', size)
let color = valueToColor(correlations[i][j], CORRELATION_COLORMAP, -1, 1)
_addTip(rect, `Corr[${attrs[i]}][${attrs[j]}]=` + correlations[i][j])
rect.setAttribute('fill', color)
rect.setAttribute('stroke', '#e7e7e7')
rect.setAttribute('stroke-width', 1)
$svg.append(rect)
}
}
// Adds mouse listener for all elements which shows a tip with given text
let $tip = $("<span></span>").addClass("tooltip-text")
$acDiv.append($tip)
let _addTip = (element, text) => {
element.onmousemove = (e) => {
$tip.show()
$tip.css("left", e.pageX + 10)
$tip.css("top", e.pageY + 15)
$tip.html(text)
}
element.onmouseout = (e) => {
$tip.hide()
}
}

// SVG with table
let count = attrs.length
let size = Math.min(30, Math.floor(300 / count))
let svg = document.createElementNS("http://www.w3.org/2000/svg", "svg");
let $svg = $(svg)
.css("background-color", "#e7e7e7")
// .css("flex-shrink", "0")
.css("margin", "5px")
.css("width", (count * size) + "px")
.css("height", (count * size) + "px")
$acDiv.append($svg)
for (let j = 0; j < count; j++) {
for (let i = 0; i < count; i++) {
let rect = document.createElementNS("http://www.w3.org/2000/svg", "rect")
rect.setAttribute('x', size * i)
rect.setAttribute('y', size * j)
rect.setAttribute('width', size)
rect.setAttribute('height', size)
let color = valueToColor(correlations[i][j], CORRELATION_COLORMAP, -1, 1)
_addTip(rect, `Corr[${attrs[i]}][${attrs[j]}]=` + correlations[i][j])
rect.setAttribute('fill', color)
rect.setAttribute('stroke', '#e7e7e7')
rect.setAttribute('stroke-width', 1)
$svg.append(rect)
}
})
}
})
}
}
Expand Down

0 comments on commit d81b188

Please sign in to comment.