Skip to content
Snippets Groups Projects
Commit 8e199d81 authored by martiivGylden's avatar martiivGylden
Browse files

Updated structure for matrix parsing FML

parent 3c1c034a
No related branches found
No related tags found
No related merge requests found
......@@ -20,19 +20,65 @@ def openFile():
)
diagram = parse.parseDiagramFile(fileName)
top = Toplevel()
top.title("Parsed diagram")
top.geometry("1500x1500")
lab = Label(top, text="Dynamic components in the diagrams")
h = Scrollbar(top, orient="vertical")
h.pack()
lab = Label(top, text="Threat components in the diagrams")
lab.config(font= ("Comic Sans MS", 25, "bold"))
lab.pack(pady=20)
createDynamic(diagram, top)
createThreats(diagram, top)
return diagram
def createThreats(diagram: Diagram, top):
for threat in diagram.threats.values():
metrics, components = findMetrics(diagram, threat.id)
threatFrame = Frame(top)
threatFrame.pack()
l1 = Label(threatFrame, text= f"ID: {threat.id} Description: {threat.threatSource}")
l2 = Label(threatFrame, text= f"Associated vulnerability: {threat.vulnerability}")
l3 = Label(threatFrame, text= f"Observable metrics: {metrics}")
l4 = Label(threatFrame, text = f"Linked Components: {components}")
l1.config(font=("Comic Sans MS", 20))
l2.config(font=("Comic Sans MS", 15))
l3.config(font=("Comic Sans MS", 15))
l4.config(font=("Comic Sans MS", 15))
l1.pack()
l2.pack()
l3.pack()
l4.pack()
def findMetrics(diagram, id):
relevantDynamic = []
relatedComponents = []
for metric in diagram.metrics.values():
if id in metric.erID:
relevantDynamic.append(metric.ID)
relatedComponents.append(metric.erID)
elif id in metric.bowtieID:
relevantDynamic.append(metric.ID)
relatedComponents.append(metric.bowtieID)
return relevantDynamic, relatedComponents
def createDynamic(diagram: Diagram, top):
......
......@@ -23,8 +23,9 @@ def parseDiagramFile(csvFile) -> component.Diagram:
consequences = parseConsequences(df, consequences)
metrics, dynamics = parseDynamic(df, metrics, dynamics)
metricsMatrix = matrix.parseTable(df, metrics) #Parse the table
metricsMatrix, metrics = matrix.parseTable(df, metrics) #Parse the table
print(metricsMatrix)
return diagram
......
......@@ -15,17 +15,20 @@ def parseTable(df, metricsDict):
matrics = pd.DataFrame(columns=cols)
print(len(table))
length = len(table.columns)
length = length-7 # Setting the length equal to the amount of text fields
stopLength = length-15
print(stopLength)
# ! 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.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.textArea18].item() # Define the Frequency
Guide1 = table[const.textArea19].item() # Define the Measurement guide
MetricName1 = table[f"Text Area {length-9}"].item() # Define the Metric Name
Value1 = table[f"Text Area {length-8}"].item() # Define the Value
MeasureDate1 = table[f"Text Area {length-7}"].item() # Define the Measure Date
Frequency1 = table[f"Text Area {length-6}"].item() # Define the Frequency
Guide1 = table[f"Text Area {length-5}"].item() # Define the Measurement guide
matrics.loc[0] = erID1, BowTieID1, MetricID1, MetricName1, Value1, MeasureDate1, Frequency1, Guide1 # Fill inn dataframe
......@@ -38,11 +41,11 @@ def parseTable(df, metricsDict):
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.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
MetricName2 = table[f"Text Area {length-4}"].item() # Define the Metric Name
Value2 = table[f"Text Area {length-3}"].item() # Define the Value
MeasureDate2 = table[f"Text Area {length-2}"].item() # Define the Measure Date
Frequency2 = table[f"Text Area {length-1}"].item() # Define the Frequency
Guide2 = table[f"Text Area {length}"].item() # Define the Measurement guide
matrics.loc[1] = erID2, BowTieID2, MetricID2, MetricName2, Value2, MeasureDate2, Frequency2, Guide2
......@@ -52,15 +55,13 @@ def parseTable(df, metricsDict):
if metric == None:
handleMissingMetric()
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 or pd.isnull(table["Text Area "+str(i+1)].item()) == True:
for i in range(10, stopLength, 8):
if i >= stopLength:
break
erID = table["Text Area "+str(i)].item() # Define the ER ID
BowTieID = table["Text Area "+str(i+1)].item() # Define the Bowtie ID
MetricID = table["Text Area "+str(i+2)].item() # Define the Metric ID
......@@ -73,9 +74,11 @@ def parseTable(df, metricsDict):
series = pd.Series([erID, BowTieID, MetricID, MetricName, Value, MeasureDate, Frequency, Guide])
matrics.loc[matricsIndex] = erID, BowTieID, MetricID, MetricName, Value, MeasureDate, Frequency, Guide
matricsIndex += 1
matricsIndex += 1
print(matrics)
return matrics
return matrics, metricsDict
def handleMissingMetric():
"""Function will communicate to end user that a metric is in the matrics but is not used in the diagram
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment