14/04/2023, 17:19
17/04/2023, 17:37
import SubFrame
from SubFrame import *
18/04/2023, 10:37
26/04/2023, 16:46
26/04/2023, 16:57
SubFrame(M, G, False).Show()
SubFrame(None, G_sub, True).Show()
09/05/2023, 21:18
import wx
import networkx as nx
import pandas as pd
import SubFrame
from SubFrame import *
import os, sys
# richiamo il percorso della cartella
sys.path.append(os.path.dirname(os.path.realpath(__file__)))
'''
Questa classe viene lanciata alla pressione di un pulsante presente nella schermata del Frame padre
(pulsante disabilitato se il numero dei componenti connessi è =1)
Viene creata la finestra con l'elenco dei componenti connessi e, selezionato il componente e premuto il tasto Extract dovrebbe partire l'elaborazione del SubFrame per il componente selezionato.
'''
class ListBoxFrame(wx.Frame):
def __init__(self, graphgraph, n, data):
try:
wx.Frame.__init__(self, None, -1, "Connected Components", size=(410, 280), style=wx.DEFAULT_DIALOG_STYLE)
panel = wx.Panel(self, -1)
self.Gr = graphgraph
self.n_col = n
self.data = data
self.Press = bool()
text = wx.StaticText(panel, -1, "Extract Connected Components of Network", wx.Point(20, 20))
text.SetFont(wx.Font(9, wx.MODERN, wx.ITALIC, wx.BOLD))
hbox = wx.BoxSizer(wx.HORIZONTAL)
i=1; List=[]
self.CompC = [len(subnodes) for subnodes in sorted(nx.connected_components(self.Gr), key=len, reverse=True)]
for component in self.CompC :
List.append('Component '+str(i)+' ('+str(component)+')') ; i+=1
self.listBox = wx.ListBox(panel, -1, wx.Point(20, 20), wx.Size(300, 250), List, wx.LB_SINGLE)
hbox.Add(self.listBox, 1, wx.EXPAND | wx.ALL, 50)
btnpanel = wx.Panel(panel, -1)
vbox = wx.BoxSizer(wx.VERTICAL)
self.Extr = wx.Button(btnpanel, -1, label='Extract', size=(90, 30))
self.Bind(wx.EVT_BUTTON, self.Extract, self.Extr)
vbox = wx.BoxSizer(wx.VERTICAL)
vbox.Add((-1, 50))
vbox.Add(self.Extr)
btnpanel.SetSizer(vbox)
hbox.Add(btnpanel, 0.6, wx.EXPAND | wx.RIGHT, 20)
panel.SetSizer(hbox)
self.Centre()
self.Show()
except:
wx.MessageDialog(self, "ERROR", "Error ListBoxFrame", wx.OK|wx.ICON_ERROR)
def Extract(self, event):
try:
sel = self.listBox.GetSelection() #val = self.listBox.GetString(sel)
# Componenti Connessi
component = self.CompC
for subnodes in sorted(nx.connected_components(self.Gr), key=len, reverse=True) :
if len(subnodes) == component[sel] : node = subnodes ; self.Press = True
else: continue
# Creazione SubGraphs
G_sub = nx.subgraph(self.Gr, node)
# Creo il dataframe delle interazioni del SubGraph e lo ricerco nel dataframe del MutiGraph
# in modo da poter risalire alle informazioni che mi interessano
data = dict(nx.get_edge_attributes(G_sub ,'label')).items()
df_data = pd.DataFrame( dict(data).keys() , columns=[0, 2])
df_data.insert(1, 1, dict(data).values())
df_netw_G_sub = (df_data[0].map(str) + "(" + df_data[1]).map(str) + ")" + df_data[2]
netw_G_sub = df_netw_G_sub.tolist()
df = self.data
# catturo righe info da MG a GiantComp
df_info_G_sub = df.loc[ ((df[0].isin(df_data[0])) & (df[1].isin(df_data[1].unique())) & (df[2].isin(df_data[2]))) | ((df[0].isin(df_data[2])) & (df[1].isin(df_data[1].unique())) & (df[2].isin(df_data[0]))) ]
info_df_G_sub=[]
for i in range(self.n_col): info_df_G_sub.append(df_info_G_sub[i].tolist())
IDTypeEdges_G_sub = df_info_G_sub[1].nunique() # number of interaction types
typeEDGES_G_sub = df_info_G_sub[1].value_counts() # number edges for each interaction type
'''
Richiamo nuovamente Il SubFrame che ripercorre il ciclo per il componente connesso selezionato i parametri sono : 1 - Multigraph; 2 - Graph/SubGraph; 3 - Pressione del tasto (variabile booleana) (tasto presente nella schermata Frame Padre: false per il padre e true per i figli/componenti)
'''
SubFrame( None, G_sub, self.Press).Show(True)
except:
wx.MessageDialog(self, "ERROR", "Error ListBoxFrame", wx.OK|wx.ICON_ERROR)
11/05/2023, 12:05
class SubFrame(wx.Frame):
def __init__(self, M, G, isPressed):
self.M_G = M
self.Gr = G
self.isPressed = isPressed
print("preso sub")
size_x, size_y = None, None # reset per chiamata GiantComp
size_x, size_y = wx.GetDisplaySize()
if self.isPressed == False: pass
else: self.num_max_Gsub = GiantComp
# carica una volta sola tutte le informazioni che poi userò in seguito
UPLOAD(self.M_G, self.Gr, self.isPressed)
# TAB 0 SUDDIVISO IN SEZIONi sezione up: VP_UP, sezione down: (VP_DX, VP_CX, VP_SX )
super(SubFrame, self).__init__(None, title ="Network Analysis", style=wx.DEFAULT_FRAME_STYLE, size=(size_x, size_y))
Skuola.net News è una testata giornalistica iscritta al Registro degli Operatori della Comunicazione.
Registrazione: n° 20792 del 23/12/2010.
©2000—
Skuola Network s.r.l. Tutti i diritti riservati. — P.I. 10404470014.
Powered by phpBB © phpBB Group - Privacy policy - Cookie privacy
phpBB Mobile / SEO by Artodia.