Skip to content
Snippets Groups Projects
Commit 863b5c45 authored by martiivGylden's avatar martiivGylden
Browse files

Working on GUI

parent fa220f42
No related branches found
No related tags found
No related merge requests found
from tkinter import *
from tkinter import ttk
from tkinter import filedialog
import diagramParser as parse
def openFile():
fileName = filedialog.askopenfilename(initialdir= "/",
title= "Select lucidchart diagram file",
filetypes=(("CSV Diagram file", "*.csv"),)
)
parse.parseDiagramFile(fileName)
guiRoot = Tk()
guiRoot.title("Dynamics Analyzer for SSC Risk")
guiRoot.geometry("1000x600")
labelWindow = Label(guiRoot, text="Please select CSV export file containing ER diagram, BowTie diagram and dynamics matrix", font=("Arial", 20), width=100, height=2)
buttonGetFile = Button(guiRoot, text="Select file", command=openFile, width=20, height=2)
labelWindow.grid(column = 1, row = 2)
buttonGetFile.grid(column = 1, row = 5)
guiRoot.mainloop()
......@@ -10,29 +10,27 @@ def parseDiagramFile(csvFile):
df = pd.read_csv(csvFile)
df.drop(["Shape Library", "Page ID", "Contained By", "Group", "Comments", "property 1"], axis=1, inplace=True) #Removing unecessary data
matrix.parseTable(df) #Parse the table
return
# List containing all threats and their descriptions
threats = {}
threats = parseThreats(df, threats)
#List containing all consequences
consequences = {}
consequences = parseConsequences(df, consequences)
# Dynamic components
dynamics = {}
#List containing all metrics
metrics = []
metricsMatrix = matrix.parseTable(df) #Parse the table
threats = parseThreats(df, threats)
consequences = parseConsequences(df, consequences)
parseDynamic(df, metrics, dynamics)
print("Number of threats: ", len(threats))
print("Number of consequences: ", len(consequences))
print("Number of dynamics: ", len(dynamics))
print("Number of metrics: ", len(metrics))
print("Number of metrics: ", len(metricsMatrix.index))
print("Threats: ", threats)
print("Consequences: ", consequences)
print("Dynamics: ", dynamics)
print("Metrics: ", metricsMatrix)
def parseThreats(df, threatDict):
......@@ -100,7 +98,7 @@ def parseDynamic(df, metricList, dynamicsDict):
df[const.textArea3][i] # Name of dynamic
)
consequenceDynamic.metrics = extractMetrics(df, i, 4) # Extracts metrics from the dynamic component
metricList = joinMetrcs(threatDynamic.metrics, metricList) # Adds the metrics to the global metric list@
metricList = joinMetrcs(consequenceDynamic.metrics, metricList) # Adds the metrics to the global metric list@
consequenceDynamic.associateBowtie(df, consequenceDynamic.type)
dynamicsDict[df.Id[i]] = consequenceDynamic
......@@ -111,7 +109,7 @@ def parseDynamic(df, metricList, dynamicsDict):
df[const.textArea3][i] # Name of dynamic
)
attackDynamic.metrics = extractMetrics(df, i, 4)
metricList = joinMetrcs(threatDynamic.metrics, metricList) # Adds the metrics to the global metric list
metricList = joinMetrcs(attackDynamic.metrics, metricList) # Adds the metrics to the global metric list
attackDynamic.associateBowtie(df,attackDynamic.type) # Associate the dynamic with the correct components
dynamicsDict[df.Id[i]] = attackDynamic
......@@ -123,12 +121,13 @@ def parseDynamic(df, metricList, dynamicsDict):
df[const.textArea5][i] # Description
)
erDynamic.metrics = extractMetrics(df, i, 8)
metricList = joinMetrcs(threatDynamic.metrics, metricList) # Adds the metrics to the global metric list
metricList = joinMetrcs(erDynamic.metrics, metricList) # Adds the metrics to the global metric list
erDynamic.associatER(df)
dynamicsDict[df.Id[i]] = erDynamic
return metricList, dynamicsDict
def extractMetrics(df, index, startRange):
for j in range(startRange, len(df.columns),2): # Parse all text areas to find metrics
listOfMetrics = []
......@@ -145,11 +144,14 @@ def extractMetrics(df, index, startRange):
return listOfMetrics # Returns metric found in the dynamic component
def joinMetrcs(localMetrics: list, globalMetrics: list) -> list:
"""_summary_
Function will use a local metric list and insert the local metrics into a global metric list
containing all the metrics in the threat landscape
:param localMetrics: List of metrics from a dynamic component
:param globalMetrics: List of metrics from the entire threat landscape
"""
def joinMetrcs(localMetrics, globalMetrics):
duplicateMetrics = 0 # Counter for duplicate metrics per function run
for i in range(len(globalMetrics)):
for j in range(len(localMetrics)):
......
Id,Name,Shape Library,Page ID,Contained By,Group,Line Source,Line Destination,Source Arrow,Destination Arrow,Status,Text Area 1,Text Area 2,Text Area 3,Text Area 4,Text Area 5,Text Area 6,Text Area 7,Text Area 8,Text Area 9,Text Area 10,Text Area 11,Text Area 12,Text Area 13,Text Area 14,Text Area 15,Text Area 16,Text Area 17,Text Area 18,Text Area 19,Text Area 20,Text Area 21,Text Area 22,Text Area 23,Text Area 24,Text Area 25,Text Area 26,Text Area 27,Text Area 28,Text Area 29,Text Area 30,Text Area 31,Text Area 32,Text Area 33,Text Area 34,Text Area 35,Text Area 36,Text Area 37,Text Area 38,Text Area 39,Text Area 40,Text Area 41,Text Area 42,Text Area 43,Text Area 44,Text Area 45,Text Area 46,Text Area 47,Text Area 48,Text Area 49,Text Area 50,Text Area 51,Text Area 52,Text Area 53,Text Area 54,Text Area 55,Text Area 56,Text Area 57,Text Area 58,Text Area 59,Text Area 60,Text Area 61,Text Area 62,Text Area 63,Text Area 64,Text Area 65,Text Area 66,Text Area 67,Text Area 68,Text Area 69,Text Area 70,Text Area 71,Text Area 72,Text Area 73,Text Area 74,Text Area 75,Text Area 76,Text Area 77,Text Area 78,Text Area 79,Text Area 80,Text Area 81,Text Area 82,Text Area 83,Text Area 84,Text Area 85,Text Area 86,Text Area 87,Text Area 88,Text Area 89,Text Area 90,Text Area 91,Text Area 92,Text Area 93,Text Area 94,Text Area 95,Text Area 96,Comments,property 1
1,Document,,,,,,,,,Draft,Thesis Bow-Tie and architecture,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
108,Table,Tables,2,,,,,,,,ER ID,Bowtie ID,Metric ID,ERID1,BowtieID1,MetricID1,ERID2,BowtieID2,MetricID2,Metric name,Name1,Name2,Value,Value1,Value2,Measure date,Date1,Date2,Frequency,Freq1,Freq2,Measurement guide,Guide1,Guide2,ERID3,EnBowtieID3,MetricID3,Name3,Value3,Date3,Freq3,Guide3,4,4,4,4,4,4,4,4,5,5,5,5,5,5,5,5,6,6,6,6,6,6,6,6,7,7,7,7,7,7,7,7,8,8,8,8,8,8,8,8,9,9,9,9,9,9,9,9,,,,,,,,,,,,,,,,,,
......@@ -74,7 +74,7 @@ Id,Name,Shape Library,Page ID,Contained By,Group,Line Source,Line Destination,So
99,Entity,Entity Relationship,2,,,,,,,,Dynamics,Type,Threat,ID,Name,ID,Name,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
100,Entity,Entity Relationship,2,,,,,,,,Dynamics,Type,Consequence,ID,Name,ID,Name,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
101,Entity,Entity Relationship,2,,,,,,,,Dynamics,Type,Consequence,ID,Name,ID,Name,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
107,Table,Tables,2,,,,,,,,ER ID,Bowtie ID,Metric ID,ID of the relationship containing the metric,Id of the threat or consequence in the bowtie model,ID of the metric,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,Metric name,Value,Measure Date,Frequency,Measurement guide,Name of the metric,Value of the metric,When the measurement was taken,How often the measurement should be taken,How to take the measurement,,,,,,,
107,Metric matrix,Tables,2,,,,,,,,Entity relationship ID,Bowtie model ID,Metric ID,1,1,1,2,2,2,Metric name,Value,Measurement date,Frequency,Measurement guide,1,1,1,1,1,2,2,2,2,2,3,3,3,3,3,3,3,3,4,4,4,4,4,4,4,4,5,5,5,5,5,5,5,5,6,6,6,6,6,6,6,6,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
108,Line,,2,,,3,23,None,None,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
109,Line,,2,,,23,22,CFN ERD One Arrow,CFN ERD Many Arrow,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
110,Line,,2,,,23,31,CFN ERD One Arrow,CFN ERD Many Arrow,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
......
This diff is collapsed.
import pandas as pd
import ERFormatConstants as const
"""_summary_
Parses csv table and returns a dataframe
This is quite finicky as lucidchart has a very weird way of structuring tables as it is based on when different cells were created
This is quite a big EDGE case and will only work for the specific table shape that I have created
"""
def parseTable(df):
cols = [const.Er_ID, const.Bowtie_ID, const.Metric_ID, const.Metric_Name, const.Value, const.Measure_date, const.Frequency ,const.Measurement_guide]
table = df.loc[df[const.Name]=='Table'] # Defines the table
table = df.loc[df[const.Name]=='Metric matrix'] # Defines the table
matrics = pd.DataFrame(columns=cols)
print(len(table))
# ! Parsing the first row of the table which has a fucked structure because lucidchart is garbage : )
erID1 = table[const.textArea4].item() # Define the ER ID
BowTieID1 = table[const.textArea5].item() # Define the Bowtie ID
MetricID1 = table[const.textArea6].item() # Define the Metric ID
MetricName1 = table[const.textArea11].item() # Define the Metric Name
Value1 = table[const.textArea14].item() # Define the Value
MetricName1 = table[const.textArea15].item() # Define the Metric Name
Value1 = table[const.textArea16].item() # Define the Value
MeasureDate1 = table[const.textArea17].item() # Define the Measure Date
Frequency1 = table[const.textArea20].item() # Define the Frequency
Guide1 = table[const.textArea23].item() # Define the Measurement guide
Frequency1 = table[const.textArea18].item() # Define the Frequency
Guide1 = table[const.textArea19].item() # Define the Measurement guide
matrics.loc[0] = erID1, BowTieID1, MetricID1, MetricName1, Value1, MeasureDate1, Frequency1, Guide1
# Parsing the second row, this row is also specialized
erID2 = table[const.textArea7].item() # Define the ER ID
BowTieID2 = table[const.textArea8].item() # Define the Bowtie ID
MetricID2 = table[const.textArea9].item() # Define the Metric ID
MetricName2 = table[const.textArea12].item() # Define the Metric Name
Value2 = table[const.textArea15].item() # Define the Value
MeasureDate2 = table[const.textArea18].item() # Define the Measure Date
Frequency2 = table[const.textArea21].item() # Define the Frequency
MetricName2 = table[const.textArea20].item() # Define the Metric Name
Value2 = table[const.textArea21].item() # Define the Value
MeasureDate2 = table[const.textArea22].item() # Define the Measure Date
Frequency2 = table[const.textArea23].item() # Define the Frequency
Guide2 = table[const.textArea24].item() # Define the Measurement guide
matrics.loc[1] = erID2, BowTieID2, MetricID2, MetricName2, Value2, MeasureDate2, Frequency2, Guide2
matricsIndex = 1
matricsIndex = 2
# Parsing from the third row and onwards is standard format
for i in range(25, len(table.columns), 8):
if pd.isnull(table["Text Area "+str(i)].item()) == True:
break
......@@ -57,9 +64,4 @@ def parseTable(df):
matrics.loc[matricsIndex] = erID, BowTieID, MetricID, MetricName, Value, MeasureDate, Frequency, Guide
matricsIndex += 1
print(matrics)
return matrics
\ No newline at end of file
pandas==2.2.1
numpy==1.26.4
i
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment