During investigations,
it's really important to establish the chain of events
that led to a specific incident, and this is where timestamps come into play.
This will enable us to identify events that
occurred at a specific point in time,
and also identify how many events occurred during a time interval.
Let's consider the following example where we have a list of timestamps.
As they are in chronological order,
we need to investigate how we can group them together.
If we focus only on the hour value, based on this dataset,
we have two categories of four events each.
But what if we need something more granular?
Well,
the next step is to group the events based on creating a key
formed by the hour and the minute value.
With this aggregation, we have three groups.
There are other situations where we need to split the time
frame into equal duration intervals.
Let's consider this example.
We want to split the duration of 60 minutes into four equal intervals.
Each interval will be exactly 15 minutes in length.
Then, we register an event at minute 34.
If we divide the minutes value by the interval length, we obtain the value 2.26.
If we convert this to an int, we obtain 2.
Based on this, we have identified that the event occurred in the third interval,
and if we multiply this by the length of the interval,
we obtain the base value of the interval.
This technique will help us identify how many events occurred
in an interval based on their timestamp.
There are scenarios in which important trends and insights can be assessed
better visually than just based on the numbers alone.
Building charts requires aggregated data,
and specific to Python, we will leverage the Matplotlib library.
The code to create a simple bar chart is quite simple to understand.
In just three lines,
this function plots the values stored in a dictionary against the y‑axis,
and also adds the tick marks on the x‑axis using the dictionary keys.