Code to help create routes for Troop51's annual mulch sale
http://tinyurl.com/troop51mulch goes to http://soulcubes.com/medcafe/index.html
- Open in LibreOffice Calc or Microsoft Excel
- Delete all rows from the last order to the end
- Delete the first row
- (optional, but good practice) Delete all columns after column O. This ensures the commas all show up for the step1 parsing
- Fill out junk content in all rows in column O - this is discarded by the code, but is needed to make easy parsing of the rows possible. I just copy the # down.
- Delete any pure donation rows (where there's no address). You'll have to copy and "paste special" over all the order numbers to paste in the values, not the formulas
- Save as CSV file with Tab delimiter and no text delimiter. Check for non-ASCII characters (slanted ' seem to be popular). If you have a text editor that you can specify the character set in, set it to US-ASCII and it'll hunt down all the weird characters for you
Need to import pygmaps: export PYTHONPATH=/home/jchoyt/devel/boyscouts/pygmaps-0.1.1
processOrders has two stages. First stage checks and caches all addresses: python step1.py Mulch_Sale_2015.csv
- After all orders are in, redirect the step 1 output to a csv file:
python step1.py Mulch_Sale_2016.csv > 2016routes.csv
- Clean up any extraneous output at the top of the file. All that should be there is a set of tab-delimted tuples
- Open in LibreCalc or Excel and make sure it cleanly separated the columns. Columns should be order no, last name, first name, phone number, neighborhood, street address, city, state, zip, comments, number of bags
- Add the analysis section at the bottom using a previous year's YEARroutes.ods spreadsheet. Modify all the formulas to account for different number of orders from year to year.
- Column L will hold the order number. Put orders which are physically close together on the same order. Use the analysis section at the bottom to show how many bags are in the order you are currently working on. The goal is to hit 320 +/- 5 bags for every order. Each 26' truck holds 7 pallets and each pallet holds 45 bags, and extra bags on a truck is preferred (except for the first route for each truck - those are already loaded). Protip: use the split screen to have the analysis section at the bottom always visible while assigning deliveries to routes. That makes it easy to track how many bags the current route has.
- Work step 5 from the outliers into the center of mass for all the deliveries. Kinda spiral in from the outside to the center as you assign routes. This makes for some ugly routes which can be done early in the day when traffic is lighter.
- Use http://routexl.com to create "shortest drive times" and "estimated drive times". Use the import button to copy/paste all the addresses for a single route and paste in the church. Once the addresses are all imported, set the church as the start AND end and let it generate the drive times. You'll have to modify slightly - put yourself in the mindset of someone who's running the routes and think about how you'd like to do them. I tend to make sure as many deliveries happen off the right side of the truck and minimize back tracking (that is, deliver off the left and right side as the truck progresses down the street). Minimize turns when possible. Record drive times on the "routes" page of the spreadsheet
- Estimate total route time by adding drive time and x bags per minute delivery. Historically 6.0 has been a good number, but I think 5.75 will be better next year, especially if we share that with the drivers. Three of 5 drivers beat that in 2016.
- Assign routes to trucks by estimating who the best drivers will be and giving them the longer routes (not all the longest - that will piss them off and they won't come back next year). But bias it towards the stronger drivers getting the less easy routes. Inevitably there will be a route you'll have to chop up at the end of the day to get everyone done as close to the same time as possible, but you can minimize it.
- Export the routes page to a csv file. Tab delimited, no text delimiters. Clean up the csv file so only routes are in the file
- Second step generates the route html pages. You have to adjust the comments at the bottom of the files. mkdir routes ./step2.py 2016routes.csv
- Use your browser to print all the html files as pdf
- Use ghost script to combine them into one big pdf for easy printing
ghostscript -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite -sOutputFile=finished.pdf rout*
- Print two copies of each route. Copy 1 will be split out for each driver/navigator. Copy 2 is backup for the yard.
- Print large master sheet on 11x17 or legal size paper
- Print a Truck Progress sheet so you can track which route a truck is doing and when you can expect them back
- in 2016, I gave a copy of the Truck Progress sheet to all the drivers - they actually filled them all out!