Example #1
0
    return tuple(
        map(lambda x: list(PATTERN_TOTAL_ENERGY.search(x).groups()), lines))


def parse_percent(lines: List[str]):
    return tuple(
        list(
            map(
                lambda x: list(
                    PATTERN_PERCENT_AND_HOURS.search(x).groupdict().values()),
                lines,
            )))


SLICES_BEPU = (
    SliceFunc(name="header", slice=slice(0, 3), func_parse=parse_header),
    SliceFunc(name="categories",
              slice=slice(5, 7),
              func_parse=lambda x: Categories),
    SliceFunc(name="content", slice=slice(9, -16), func_parse=parse_content),
    SliceFunc(name="total", slice=slice(-12, -10), func_parse=parse_total),
    SliceFunc(name="percent", slice=slice(-8, -4), func_parse=parse_percent),
    SliceFunc(name="note",
              slice=slice(-3, -2),
              func_parse=lambda x: [[x[0].strip()]]),
)


def parse_bepu(report: List[str]):
    bepu = list()
Example #2
0
def parse_sum(lines: List[str]):
    return [["", "", "", "", "", lines[0].strip()]]


def parse_average(lines: List[str]):
    return list(
        map(
            lambda x: ["", "", "", "", *PATTERN_AVERAGE.search(x).groupdict().values()],
            lines,
        )
    )


SLICES_ES_D = (
    SliceFunc(name="header", slice=slice(0, 3), func_parse=parse_header),
    SliceFunc(
        name="categories", slice=slice(6, 8), func_parse=lambda x: Categories),
    SliceFunc(name="content", slice=slice(10, -6), func_parse=parse_content),
    SliceFunc(name="summary", slice=slice(-5, -4), func_parse=parse_sum),
    SliceFunc(name="percent", slice=slice(-2, None), func_parse=parse_average),
)


def parse_es_d(report: List[str]):
    es_d = list()
    for slice_ in SLICES_ES_D:
        es_d.extend(slice_.func_parse(report[slice_.slice]))

    return es_d
(?P<si_value>\d+\.\d{6})\s{3}
(?P<ip_unit_2>.+?)\s*$
""",
    flags=re.VERBOSE,
)


def parse_content(lines: List[str]) -> List[List[str]]:
    content = list()
    for line in filter(lambda x: x.strip(), lines):
        _ = PATTERN_CONTENT.search(line).groupdict().values()
        content.append(list(_))
    return content


SLICES = (
    SliceFunc(name="header", slice=slice(0, 3), func_parse=parse_header),
    SliceFunc(name="categories", slice=slice(4, 6), func_parse=lambda x: Cat),
    SliceFunc(name="content", slice=slice(7, None), func_parse=parse_content),
)


def parse_lv_m(report: List[str]) -> List[List[str]]:
    lv_m = list()
    for slice_ in SLICES:
        lines = report[slice_.slice]
        _ = slice_.func_parse(lines)
        lv_m.extend(_)

    return lv_m

def parse_content(lines: List[str]):
    contents: List[List[str]] = list()
    for line in lines:
        contents.append(
            list(
                map(lambda x: x.strip(),
                    PATTERN_REPORT_HOURLY_REPORT_CONTENT.search(
                        line).groups())))

    return contents


SLICES_HOURLY_REPORT = (
    SliceFunc(name="header", slice=slice(4, 5), func_parse=parse_headers),
    SliceFunc(name="header", slice=slice(6, 9), func_parse=parse_headers),
    SliceFunc(name="header", slice=slice(11, 35), func_parse=parse_content),
)


def get_columns(report: Report):
    column_slices = list()
    for match in PATTERN_VARIABLE.finditer(report.report[10]):
        column_slices.append(slice(*match.span()))

    columns = ['MM', 'DD', 'HH']
    for slice_ in column_slices:
        columns.append(' '.join(
            map(lambda x: x[slice_].strip(),
                (report.report[4], *report.report[6:9]))))