Combining Weather Data and Operation Performance to Improve Service Level Agreements
Published: 2023-04-25 14:09:14

Service Level Agreements (SLA) are a critical part of any business.  They serve several critical purposes.  Customers know what they can expect from a vendor in terms of quality, schedule, and what sort of uncertainty is acceptable.  SLA’s acknowledge that no one can provide perfect service; instead, that level of service should be discussed, agreed to, and penalties should be agreed upon well before a service obligation is not met.  They also allow the customer to express in writing what metrics are most important to them.  [Key SLA metrics](https://www.cio.com/article/274740/outsourcing-sla-definitions-and-solutions.html) can be many, and for each one agreed to there is an indirect price paid by the customer, as it means the vendor has to go to extra lengths to ensure the metric is met, avoiding penalties.

Uncertain events are the bane of SLA’s, and weather is a key contributor.  While there are ways to improve your internal business processes, such as [using Python to improve data pre-processing](https://dev.to/amelia19/python-for-business-optimize-pre-processing-data-for-decision-making-4d3b) and analyzing key metrics to ensure they are at the right levels, it can be difficult to track uncertain factors that are out of a business’ hands.  By using Python and pulling weather data for analysis, you can better understand what weather affects your SLA metrics, and can begin to improve the metrics themselves while gaining a better understanding of reasonable SLA with your customers.

### Using Weather API Data to Predict the Impact of Extreme Weather on Your SLA Metrics

This tutorial will walk through a very straightforward way to pull historical weather data, pre-process it, and align it with key metrics that reflect your SLA targets (on time deliveries, reliability, outages, etc.).  Because we are using Python, we can pull the weather data, input the SLA metrics, and create visualizations of their correlations all in the same script.  This can quickly help your team better understand weather impacts, which is critical for two reasons:  You can better optimize your SLA metrics around current and predicted weather events that you know may affect you, and you can better adjust your service level agreements in a way that reflect weather intrusions and show your customers that your SLA is more reliable.

#### Setup

This tutorial utilizes Python, along with the following libraries (shown in the screenshot) to collect and analyze historical weather data.  For this example we will [use Tomorrow.io’s Weather API call](https://www.tomorrow.io/weather-api/) as it has a vast amount of weather data available and has been designed for easy use.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/d2xw0fozgn4m4nm9rcv1.png)

#### Get/Input API Key

For this example we are using Tomorrow.io, so you will need to [sign up](https://www.tomorrow.io/weather-api/) to get your API key, then enter it at the prompt to gain access to the data.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/imx6p2h0rmfuxbqjrabo.png)

#### Select A Location of Interest

For a location there is some flexibility, as you can enter it as a Latlong pair, or you can either use a geometry attribute of a GeoJSON or you can use a “locationID”, which is pulled from a Locations API (more info on the locations format [here](https://docs.tomorrow.io/reference/api-formats#locations)).

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ahlb1zbi05tmfhmed63q.png)

#### List the Weather Fields of Interest

We will pull key weather metrics that most likely affect uptime, deliveries, and overall service, depending on your business.  These include:

1. Precipitation that has accumulated
2. Wind
- Speed
- Gust
- Direction
3. Snow accumulation

There are many other data points that can be pulled, with the details of each metric explained [here](https://docs.tomorrow.io/reference/historical).  However these should offer a glimpse at potential service interruption due to weather.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6qogqx52h9ctufhqlv1h.png)

#### Decide What Unit System to Use

This step is simple, you can select either metric or imperial measurements.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/i62blqqwo1wekuk05hfs.png)

#### Select The Timestep

For timesteps, you can select either  hourly or daily steps (1h and 1d).  However, it is helpful to know that this will pull the max value in that timestep, not the average.  You can add Min, Max, or Avg to the timestamp to specify (syntax [here](https://docs.tomorrow.io/reference/data-layers-overview#field-availability)), or you can specify a MinTime or MaxTime variable to alert when in the timestep the event occurs. 

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/86b1b8sdfaepp1tgdf5r.png)


#### Set Up The Time Frame

This allows you to decide how much historical data to look at, and supports data from January 01 2015 onward.  This can be helpful even if you don’t have business data that goes back that far, as you can use what you have to determine basic correlation of weather increasing risk of affecting SLA metrics, then apply that correlation to the historic weather data to get a longer term look at how the weather has or would have affected your business.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/o6fcgoy5uz62h1q9bxtx.png)

#### Select Time Zone

The time zone should use the [standard IANA](https://docs.tomorrow.io/reference/api-formats#timezone) database format.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/t2lxbcxaag57o07uszzx.png)

#### Pull The Timelines

This step pulls the data from the timelines as requested, but you will need to include [corresponding units](https://docs.tomorrow.io/reference/historical?) to each item in order to keep track of what the data represents.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1az99q8hce4pgk6nei0z.png)

#### Construct A Dataframe to Hold The Response

This step creates and populates a dataframe so that you can analyze and manipulate it, as well as bring in your own data to conduct the correlation analysis.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/s97b5bt2fto4c9i1brwu.png)

#### Bring In Your Business Data

At this point you have the weather data you need, and it’s time to bring in the business data.  For this example we will keep it simple, importing data (using the same timesteps as the weather data) that includes:

- # Delays
- Average duration of each delay
- Missed deliveries
- Average route length
There are countless other metrics that could be used, and it’s important to select your own metrics based on the nature of your business.  You will need to brainstorm which metrics could be affected by adverse weather, directly or indirectly.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ix3w00dh2wfvytc8z5ia.png)

#### Create Visualizations for Faster Decision Making

At this point you can use whatever visualization tools you’d like to paint a picture of weather / SLA correlation.  Remember, visualization isn’t about creating a good looking chart; what matters is the metric “time to action”.  In other words, what decisions will I need to make once I see the data, and how can I create a visualization that guides me to those decisions as quickly as possible.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/25ivfsp4eqs123144kat.png)

#### Final Thoughts

This tutorial for pulling weather data and correlating with SLA metrics should give you plenty of flexibility to customize it for your own needs.  Remember, more accurate SLA’s mean fewer penalties, happier customers, and more revenue.  Good luck!

Source: main image [Depositphotos](https://depositphotos.com/265662360/stock-photo-wireless-high-speed-lightning-power.html)