Created
August 26, 2016 09:49
-
-
Save joaofig/8b629a031905b7a396a33e8b70fd5ca9 to your computer and use it in GitHub Desktop.
WeeklyLogModel
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace Sagaceco.ServerLog | |
{ | |
public class WeeklyLogModel | |
{ | |
private ExponentialMovingModel[] models = new ExponentialMovingModel[2016]; | |
private double radius = 3.0; | |
public WeeklyLogModel() | |
{ | |
for(int i = 0; i < models.Length; i++) | |
models[i] = new ExponentialMovingModel(); | |
} | |
public WeeklyLogModel(double weight, double radius) | |
{ | |
this.radius = radius; | |
for(int i = 0; i < models.Length; i++) | |
models[i] = new ExponentialMovingModel(weight); | |
} | |
public void Update(LogRecord record) | |
{ | |
int index = record.Period % models.Length; | |
models[index].Update(record.Value); | |
} | |
public bool IsOutlier(LogRecord record) | |
{ | |
int index = record.Period % models.Length; | |
return models[index].IsOutlier(radius, record.Value); | |
} | |
public double GetAverage(LogRecord record) | |
{ | |
int index = record.Period % models.Length; | |
return models[index].Average; | |
} | |
public double GetVariance(LogRecord record) | |
{ | |
int index = record.Period % models.Length; | |
return models[index].Variance; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment