Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches

◆ Aggregate()

override object System.Data.Common.TimeSpanStorage.Aggregate ( int[] records,
AggregateType kind )
inlinevirtual

Reimplemented from System.Data.Common.DataStorage.

Definition at line 18 of file TimeSpanStorage.cs.

19 {
20 bool flag = false;
21 try
22 {
23 switch (kind)
24 {
25 case AggregateType.Min:
26 {
27 TimeSpan timeSpan = TimeSpan.MaxValue;
28 foreach (int num9 in records)
29 {
30 if (!IsNull(num9))
31 {
32 timeSpan = ((TimeSpan.Compare(_values[num9], timeSpan) < 0) ? _values[num9] : timeSpan);
33 flag = true;
34 }
35 }
36 if (flag)
37 {
38 return timeSpan;
39 }
40 return _nullValue;
41 }
42 case AggregateType.Max:
43 {
44 TimeSpan timeSpan2 = TimeSpan.MinValue;
45 foreach (int num13 in records)
46 {
47 if (!IsNull(num13))
48 {
50 flag = true;
51 }
52 }
53 if (flag)
54 {
55 return timeSpan2;
56 }
57 return _nullValue;
58 }
59 case AggregateType.First:
60 if (records.Length != 0)
61 {
62 return _values[records[0]];
63 }
64 return null;
65 case AggregateType.Count:
66 return base.Aggregate(records, kind);
67 case AggregateType.Sum:
68 {
69 decimal d = default(decimal);
70 foreach (int num14 in records)
71 {
72 if (!IsNull(num14))
73 {
74 d += (decimal)_values[num14].Ticks;
75 flag = true;
76 }
77 }
78 if (flag)
79 {
80 return TimeSpan.FromTicks((long)Math.Round(d));
81 }
82 return null;
83 }
84 case AggregateType.Mean:
85 {
86 decimal num10 = default(decimal);
87 int num11 = 0;
88 foreach (int num12 in records)
89 {
90 if (!IsNull(num12))
91 {
92 num10 += (decimal)_values[num12].Ticks;
93 num11++;
94 }
95 }
96 if (num11 > 0)
97 {
98 return TimeSpan.FromTicks((long)Math.Round(num10 / (decimal)num11));
99 }
100 return null;
101 }
102 case AggregateType.StDev:
103 {
104 int num = 0;
105 decimal num2 = default(decimal);
106 foreach (int num3 in records)
107 {
108 if (!IsNull(num3))
109 {
110 num2 += (decimal)_values[num3].Ticks;
111 num++;
112 }
113 }
114 if (num > 1)
115 {
116 double num4 = 0.0;
117 decimal num5 = num2 / (decimal)num;
118 foreach (int num6 in records)
119 {
120 if (!IsNull(num6))
121 {
122 double num7 = (double)((decimal)_values[num6].Ticks - num5);
123 num4 += num7 * num7;
124 }
125 }
126 ulong num8 = (ulong)Math.Round(Math.Sqrt(num4 / (double)(num - 1)));
127 if (num8 > long.MaxValue)
128 {
129 num8 = 9223372036854775807uL;
130 }
131 return TimeSpan.FromTicks((long)num8);
132 }
133 return null;
134 }
135 case AggregateType.Var:
136 break;
137 }
138 }
139 catch (OverflowException)
140 {
141 throw ExprException.Overflow(typeof(TimeSpan));
142 }
143 throw ExceptionBuilder.AggregateException(kind, _dataType);
144 }
static TimeSpan FromTicks(long value)
Definition TimeSpan.cs:277

References System.Data.Common.DataStorage._dataType, System.Data.Common.DataStorage._nullValue, System.Data.Common.TimeSpanStorage._values, System.Data.ExceptionBuilder.AggregateException(), System.TimeSpan.Compare(), System.Xml.Dictionary, System.TimeSpan.FromTicks(), System.Data.IsNull, System.TimeSpan.MaxValue, System.TimeSpan.MinValue, System.Data.ExprException.Overflow(), System.Math.Round(), System.Math.Sqrt(), and System.TimeSpan.Ticks.