Select Git revision
findsalamanderinfo.py
-
Herman Andersen Dyrkorn authoredHerman Andersen Dyrkorn authored
Code owners
Assign users and groups as approvers for specific file changes. Learn more.
matrices.py 5.57 KiB
import pandas as pd
import ERFormatConstants as const
"""_summary_
Parses csv table and returns a dataframe
This is quite finicky as lucidchart has a very weird way of structuring tables as it is based on when different cells were created
This is quite a big EDGE case and will only work for the specific table shape that I have created
"""
def parseTable(df, metricsDict):
cols = [const.Er_ID, const.Bowtie_ID, 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
matrics = pd.DataFrame(columns=cols)
print(len(table))
# ! 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
BowTieID1 = table[const.textArea5].item() # Define the Bowtie ID
MetricID1 = table[const.textArea6].item() # Define the Metric ID
MetricName1 = table[const.textArea15].item() # Define the Metric Name
Value1 = table[const.textArea16].item() # Define the Value
MeasureDate1 = table[const.textArea17].item() # Define the Measure Date
Frequency1 = table[const.textArea18].item() # Define the Frequency
Guide1 = table[const.textArea19].item() # Define the Measurement guide
matrics.loc[0] = erID1, BowTieID1, 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"
metricsdict = fillMetricinfo(erID1, BowTieID1, MetricID1, MetricName1, Value1, MeasureDate1, Frequency1, Guide1, metricsDict)
# Parsing the second row, this row is also specialized
erID2 = table[const.textArea7].item() # Define the ER ID
BowTieID2 = table[const.textArea8].item() # Define the Bowtie ID
MetricID2 = table[const.textArea9].item() # Define the Metric ID
MetricName2 = table[const.textArea20].item() # Define the Metric Name
Value2 = table[const.textArea21].item() # Define the Value
MeasureDate2 = table[const.textArea22].item() # Define the Measure Date
Frequency2 = table[const.textArea23].item() # Define the Frequency
Guide2 = table[const.textArea24].item() # Define the Measurement guide
matrics.loc[1] = erID2, BowTieID2, MetricID2, MetricName2, Value2, MeasureDate2, Frequency2, Guide2
metric = metricsDict[MetricID2] # Access the appropriate metric in the dictionary
# 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:
handleMissingMetric()
matricsIndex = 2
# Parsing from the third row and onwards is standard format
for i in range(25, len(table.columns), 8):
if pd.isnull(table["Text Area "+str(i)].item()) == True or pd.isnull(table["Text Area "+str(i+1)].item()) == True:
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])
matrics.loc[matricsIndex] = erID, BowTieID, MetricID, MetricName, Value, MeasureDate, Frequency, Guide
matricsIndex += 1
return matrics
def handleMissingMetric():
"""Function will communicate to end user that a metric is in the matrics but is not used in the diagram
This will provide clarity to the end user and inform them of unlinked metrics
"""
pass
def fillMetricinfo(erID1: str,
BowTieID1: str,
MetricID1: str,
MetricName1: str,
Value1: str,
MeasureDate1: str,
Frequency1: str,
Guide1: str, metricsDict: dict)-> dict:
"""Function will fill in the metric information in the dataframe into the metric object and return the updated dictionary
"""
metric = metricsDict[MetricID1] # Access the appropriate metric in the dictionary
if metric == None:
print("Metric is not used in the diagram!!!")
return
# 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.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.frequency = Frequency1 # Should be string
metric.guide = Guide1 # Should be string
metricsDict[MetricID1] = metric
return metricsDict