Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add cost and time estimates as well #31

Open
shankari opened this issue Dec 16, 2021 · 16 comments
Open

Add cost and time estimates as well #31

shankari opened this issue Dec 16, 2021 · 16 comments

Comments

@shankari
Copy link
Contributor

We want to add simple cost and time estimates to assess the broader impacts of programs.
We will do so by creating simple distance-based maps for each metric - e.g.

cost_per_mile = { "drove_alone": ..., "shared_ride": ...., "pilot_ebike": ....
}

We can then compute the overall impact of the metric by pseudo code similar to:

for trip in trips:
    cost_impact_trip = (cost_per_mile[“ebike”] – cost_per_mile[trip.replaced_mode]) * trip.length_in_miles
    cost_impact_trips.append(cost_impact_trip)

cost_impact_overall = sum(cost_impact_trips)

Of course, we could also use pandas if that works better - e.g. something like:

cost_impact_trips = trips.apply(lambda trip_row: (cost_per_mile["ebike"] - cost_per_mile[trip_row.replaced_mode]) * trip_row.length__in_miles
cost_impact_overall = cost_impact_trips.sum()
@styoung3
Copy link
Contributor

Is it a requirement that I have mongodb installed on my local machine in order to access the data?
If so, is it possible to install mongodb without administrator privileges?
If administrator privileges are required, how do I obtain them?

@shankari
Copy link
Contributor Author

shankari commented Dec 16, 2021

@styoung3 the data is a mongodump, so you do need to have mongodb installed.

The instructions (docker-compose.yml) in the README will create a mongodb docker container running on your local machine. You can then load the data using a script, as outlined in the README as well.

docker is authorized by IT; you can file a ticket to have it installed on your laptop.

@styoung3
Copy link
Contributor

styoung3 commented Jan 5, 2022

Attempting to use the load_mongodump.sh helper script. It claims the file doesn't exist, but I can see it exists in my directory. Any idea why this is happening? I am operating in the dark here.

em-public-dashboard % ls
LICENSE docker-compose.dev.yml
OpenSourceLicenses.md frontend
README.md plots
canbikeco_mongodump_participant_only_jan_31_2021.tar.gz viz_scripts

em-public-dashboard % bash viz_scripts/docker/load_mongodump.sh canbikeco_mongodump_participant_only_jan_31_2021.tar.gz
Restoring the dump from canbikeco_mongodump_participant_only_jan_31_2021.tar.gz
tar: canbikeco_mongodump_participant_only_jan_31_2021.tar.gz: Cannot open: No such file or directory
tar: Error is not recoverable: exiting now

@shankari
Copy link
Contributor Author

shankari commented Jan 5, 2022

The tar error is coming from the container. It looks like the file is not copied correctly? I can take a look, but if you want to debug,

docker container list

to find the container name, and then

docker exec -it <container_name> /bin/bash

to access the container's shell

@shankari
Copy link
Contributor Author

shankari commented Jan 5, 2022

This is because the step to copy the file into the container is commented out!?!?
https://github.com/e-mission/em-public-dashboard/blob/main/viz_scripts/docker/load_mongodump.sh#L4

@shankari
Copy link
Contributor Author

shankari commented Jan 5, 2022

I commented it out in 73b9daf but I was wrong. We can pass in the value as an environment variable, but we still need to copy it first!!

@shankari
Copy link
Contributor Author

shankari commented Jan 5, 2022

@styoung3 can you restore that line, confirm that it works and then submit a pull request?

@styoung3
Copy link
Contributor

Calculating $/PMT for 'Car, drove alone', 'Car, with others', and 'Taxi/Uber/Lyft' using average fuel economy from here: https://afdc.energy.gov/data/10310 and average gas prices from here: https://gasprices.aaa.com/state-gas-price-averages/. Assuming regular gas type, and divide by two for 'Car, with others'. This is simplified but functional for now.

@shankari
Copy link
Contributor Author

shankari commented Jan 13, 2022

@styoung3 there are actually calculators for mileage that take maintenance etc into account in addition to the fuel costs. We should also account for the drivers' salary for taxi/uber/lyft. Given US labor costs, that is likely to be much larger than the fuel costs.

I would suggest that you understand the existing code and write the unit tests first and then we can discuss what the actual values for cost and time should be (I have some references).

@styoung3
Copy link
Contributor

styoung3 commented Jan 13, 2022

How do I run my unit_tests.py script inside the docker environment? I am getting an error when I attempt to run it from visual studio code (see below). Another way of asking this is, is there another way to edit and run code in the docker environment than just Jupyter Notebooks? It looks like I can run a terminal through Jupyter Notebook actually. Nice!

Error Message

Traceback (most recent call last):
File "/Users/syoung3/GitHub/em-public-dashboard/viz_scripts/unit_tests.py", line 14, in
import scaffolding
File "/Users/syoung3/GitHub/em-public-dashboard/viz_scripts/scaffolding.py", line 4, in
import emission.storage.timeseries.abstract_timeseries as esta
ModuleNotFoundError: No module named 'emission'

@shankari
Copy link
Contributor Author

shankari commented Jan 13, 2022

@styoung3 If you want to run scripts inside the docker container from outside, you need to use docker run.
Please check the docker documentation for details.
viz_scripts/run_from_host/ has some examples, notably generate_plots.sh

Again, you may want to read up a bit more on what containerization means and how it works.

@shankari
Copy link
Contributor Author

For the cost estimates, we want to use the cost to the user. So this should take into account fuel, but also maintenance etc

  • For private car (shared_ride and drove_alone), I suggest that we use the Federal reimbursement rate
  • For transit, we use the value from MEP (0.855 $/PMT and make sure to cite them or the FTA)
  • For taxi/uber/lyft, we can use the value from Alejandro's paper below, which is apparently 2.50 $/PMT, including fare, fees, tools and gratuity.
  • For walk, we can assume that the cost is 0
  • For bike, e-bike and e-scooter, please ask @andyduvall for values

Alejandro Henao, Wesley E. Marshall,
An analysis of the individual economics of ride-hailing drivers,
Transportation Research Part A: Policy and Practice,
Volume 130,
2019,
Pages 440-451,
ISSN 0965-8564,
https://doi.org/10.1016/j.tra.2019.09.056.
(https://www.sciencedirect.com/science/article/pii/S0965856419300333)

@shankari
Copy link
Contributor Author

shankari commented Jan 18, 2022

For time estimates, given that we cannot capture wait times, parking times, or times to drop off passengers in the pool (if any), we thought that we could use average speeds for other trips using the replaced mode.

So you would calculate the speeds for trips in the dataset labeled drove_alone, take the mean/median and use that to multiply the distance to get the "replaced_time".

Please write a separate function to compute the mean/median speeds. We can then think about whether we should compute these weekly or compute them once and then keep them constant.

@shankari
Copy link
Contributor Author

shankari commented Jan 25, 2022

To refactor the existing impact code, I would suggest something like:

def energy_impact(x,y,color,plot_title,file_name):
    display_impact(x,y,color,plot_title,file_name, ('Energy Savings', 'Energy Loss'), 'Energy_Impact(kWH)')
def CO2_impact(x,y,color,plot_title,file_name):
    display_impact(x,y,color,plot_title,file_name, ('CO2 Reduction', 'CO2 Increase'), 'CO2 Emissions (lb)')
def display_impact(x,y,color,plot_title,file_name, objects,x_label):
   # existing implementation of CO2_impact with the following changes
   # remove line 323 (objects = ('CO2 Reduction', 'CO2 Increase') since it is now a parameter)
   # change line 330 to ax.set_xlabel(x_label, fontsize=18)

There's even more potential fixes to make the display_impact parameters more meaningful. For example, change it to

def display_impact(x,y,color,plot_title,file_name, metric,units):
   # construct the objects and the x_label from the metric (CO2/Energy) and the units (kWH/lbs)

@styoung3
Copy link
Contributor

styoung3 commented Jan 25, 2022

How do I import the scaffolding file as a module in the tests files that are in a separate directory?

viz_scripts
 |_ scaffolding.py
 |_ unit_tests
    |_ Test.py

https://blog.finxter.com/python-how-to-import-modules-from-another-folder/ says I can do dot notation using __init__.py, but I can't get it to work.

@shankari
Copy link
Contributor Author

@styoung3 what error do you get?
I import the emission modules into emission/test Test* all the time and it works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants