wasSharp

Subversion Repositories:
Compare Path: Rev
With Path: Rev
?path1? @ 26  →  ?path2? @ 27
/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);
}
}
}
}
/Timers/TimedThrottle.cs
@@ -70,4 +70,4 @@
}
}
}
}
}
/Timers/Timer.cs
@@ -109,6 +109,7 @@
ScheduledTime = DateTime.UtcNow;
Delay = Task.Delay(DueTime, tokenSource.Token);
break;
 
default:
Delay = CompletedTask;
break;
@@ -124,6 +125,7 @@
ScheduledTime = DateTime.UtcNow;
Delay = Task.Delay(DueTime, tokenSource.Token);
break;
 
default:
Delay = CompletedTask;
break;
@@ -156,4 +158,4 @@
Change(0, 0);
}
}
}
}
/Timers/Utilities/TimeExtensions.cs
@@ -29,7 +29,7 @@
/// <remarks>the function assumes UTC time</remarks>
public static uint DateTimeToUnixTimestamp(this DateTime dateTime)
{
return (uint) (DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc)).TotalSeconds;
return (uint)(DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc)).TotalSeconds;
}
}
}
}