//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); |
@@ -99,24 +114,28 @@ |
{ |
case DECAY_TYPE.ARITHMETIC: |
alarm?.Change( |
(int) ((deadline + times.Aggregate((a, b) => b + a))/(1f + times.Count)), 0); |
(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); |
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); |
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 d = new HashSet<double>(times) { deadline }; |
var total = d.Aggregate((a, b) => b + a); |
alarm?.Change( |
(int) d.Aggregate((a, b) => Math.Pow(a, 2)/total + Math.Pow(b, 2)/total), 0); |
(int)d.Aggregate((a, b) => Math.Pow(a, 2) / total + Math.Pow(b, 2) / total), 0); |
break; |
|
default: |
alarm?.Change((int) deadline, 0); |
alarm?.Change((int)deadline, 0); |
break; |
} |
elapsed.Reset(); |
@@ -140,4 +159,4 @@ |
return new DecayingAlarm(decay); |
} |
} |
} |
} |