7
7
import sys
8
8
sys .path .append (os .path .abspath (os .path .join (os .path .dirname (__file__ ), '..' , 'pyloghub' )))
9
9
from save_to_platform import save_scenario_check , create_button
10
- from input_data_validation import convert_dates , validate_and_convert_data_types
10
+ from input_data_validation import convert_dates , validate_and_convert_data_types , convert_to_float , convert_df_to_dict_excluding_nan
11
11
from sending_requests import post_method , create_headers , create_url , get_workspace_entities
12
12
13
13
def forward_freight_shipment_emissions_road (addresses : pd .DataFrame , parameters : dict , api_key : str , save_scenario = {}, show_buttons = False ) -> Optional [Tuple [pd .DataFrame , pd .DataFrame ]]:
@@ -33,11 +33,12 @@ def forward_freight_shipment_emissions_road(addresses: pd.DataFrame, parameters:
33
33
- toCity (str): City name of the address to which a shipment should arrive at.
34
34
- toStreet (str): Street name with house number of the address to which a shipment should arrive at.
35
35
- isRefrigirated (str): A YES/NO option that specifies whether the content being transferred through the shipments is refrigirated or not. If not specified will be taken as NO.
36
+ -distance: Distance between sender and recipient. It will be calculated if not provided.
36
37
- weight (number): The weight of the shipment.
37
38
38
39
parameters (dict): A dictionary containing parameters:
39
40
- vehicleType: "van(0-3.5)", "truck", "truckUrbanTruck", "truckMGV", "truckHGV", "truckRigid(3.5-7.5)", "truckRigid(7.5-12)", "truckRigid(12-20)" , "truckRigid(20-26)", "truckRigid(26-32)", "truckArticulated(3.5-34)", "truckArticulated(34-40)", "truckArticulated(40-44)", "truckArticulated(44-60)", "truckArticulated(60-72)", "truckGeneral", "truckAutoCarrier", "truckDray", "truckExpedited", "truckFlatbed", "truckHeavybulk", "truckLTL", "truckMixed", "truckMoving", "truckPackage", "truckSpecialized", "truckTanker" or "truckTL"
40
- - fuelType: enum "diesel", "petrol", "hybrid", " CNG", "LPG", "pluginHybrid ", "electricity" or "other"
41
+ - fuelType: enum "diesel", "petrol", "CNG", "LPG", "electricity" or "other"
41
42
- weightUnit: enum "kilograms" or "lbs"
42
43
- emissionStandard: enum "EURO_5" or :EURO_6"
43
44
@@ -60,13 +61,16 @@ def create_buttons():
60
61
61
62
addresses_mandatory_columns = {'shipmentId' : 'str' , 'shipmentDate' : 'str' , 'fromCountry' : 'str' , 'toCountry' : 'str' , 'weight' : 'float' }
62
63
addresses_optional_columns = {'fromState' : 'str' , 'fromPostalCode' : 'str' , 'fromCity' : 'str' , 'fromStreet' : 'str' , 'toState' : 'str' , 'toPostalCode' : 'str' , 'toCity' : 'str' , 'toStreet' : 'str' , 'isRefrigirated' : 'str' }
64
+ addresses_optional_floats = ['distance' ]
63
65
64
66
# Validate and convert data types
65
67
addresses = validate_and_convert_data_types (addresses , addresses_mandatory_columns , 'mandatory' , 'addresses' )
66
68
if not addresses is None :
67
69
addresses = validate_and_convert_data_types (addresses , addresses_optional_columns , 'optional' , 'addresses' )
68
- if not addresses is None :
69
- addresses = convert_dates (addresses , ['shipmentDate' ])
70
+ if not addresses is None :
71
+ addresses = convert_dates (addresses , ['shipmentDate' ])
72
+ addresses = convert_to_float (addresses , addresses_optional_floats , 'optional' )
73
+ addresses = convert_df_to_dict_excluding_nan (addresses , addresses_optional_floats )
70
74
if addresses is None :
71
75
return None
72
76
@@ -75,7 +79,7 @@ def create_buttons():
75
79
headers = create_headers (api_key )
76
80
77
81
payload = {
78
- 'freightShipmentEmissionsByRoad' : addresses . to_dict ( orient = 'records' ) ,
82
+ 'freightShipmentEmissionsByRoad' : addresses ,
79
83
'parameters' : parameters
80
84
}
81
85
payload = save_scenario_check (save_scenario , payload )
@@ -95,7 +99,7 @@ def create_buttons():
95
99
def forward_freight_shipment_emissions_road_sample_data ():
96
100
warnings .simplefilter ("ignore" , category = UserWarning )
97
101
data_path = os .path .join (os .path .dirname (__file__ ), 'sample_data' , 'CO2RoadAddresses.xlsx' )
98
- addresses_df = pd .read_excel (data_path , sheet_name = 'addresses' , usecols = 'A:O ' ).fillna ("" )
102
+ addresses_df = pd .read_excel (data_path , sheet_name = 'addresses' , usecols = 'A:P ' ).fillna ("" )
99
103
parameters = {
100
104
"vehicleType" : "truck" ,
101
105
"fuelType" : "diesel" ,
@@ -128,11 +132,12 @@ def reverse_freight_shipment_emissions_road(coordinates: pd.DataFrame, parameter
128
132
- toLatitude (number): The latitude of the coordinate to which a shipment should arrive at.
129
133
- toLongitude (numebr): The longitude of the coordinate to which a shipment should arrive at.
130
134
- isRefrigirated (str): A YES/NO option that specifies whether the content being transferred through the shipments is refrigirated or not. If not specified will be taken as NO.
135
+ - distance: Distance beteen sender and recipient. It will be calculated if not provided.
131
136
- weight (number): The weight of the shipment.
132
137
133
138
parameters (dict): A dictionary containing parameters:
134
139
- vehicleType: "van(0-3.5)", "truck", "truckUrbanTruck", "truckMGV", "truckHGV", "truckRigid(3.5-7.5)", "truckRigid(7.5-12)", "truckRigid(12-20)" , "truckRigid(20-26)", "truckRigid(26-32)", "truckArticulated(3.5-34)", "truckArticulated(34-40)", "truckArticulated(40-44)", "truckArticulated(44-60)", "truckArticulated(60-72)", "truckGeneral", "truckAutoCarrier", "truckDray", "truckExpedited", "truckFlatbed", "truckHeavybulk", "truckLTL", "truckMixed", "truckMoving", "truckPackage", "truckSpecialized", "truckTanker" or "truckTL"
135
- - fuelType: enum "diesel", "petrol", "hybrid", " CNG", "LPG", "pluginHybrid ", "electricity" or "other"
140
+ - fuelType: enum "diesel", "petrol", "CNG", "LPG", "electricity" or "other"
136
141
- weightUnit: enum "kilograms" or "lbs"
137
142
- emissionStandard: enum "EURO_5" or :EURO_6"
138
143
@@ -155,21 +160,24 @@ def create_buttons():
155
160
156
161
coordinates_mandatory_columns = {'shipmentId' : 'str' , 'shipmentDate' : 'str' , 'fromLatitude' : 'float' , 'fromLongitude' : 'float' , 'toLatitude' : 'float' , 'toLongitude' : 'float' , 'weight' : 'float' }
157
162
coordinates_optional_columns = {'isRefrigirated' : 'str' }
163
+ coordinates_optional_floats = ['distance' ]
158
164
159
165
# Validate and convert data types
160
166
coordinates = validate_and_convert_data_types (coordinates , coordinates_mandatory_columns , 'mandatory' , 'coordinates' )
161
167
if not coordinates is None :
162
168
coordinates = validate_and_convert_data_types (coordinates , coordinates_optional_columns , 'optional' , 'coordinates' )
163
- if not coordinates is None :
164
- coordinates = convert_dates (coordinates , ['shipmentDate' ])
169
+ if not coordinates is None :
170
+ coordinates = convert_dates (coordinates , ['shipmentDate' ])
171
+ coordinates = convert_to_float (coordinates , coordinates_optional_floats , 'optional' )
172
+ coordinates = convert_df_to_dict_excluding_nan (coordinates , coordinates_optional_floats )
165
173
if coordinates is None :
166
174
return None
167
175
url = create_url ("reverseco2emissionsroad" )
168
176
169
177
headers = create_headers (api_key )
170
178
171
179
payload = {
172
- 'freightShipmentEmissionsByRoad' : coordinates . to_dict ( orient = 'records' ) ,
180
+ 'freightShipmentEmissionsByRoad' : coordinates ,
173
181
'parameters' : parameters
174
182
}
175
183
payload = save_scenario_check (save_scenario , payload )
@@ -189,7 +197,7 @@ def create_buttons():
189
197
def reverse_freight_shipment_emissions_road_sample_data ():
190
198
warnings .simplefilter ("ignore" , category = UserWarning )
191
199
data_path = os .path .join (os .path .dirname (__file__ ), 'sample_data' , 'CO2RoadReverse.xlsx' )
192
- coordinates_df = pd .read_excel (data_path , sheet_name = 'coordinates' , usecols = 'A:I ' ).fillna ("" )
200
+ coordinates_df = pd .read_excel (data_path , sheet_name = 'coordinates' , usecols = 'A:J ' ).fillna ("" )
193
201
parameters = {
194
202
"vehicleType" : "truck" ,
195
203
"fuelType" : "diesel" ,
0 commit comments