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

Working on parsing metrics

parent 784f6409
No related branches found
No related tags found
No related merge requests found
......@@ -71,12 +71,8 @@ AttackDescription = textArea6 # The description of the attack
AttackDescriptionValue = textArea7 # Value
#Dynamics
ThreatDynamic = "Threat Dynamics" # The dynamics
ConsequenceDynamic = "Consequence Dynamics" # The dynamics
AttackDynamic = "Attack Dynamics" # The dynamics
Dynamics = "Dynamics" # The dynamics
ThreatDynamic = "Threat" # The threat dynamics
ConsequenceDynamic = "Consequence" # The consequence dynamics
AttackDynamic = "Attack" # The attack dynamics
ERDynamic = "ER" # The ER dynamics
......@@ -10,20 +10,19 @@ def parseDiagramFile(csvFile):
# List containing all threats and their descriptions
threats = {}
threats = parseThreats(df, threats)
print(threats)
print(len(threats))
#threats = parseThreats(df, threats)
#List containing all consequences
consequences = {}
consequences = parseConsequences(df, consequences)
print(consequences)
#consequences = parseConsequences(df, consequences)
#List containing all metrics
metrics = []
#List containing all attacks
attacks = []
parseDynamic(df)
def parseThreats(df, threatDict):
for i in range(len(df)):
......@@ -69,7 +68,29 @@ def parseAttacks(df, attackDict):
return attackDict
#Parses metrics components and adds it to list
def parseDynamic(df, dynamicsDict):
for i in range(len(df)):
pass
def parseDynamic(df):
for i in range(len(df)): # Iterates through the dataframe
if df[const.textArea1][i] == const.Dynamics: # If the component is a dynamic component
if df[const.textArea3][i] == const.ThreatDynamic: # If the dynamic component is a threat
print("Found threat dynamic")
elif df[const.textArea3][i] == const.ConsequenceDynamic:
print("Found consequence dynamic")
elif df[const.textArea3][i] == const.AttackDynamic:
print("Found attack dynamic")
elif df[const.textArea3][i] == const.ERDynamic:
print("Found ER dynamic")
for j in range(8, len(df.columns),2): # Parse all text areas to find metrics
metric = "Text Area "+str(j)
metricDescription = "Text Area "+str(j+1)
if pd.isnull(df[metric][i]) == False: # If the text area is not
print(df["Id"][i])
print(f"Found Metric with type: {df[metric][i]}")
print(f"Metric description: {df[metricDescription][i]}")
else:
break # First empty field indicates no more metrics
This diff is collapsed.
This diff is collapsed.
import logging as log
from enum import Enum
#Dynamics class parent class for all dynamic components in the diagram
class Dynamics:
# Dynamics class parent class for both the bowtie dynamics and the architecture dynamics
class DynamicComponent:
def __init__(self, componentID) -> None:
def __init__(self, componentID, type) -> None:
self.componentID = componentID
self.metrics = [Metric] # List of metrics for the dynamic
self.DynamicsRow = None # The row in the dynamics table the dynamic is associated with
#String only returns necessary info
def __str__(self) -> str:
return f"ThreatDynamic: {self.id}, {self.metrics}"
return f"Dynamic Component: {self.componentID}, {len(self.metrics)}"
#Simple contains function to check if metric already exists
def containsMetric(metrics, metric):
if len(metrics)==0:
def containsMetric(metricList, metric):
if len(metricList)==0:
return False
for i in metrics:
for i in metricList:
if i.name == metric:
return True
return False
......@@ -28,7 +28,7 @@ class Dynamics:
metric = Metric(newMetric, description, metricType)
#Check if metric is already in the global metrics list if it is the metric will not be added to the global list
if Dynamics.containsMetric(globalMetricList, newMetric) == False:
if DynamicComponent.containsMetric(globalMetricList, newMetric) == False:
globalMetricList = globalMetricList.append(metric)
log.info(f"Added metric {newMetric} to GLOBAL dynamics list with ID: {self.id}")
else:
......@@ -36,24 +36,6 @@ class Dynamics:
self.metrics.append(metric)
log.info(f"Added metric {newMetric} to LOCAL dynamics list with ID: {self.id}")
#Threat dynamic entity, will be linked to the different threats and the dynamic matrix
class ThreatDynamics(Dynamics):
def __init__(self, id, threatID) -> None:
super().__init__(id)
self.threatID = threatID
def __str__(self) -> str:
return f"ThreatDynamic: {self.id}, {self.threatID}"
#Consequence dynamic will also be linked to the different consequences and the dynamic matrix
class ConsequenceDynamics(Dynamics):
def __init__(self, id, consequenceID) -> None:
super().__init__(id)
self.consequenceID = consequenceID
def __str__(self) -> str:
return f"ConsequenceDynamic: {self.id}, {self.consequenceID}"
#Metric class, will be used for all dynamics
class Metric:
......@@ -65,4 +47,20 @@ class Metric:
def __str__(self) -> str:
return f"Metric: {self.name}, {self.description}"
class BowtieDynamic(DynamicComponent):
def __init__(self, componentID, type) -> None:
super().__init__(componentID, type)
self.associatedThreat = None # List of threats associated with the dynamic
self.associatedAttack = None # List of attacks associated with the dynamic
class ERDynamic(DynamicComponent):
def __init__(self, componentID, type, description) -> None:
super().__init__(componentID, type)
self.description = description # Description of the dynamic
self.associatedComponent = None # Associated ER component
\ No newline at end of file
......@@ -4,7 +4,7 @@ def main():
dynamicMetricsBowtie = [] # List of metrics for the bowtie model
dynamicMetricsArchitecture = [] # List of metrics for the architecture
parse.parseDiagramFile('diagrams/Thesis Bow-Tie and architecture - Bowtie.csv') # Parse the diagram
parse.parseDiagramFile('diagrams/Thesis Bow-Tie and architecture - Meta model.csv') # Parse the diagram
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment