Commit e50dfbf8 authored by Jan Kiene's avatar Jan Kiene
Browse files

finish with wMOPS JS file generation

parent 98a66be7
Loading
Loading
Loading
Loading
+85 −7
Original line number Diff line number Diff line
import argparse


MAX_VALUES = 40

RUNS_KEYS_COMMON = ["fullDate", "shortDate", "revision"]
RUNS_KEYS_WMOPS = RUNS_KEYS_COMMON + [
    "worstCaseEnc",
@@ -20,17 +22,81 @@ RUNS_LINE_IDX = {
    "wmops": [2, 1, 0, 4, 6, 8, 12, 14, 16, 10, 18],
}

DISPLAY_IDS = {
    "wmops": [
        "requirement",
        "worst case codec",
        "worst case enc/dec",
        "worst case enc",
        "worst case dec",
        "worst case codec rs",
        "worst case enc/dec rs",
        "worst case enc rs",
        "worst case dec rs",
    ]
}
DISPLAY_LINE_IDX = {
    "wmops": [-1, 9, 3, 5, 7, 17, 11, 13, 15],
}
DISPLAY_ELEM_TEMPLATE = '{{ lines: {{ show: true }}, points: {{ show: true, fillColor: "#ffffff" }}, borderWidth: 1.5, borderColor: "#BEBEBE", markingsLineWidth: .75, hoverable: true, clickable: false, shadowSize: 0, color: "{color}", id: "{id}", data: [ {data} ] }}'

def main(wmops_log):
    with open(wmops_log) as f:
        wmops_log_lines = f.readlines()
LINE_COLORS = [
    "#000000",
    "#0080FF",
    "#FF8000",
    "#CF4B4B",
    "#008040",
    "#40C4FF",
    "#FFC480",
    "#CF8080",
    "#00F040",
]

    wmops_runs = [
        create_runs_string(line.strip().split(" "), "wmops") for line in wmops_log_lines
JS_FILE_TEMPLATE = """var {var_name} = {{
    {elem_name}: {{
        description: "{description}",
        direction: -1,
        runs: [
            {runs}
            ],
        displays: [
            {displays}
            ]
    wmops_runs_string = ",\n".join(wmops_runs)
        }}
}};
"""

    print(wmops_runs_string)
FILE_DATA = {
    "wmops": {
        "var_name": "Graphs_WMOPS",
        "elem_name": "wmops_worstcase",
        "description": "Worst Case WMOPS",
        "filename": "graphs_wmops_flc.js",
    }
}


def main(wmops_log):
    FILE_DATA["wmops"]["log_file"] = wmops_log

    for x, data in FILE_DATA.items():
        with open(data["log_file"]) as f:
            log_lines = f.readlines()[-MAX_VALUES:]

        runs = [create_runs_string(line.strip().split(" "), x) for line in log_lines]
        displays = [
            create_display_string(log_lines, id, idx, color)
            for id, idx, color in zip(DISPLAY_IDS[x], DISPLAY_LINE_IDX[x], LINE_COLORS)
        ]
        wmops_js_string = JS_FILE_TEMPLATE.format(
            var_name=data["var_name"],
            elem_name=data["elem_name"],
            description=data["description"],
            runs=",\n".join(runs),
            displays=",\n".join(displays),
        )
        with open(data["filename"], "w") as f:
            print(wmops_js_string, file=f)


def create_runs_string(line: list[str], which: str) -> str:
@@ -41,6 +107,18 @@ def create_runs_string(line: list[str], which: str) -> str:
    return run


def create_display_string(log_lines, id, idx, color):
    data = list()
    for i, line in enumerate(log_lines):
        value = line.split(" ")[idx]
        if id == "requirement":
            value = 0
        data.append(f"[{i}, {value}]")

    display = DISPLAY_ELEM_TEMPLATE.format(color=color, id=id, data=", ".join(data))
    return display


if __name__ == "__main__":
    parser = argparse.ArgumentParser()
    parser.add_argument("wmops_log")