# -*- coding: utf-8 -*-
#
# Copyright (c) 2021 European Union;
# Licensed under the EUPL, Version 1.2 or – as soon they will be approved by the European Commission
# – subsequent versions of the EUPL (the "Licence");
#
# You may not use this work except in compliance with the Licence.
# You may obtain a copy of the Licence at: https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12
"""
Functions and `dsp` model to load data from a GEARSHIFT input file.
Sub-Modules:
.. currentmodule:: gearshift.core.load
.. autosummary::
:nosignatures:
:toctree: load/
excel
"""
import io
import os
import logging
import pandas as pd
import schedula as sh
from .excel import parse_excel_file
log = logging.getLogger(__name__)
dsp = sh.BlueDispatcher(
name="load_inputs",
description="Loads from files the inputs for the GEARSHIFT model.",
)
# noinspection PyUnusedLocal
dsp.add_function(
function=parse_excel_file,
inputs=["input_file_name", "input_file"],
outputs=["raw_data"],
input_domain=check_file_format,
)
def _load_speed_phase_data():
"""
Load speed phase data
:return:
Speed phase data dict
:rtype: dict
"""
dir = os.path.dirname(__file__) + "/speed_phases/"
speed_phases_dict = {}
for file in os.listdir(dir):
name = file.split(".")[0]
data = pd.read_feather(dir + file, columns=None, use_threads=True)
speed_phases_dict[name] = data
return speed_phases_dict
[docs]@sh.add_function(dsp, inputs_kwargs=True, outputs=["data"])
def merge_data(raw_data):
"""
Merge raw data with the speed phases data
:param raw_data:
Raw input data.
:type raw_data: dict
:return:
Merged raw data
:rtype: dict
"""
speed_phase_data = _load_speed_phase_data()
data = {**speed_phase_data, **raw_data}
return data
@sh.add_function(dsp, inputs_kwargs=True, outputs=["base"])
def _validation(data):
base = data
return base