-
Notifications
You must be signed in to change notification settings - Fork 0
/
uStatisticsBase.pas
250 lines (203 loc) · 6.39 KB
/
uStatisticsBase.pas
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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
unit uStatisticsBase;
interface
uses uDBBase, Classes, Sysutils, Graphics;
var sColors : array of tColor;
type
//tDBList = array of tDBBaseClass;
tStatOptions = record
Ranking : Boolean;
BeginDate,
EndDate : tDateTime;
Param : String;
end;
tStatShow = record
Options : set of (ssoDisable, ssoRanking, ssoBDate, ssoEDate,
ssoEdParam, ssoHasGraph);
Caption : String;
ParamCapt : String;
DefParam : String;
end;
tChartOneResult = record
groupname : String; //Or ALL for all
values : Array of Integer;
end;
tChartResult = record
name : String; //Name of whole statistic
xAxis : String;
yAxis : String;
valueNames : Array of String; //Names of columns (same length as values)
results : Array of tChartOneResult; //Same Length as groupnames
end;
tProgressData = record
FindCount : Integer;
GrpCount : Integer;
GrpMax : Integer;
GrpName : String;
end;
tProgressStep = procedure (data : tProgressData; out cancel : Boolean) of Object;
tFindProgressStep = procedure (cnt : Integer) of Object;
tStatisticBaseClass = class of tStatisticBase;
tStatisticBase = class //Base Statistic (Base-Class)
private //Fuer den GUI-Ruecksprung
progress : tProgressData;
fEventProgress : tProgressStep;
fEventFindProgress : tFindProgressStep;
protected //Fuer den GUI-Ruecksprung
procedure clearFindCount();
procedure incFindCount();
procedure clearGrpCount(name : String; max : Integer);
function incGrpCount() : Boolean;
protected
fStatOptions : tStatOptions;
fResultAsText : String;
fResultAsChart : tChartResult;
function DayOK( DateTime: tDateTime ): Boolean;
function StatDayBaseText: String;
procedure initializeChart(valueCount : Integer; GroupCount : Integer);
public
function GetShowOptions : tStatShow; virtual; abstract;
procedure SetOptions( Options : tStatOptions); virtual;
procedure MakeStatistic( Groups : tGroupList); virtual; abstract;
function GetResultAsText : String; virtual;
function GetResultAsChart : tChartResult; virtual;
Constructor Create(EventProgress : tProgressStep; EventFindProgress : tFindProgressStep);
Destructor Destroy; override;
end;
tStatNONE = class (tStatisticBase)
public
function GetShowOptions : tStatShow; override;
procedure MakeStatistic( Groups : tGroupList); override;
end;
Const CRLF = #13#10;
function GetGruppenTrenner() : string;
const OldDefault = 29221.0; // =EncodeDate(1980,1,1)
//See RfcDateTimeToDateTimeGMT
implementation
uses uConfiguration;
function GetGruppenTrenner() : string;
begin
case (Conf.fGroupParter) of
gpNone: Result := CRLF + CRLF;
gpBoth: Result := CRLF + '_________-_________-_________-_________-_________-_________-_________-' + CRLF;
gpSingle:Result := CRLF + '- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ' + CRLF;
end;
end;
{ tStatisticBase }
constructor tStatisticBase.Create(EventProgress : tProgressStep; EventFindProgress : tFindProgressStep);
begin
inherited Create;
fEventProgress := EventProgress;
fEventFindProgress := EventFindProgress;
fResultAsText := '';
initializeChart(0, 0);
with fStatOptions do begin
Param := '';
Ranking := false;
BeginDate := now;
EndDate := now
end;
end;
destructor tStatisticBase.Destroy;
begin
initializeChart(0, 0);
inherited;
end;
function tStatisticBase.GetResultAsChart: tChartResult;
begin
Result := fResultAsChart
end;
function tStatisticBase.GetResultAsText: String;
begin
Result := fResultAsText
end;
procedure tStatisticBase.SetOptions(Options: tStatOptions);
begin
fStatOptions := Options
end;
function tStatisticBase.DayOK( DateTime: tDateTime ): Boolean;
var Days: LongInt;
begin
Days := Trunc(DateTime);
Result := ((Trunc(fStatOptions.BeginDate)<=Days)
and (Trunc(fStatOptions.EndDate)>=Days))
or (DateTime = OldDefault)
end;
function tStatisticBase.StatDayBaseText: String;
begin
Result := 'between ' + DateToStr(fStatOptions.BeginDate) + ' and ' + DateToStr(fStatOptions.EndDate)
end;
procedure tStatisticBase.initializeChart(valueCount, GroupCount: Integer);
var i : Integer;
begin
with (fResultAsChart) do begin
//Freigabe von Speicher
for i := Length(results)-1 downto 0 do
setlength(results[i].values, 0);
//Anzahl an Spaltenueberschriften
setlength(valueNames, valueCount);
//Anzahl Charts (Mit oder ohne "all groups")
if GroupCount=1 then
setlength(results, 1)
else
setlength(results, GroupCount + 1);
//Values der Charts
for i := 0 to Length(results)-1 do
setlength(results[i].values, valueCount);
end
end;
//Ausgelagerte FindCount fuer spaetere GUI
procedure tStatisticBase.clearFindCount;
begin
progress.FindCount := 0;
end;
procedure tStatisticBase.incFindCount;
//var tmp : Boolean;
begin
inc(progress.FindCount);
if (Assigned(fEventFindProgress)) then begin
fEventFindProgress(progress.FindCount);
end;
//Wegen dem Cancel-Button ist das nicht so toll:
//TODO Ueberlegen...
//if (Assigned(fEventProgress)) then
// fEventProgress(progress, tmp);
end;
procedure tStatisticBase.clearGrpCount(name : String; max: Integer);
begin
progress.GrpMax := max;
progress.GrpCount := 0;
progress.GrpName := name;
end;
function tStatisticBase.incGrpCount : Boolean;
begin
Result := false;
inc(progress.GrpCount);
if (Assigned(fEventProgress)) then
fEventProgress(progress, Result)
end;
{ tStatNONE }
function tStatNONE.GetShowOptions: tStatShow;
begin
with Result do begin
Options := [ssoDisable];
Caption := '------------';
ParamCapt := '';
DefParam := ''
end
end;
procedure tStatNONE.MakeStatistic(Groups: tGroupList);
begin
fResultAsText := '';
end;
procedure setSColors(arr : Array of tColor);
var i : Integer;
begin
SetLength(sColors, length(arr));
for i := 0 to length(arr)-1 do
sColors[i] := arr[i];
end;
initialization
SetSColors([clMaroon, clGreen, clNavy, clPurple, clTeal, clSilver,
clRed, clLime, clYellow, clBlue, clFuchsia, clAqua, clLtGray,
clDkGray, clOlive, clGray]);
end.