DAWN.COM

Today's Paper | December 22, 2024

Updated 26 Jul, 2023 12:58pm

Tired of getting stuck in rush hour traffic? Here’s how you can beat it with data

“I leave at 8am on the dot, leave a minute later and you’ll get stuck at the Drigh Road intersection.”

“8am might just be too late, or too early if you ask me. Leave at 9am if you want to avoid getting stuck near Baloch Colony Flyover — yes you’ll reach the office late but at least you won’t have to deal with traffic”.

If this lunchtime banter seems familiar to you, then you’re probably one of the millions of Karachiites required to commute for work. Waking up, getting dressed and going to work has always been considered part and parcel of working a corporate job — that is until Covid-19 hit.

I remember it was sometime around the middle of March 2020 when people in Pakistan started to take the pandemic seriously, which in turn resulted in hundreds, if not thousands, of companies across the country mandating work from home for their employees.

Covid-19 was a terrible thing for a great many people, who lost jobs and loved ones, but for the vast majority of ‘corporate drones’ such as myself, it meant you did not have to wake up absurdly early for work, or iron your clothes or spend money on fuel. Yes, it took a bit of adjusting and getting used to but it ultimately meant more time for yourself during a day and a break from aggressively negotiating for space on Sharea Faisal or University Road.

“What about you, Hisham? When do you think you’ll find the least amount of traffic?” I was asked. I did not want to answer this question, partially because I did not know the answer and partially because I was too focused on the plate of biryani in front of me.

But the gears in my head were turning — what time should I leave home to avoid traffic on Sharea Faisal? And what time should I leave the office to get home quicker? I decided to put my background in data analytics to use and develop a more empirical method to find out.

A Google Maps study

The Google Maps platform comes with a collection of application programming interfaces (API) that let you programmatically access the features in the platform. One of these is the Distance Matrix API. When you use Google Maps on your phone, you input your destination and current location, and you get the route you need to follow on a map, along with the time it will take you to get to that location.

You might also notice how the estimated time of arrival (ETA) varies by time of day. I will not get into the full set of features offered by different APIs of the Google Maps platform, but what is important is that the Distance Matrix API allows you send inputs to Google Maps for a departure time in the future and gives you back the route and ETA based on your input time, origin location, and destination. The ETA is modelled on historic location data captured and aggregated by Google, and not the actual traffic conditions at the time you leave (since it is still in the future).

I wrote some code that asked Google Maps for the time required for me to get to work, for each five minute interval between 7:30am and 11am. What follows are the results from this experiment.

Let’s assume I live in Malir and my place of work is at Avari Towers near Saddar. This is what my commute looks like:

Morning commute

If we plot the time required to get to work from Monday to Saturday, this is what it looks like:

This visualisation gives us a sense of peak traffic times by day-of-week. The y-axis (vertical) has the time in minutes to get to my destination (in this case my workplace), based on the x-axis (horizontal), which represents the time I would hypothetically leave home.

We can observe a visible peak between 8:20-8:25am for most weekdays. For example, if I leave at 8:25am on a Tuesday I would have to spend 42 minutes in traffic. Whereas, if I leave any time between 9-9:30am on the same day, I’ll spend 36 to 33 minutes in traffic.

The only noticeable divergence from the overall trend is Saturday (should God forbid, you work on Saturdays), where there’s a steady decrease in travel time.

The line chart above looks a bit crowded, and might be difficult to read — so let’s create a heat map of the data.

In this visualisation, each column is one weekday (excluding Saturday) and each row indicates the time at which you leave home. The colour range from blue to red represents commute time in minutes, where red is high and blue is low.

Our initial findings are only reinforced here — leaving anytime between 8:10-8:50am is less than ideal. There are two additional interesting insights here:

  1. Tuesday is more traffic-heavy than Monday, which seems a bit counter-intuitive since Monday morning commutes seem to be the worst. Perhaps this is more psychological than anything else.

  2. There is very less traffic on Thursdays. While I expected the Friday traffic load to be low, since many markets remain closed or open late, and some workers are allowed to work from home, I did not expect light traffic on Thursday.

Evening commute

Driving to work is only part of what makes us miserable, driving back home after work is equally painful. Here I ran the same experiment but switched the origin and destination locations, and the time range to 5-8pm.

This line chart gives us one single message: leave work at 8:30pm. However, since most of us like to have a life after an eight-hour-workday, this would be less than ideal. Another way to look at this chart would be to not leave between peak hour traffic, which is 6-7pm. That way you get to avoid the worst of it. Of course, in an ideal world leaving at 5pm on the dot would be the best course of action.

This heat map tells us that on Monday you will find horrible traffic on the way back, which which reinforces our initial finding — do not leave between 6-7pm, especially on a Monday.

A multiverse of mathematics

Based on this analysis, I can save between 20-25 per cent of my current commute time if I pick the right time to leave for and from work. This obviously does not account for the time it takes to get ready for work which can be easily between 40 minutes to one hour every day. Saving 15-20 minutes every day on one’s commute does not seem like a lot, but in order to understand the true impact of this — beyond the fatigue and bodily drain traffic itself causes — we need to zoom out and widen our perspective.

According to the Sindh Bureau of Statistics, there were 1.26 million registered motor vehicles in Karachi in 2020, the last year for which the data is publicly available. This includes cars, motorcycles, taxies, rickshaws, buses, trucks and other forms of motor transport — approximately 84pc of all motor vehicles registered in Sindh.

At the same time, 1.36m tons [1.23m tonnes] of motor spirits or petrol, and High Speed Diesel (HSD) was sold in Karachi for the same year. In the context of Sindh, this is 46pc of total fuel of motor spirits and HSD consumed in the province.

Let’s assume that 50pc, or 760,000 tons [689,320m tonnes], of all this fuel is consumed by motor vehicles when workers commute for work. A 20pc reduction in travel time would, therefore, directly affect the consumption of 760,000 tons of fuel.

If we conservatively estimate that car idling, and generally a lower fuel average caused by constant braking, lower speed, has an impact of 10pc on fuel consumed during our commute, this amounts to 76,000 tons [68,932 tonnes] of fuel, which can be saved simply through better traffic and transport management in Karachi alone. Now apply the same working nationally, and we can potentially save a considerable amount of foreign exchange that we currently burn (quite literally) on fuel imports.

At a more personal level, suppose I spend Rs40,000 a month on fuel, of which 80pc I can safely say is spent on commuting. This comes to Rs32,000.

If I save 10pc of this amount every month, I am easily saving Rs3,200. Now add that up for every month in the year and I am saving around Rs40,000 annually — which is enough money to feed and cloth a small family for a month!


If you have basic coding skills and want to replicate this experiment, you can follow this step-by-step tutorial here:https://medium.com/@hishamsajid113


Header illustration: Shutterstock

Read Comments

Shocking US claim on reach of Pakistani missiles Next Story