Python Web Traffic Probability Calculation and Plot
New here? Learn about Bountify and follow @bountify to get notified of new bounties! x

Looking for a python function and plot that plots the probability of a peak number of web calls for a given time period. For examples assuming:
avg is an average amount of calls in an hour.
A function like:

def pcalc (average = avg, probability = p):

# p is range starts from .001


A plot function where:

y_axis is the probability in %.

x_axis is the number of web calls for the time period

The plot needs to show the distribution curve like what's below; options that provide better insight and visualization welcome and rewarded.

from scipy.stats import poisson

import matplotlib.pyplot as plt.

x2 = pcalc(avg).

plt.plot(x2, poisson.pmf(x2,tph)).

plt.title("Probable Peak Calls")

plt.xlabel('Calls per Hour')

plt.ylabel('Probability %').

Hi, can you please be more precise on your demand ? I don't really understand what the "pcalc" function is supposed to generate Also in your poisson.pmf, the parameter tph is not defined in your request.
kerncy almost 2 years ago
Very poor pseudo code, apologies. Examples: web site averages 1000 hits per hour, what is the probability the website will have 2000 hits in 1 hour? or 4000 hits in 1 hour.
broadreach almost 2 years ago
Sorry but I'm still confused. Data are missing in your request. You have an average amount of calls per hour named avg. Than you say "p is range starts from .001". This point is very unclear. P is a probability but this probability should evolve during the time of day, but we don't know how. Do you have any data for the probabilities ? a sample of what is expected would be welcome (simple paint drawing for example).
kerncy almost 2 years ago
if a website get 100 hits in 1 hour, there is a very small probability it could get 500 hits in one hour. I am looking for that very small probability(for n number of hits in 1 hour). Erlang traffic formulas do something similar, they look at max peak calls. I was hoping a poisson approach would be simpler because I don't care about lost calls dropped or queued.
broadreach almost 2 years ago
awarded to kerncy

Crowdsource coding tasks.

1 Solution

Winning solution


I'm not sure that it will fit your need but here is my proposition :

from scipy.stats import norm
import matplotlib.pyplot as plt
average=int(input("Enter average calls per hour [default = 500] :") or 500)
probability = int(input("Enter probability to get the average call per hour (range 1 (low prob) to 10 (high prob)) [default = 3] :") or 3) 
x = range(0,2*average)
y = norm.pdf(x, average, average / probability)
plt.plot(x, y)
plt.title("Probable Peak Calls")
plt.xlabel('Calls per Hour')
plt.ylabel('Probability %')

It will ask for your average calls per hour and your probability (from 1 to 10) to have the average call per hour. That will generate the graphe of the "normal law" with probability to have a the amount of call reached.