Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitf67210c

Browse files
changed sample data and data validation in road mode
1 parent7f0aadf commitf67210c

File tree

5 files changed

+21
-25
lines changed

5 files changed

+21
-25
lines changed

‎pyloghub/freight_shipment_emissions_air.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,4 +101,4 @@ def forward_freight_shipment_emissions_air_sample_data():
101101
'workspaceId':'Your workspace id',
102102
'scenarioName':'Your scenario name'
103103
}
104-
return {'iataCodes':iata_codes_df,'parameters':parameters,'saveScenarioParameters':save_scenario}
104+
return {'iataCodes':iata_codes_df,'parameters':parameters,'saveScenarioParameters':save_scenario}

‎pyloghub/freight_shipment_emissions_road.py‎

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
importsys
88
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__),'..','pyloghub')))
99
fromsave_to_platformimportsave_scenario_check,create_button
10-
frominput_data_validationimportconvert_dates,validate_and_convert_data_types
10+
frominput_data_validationimportconvert_dates,validate_and_convert_data_types,convert_to_float,convert_df_to_dict_excluding_nan
1111
fromsending_requestsimportpost_method,create_headers,create_url,get_workspace_entities
1212

1313
defforward_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:
3333
- toCity (str): City name of the address to which a shipment should arrive at.
3434
- toStreet (str): Street name with house number of the address to which a shipment should arrive at.
3535
- 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.
3637
- weight (number): The weight of the shipment.
3738
3839
parameters (dict): A dictionary containing parameters:
3940
- 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"
4142
- weightUnit: enum "kilograms" or "lbs"
4243
- emissionStandard: enum "EURO_5" or :EURO_6"
4344
@@ -60,13 +61,16 @@ def create_buttons():
6061

6162
addresses_mandatory_columns= {'shipmentId':'str','shipmentDate':'str','fromCountry':'str','toCountry':'str','weight':'float'}
6263
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']
6365

6466
# Validate and convert data types
6567
addresses=validate_and_convert_data_types(addresses,addresses_mandatory_columns,'mandatory','addresses')
6668
ifnotaddressesisNone:
6769
addresses=validate_and_convert_data_types(addresses,addresses_optional_columns,'optional','addresses')
68-
ifnotaddressesisNone:
69-
addresses=convert_dates(addresses, ['shipmentDate'])
70+
ifnotaddressesisNone:
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)
7074
ifaddressesisNone:
7175
returnNone
7276

@@ -75,7 +79,7 @@ def create_buttons():
7579
headers=create_headers(api_key)
7680

7781
payload= {
78-
'freightShipmentEmissionsByRoad':addresses.to_dict(orient='records'),
82+
'freightShipmentEmissionsByRoad':addresses,
7983
'parameters':parameters
8084
}
8185
payload=save_scenario_check(save_scenario,payload)
@@ -95,7 +99,7 @@ def create_buttons():
9599
defforward_freight_shipment_emissions_road_sample_data():
96100
warnings.simplefilter("ignore",category=UserWarning)
97101
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("")
99103
parameters= {
100104
"vehicleType":"truck",
101105
"fuelType":"diesel",
@@ -128,11 +132,12 @@ def reverse_freight_shipment_emissions_road(coordinates: pd.DataFrame, parameter
128132
- toLatitude (number): The latitude of the coordinate to which a shipment should arrive at.
129133
- toLongitude (numebr): The longitude of the coordinate to which a shipment should arrive at.
130134
- 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.
131136
- weight (number): The weight of the shipment.
132137
133138
parameters (dict): A dictionary containing parameters:
134139
- 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"
136141
- weightUnit: enum "kilograms" or "lbs"
137142
- emissionStandard: enum "EURO_5" or :EURO_6"
138143
@@ -155,21 +160,24 @@ def create_buttons():
155160

156161
coordinates_mandatory_columns= {'shipmentId':'str','shipmentDate':'str','fromLatitude':'float','fromLongitude':'float','toLatitude':'float','toLongitude':'float','weight':'float'}
157162
coordinates_optional_columns= {'isRefrigirated':'str'}
163+
coordinates_optional_floats= ['distance']
158164

159165
# Validate and convert data types
160166
coordinates=validate_and_convert_data_types(coordinates,coordinates_mandatory_columns,'mandatory','coordinates')
161167
ifnotcoordinatesisNone:
162168
coordinates=validate_and_convert_data_types(coordinates,coordinates_optional_columns,'optional','coordinates')
163-
ifnotcoordinatesisNone:
164-
coordinates=convert_dates(coordinates, ['shipmentDate'])
169+
ifnotcoordinatesisNone:
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)
165173
ifcoordinatesisNone:
166174
returnNone
167175
url=create_url("reverseco2emissionsroad")
168176

169177
headers=create_headers(api_key)
170178

171179
payload= {
172-
'freightShipmentEmissionsByRoad':coordinates.to_dict(orient='records'),
180+
'freightShipmentEmissionsByRoad':coordinates,
173181
'parameters':parameters
174182
}
175183
payload=save_scenario_check(save_scenario,payload)
@@ -189,7 +197,7 @@ def create_buttons():
189197
defreverse_freight_shipment_emissions_road_sample_data():
190198
warnings.simplefilter("ignore",category=UserWarning)
191199
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("")
193201
parameters= {
194202
"vehicleType":"truck",
195203
"fuelType":"diesel",

‎pyloghub/freight_shipment_emissions_sea.py‎

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -102,16 +102,4 @@ def forward_freight_shipment_emissions_sea_sample_data():
102102
'workspaceId':'Your workspace id',
103103
'scenarioName':'Your scenario name'
104104
}
105-
return {'unLocodes':un_locodes_df,'parameters':parameters,'saveScenarioParameters':save_scenario}
106-
107-
108-
if__name__=="__main__":
109-
110-
sample_data=forward_freight_shipment_emissions_sea_sample_data()
111-
locodes_df=sample_data['unLocodes']
112-
parameters=sample_data['parameters']
113-
save_scenario=sample_data['saveScenarioParameters']
114-
115-
api_key_dev="2c010d62ff7508c3e5362126ca22ed859eb68ddd"
116-
117-
df=forward_freight_shipment_emissions_sea(locodes_df,parameters,api_key_dev,save_scenario)
105+
return {'unLocodes':un_locodes_df,'parameters':parameters,'saveScenarioParameters':save_scenario}
-5 Bytes
Binary file not shown.
115 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp