Repository navigation
Expand file tree
/
Copy pathSample.cs
More file actions
143 lines (118 loc) · 4.17 KB
/
Copy pathSample.cs
File metadata and controls
143 lines (118 loc) · 4.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ImpactAnalyzer
{
class Sample
{
public DateTime Time { get; set; }
public double Value { get; set; }
public double AbsValue { get; set; }
public bool IsPeakOrValley { get; set; }
public double Average { get; set; }
public Sample(DateTime time, float value)
{
Time = time;
Value = value;
AbsValue = Math.Abs(Value);
IsPeakOrValley = false;
}
}
public class ActivityDefinition
{
public double ImpactLowWaterMark { get; set; }
// Impact high water mark for this activity
public double ImpactHighWaterMark { get; set; }
public string Name { get; set; }
public ActivityDefinition(double impactLowWaterMark, double impactHighWaterMark, string name)
{
ImpactLowWaterMark = impactLowWaterMark;
ImpactHighWaterMark = impactHighWaterMark;
Name = name;
}
}
class Activity
{
public ActivityDefinition Definition { get; set; }
public List<Sample> SampleList { get; set; }
// The time difference between the peaks in the activity
public List<TimeSpan> TimeDifference { get; set; }
// Average time difference
public TimeSpan AverageTimeDifference { get; set; }
// Unique identifier for this activity
public int ActivityId { get; set; }
public Activity(List<Sample> sampleList, ActivityDefinition definition, int id)
{
SampleList = sampleList;
Definition = definition;
ActivityId = id;
ComputeSampleTimeDifference();
}
void ComputeSampleTimeDifference()
{
if (SampleList.Count > 0)
{
TimeDifference = new List<TimeSpan>(SampleList.Count - 1);
TimeSpan TotalTimeDifference = new TimeSpan(0);
for (int i = 1; i < SampleList.Count; i++)
{
TimeDifference.Add(SampleList[i].Time - SampleList[i - 1].Time);
TotalTimeDifference += TimeDifference[i - 1];
}
AverageTimeDifference = new TimeSpan((long)(TotalTimeDifference.TotalMilliseconds * 10000 / (SampleList.Count - 1)));
}
else
{
TimeDifference = new List<TimeSpan>(0);
AverageTimeDifference = new TimeSpan(0);
}
}
public Int32 FindBreakInActivity(ImpactAnalysisParams Params)
{
return TimeDifference.FindIndex(timedifference => timedifference >= Params.MaxActivityPeriod);
}
public Activity BreakOff(Int32 index)
{
// The index is an index into the TimeDifference list
// This means that we should break off index+1 elements from the head of the activity list
Activity BreakOffActivity = new Activity(SampleList.GetRange(0, index + 1), Definition, ActivityId);
SampleList.RemoveRange(0, index + 1);
ComputeSampleTimeDifference();
return BreakOffActivity;
}
public DateTime ActivityStartTime()
{
return (SampleList.Count > 0) ? SampleList[0].Time : new DateTime(0, DateTimeKind.Utc);
}
public DateTime ActivityEndTime()
{
return (SampleList.Count > 0) ? SampleList[SampleList.Count - 1].Time : new DateTime(0, DateTimeKind.Utc);
}
}
class ActivityData
{
private ImpactAnalysisParams _Params;
public ImpactAnalysisParams Params
{
get
{
return _Params;
}
}
private List<Activity> _ActivityList;
public List<Activity> ActivityList
{
get
{
return _ActivityList;
}
}
public ActivityData(List<Activity> activityList, ImpactAnalysisParams param)
{
_Params = param;
_ActivityList = activityList;
}
}
}