Skip to main content
  • Home
  • Development
  • Documentation
  • Donate
  • Operational login
  • Browse the archive

swh logo
SoftwareHeritage
Software
Heritage
Archive
Features
  • Search

  • Downloads

  • Save code now

  • Add forge now

  • Help

  • ece7ce6
  • /
  • source
  • /
  • evaluate_payload_vs_mileage.py
Raw File Download

To reference or cite the objects present in the Software Heritage archive, permalinks based on SoftWare Hash IDentifiers (SWHIDs) must be used.
Select below a type of object currently browsed in order to display its associated SWHID and permalink.

  • content
  • directory
content badge
swh:1:cnt:cf9b335fb10285c8de32202083afdd614b9a0df9
directory badge
swh:1:dir:fa5362aac1bafdd90967fcc63c7c01b393027131

This interface enables to generate software citations, provided that the root directory of browsed objects contains a citation.cff or codemeta.json file.
Select below a type of object currently browsed in order to generate citations for them.

  • content
  • directory
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
evaluate_payload_vs_mileage.py
"""
Date: March 25, 2024
Purpose: Evaluate the payload and energy economy for each drivecycle
"""

import payload_matching_tools
import data_collection_tools
import concurrent.futures
from datetime import datetime
import pandas as pd

KG_PER_TON = 1000
KG_PER_LB = 0.453592
SECONDS_PER_HOUR = 3600

###################################### Select drivecycles to consider #####################################
drivecycles = {
    'pepsi_1': [2, 9, 13, 15, 33],
    'pepsi_2': [7, 10, 14, 22, 25, 31],
    'pepsi_3': [8, 10, 13, 16, 21, 24, 28, 32, 33]
}
###########################################################################################################

# Function to evaluate matching payloads in parallel
def parallel_evaluate_matching_payload(args):

    # Wrapper function to call evaluate_matching_gvw with a specific combined_eff.
    # This is necessary because ProcessPoolExecutor.map only works with functions that take a single argument.
    
    # Unpack arguments
    truck_name, driving_event, parameters, battery_params_dict = args
    
    return payload_matching_tools.evaluate_matching_payload(truck_name, driving_event, parameters, battery_params_dict)

def main():
    parameters = data_collection_tools.read_parameters(truck_params='semi', vmt_params = 'daycab_vmt_vius_2021')
    parameters.m_max = 120000
    battery_params_dict = data_collection_tools.read_battery_params()

    evaluated_gvws_df = pd.DataFrame(columns=['Payload (lb)', 'Gross Vehicle Weight (lb)', 'Mileage (kWh/mi)'])
    for truck_name in drivecycles:
        drivecycle_events_list = drivecycles[truck_name]
        args_list = [(truck_name, driving_event, parameters, battery_params_dict) for driving_event in drivecycle_events_list]
        startTime = datetime.now()
        print(f'Processing {truck_name}')
        # Use ProcessPoolExecutor to parallelize the evaluation
        with concurrent.futures.ProcessPoolExecutor() as executor:
            results = list(executor.map(parallel_evaluate_matching_payload, args_list))
        
        # Assuming results are in the format expected, create a DataFrame
        evaluated_gvws_df = pd.concat([evaluated_gvws_df, pd.DataFrame(results, columns=['Payload (lb)', 'Gross Vehicle Weight (lb)', 'Mileage (kWh/mi)'])])
        run_time = datetime.now() - startTime
        run_time = run_time.total_seconds()
        print(f'Processing time for {truck_name}: {run_time}s')

    # Save the evaluated GVWs as a csv file
    filename = f'tables/payload_vs_mileage_semi.csv'
    
    evaluated_gvws_df.to_csv(filename, index=False)
    
    
if __name__ == '__main__':
    main()
    

back to top

Software Heritage — Copyright (C) 2015–2026, The Software Heritage developers. License: GNU AGPLv3+.
The source code of Software Heritage itself is available on our development forge.
The source code files archived by Software Heritage are available under their own copyright and licenses.
Terms of use: Archive access, API— Content policy— Contact— JavaScript license information— Web API