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

Finished evaluation for case 1

parent bd3e254d
No related branches found
No related tags found
No related merge requests found
......@@ -87,7 +87,7 @@ def tempTestFunction():
windowWidth = 1250
windowHeight = 1200
diagram = parse.parseDiagramFile("diagrams/DiagramTest3.csv")
diagram = parse.parseDiagramFile("diagrams/Case1.csv")
top = Toplevel(guiRoot, bg="blue")
top.title("Result Window")
......
......@@ -51,8 +51,6 @@ def parseConsequences(df, consequenceDict):
for i in range(len(df)):
if df[const.ConsequenceValue][i] == const.Consequence:
print(df[const.ConsequenceDescriptionValue][i])
consequence = component.Consequence(
df[const.ConsequenceIDValue][i],
df[const.Id][i],
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
......@@ -85,6 +85,7 @@ class BowtieDynamic(DynamicComponent):
Abstracting this saves time
"""
componentId = self.componentID # Define the ID of the component
lines = df.loc[df['Name']=='Line'] # Find all lines in the diagram
......@@ -110,6 +111,7 @@ class BowtieDynamic(DynamicComponent):
sourceComponent = df.loc[df[const.Id]==lineTwo[const.From].item()] # Defines the source of the line connecting threats/consequences and attacks
destinationComponent = df.loc[df[const.Id]==lineTwo[const.To].item()] # Defines the destination of the line connecting threats/consequences and attacks
if componentType == const.ThreatDynamic: # * If the component is a threat
if sourceComponent[const.textArea1].item() == const.Threat: # Checks if source or destination is the threat
self.associatedThreat = sourceComponent
......@@ -119,6 +121,7 @@ class BowtieDynamic(DynamicComponent):
self.associatedAttack = sourceComponent
elif componentType == const.ConsequenceDynamic: # * If the component is a consequence
if sourceComponent[const.textArea1].item() == const.Consequence:
self.associatedConsequence = sourceComponent
self.associatedAttack = destinationComponent
......
......@@ -9,50 +9,41 @@ This is quite a big EDGE case and will only work for the specific table shape th
"""
def parseTable(df, metricsDict, diagram):
cols = [const.Er_ID, const.Bowtie_ID, const.Metric_ID, const.Metric_Name, const.Value, const.Measure_date, const.Frequency ,const.Measurement_guide]
cols = [const.Metric_ID, const.Metric_Name, const.Value, const.Measure_date, const.Frequency ,const.Measurement_guide]
table = df.loc[df[const.Name]=='Metric matrix'] # Defines the table
table = df.loc[df[const.Name]=='Table'] # Defines the table
matrics = pd.DataFrame(columns=cols)
length = len(table.columns)
length = length-7 # Setting the length equal to the amount of text fields
stopLength = length-15
stopLength = 226
# ! 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[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
MetricID1 = table[const.textArea4].item() # Define the Metric ID
MetricName1 = table[const.textArea5].item() # Define the Metric Name
Value1 = table[const.textArea6].item() # Define the Value
MeasureDate1 = table[f"Text Area 229"].item() # Define the Measure Date
Frequency1 = table[f"Text Area 230"].item() # Define the Frequency
Guide1 = table[f"Text Area 231"].item() # Define the Measurement guide
MetricID1 = int(MetricID1)
matrics.loc[0] = erID1, BowTieID1, MetricID1, MetricName1, Value1, MeasureDate1, Frequency1, Guide1 # Fill inn dataframe
matrics.loc[0] = MetricID1, MetricName1, Value1, MeasureDate1, Frequency1, Guide1 # Fill inn dataframe
# TODO Error handle/Communicate to end user here, "You seem to have a metric in your table which is not used etc"
fillMetricinfo(erID1, BowTieID1, MetricID1, MetricName1, Value1, MeasureDate1, Frequency1, Guide1, metricsDict, diagram)
fillMetricinfo(MetricID1, MetricName1, Value1, MeasureDate1, Frequency1, Guide1, metricsDict, diagram)
# 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[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
MetricID2 = table[const.textArea7].item() # Define the Metric ID
MetricName2 = table[const.textArea8].item() # Define the Metric Name
Value2 = table[const.textArea9].item() # Define the Value
MeasureDate2 = table[f"Text Area 232"].item() # Define the Measure Date
Frequency2 = table[f"Text Area 233"].item() # Define the Frequency
Guide2 = table[f"Text Area 234"].item() # Define the Measurement guide
MetricID2 = int(MetricID2)
matrics.loc[1] = erID2, BowTieID2, MetricID2, MetricName2, Value2, MeasureDate2, Frequency2, Guide2
matrics.loc[1] = MetricID2, MetricName2, Value2, MeasureDate2, Frequency2, Guide2
metric = metricsDict[MetricID2] # Access the appropriate metric in the dictionary
fillMetricinfo(erID2, BowTieID2, MetricID2, MetricName2, Value2, MeasureDate2, Frequency2, Guide2, metricsDict, diagram)
fillMetricinfo(MetricID2, MetricName2, Value2, MeasureDate2, Frequency2, Guide2, metricsDict, diagram)
# TODO Error handle/Communicate to end user here, "You seem to have a metric in your table which is not used etc"
if metric == None:
......@@ -61,23 +52,26 @@ def parseTable(df, metricsDict, diagram):
matricsIndex = 2
# Parsing from the third row and onwards is standard format
for i in range(10, stopLength, 8):
for i in range(10, stopLength, 6):
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
MetricName = table["Text Area "+str(i+3)].item() # Define the Metric Name
Value = table["Text Area "+str(i+4)].item() # Define the Value
MeasureDate = table["Text Area "+str(i+5)].item() # Define the Measure Date
Frequency = table["Text Area "+str(i+6)].item() # Define the Frequency
Guide = table["Text Area "+str(i+7)].item() # Define the Measurement guide
MetricID = table["Text Area "+str(i)].item() # Define the Metric ID
MetricName = table["Text Area "+str(i+1)].item() # Define the Metric Name
Value = table["Text Area "+str(i+2)].item() # Define the Value
MeasureDate = table["Text Area "+str(i+3)].item() # Define the Measure Date
Frequency = table["Text Area "+str(i+4)].item() # Define the Frequency
Guide = table["Text Area "+str(i+5)].item() # Define the Measurement guide
matrics.loc[matricsIndex] = MetricID, MetricName, Value, MeasureDate, Frequency, Guide
print("Matrise:")
print(matrics)
fillMetricinfo(MetricID, MetricName, Value, MeasureDate, Frequency, Guide,metricsDict, diagram)
series = pd.Series([erID, BowTieID, MetricID, MetricName, Value, MeasureDate, Frequency, Guide])
matrics.loc[matricsIndex] = erID, BowTieID, MetricID, MetricName, Value, MeasureDate, Frequency, Guide
fillMetricinfo(erID, BowTieID, MetricID, MetricName, Value, MeasureDate, Frequency, Guide,metricsDict, diagram)
matricsIndex += 1
return matrics, metricsDict
......@@ -88,8 +82,7 @@ def handleMissingMetric():
"""
pass
def fillMetricinfo(erID1: str,
BowTieID1: str,
def fillMetricinfo(
MetricID1: str,
MetricName1: str,
Value1: str,
......@@ -100,37 +93,13 @@ def fillMetricinfo(erID1: str,
"""
MetricID1 = int(MetricID1)
if MetricID1 in metricsDict:
metric = metricsDict[MetricID1] # Access the appropriate metric in the dictionary
if metric == None:
else:
print("Metric is not used in the diagram!!!")
return
if erID1 == "ID":
pass
else:
erID1 = erID1.split(",")
erID1 = [eval(i) for i in erID1] # Parse ERID list to int
if type(BowTieID1) == str:
if "," in BowTieID1: # If the amount of associated bowtie IDs is only one or none
BowTieID1 = BowTieID1.split(",")
BowTieID1 = [eval(i) for i in BowTieID1] # Parse BowtieID to int
for i in range(len(BowTieID1)):
BowTieID1[i] = findComponentIDBowtie(BowTieID1[i], diagram)
else:
BowTieID1 = findComponentIDBowtie(BowTieID1, diagram)
BowTieID1 = [BowTieID1]
else:
BowTieID1 = int(BowTieID1)
BowTieID1 = findComponentIDBowtie(BowTieID1, diagram)
BowTieID1 = [BowTieID1]
# Updates the metric with the information found in the dynamics matrix
#! metric.erID = erID1 # Should be string
metric.bowtieID = BowTieID1 # is list and should be i guess
metric.name = MetricName1 # Should be string
metric.value = Value1 # Should be string
metric.date = MeasureDate1 # TODO Parse this and change it to a date object maybe? Not sure if its necessary...
......
print("Description of dynamic: ", dynamicDescription, "Associated entity relationship components: ", textList)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment