From 4a0ccced8abcf7e36c81dfb54b6c5e162b633405 Mon Sep 17 00:00:00 2001 From: martiivGylden <martin.iversen@gyldendal.no> Date: Tue, 12 Mar 2024 15:01:12 +0100 Subject: [PATCH] Function adds all dynamics into list --- analysis.py | 0 diagramParser.py | 33 ++++++++++++++++++++------------- 2 files changed, 20 insertions(+), 13 deletions(-) create mode 100644 analysis.py diff --git a/analysis.py b/analysis.py new file mode 100644 index 0000000..e69de29 diff --git a/diagramParser.py b/diagramParser.py index af6f1bf..cea7b85 100644 --- a/diagramParser.py +++ b/diagramParser.py @@ -20,13 +20,15 @@ def parseDiagramFile(csvFile): # ER components erComponents = {} + # Dynamic components + dynamics = {} #List containing all metrics metrics = [] #List containing all attacks attacks = [] - parseDynamic(df, metrics) + parseDynamic(df, metrics, dynamics) def parseThreats(df, threatDict): @@ -73,7 +75,7 @@ def parseAttacks(df, attackDict): return attackDict #Parses metrics components and adds it to list -def parseDynamic(df, metricList): +def parseDynamic(df, metricList, dynamicsDict): for i in range(len(df)): # Iterates through the dataframe if df[const.textArea1][i] == const.Dynamics: # If the component is a dynamic component @@ -83,21 +85,21 @@ def parseDynamic(df, metricList): df[const.textArea3][i] # Name of dynamic ) threatDynamic.metrics = extractMetrics(df, i, 4) # Extracts metrics from the dynamic component - joinMetrcs(threatDynamic.metrics, metricList) # Adds the metrics to the global metric list + metricList = joinMetrcs(threatDynamic.metrics, metricList) # Adds the metrics to the global metric list threatDynamic.associateBowtie(df, threatDynamic.type) # Associate the dynamic with the correct components - print(threatDynamic, "\n") - + dynamicsDict[df.Id[i]] = threatDynamic + elif df[const.textArea3][i] == const.ConsequenceDynamic: consequenceDynamic = dynamic.BowtieDynamic( df[const.Id][i], # Component ID LucidChart df[const.textArea3][i] # Name of dynamic ) consequenceDynamic.metrics = extractMetrics(df, i, 4) # Extracts metrics from the dynamic component - joinMetrcs(threatDynamic.metrics, metricList) # Adds the metrics to the global metric list + metricList = joinMetrcs(threatDynamic.metrics, metricList) # Adds the metrics to the global metric list@ + consequenceDynamic.associateBowtie(df, consequenceDynamic.type) - print(consequenceDynamic, "\n")# Associate the dynamic with the correct components - + dynamicsDict[df.Id[i]] = consequenceDynamic elif df[const.textArea3][i] == const.AttackDynamic: attackDynamic = dynamic.BowtieDynamic( @@ -105,10 +107,11 @@ def parseDynamic(df, metricList): df[const.textArea3][i] # Name of dynamic ) attackDynamic.metrics = extractMetrics(df, i, 4) - joinMetrcs(threatDynamic.metrics, metricList) # Adds the metrics to the global metric list + metricList = joinMetrcs(threatDynamic.metrics, metricList) # Adds the metrics to the global metric list + attackDynamic.associateBowtie(df,attackDynamic.type) # Associate the dynamic with the correct components - print(attackDynamic, "\n") - + dynamicsDict[df.Id[i]] = attackDynamic + elif df[const.textArea3][i] == const.ERDynamic: erDynamic = dynamic.ERDynamic( df[const.Id][i], # Component ID LucidChart @@ -116,9 +119,11 @@ def parseDynamic(df, metricList): df[const.textArea5][i] # Description ) erDynamic.metrics = extractMetrics(df, i, 8) - joinMetrcs(threatDynamic.metrics, metricList) # Adds the metrics to the global metric list + metricList = joinMetrcs(threatDynamic.metrics, metricList) # Adds the metrics to the global metric list + erDynamic.associatER(df) - print(erDynamic , "\n") + dynamicsDict[df.Id[i]] = erDynamic + print("Number of dynamics: ", len(dynamicsDict)) def extractMetrics(df, index, startRange): @@ -152,3 +157,5 @@ def joinMetrcs(localMetrics, globalMetrics): globalMetrics.append(localMetrics[j]) # Add the local metric to the global metric list log.info("New local metric added to global metric list, metric: ", localMetrics[j].name) log.info("Added all metrics in local list \n, number of duplicate metrics: ", duplicateMetrics, "\n Number of new metrics: ", len(localMetrics)-duplicateMetrics) + return globalMetrics + -- GitLab