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

Working on metrics definitions

parent 65a0ccfe
No related branches found
No related tags found
No related merge requests found
import logging as log
from enum import Enum
#Dynamics class parent class for all dynamic components in the diagram
class Dynamics:
def __init__(self, id, matrixRow) -> None:
def __init__(self, id) -> None:
self.id = id
self.metrics = []
self.matrixRow = matrixRow
self.metrics = [Metric] #List of metrics for the dynamic
#String only returns necessary info
def __str__(self) -> str:
......@@ -14,6 +15,8 @@ class Dynamics:
#Simple contains function to check if metric already exists
def containsMetric(metrics, metric):
if len(metrics)==0:
return False
for i in metrics:
if i.name == metric:
return True
......@@ -21,48 +24,45 @@ class Dynamics:
# Function used to add a metric to the dynamics list
# The function will check if the metric already exists in the global list, if it does it will not be added to the global list
def addMetrics(self, localMetricList , newMetric, description):
metric = Metric(newMetric, description) #Create a new metric
def addMetrics(self, globalMetricList , newMetric, description, metricType ):
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(self.metrics, newMetric) == False:
self.metrics = self.metrics.append(metric)
if Dynamics.containsMetric(globalMetricList, newMetric) == False:
globalMetricList = globalMetricList.append(metric)
log.info(f"Added metric {newMetric} to GLOBAL dynamics list with ID: {self.id}")
else:
log.info(f"Metric {newMetric} already exists in GLOBAL dynamics list with ID: {self.id}")
localMetricList.append(metric)
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, metrics, matrixRow, threat) -> None:
super().__init__(id, metrics, matrixRow)
self.threat = threat
self.localMetrics = []
def __init__(self, id, threatID) -> None:
super().__init__(id)
self.threatID = threatID
def __str__(self) -> str:
return f"ThreatDynamic: {self.id}, {self.metrics}, {self.threat}"
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, metrics, matrixRow, consequence) -> None:
super().__init__(id, metrics, matrixRow)
self.consequence = consequence
self.localMetrics = []
def __init__(self, id, consequenceID) -> None:
super().__init__(id)
self.consequenceID = consequenceID
def __str__(self) -> str:
return f"ConsequenceDynamic: {self.id}, {self.metrics}, {self.consequence}"
return f"ConsequenceDynamic: {self.id}, {self.consequenceID}"
#Metric class, will be used for all dynamics
class Metric:
def __init__(self, name, type) -> None:
self.name = name
self.type = type
def __init__(self, name, type, description) -> None:
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
def __str__(self) -> str:
return f"Metric: {self.name}, {self.description}"
\ No newline at end of file
\ No newline at end of file
import dynamics as dyn
def main():
dynamicMetrics = []
threat = dyn.ThreatDynamics(1, "Threat1")
print(threat)
threat.addMetrics(dynamicMetrics, "Metric1", "Description1", "opensource")
threat.addMetrics(dynamicMetrics, "Metric2", "Description2","opensource")
threat.addMetrics(dynamicMetrics, "Metric3", "Description3", "opensource")
print("Threat object:", threat)
print("Metrics:", dynamicMetrics)
if __name__=="__main__":
main()
\ 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