"""
To run this as a script that drives all the t3co files as a module:
    The working directory for this script should be at the same depth as the t3co/ module.
    Thus the scripts (run_scenario.py, etc.) will have a parent package and you won't get relative import errors.
    ex: run_one.__name__ will be "t3co.run_one"

    First step, generateinputs.generate(vocation)
    Create the files necessary such that run_scenario.run() can read information for Vehicle and Scenario object
    instantiation.

        tldr:
        generateinputs(vocation) -> gl.FASTSIM_INPUTS, gl.OTHER_INPUTS -> run_scenario.run(gl.FASTSIM_INPUTS, gl.OTHER_INPUTS)

        Generate Inputs (GI) first retrieves specific user generated information necessary to create
        two final product files used for TCO and optimization: gl.FASTSIM_INPUTS & gl.OTHER_INPUTS.

        (GI) gets the user generated information via the specified vocation and the following files:
        "t3co/resources/vehicles/{vocation}/specifications/BaselineVehicle.csv"
                                                       "...OptimizerInitializationValues.csv"
                                                       "...PowertrainTechTargets.csv"
                                                       "...VocationRequirements.csv"

        Note: the folder {vocation} must exist and be populated by the user beforehand.

        gl.FASTSIM_INPUTS & gl.OTHER_INPUTS are populated and stored in the default global locations that
        run_scenario.run() uses as default params - implying run() can use other FASTSIM_INPUTS & OTHER_INPUTS files
        if desired.

        Content of gl.FASTSIM_INPUTS and gl.OTHER_INPUTS:

            gl.FASTSIM_INPUTS content:
                # standard FASTSim input file header and rows
                selection,scenario_name,veh_pt_type,drag_coef,frontalAreaM2,glid...
                1.0,"Conv 2020 tech,  750 mi range",1.0,0.546,10.18,11776.0,0...
                2.0,"Conv 2025 tech,  750 mi range",1.0,0.5026666670000001,10...
                3.0,"Conv 2030 tech,  750 mi range",1.0,0.473125,10.18,11776....
                4.0,"Conv 2035 tech,  750 mi range",1.0,0.46,10.18,11776.0,0....

            gl.OTHER_INPUTS content:
                # all information necessary to determine vehicle TCO as well as performance targets
                selection,drive_cycle,vmt_reduct_per_yr,vmt,constant_trip_distance_mi,vehicle_life_yr,...,region,target_range_mi,min_speed_at_6pct_grade_in_5min_mph,min_speed_at_1p25pct_grade_in_5min_mph,max0to60secAtGV
                1.0,long_haul_cyc.csv,0.0,"[100000, 100000, 100000, 100000, 100000, 100000...United States,750.0,30.0,65.0,80.0,20.0
                2.0,long_haul_cyc.csv,,"[100000, 100000, 100000, 100000, 100000, 100000, 1...United States,750.0,30.0,65.0,80.0,20.0
                3.0,long_haul_cyc.csv,,"[100000, 100000, 100000, 100000, 100000, 100000, 1...United States,750.0,30.0,65.0,80.0,20.0
                4.0,long_haul_cyc.csv,,"[100000, 100000, 100000, 100000, 100000, 100000, 1...United States,750.0,30.0,65.0,80.0,20.0
                5.0,long_haul_cyc.csv,,"[100000, 100000, 100000, 100000, 100000, 100000, 1...United States,750.0,30.0,65.0,80.0,20.0

        default values for these files generated by generateinputs():
        gl.FASTSIM_INPUTS: ./t3co/resources/"FASTSimInputs.csv"
        gl.OTHER_INPUTS:   ./t3co/resources/"OtherInputs.csv"

        These files are populated in generateinputs.generate()
        FASTSimInputsDf.to_csv(dst/gl.FASTSIM_INPUTS_FILE, index=False)
        OtherInputsDf.to_csv(dst/gl.OTHER_INPUTS_FILE, index=False)

        where
        gl.FASTSIM_INPUTS_FILE = "FASTSimInputs.csv"
        gl.OTHER_INPUTS = "OtherInputs.csv"
        and
        dst is usually ./t3co/resources

        run() usage:
        run_scenario.run(veh_no, vocation, vehicle_input_path=gl.FASTSIM_INPUTS,
                     scenario_inputs_path=gl.OTHER_INPUTS,

    >>> print('running', __name__)
    >>> generateinputs.generate('Class8_long_haul')
    >>> use_jit = False
    >>> start = time.time()
    >>> res1 = run_scenario.run(1, 'Class8_long_haul', use_jit=use_jit)
    >>> print(f'classic time [s] {time.time()-start} | use jit? {use_jit}')
"""

import time

from t3co import run_scenario
from t3co import generateinputs

if __name__ == "__main__":
    # to regenerate inputs
    # if not Path('t3co/resources/FASTSimInputs.csv').exists():
    #     generateinputs.generate()
    generateinputs.generate('Class8_long_haul')
    use_jit = False
    start = time.time()
    res1 = run_scenario.run(1, 'Class8_long_haul', use_jit=use_jit)
    # res10 = run_one.run_one_scenario(10, use_jit=False)
    # res15 = run_one.run_one_scenario(15, use_jit=False)
    # res22 = run_one.run_one_scenario(22, use_jit=False)
    # res29 = run_one.run_one_scenario(29, use_jit=False)

    print(f'classic time [s] {time.time()-start} | use jit? {use_jit}')

    # start = time.time()
    # jres1 = run_one.run_one_scenario(1, use_jit=True)
    # # jres10 = run_one.run_one_scenario(10, use_jit=True)
    # # jres15 = run_one.run_one_scenario(15, use_jit=True)
    # # jres22 = run_one.run_one_scenario(22, use_jit=True)
    # # jres29 = run_one.run_one_scenario(29, use_jit=True)
    #
    # print(f'jit time [s] {time.time()-start}')
    #
    # print(res1['zero_to_30']==jres1['zero_to_30'])
    # print(res1['zero_to_60_loaded']==jres1['zero_to_60_loaded'])
    # print(res1['mpgge']==jres1['mpgge'])
    # print(res1['grade_6_mph_ach']==jres1['grade_6_mph_ach'])
    # print(res1['veh_cost_set']['msrp']==jres1['veh_cost_set']['msrp'])

    # 'disc_cost': disc_cost,
    # 'discounted_costs_df': discounted_costs_df,
    # 'mpgge': mpgge,
    # 'veh_cost_set': veh_cost_set,
    # 'sim_drive_record': sim_drive_record,
    # 'vehicle': vehicle,
    # 'vehicle_mass': vehicle_mass,
    # 'zero_to_60': zero_to_60,
    # 'zero_to_30': zero_to_30,
    # 'zero_to_60_loaded': zero_to_60_loaded,
    # 'zero_to_30_loaded': zero_to_30_loaded,
    # 'grade_6_mph_ach': grade_6_mph_ach,
    # 'grade_1_25_mph_ach': grade_1_25_mph_ach}