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(): ...@@ -87,7 +87,7 @@ def tempTestFunction():
windowWidth = 1250 windowWidth = 1250
windowHeight = 1200 windowHeight = 1200
diagram = parse.parseDiagramFile("diagrams/DiagramTest3.csv") diagram = parse.parseDiagramFile("diagrams/Case1.csv")
top = Toplevel(guiRoot, bg="blue") top = Toplevel(guiRoot, bg="blue")
top.title("Result Window") top.title("Result Window")
......
...@@ -50,9 +50,7 @@ def parseThreats(df, threatDict): ...@@ -50,9 +50,7 @@ def parseThreats(df, threatDict):
def parseConsequences(df, consequenceDict): def parseConsequences(df, consequenceDict):
for i in range(len(df)): for i in range(len(df)):
if df[const.ConsequenceValue][i] == const.Consequence: if df[const.ConsequenceValue][i] == const.Consequence:
print(df[const.ConsequenceDescriptionValue][i])
consequence = component.Consequence( consequence = component.Consequence(
df[const.ConsequenceIDValue][i], df[const.ConsequenceIDValue][i],
df[const.Id][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): ...@@ -85,6 +85,7 @@ class BowtieDynamic(DynamicComponent):
Abstracting this saves time Abstracting this saves time
""" """
componentId = self.componentID # Define the ID of the component componentId = self.componentID # Define the ID of the component
lines = df.loc[df['Name']=='Line'] # Find all lines in the diagram lines = df.loc[df['Name']=='Line'] # Find all lines in the diagram
...@@ -109,7 +110,8 @@ class BowtieDynamic(DynamicComponent): ...@@ -109,7 +110,8 @@ class BowtieDynamic(DynamicComponent):
sourceComponent = df.loc[df[const.Id]==lineTwo[const.From].item()] # Defines the source of the line connecting threats/consequences and attacks 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 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 componentType == const.ThreatDynamic: # * If the component is a threat
if sourceComponent[const.textArea1].item() == const.Threat: # Checks if source or destination is the threat if sourceComponent[const.textArea1].item() == const.Threat: # Checks if source or destination is the threat
self.associatedThreat = sourceComponent self.associatedThreat = sourceComponent
...@@ -119,6 +121,7 @@ class BowtieDynamic(DynamicComponent): ...@@ -119,6 +121,7 @@ class BowtieDynamic(DynamicComponent):
self.associatedAttack = sourceComponent self.associatedAttack = sourceComponent
elif componentType == const.ConsequenceDynamic: # * If the component is a consequence elif componentType == const.ConsequenceDynamic: # * If the component is a consequence
if sourceComponent[const.textArea1].item() == const.Consequence: if sourceComponent[const.textArea1].item() == const.Consequence:
self.associatedConsequence = sourceComponent self.associatedConsequence = sourceComponent
self.associatedAttack = destinationComponent self.associatedAttack = destinationComponent
......
...@@ -9,50 +9,41 @@ This is quite a big EDGE case and will only work for the specific table shape th ...@@ -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): 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) matrics = pd.DataFrame(columns=cols)
length = len(table.columns) stopLength = 226
length = length-7 # Setting the length equal to the amount of text fields
stopLength = length-15
# ! Parsing the first row of the table which has a fucked structure because lucidchart is garbage : ) # ! 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 MetricID1 = table[const.textArea4].item() # Define the Metric ID
BowTieID1 = table[const.textArea5].item() # Define the Bowtie ID MetricName1 = table[const.textArea5].item() # Define the Metric Name
MetricID1 = table[const.textArea6].item() # Define the Metric ID Value1 = table[const.textArea6].item() # Define the Value
MetricName1 = table[f"Text Area {length-9}"].item() # Define the Metric Name MeasureDate1 = table[f"Text Area 229"].item() # Define the Measure Date
Value1 = table[f"Text Area {length-8}"].item() # Define the Value Frequency1 = table[f"Text Area 230"].item() # Define the Frequency
MeasureDate1 = table[f"Text Area {length-7}"].item() # Define the Measure Date Guide1 = table[f"Text Area 231"].item() # Define the Measurement guide
Frequency1 = table[f"Text Area {length-6}"].item() # Define the Frequency
Guide1 = table[f"Text Area {length-5}"].item() # Define the Measurement guide
MetricID1 = int(MetricID1) 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" # 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 MetricID2 = table[const.textArea7].item() # Define the Metric ID
erID2 = table[const.textArea7].item() # Define the ER ID MetricName2 = table[const.textArea8].item() # Define the Metric Name
BowTieID2 = table[const.textArea8].item() # Define the Bowtie ID Value2 = table[const.textArea9].item() # Define the Value
MetricID2 = table[const.textArea9].item() # Define the Metric ID MeasureDate2 = table[f"Text Area 232"].item() # Define the Measure Date
MetricName2 = table[f"Text Area {length-4}"].item() # Define the Metric Name Frequency2 = table[f"Text Area 233"].item() # Define the Frequency
Value2 = table[f"Text Area {length-3}"].item() # Define the Value Guide2 = table[f"Text Area 234"].item() # Define the Measurement guide
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 = int(MetricID2) 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 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" # 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: if metric == None:
...@@ -61,23 +52,26 @@ def parseTable(df, metricsDict, diagram): ...@@ -61,23 +52,26 @@ def parseTable(df, metricsDict, diagram):
matricsIndex = 2 matricsIndex = 2
# Parsing from the third row and onwards is standard format # 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: if i >= stopLength:
break 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
series = pd.Series([erID, BowTieID, MetricID, MetricName, Value, MeasureDate, Frequency, 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)
matrics.loc[matricsIndex] = erID, BowTieID, MetricID, MetricName, Value, MeasureDate, Frequency, Guide
fillMetricinfo(erID, BowTieID, MetricID, MetricName, Value, MeasureDate, Frequency, Guide,metricsDict, diagram)
matricsIndex += 1 matricsIndex += 1
return matrics, metricsDict return matrics, metricsDict
...@@ -88,8 +82,7 @@ def handleMissingMetric(): ...@@ -88,8 +82,7 @@ def handleMissingMetric():
""" """
pass pass
def fillMetricinfo(erID1: str, def fillMetricinfo(
BowTieID1: str,
MetricID1: str, MetricID1: str,
MetricName1: str, MetricName1: str,
Value1: str, Value1: str,
...@@ -99,38 +92,14 @@ def fillMetricinfo(erID1: str, ...@@ -99,38 +92,14 @@ def fillMetricinfo(erID1: str,
"""Function will fill in the metric information in the dataframe into the metric object and return the updated dictionary """Function will fill in the metric information in the dataframe into the metric object and return the updated dictionary
""" """
MetricID1 = int(MetricID1) MetricID1 = int(MetricID1)
metric = metricsDict[MetricID1] # Access the appropriate metric in the dictionary
if metric == None: if MetricID1 in metricsDict:
metric = metricsDict[MetricID1] # Access the appropriate metric in the dictionary
else:
print("Metric is not used in the diagram!!!") print("Metric is not used in the diagram!!!")
return 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.name = MetricName1 # Should be string
metric.value = Value1 # 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... 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