/Timers/DecayingAlarm.cs |
@@ -28,11 +28,25 @@ |
[Flags] |
public enum DECAY_TYPE |
{ |
[Reflection.NameAttribute("none")] [XmlEnum(Name = "none")] NONE = 0, |
[Reflection.NameAttribute("arithmetic")] [XmlEnum(Name = "arithmetic")] ARITHMETIC = 1, |
[Reflection.NameAttribute("geometric")] [XmlEnum(Name = "geometric")] GEOMETRIC = 2, |
[Reflection.NameAttribute("harmonic")] [XmlEnum(Name = "harmonic")] HARMONIC = 4, |
[Reflection.NameAttribute("weighted")] [XmlEnum(Name = "weighted")] WEIGHTED = 5 |
[Reflection.NameAttribute("none")] |
[XmlEnum(Name = "none")] |
NONE = 0, |
|
[Reflection.NameAttribute("arithmetic")] |
[XmlEnum(Name = "arithmetic")] |
ARITHMETIC = 1, |
|
[Reflection.NameAttribute("geometric")] |
[XmlEnum(Name = "geometric")] |
GEOMETRIC = 2, |
|
[Reflection.NameAttribute("harmonic")] |
[XmlEnum(Name = "harmonic")] |
HARMONIC = 4, |
|
[Reflection.NameAttribute("weighted")] |
[XmlEnum(Name = "weighted")] |
WEIGHTED = 5 |
} |
|
private readonly DECAY_TYPE decay = DECAY_TYPE.NONE; |
@@ -92,6 +106,7 @@ |
} |
}, deadline, 0); |
return; |
|
case false: |
elapsed.Stop(); |
times.Add(elapsed.ElapsedMilliseconds); |
@@ -101,14 +116,17 @@ |
alarm?.Change( |
(int) ((deadline + times.Aggregate((a, b) => b + a))/(1f + times.Count)), 0); |
break; |
|
case DECAY_TYPE.GEOMETRIC: |
alarm?.Change((int) Math.Pow(deadline*times.Aggregate((a, b) => b*a), |
1f/(1f + times.Count)), 0); |
break; |
|
case DECAY_TYPE.HARMONIC: |
alarm?.Change((int) ((1f + times.Count)/ |
(1f/deadline + times.Aggregate((a, b) => 1f/b + 1f/a))), 0); |
break; |
|
case DECAY_TYPE.WEIGHTED: |
var d = new HashSet<double>(times) {deadline}; |
var total = d.Aggregate((a, b) => b + a); |
@@ -115,6 +133,7 @@ |
alarm?.Change( |
(int) d.Aggregate((a, b) => Math.Pow(a, 2)/total + Math.Pow(b, 2)/total), 0); |
break; |
|
default: |
alarm?.Change((int) deadline, 0); |
break; |