Skip to content

Instantly share code, notes, and snippets.

@joaofig
Created August 26, 2016 09:49
Show Gist options
  • Save joaofig/8b629a031905b7a396a33e8b70fd5ca9 to your computer and use it in GitHub Desktop.
Save joaofig/8b629a031905b7a396a33e8b70fd5ca9 to your computer and use it in GitHub Desktop.
WeeklyLogModel
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