]> git.tdb.fi Git - netvis.git/blob - source/activity.cpp
Restructure packet handling
[netvis.git] / source / activity.cpp
1 #include <cmath>
2 #include <msp/time/units.h>
3 #include "activity.h"
4
5 using namespace Msp;
6
7 Activity::Activity():
8         average(0)
9 { }
10
11 void Activity::add_bytes(unsigned n)
12 {
13         // Scale for correct integral
14         average += n*0.06935;
15 }
16
17 void Activity::tick(const Time::TimeDelta &dt)
18 {
19         static Time::TimeDelta last_dt;
20         static float decay = 0;
21
22         if(dt!=last_dt)
23         {
24                 // Half-life in 10 seconds
25                 decay = pow(0.933f, dt/Time::sec);
26                 last_dt = dt;
27         }
28
29         average *= decay;
30 }