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

Parsing metrics for the dynamics component

parent 45564237
No related branches found
No related tags found
No related merge requests found
#File contains constants from the CSV export format of the entity relationship tool #File contains constants from the CSV export format of the entity relationship tool
#Generic fields for all rows in the CSV file #Generic fields for all rows in the CSV file
componentID = "Id" # LucidChart ID
Id = "Id" # The id of the entity Id = "Id" # The id of the entity
textArea1 = "Text Area 1" textArea1 = "Text Area 1"
...@@ -76,3 +75,4 @@ ThreatDynamic = "Threat" # The threat dynamics ...@@ -76,3 +75,4 @@ ThreatDynamic = "Threat" # The threat dynamics
ConsequenceDynamic = "Consequence" # The consequence dynamics ConsequenceDynamic = "Consequence" # The consequence dynamics
AttackDynamic = "Attack" # The attack dynamics AttackDynamic = "Attack" # The attack dynamics
ERDynamic = "ER" # The ER dynamics ERDynamic = "ER" # The ER dynamics
BowtieDynamicType = textArea3 # The bowtie dynamics
...@@ -21,6 +21,7 @@ def parseDiagramFile(csvFile): ...@@ -21,6 +21,7 @@ def parseDiagramFile(csvFile):
#List containing all attacks #List containing all attacks
attacks = [] attacks = []
parseDynamic(df) parseDynamic(df)
...@@ -68,29 +69,46 @@ def parseAttacks(df, attackDict): ...@@ -68,29 +69,46 @@ def parseAttacks(df, attackDict):
return attackDict return attackDict
#Parses metrics components and adds it to list #Parses metrics components and adds it to list
def parseDynamic(df): def parseDynamic(df, metricList):
for i in range(len(df)): # Iterates through the dataframe 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.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 if df[const.textArea3][i] == const.ThreatDynamic: # If the dynamic component is a threat
print("Found threat dynamic") threatDynamic = dynamic.BowtieDynamic(
df[const.Id][i], # Component ID LucidChart
df[const.textArea3][i]
)
extractMetrics(df, i, 4)
elif df[const.textArea3][i] == const.ConsequenceDynamic: elif df[const.textArea3][i] == const.ConsequenceDynamic:
print("Found consequence dynamic") consequenceDynamic = dynamic.BowtieDynamic()
extractMetrics(df, i, 4)
elif df[const.textArea3][i] == const.AttackDynamic: elif df[const.textArea3][i] == const.AttackDynamic:
print("Found attack dynamic") attackDynamic = dynamic.BowtieDynamic()
extractMetrics(df, i, 4)
elif df[const.textArea3][i] == const.ERDynamic: elif df[const.textArea3][i] == const.ERDynamic:
print("Found ER dynamic") erDynamic = dynamic.ERDynamic()
extractMetrics(df, i, 8)
for j in range(8, len(df.columns),2): # Parse all text areas to find metrics
metric = "Text Area "+str(j) def extractMetrics(df, index, startRange, metricList):
metricDescription = "Text Area "+str(j+1) for j in range(startRange, len(df.columns),2): # Parse all text areas to find metrics
if pd.isnull(df[metric][i]) == False: # If the text area is not metricID = "Text Area "+str(j)
print(df["Id"][i]) metricName = "Text Area "+str(j+1)
print(f"Found Metric with type: {df[metric][i]}")
print(f"Metric description: {df[metricDescription][i]}") if pd.isnull(df[metric][index]) == False: # If the text area is not empty
print("Metric: ID", df[metricID][index], "Name: ", df[metricName][index])
metric = dynamic.Metric(df[metricID][index], df[metricName][index])
metricList.append(metric)
else: else:
j=0
break # First empty field indicates no more metrics break # First empty field indicates no more metrics
return metricList # Returns metric found in the dynamic component
...@@ -3,7 +3,7 @@ import logging as log ...@@ -3,7 +3,7 @@ import logging as log
# Dynamics class parent class for both the bowtie dynamics and the architecture dynamics # Dynamics class parent class for both the bowtie dynamics and the architecture dynamics
class DynamicComponent: class DynamicComponent:
def __init__(self, componentID, type) -> None: def __init__(self, componentID) -> None:
self.componentID = componentID self.componentID = componentID
self.metrics = [Metric] # List of metrics for the dynamic self.metrics = [Metric] # List of metrics for the dynamic
self.DynamicsRow = None # The row in the dynamics table the dynamic is associated with self.DynamicsRow = None # The row in the dynamics table the dynamic is associated with
...@@ -39,18 +39,25 @@ class DynamicComponent: ...@@ -39,18 +39,25 @@ class DynamicComponent:
#Metric class, will be used for all dynamics #Metric class, will be used for all dynamics
class Metric: class Metric:
def __init__(self, name, type, description) -> None: def __init__(self, ID, name) -> None:
#Metrics found in the dynamics tables
self.ID = ID # ID of the metric used to locate in dynamics matrics
self.name = name # Name of the metric self.name = name # Name of the metric
self.description = description # Description of the metric
self.type = type # Four types of dynamic metrics: process, devteam, opensource and vendor
# Metrics found in the metric table
def __str__(self) -> str: def __str__(self) -> str:
return f"Metric: {self.name}, {self.description}" return f"Metric: {self.name}, {self.description}"
class BowtieDynamic(DynamicComponent): class BowtieDynamic(DynamicComponent):
def __init__(self, componentID, type) -> None: def __init__(self, componentID, type) -> None:
super().__init__(componentID, type) super().__init__(componentID)
self.type = type # Type of dynamicM
self.associatedThreat = None # List of threats associated with the dynamic self.associatedThreat = None # List of threats associated with the dynamic
self.associatedAttack = None # List of attacks associated with the dynamic self.associatedAttack = None # List of attacks associated with the dynamic
......
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