Esempio n. 1
0
def store_results_per_car(
    h5db,
    specs,
    overrides,
    pwots,
    cycles,
    all_cases=None,
    props_group_suffix="prop",
    overrides_group_suffix="override",
    wot_group_suffix="wot",
    cycle_group_suffix="cycle",
    c_vehnum=c_vehnum,
    c_case_id=c_case,
):
    """
    Populate h5db with results collected from a folder full of (`V123.xls`, ...) exchel-files.

    :param cycles:
        if none, also `specs` are not stored!

        vehicles/
            +--v001/
            |   +--props      (series) scalar inputs & outputs generated by AccDB
            |   +--wot        (df) not all vehicles have wot
            |   +--cycle      (df) cycle-run generated by AccDB
            |   +--override   (series) pyalgo must also override these kv-pairs
            +...
    """
    base = vehdb.provenance_info(files=[veh_inputs_excel[0], veh_results_excel[0]])

    if all_cases is None:
        all_cases = set()
        if specs is not None:
            all_cases.update(specs[c_case_id])
        if overrides is not None:
            all_cases.update(overrides.keys())
        if cycles is not None:
            all_cases.update(cycles[c_case_id].unique())
    log.info("Will store %s cases: %s", len(all_cases), all_cases)

    for case in sorted(all_cases):
        vehnum = cycles is not None and int(
            cycles.loc[cycles[c_case_id] == case, c_vehnum].iloc[0]
        )
        log.info(f"+++ Case: %s, Veh: %s (out of %s)...", case, vehnum, len(all_cases))

        ## Store WOT
        #
        if pwots is not None:
            pwot = pwots.loc[pwots[c_engno] == vehnum, :]
            assert pwot.size, (case, vehnum)
            pwot, SM = extract_SM_from_pwot(pwot)
            assert SM and pwot.size, (case, vehnum, SM, pwot)
            pwot_node = vehdb.vehnode(vehnum, wot_group_suffix)
            if not skip_h5_write:
                h5db.put(pwot_node, pwot)
                vehdb.provenir_h5node(
                    h5db,
                    pwot_node,
                    title="Full-load-curve of the test-car, as delivered by Heinz on 13 May 2019",
                    files=[wots_excel[0]],
                    base=base,
                )

        if specs is not None and cycles is not None:
            cyc = cycles.loc[cycles[c_case_id] == case].set_index("tim")
            try:
                cyc, oprops = vehdb.drop_scalar_columns(cyc, scalar_columns)
            except Exception:
                display(case, vehdb.grid(cyc, fitcols=False))
                raise

            ## Store INP/OUT props
            #
            props = specs.loc[specs[c_case_id] == vehnum, :].squeeze()
            assert isinstance(props, pd.Series), props
            props.update(pd.Series(oprops))
            props[c_SM] = SM
            props_group = vehdb.vehnode(case, props_group_suffix)
            if not skip_h5_write:
                h5db.put(props_group, pd.Series(props))
                vehdb.provenir_h5node(
                    h5db,
                    props_group,
                    title="Input specs & scalar results produced by AccDB",
                    base=base,
                )

            ## Store CYCLE
            #
            cycle_group = vehdb.vehnode(case, cycle_group_suffix)
            if not skip_h5_write:
                h5db.put(cycle_group, cyc)
                vehdb.provenir_h5node(
                    h5db, cycle_group, title="Cycle-run produced by AccDB", base=base
                )

        ## Store OVERRIDES
        #
        if overrides is not None and case in overrides:
            overrides_group = vehdb.vehnode(case, overrides_group_suffix)
            if not skip_h5_write:
                h5db.put(overrides_group, pd.Series(overrides[case]))
                vehdb.provenir_h5node(
                    h5db,
                    overrides_group,
                    title="Values to override, as specified manually by Heinz",
                    files=[
                        "VehData/Differences between ACCESS tool versions 16_ and 20_09_2019.xlsx"
                    ],
                    base=base,
                )
Esempio n. 2
0
def grid(df):
    """Display a dynamic grid if given `df` too long. """
    display(vehdb.grid(df, fitcols=len(df.shape) < 2 or df.shape[1] < 12))
Esempio n. 3
0
# pmr_tm      rated_speed     ndv_3  ndv_9               v_max_1      v_max_7  f0        Pres_130         n_max3
# IDclass     idling_speed    ndv_4  ndv_10              v_max_2      v_max_8  f1        Pres_130_Prated  n_max_wot
# class       v_max_declared  ndv_5  v_max_transmission  v_max_3      v_max_9  f2        n95_low          below_s
#
# Index(['no_engine', 'n', 'Pwot', 'Twot', 'Pwot_norm', 'Twot_norm', 'SM', 'ASM',
#        'Pavai'],
#       dtype='object')
# ```

# %%
import qgrid

print(columnize(list(specs.columns), displaywidth=160))
print(pwots.columns)
print(specs[c_vehnum].unique(), specs[c_case].unique())
display(vehdb.grid(specs, fitcols=False), vehdb.grid(pwots))


# %%
def extract_SM_from_pwot(
    pwot, c_n=c_n, c_pwot=c_pwot, c_SM=c_SM, c_ASM=c_ASM
) -> "Tuple(pd.DataFrame, float)":
    """
    Keep just (n, Pwot, ASM) columns & extract SM column as scalar value.

    :param pwot:
        the wot-curve dataframe for a single vehicle, with columns::

            IX	no_engine	n	Pwot	Twot	Pwot_norm	Twot_norm	SM	ASM	Pavai

    :return:
Esempio n. 4
0
p1, c1, p2, c2 = load_accdb_and_python_datasets()

# %%
## EXPORT RESULTS to upload them for the GS-group when releasing.
#
# p2.drop('v116', axis=0).to_excel('pyalgo-props-124cases-1.0.0.dev12.xlsx')
# c2.drop('v116', axis=0).to_excel('pyalgo-cycles-124cases-1.0.0.dev12.xlsx')

# %%
# Available PROPs
print(columnize(list(p1.columns), displaywidth=160))
print(columnize(list(p2.columns), displaywidth=160))

# %%
display(
    vehdb.grid(p1, fitcols=False),
    vehdb.grid(p2, fitcols=False),
    # vehdb.grid(c1, fitcols=0),
)

# %%
sr_cmpr = vehdb.Comparator(lambda d, c: d[:, c], no_styling=True)
dataset_names = "accdb Python".split()  # Must sort with "diff" column.

# %%
## Report PROP differences
#
#     ACCDB,  PYALGO
equivalent_columns = [
    ("Description", None),
    ("test_mass", None),