Commit 6377fa33 authored by Andreas Schmidt's avatar Andreas Schmidt

Completly refactored parse component.

parent bfe7ff49
import numpy as np
import math
import pandas as pd
import collections
from operator import itemgetter
from sklearn import datasets, linear_model
def _extract_duration_by_src(all_durations, src):
return [c for c, v in all_durations.items() if v["Source"] == src]
def _stamp_name_by_src_and_type(all_stamps, src, kind=None):
if kind is None:
kind = ["time", "cycle"]
columns = [c for c, v in all_stamps.items() if v["Source"] == src and v["Type"] in kind]
return columns
return [c for c, v in all_stamps.items() if v["Source"] == src and v["Type"] in kind]
def _extract_stamps_by_type(all_stamps, src, kind=None):
columns = _stamp_name_by_src_and_type(all_stamps, src, kind)
return _stamp_names(columns)
def _stamp_names(columns):
stamps = [x + "_T" for x in columns] + [x + "_C" for x in columns]
return stamps
return [x + "_T" for x in columns] + [x + "_C" for x in columns]
def _evaluate_file(file_name, stamps, kind, sender=False):
# Remove first line, as this is the dummy line for intermittently storing data.
df = pd.read_csv(file_name)[1:]
df = df[df["Kind"] == kind].drop(["Kind"], axis=1).set_index("SeqNo")
# Drop columns of opposing side.
if sender:
df.drop(_extract_stamps_by_type(stamps, "receiver"), axis=1, inplace=True)
else:
df.drop(_extract_stamps_by_type(stamps, "sender"), axis=1, inplace=True)
df = df[pd.notnull(df).all(axis=1)]
return df
# Drop empty rows (as they have probably not been written out).
return df[pd.notnull(df).all(axis=1)]
def _diff_t_c(df, name, start, stop):
def _diff_t_c(df, start, stop):
time = df[stop + "_T"] - df[start + "_T"]
cycles = (df[stop + "_C"] - df[start + "_C"])
return time.astype(float), cycles.astype(float)
def _generate_cycle_time(df, name, start, stop):
time, cycles = _diff_t_c(df, name, start, stop)
df[name + "Cycle_D"] = time / cycles
def _generate_duration(df, name, start, stop, cycle_time_column):
diff = df[stop + "_C"] - df[start + "_C"]
df[name + "Cycles"] = diff
df[name + "Time"] = diff * df[cycle_time_column + "Cycle_D"]
def evaluate(sender_file, receiver_file, config, kind=0):
stamps = config["stamps"]
df1 = _evaluate_file(sender_file, stamps, kind, True)
......@@ -76,12 +54,13 @@ def evaluate(sender_file, receiver_file, config, kind=0):
# Generate Processing Duration
src_name = src.capitalize()
time, cycles = _diff_t_c(df, src_name, tr[src]["Start"], tr[src]["Stop"])
time, cycles = _diff_t_c(df, tr[src]["Start"], tr[src]["Stop"])
df[src_name + "_D"] = time
df[src_name + "_C"] = cycles
# Generate Cycle Times
_generate_cycle_time(df, src_name, cr[src]["Start"], cr[src]["Stop"])
time, cycles = _diff_t_c(df, cr[src]["Start"], cr[src]["Stop"])
df[src_name + "Cycle_D"] = time / cycles
# Recreate missing timestamps from cycles
for stamp_name in _stamp_name_by_src_and_type(stamps, src, "cycle"):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment