-
Notifications
You must be signed in to change notification settings - Fork 0
/
AGTSTAT.PAS
1586 lines (1356 loc) · 51.8 KB
/
AGTSTAT.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
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
unit AgtStat;
interface
procedure AgtStat_PerDay;
procedure AgtStat_PerWeekDay;
procedure AgtStat_PerHour;
procedure AgtStat_PerMonth;
procedure AgtStat_Header( InitHdrNam: String );
procedure AgtStat_DauJones( FromPart: String;
SortByRatio: Boolean;
GroupByName: Boolean );
procedure AgtStat_Path_Relayers;
procedure AgtStat_Path_Feeds( sFeedMax: String );
procedure AgtStat_Path_FeedsOf( Newsserver: String );
implementation
uses Classes, SysUtils, Forms, Dialogs,
{$IFDEF USEDLL} AgtDllI, {$ELSE} DllGrp, DllArt, {$ENDIF}
AgtBase, Main, uperlre, uEncoding, cStats, cArts, series, graphics, Windows, Options;
const
GroundDate = 25569.0; // =EncodeDate(1970,1,1)
type
plArray = ^lArray;
lArray = array[0..1000] of LongInt;
function ValToPercent( l, g : LongInt ) : String;
var Wert : Single;
begin
if g=0 then g:=1;
Wert := 100.0 * l / g;
Result := FloatToStrF( Wert, ffFixed, 7, 2 );
end;
function StatDayBaseText: String;
begin
if DayDates then begin
Result := 'between ' + DateToStr(DayFrom) + ' and ' + DateToStr(DayTil);
end else begin
Result := 'within last ' + IntToStr(ForDays) + ' days';
end;
end;
procedure AddSerieInChart(DataCount : Integer; Data: plArray; sColor : tColor; sTitle, sXAxisTitle, sGroupName : String; sInverted : Boolean);
VAR
TempSerie : tLineSeries;
i : integer;
begin
tempserie := tLineSeries.create(nil);
with form1.chart do begin
title.Text.clear;
title.text.Add(sTitle);
BottomAxis.Inverted := sInverted;
BottomAxis.Title.Caption := sXAxisTitle;
end;
with tempserie do begin
Assign( form1.chart.SeriesList[0]);
Clear;
tempserie.Title := sGroupname;
ShowInLegend := true;
SeriesColor := sColor;
for i:=0 to DataCount do
AddY(Data^[i]);
// AddXY(i,Data^[i],IntToStr(i));
end;
form1.chart.addseries(TempSerie);
end;
function IsStartOfWeek( dt: TDateTime ): Boolean; /// neu //JH
var dw1: Integer;
begin
dw1 := ord( GetLocaleChar( GetThreadLocale, LOCALE_IFIRSTDAYOFWEEK, '0' ) )
- ord('0') + 2 {-> DayOfWeek-format};
if dw1 > 7 then dec( dw1, 7 );
Result := ( DayOfWeek(dt) = dw1 );
end;
function FillBlanks( count : integer) : String;
var i : integer;
begin
Result := '';
for i := 1 to count do
Result := Result + ' ';
end;
function GoodTab( count : Integer; const s : string) : string;
begin
Result := FillBlanks(count-(length(s))) + s;
end;
procedure AgtStat_PerDay;
var TG : TAgtGroupMem;
i : Integer;
gnr,anr,l, Tage, GrpCnt: LongInt;
s, tit : String;
ADT : TDateTime;
FromDT, TilDT : TDateTime;
AnzTage: LongInt;
GrpCount, SumCount: plArray;
begin
if not Form1.FindBegin then exit;
if DayDates then begin
FromDT := DayFrom;
TilDT := DayTil;
end else begin
FromDT := int(Now)-ForDays;
TilDT := int(Now);
end;
AnzTage := trunc(TilDT) - trunc(FromDT) + 1;
GetMem( GrpCount, AnzTage*sizeof(LongInt) );
GetMem( SumCount, AnzTage*sizeof(LongInt) );
for i:=0 to AnzTage-1 do SumCount^[i]:=0;
GrpCnt := 0;
Form1.rtfStat.Lines.Clear;
tit := 'Statistics: Messages per Day ('+DateToStr(FromDT)+' - '+DateToStr(TilDT)+')';
Form1.rtfStat.Lines.Add( tit );
Form1.rtfStat.Lines.Add( '' );
Application.ProcessMessages;
for gnr:=0 to Form1.lstGroups.Items.Count-1 do begin
if not(Form1.Stop) and (Form1.lstGroups.Selected[gnr]) then begin
TG := TAgtGroupMem( Form1.lstGroups.Items.Objects[gnr] );
for i:=0 to AnzTage-1 do GrpCount^[i]:=0;
OpenMyArt( Opt.Database.Names[TG.PathIdx], TG.GrpID );
for anr:=0 to AgtArtCount(HArt)-1 do begin
inc( Form1.BalkenCount );
if (Form1.BalkenCount mod 25)=0 then begin
Form1.FindStatus(TG,anr);
Form1.BalkenG.Progress := Form1.BalkenCount;
end;
AgtArtLoadIndex( HArt, anr );
l := AgtArtUnixTime(HArt,0);
if DayOK( l ) then begin
ADT := GroundDate + (l div 86400);
ADT := TilDT - ADT;
Tage := trunc(ADT);
inc(Form1.FindCount);
inc(GrpCount^[Tage]);
inc(SumCount^[Tage]);
end;
end;
CloseMyArt;
Form1.rtfStat.Lines.Add( TG.GrpNam );
form1.rtfStat.Lines.Add( '' );
Form1.rtfStat.Lines.Add( ' Mon Tue Wed Thu Fri Sat Sun');
//Form1.rtfStat.Lines.Add( ' Mon | Tue | Wed | Thu | Fri | Sat | Sun |');
inc( GrpCnt );
s := '';
for i:=AnzTage-1 downto 0 do begin
if (s>'') and IsStartOfWeek(TilDT-i) then begin
if length(s)<42 then
s := GoodTab(42,s);
s := s + #13#10;//' '; /// neu
end;
s := s + GoodTab(6,Format(' %3d',[GrpCount^[i]]));
/// raus: if (i<>0) and [...] then s := s + ' ';
end;
Form1.rtfStat.Lines.Add( s );
Form1.rtfStat.Lines.Add( '' );
form1.rtfStat.Lines.Add( '' );
AddSerieInChart(AnzTage-1, GrpCount, GrpCnt*4048, tit, 'Days back', TG.GrpNam, true); //ToDo: Color für Series
Application.ProcessMessages;
end;
Application.ProcessMessages;
end;
if GrpCnt > 1 then begin
Form1.rtfStat.Lines.Add( 'All selected groups' );
form1.rtfStat.Lines.Add( '' );
Form1.rtfStat.Lines.Add( ' Mon Tue Wed Thu Fri Sat Sun ');
s := '';
for i:=AnzTage-1 downto 0 do begin
if (s>'') and IsStartOfWeek(TilDT-i) then begin
if length(s)<42 then
s := GoodTab(42,s);
s := s + #13#10;//' '; /// neu
end;
s := s + GoodTab(6,Format(' %3d',[SumCount^[i]]));
/// raus: if (i<>0) and [...] then s := s + ' ';
end;
Form1.rtfStat.Lines.Add( s );
Form1.rtfStat.Lines.Add( '' );
end;
FreeMem( GrpCount, AnzTage*sizeof(LongInt) );
FreeMem( SumCount, AnzTage*sizeof(LongInt) );
Form1.FindEnd;
Form1.rtfStat.SelStart := 0;
Form1.rtfStat.SetFocus;
end;
procedure AgtStat_PerWeekDay;
var TG : TAgtGroupMem;
i : Integer;
gnr,anr,l, Tage, GrpCnt: LongInt;
tit : String;
ADT : TDateTime;
FromDT, TilDT : TDateTime;
AnzTage: LongInt;
GrpCount{, SumCount}: plArray;
dSUN, dMON, dTUE, dWED, dTHU, dFRI, dSAT : Integer;
begin
if not Form1.FindBegin then exit;
if DayDates then begin
FromDT := DayFrom;
TilDT := DayTil;
end else begin
FromDT := int(Now)-ForDays;
TilDT := int(Now);
end;
AnzTage := trunc(TilDT) - trunc(FromDT) + 1;
GetMem( GrpCount, AnzTage*sizeof(LongInt) );
// GetMem( SumCount, AnzTage*sizeof(LongInt) );
// for i:=0 to AnzTage-1 do SumCount^[i]:=0;
GrpCnt := 0;
Form1.rtfStat.Lines.Clear;
tit := 'Statistics: Messages per Weekday ('+DateToStr(FromDT)+' - '+DateToStr(TilDT)+')';
Form1.rtfStat.Lines.Add( tit );
Form1.rtfStat.Lines.Add( '' );
Application.ProcessMessages;
for gnr:=0 to Form1.lstGroups.Items.Count-1 do begin
if not(Form1.Stop) and (Form1.lstGroups.Selected[gnr]) then begin
TG := TAgtGroupMem( Form1.lstGroups.Items.Objects[gnr] );
for i:=0 to AnzTage-1 do GrpCount^[i]:=0;
OpenMyArt( Opt.Database.Names[TG.PathIdx], TG.GrpID );
for anr:=0 to AgtArtCount(HArt)-1 do begin
inc( Form1.BalkenCount );
if (Form1.BalkenCount mod 25)=0 then begin
Form1.FindStatus(TG,anr);
Form1.BalkenG.Progress := Form1.BalkenCount;
end;
AgtArtLoadIndex( HArt, anr );
l := AgtArtUnixTime(HArt,0);
if DayOK( l ) then begin
ADT := GroundDate + (l div 86400);
ADT := TilDT - ADT;
Tage := trunc(ADT);
inc(Form1.FindCount);
inc(GrpCount^[Tage]);
// inc(SumCount^[Tage]);
end;
end;
CloseMyArt;
Form1.rtfStat.Lines.Add( TG.GrpNam );
inc( GrpCnt );
dSUN := 0; dMON := 0; dTUE := 0;
dWED := 0; dTHU := 0; dFRI := 0;
dSAT := 0;
for i:=AnzTage-1 downto 0 do begin
if (i<>0) then
case DayOfWeek(TilDT-i) of //SUN, MON, TUE, WED, THU, FRI, SAT
1: inc(dSun,GrpCount^[i]);
2: inc(dMon,GrpCount^[i]);
3: inc(dTue,GrpCount^[i]);
4: inc(dWed,GrpCount^[i]);
5: inc(dThu,GrpCount^[i]);
6: inc(dFri,GrpCount^[i]);
7: inc(dSat,GrpCount^[i]);
else
end;
end;
with Form1.rtfStat.Lines do begin
Add( 'Monday: '+ IntToStr(dMon));
Add( 'Tuesday: '+ IntToStr(dTue));
Add( 'Wednesday: '+ IntToStr(dWed));
Add( 'Thursday: '+ IntToStr(dThu));
Add( 'Friday: '+ IntToStr(dFri));
Add( 'Saturday: '+ IntToStr(dSat));
Add( 'Sunday: '+ IntToStr(dSun));
Add( '' );
end;
// AddSerieInChart(AnzTage-1, GrpCount, GrpCnt*4048, tit, 'Days back', TG.GrpNam, true); //ToDo: Color für Series
Application.ProcessMessages;
end;
Application.ProcessMessages;
end;
{ if GrpCnt > 1 then begin
Form1.rtfStat.Lines.Add( 'All selected groups' );
s := '';
for i:=AnzTage-1 downto 0 do begin
s := s + Format(' %3d',[SumCount^[i]]);
if (i<>0) and (DayOfWeek(TilDT-i)=DayOfWeek(Now)) then s := s + ' ';
end;
Form1.rtfStat.Lines.Add( s );
Form1.rtfStat.Lines.Add( '' );
end;
}
FreeMem( GrpCount, AnzTage*sizeof(LongInt) );
// FreeMem( SumCount, AnzTage*sizeof(LongInt) );
Form1.FindEnd;
Form1.rtfStat.SelStart := 0;
Form1.rtfStat.SetFocus;
end;
procedure AgtStat_PerMonth;
var TG : TAgtGroupMem;
i : Integer;
gnr,anr,l, GrpCnt: LongInt;
s, tit : String;
ADT : TDateTime;
FromDT, TilDT : TDateTime;
GrpTS, SumTS: TStatList;
TempSerie : tLineSeries;
begin
if not Form1.FindBegin then exit;
if DayDates then begin
FromDT := DayFrom;
TilDT := DayTil;
end else begin
FromDT := int(Now)-ForDays;
TilDT := int(Now);
end;
GrpTS := TStatList.Create;
SumTS := TStatList.Create;
GrpCnt := 0;
Form1.rtfStat.Lines.Clear;
tit := 'Statistics: Messages per Month ('+DateToStr(FromDT)+' - '+DateToStr(TilDT)+')';
Form1.rtfStat.Lines.Add( tit );
Form1.rtfStat.Lines.Add( '' );
Application.ProcessMessages;
for gnr:=0 to Form1.lstGroups.Items.Count-1 do begin
if not(Form1.Stop) and (Form1.lstGroups.Selected[gnr]) then begin
GrpTS.Clear;
TG := TAgtGroupMem( Form1.lstGroups.Items.Objects[gnr] );
OpenMyArt( Opt.Database.Names[TG.PathIdx], TG.GrpID );
for anr:=0 to AgtArtCount(HArt)-1 do begin
inc( Form1.BalkenCount );
if (Form1.BalkenCount mod 25)=0 then begin
Form1.FindStatus(TG,anr);
Form1.BalkenG.Progress := Form1.BalkenCount;
end;
AgtArtLoadIndex( HArt, anr );
l := AgtArtUnixTime(HArt,0);
if DayOK( l ) then begin
ADT := GroundDate + (l div 86400);
s := FormatDateTime( 'yyyy.mm', ADT );
GrpTS.Add( s );
SumTS.Add( s );
inc(Form1.FindCount);
end;
end;
CloseMyArt;
Form1.rtfStat.Lines.Add( TG.GrpNam );
inc( GrpCnt );
for i:=0 to GrpTS.Count-1 do begin
s := GrpTS.Keys[i] + GoodTab(12,Format(' %5d',[GrpTS.Infos[i].Counter]));
Form1.rtfStat.Lines.Add( s );
end;
Form1.rtfStat.Lines.Add( '' );
Application.ProcessMessages;
tempserie := tLineSeries.create(nil);
with form1.chart do begin
title.Text.clear;
title.text.Add(Tit);
BottomAxis.Inverted := false;
BottomAxis.Title.Caption := 'Month';
end;
with tempserie do begin
Assign( form1.chart.SeriesList[0]);
Clear;
title := tg.GrpNam;
ShowInLegend := true;
SeriesColor := GrpCnt*2048;
for i:=0 to GrpTS.Count-1 do
AddY(GrpTS.Infos[i].counter);
// AddXY(i,GrpTS.Infos[i].counter,GrpTS.Keys[i]);
end;
form1.chart.addseries(TempSerie);
end;
Application.ProcessMessages;
end;
if GrpCnt > 1 then begin
Form1.rtfStat.Lines.Add( 'All selected groups' );
for i:=0 to SumTS.Count-1 do begin
s := SumTS.Keys[i] + GoodTab(12,Format(' %5d',[SumTS.Infos[i].Counter]));
Form1.rtfStat.Lines.Add( s );
end;
Form1.rtfStat.Lines.Add( '' );
end;
GrpTS.Free;
SumTS.Free;
Form1.FindEnd;
Form1.rtfStat.SelStart := 0;
Form1.rtfStat.SetFocus;
end;
procedure AgtStat_PerHour;
var TG : TAgtGroupMem;
i : Integer;
gnr,anr,l: LongInt;
s, tit : String;
FromDT, TilDT : TDateTime;
Intervals, ZaehlSum: LongInt;
ZaehlAnz : plArray;
Hour, mm, ss, ms: Word;
GrpCnt : Integer;
begin
if not Form1.FindBegin then exit;
if DayDates then begin
FromDT := DayFrom;
TilDT := DayTil;
end else begin
FromDT := int(Now)-ForDays;
TilDT := int(Now);
end;
Intervals := 24;
GetMem( ZaehlAnz, Intervals*sizeof(LongInt) );
for i:=0 to Intervals-1 do ZaehlAnz^[i]:=0;
ZaehlSum := 0;
Form1.rtfStat.Lines.Clear;
tit := 'Statistics: Messages per hour ('+DateToStr(FromDT)+' - '+DateToStr(TilDT)+')';
Form1.rtfStat.Lines.Add( tit );
Form1.rtfStat.Lines.Add( '' );
Application.ProcessMessages;
GrpCnt := 0;
for gnr:=0 to Form1.lstGroups.Items.Count-1 do begin
if not(Form1.Stop) and (Form1.lstGroups.Selected[gnr]) then begin
TG := TAgtGroupMem( Form1.lstGroups.Items.Objects[gnr] );
Form1.rtfStat.Lines.Add( TG.GrpNam );
OpenMyArt( Opt.Database.Names[TG.PathIdx], TG.GrpID );
for anr:=0 to AgtArtCount(HArt)-1 do begin
inc( Form1.BalkenCount );
if (Form1.BalkenCount mod 25)=0 then begin
Form1.FindStatus(TG,anr);
Form1.BalkenG.Progress := Form1.BalkenCount;
end;
AgtArtLoadIndex( HArt, anr );
l := AgtArtUnixTime(HArt,0);
if DayOK( l ) then begin
DecodeTime( AgtArtDateTime(HArt,0), Hour, mm, ss, ms );
inc(Form1.FindCount);
inc(ZaehlAnz^[Hour]);
inc( ZaehlSum );
end;
end;
CloseMyArt;
AddSerieInChart(23, ZaehlAnz, GrpCnt*4048, tit, 'Hour-Intervall', TG.GrpNam, false); //ToDo: Color für Series
inc(GrpCnt);
end;
Application.ProcessMessages;
end;
Form1.rtfStat.Lines.Add( '' );
s := ' Msgs';
s := s + FillBlanks(8) + '%';
s := s + FillBlanks(8) + 'Interval';
Form1.rtfStat.Lines.Add( s );
for i:=0 to Intervals-1 do begin
s := GoodTab(6,Format( '%5d', [ ZaehlAnz^[i] ] ));
s := s + GoodTab(10,ValToPercent(ZaehlAnz^[i],ZaehlSum)+'%');
s := s + GoodTab(15,Format( '%d%d', [ i div 10, i mod 10 ] ) + ':00-'
+ Format( '%d%d', [ i div 10, i mod 10 ] ) + ':59');
Form1.rtfStat.Lines.Add( s );
end;
Form1.rtfStat.Lines.Add( '' );
s := GoodTab(6,Format( '%5d', [ ZaehlSum ] ));
s := s + GoodTab(10,ValToPercent(ZaehlSum,ZaehlSum)+'%');
s := s + GoodTab(16,'(probe count)');
Form1.rtfStat.Lines.Add( s );
Form1.rtfStat.Lines.Add( '' );
FreeMem( ZaehlAnz, Intervals*sizeof(LongInt) );
Form1.FindEnd;
Form1.rtfStat.SelStart := 0;
Form1.rtfStat.SetFocus;
end;
function DauJones( ArtText: PChar; AddEach: Boolean;
GrpTS, SumTS: TStatList ): Integer;
var Art : TArt;
s, h : String;
i, j, k, n : Integer;
qc : Char;
procedure DauAdd( Pts: Integer; Why: String );
begin
Result := Result + Pts;
if AddEach then begin
GrpTS.Add( Why, Pts, 2 );
SumTS.Add( Why, Pts, 2 );
end;
end;
begin
Result := 0;
s := LowerCase( GetArtHeader('From:') );
i := Pos( '@', s );
if (i<=1) or (i=length(s)) then begin
DauAdd(50,'invalid From:');
end else begin
h := copy( s, i+1, 255 );
if Pos('.',h)=0 then DauAdd(50,'invalid From:');
end;
for n:=1 to 2 do begin
if Pos('@dev.nul',s)>0 then DauAdd(25,'From:-fake assumed');
if Pos('xxx' ,s)>0 then DauAdd(25,'From:-fake assumed');
i := Pos('this',s);
if i>0 then begin
j:=Pos('remove',s); if (j>0) and (j<i) then DauAdd(25,'From:-fake assumed');
j:=Pos('erase' ,s); if (j>0) and (j<i) then DauAdd(25,'From:-fake assumed');
j:=Pos('del' ,s); if (j>0) and (j<i) then DauAdd(25,'From:-fake assumed');
j:=Pos('cut' ,s); if (j>0) and (j<i) then DauAdd(25,'From:-fake assumed');
end;
i := Pos('spam',s);
if i>0 then begin
j:=Pos('no' ,s); if (j>0) and (j<i) then DauAdd(25,'From:-fake assumed');
j:=Pos('stop',s); if (j>0) and (j<i) then DauAdd(25,'From:-fake assumed');
j:=Pos('dont',s); if (j>0) and (j<i) then DauAdd(25,'From:-fake assumed');
j:=Pos('anti',s); if (j>0) and (j<i) then DauAdd(25,'From:-fake assumed');
end;
i := Pos('sig',s);
if i>0 then begin
j:=Pos('see',s); if (j>0) and (j<i) then DauAdd(25,'From:-fake assumed');
end;
s := ROT13(s);
end;
s := LowerCase( GetArtHeader('From:') );
n := 1;
repeat
i := Pos(' ',s);
j := Pos('_',s);
if i=0 then i:=j;
if (i>0) and (j>0) and (j<i) then i:=j;
if i>0 then begin inc(n); System.Delete(s,1,i); end;
until i=0;
if n<3 then DauAdd(10,'no name in From: assumed');
s := LowerCase( FilterMailAdr( GetArtHeader('From:' ) ) );
h := LowerCase( FilterMailAdr( GetArtHeader('Reply-To:') ) );
if h<>'' then begin
if s=h then DauAdd(1,'Reply-To: = From:');
i := Pos('@',h);
if (i=0) then DauAdd(25,'invalid Reply-To:');
if (i=1) or (i=length(h)) then begin i:=0; DauAdd(25,'invalid Reply-To:'); end;
if (i=2) and (h[1]='<') then begin i:=0; DauAdd(25,'invalid Reply-To:'); end;
if i>0 then begin
h := copy(h,i+1,255);
if Pos('.',h)=0 then DauAdd(25,'invalid Reply-To:');
end;
end;
s := GetArtHeader('Message-ID:');
i := Pos('@',s);
if i=0 then DauAdd(5,'invalid M-ID:')
else begin
if Pos('.',s)=0 then DauAdd(5,'invalid M-ID: assumed');
end;
s := GetArtHeader('Newsgroups:');
n := 0;
repeat
i:=Pos(',',s);
if i>0 then begin inc(n); System.Delete(s,1,i); end;
until i=0;
s := GetArtHeader('Followup-To:');
if s<>'' then begin
if Pos(',',s)=0 then n:=0 else inc(n);
end;
if n>0 then DauAdd( n*10, 'crosspost w/o FollowUp-To' );
Art := TArt.Create;
Art.Text := ArtText;
for i:=0 to Art.Count-1 do begin
s := Lowercase(Trim(Art[i]));
if copy(s,1,13)='content-type:' then begin
if Pos('html',s)>0 then DauAdd(50,'html');
if Pos('vcard',s)>0 then DauAdd(25,'vcard');
if Pos('application/octet-stream',s)>0 then begin
h := LowerCase( GetArtHeader('Newsgroups:') );
if Pos('bina',h)+Pos('datei',h)=0 then DauAdd(50,'binary in non-b.-group assumed');
end;
end;
end;
n := 0;
for i:=0 to Art.Count-1 do begin
s := Art[i];
if s='' then break;
for k:=1 to length(s) do begin
if Ord(s[k])>=$80 then begin inc(n); break; end;
end;
if n>0 then begin DauAdd(5,'uncoded 8bit-chars in header'); break; end;
end;
Art.SkipBoundary;
Art.SkipHeader;
qc := Art.GetQuoteChar;
if Art.Count>10 then begin
n := 0;
for i:=0 to Art.Count-1 do begin
s := Art[i];
if (s='-- ') or (s='--=20') or (s='-- =') then break;
s := Trim(s);
if (s<>'') and (s<>qc) then begin
if s[1]=qc then inc(n) else dec(n);
end;
end;
if n>=10 then DauAdd( n ,'quote-ratio');
n := 0;
for i:=0 to Art.Count-1 do begin
s := Art[i];
if (s='-- ') or (s='--=20') or (s='-- =') then break;
if Pos('-----== Posted via D',s)=1 then break; // Deja News
s := Trim(s);
if (s<>'') and (s<>qc) then begin
if copy(s,1,1)=qc then
inc(n)
else begin
if n>9 then DauAdd( n ,'mega-quote');
n := 0;
end;
end;
end;
if n>9 then DauAdd( n*2 ,'trailing mega-quote');
end;
k := -1;
for i:=0 to Art.Count-1 do begin
s := Art[i];
if (s='-- ') or (s='--=20') or (s='-- =') then begin
n := (Art.Count-1) - i;
if n>4 then begin
if Art[Art.Count-1]='' then dec(n);
if n>4 then DauAdd(n,'.sig > 4 lines');
end;
k := i;
break;
end;
end;
if k<0 then begin
j := Art.Count - 1;
while (j>0) and (Trim(Art[j])='') do dec(j);
dec(j,2);
k := -1;
for i:=0 to j do begin
s := Art[i];
if (copy(s,1,2)='--') and (copy(s,1,5)<>'-----') and (length(s)<10) then begin
if s<>'-->' then k:=i;
end;
end;
if k>0 then begin
DauAdd(1,'pseudo-.sig assumed "'+Art[k]+'"');
n := (Art.Count-1) - k;
if n>4 then begin
if Art[Art.Count-1]='' then dec(n);
if n>4 then DauAdd(n,'pseudo-.sig > 4 lines assumed');
end;
end;
end;
n := 0;
j := Art.Count-1;
while (j>=0) and (Art[j]='') do begin inc(n); dec(j); end;
if n>1 then DauAdd(n-1,'trailing empty-lines');
Art.Free;
if Result<0 then Result:=0; // no bonus-points
if AddEach then begin
GrpTS.Add( '(probe count)', Result, 0 );
SumTS.Add( '(probe count)', Result, 0 );
if Result<=0 then begin
GrpTS.Add( '"DAU Jones ;-)" tested and approved!', 0, 1 );
SumTS.Add( '"DAU Jones ;-)" tested and approved!', 0, 1 );
end else begin
GrpTS.Add( '"DAU Jones ;-)" failed!', Result, 1 );
SumTS.Add( '"DAU Jones ;-)" failed!', Result, 1 );
end;
end;
end;
procedure AgtStat_DauJones( FromPart: String;
SortByRatio: Boolean;
GroupByName: Boolean );
const DAUHeader = 'DAU Jones ;-) ';
procedure Report( const Title: String;
const TS: TStatList );
var s: String;
i, summsg, sumdau, d, l: Integer;
TH: TStatInfo;
begin
if FromPart<>'' then SortByRatio:=False; // nur bei Ranking
if SortByRatio then TS.SortBy_Group_WCRatioDesc
else TS.SortBy_GroupDesc_Weight;
Form1.rtfStat.Lines.Add( Title );
s := 'Pos.' + #9 + 'DAUs';
s := s + #9 + 'Msgs';
s := s + #9 + 'Ratio';
if FromPart='' then s := s + #9 + 'Who'
else s := s + #9 + 'Why';
Form1.rtfStat.Lines.Add( s );
if FromPart='' then begin
for i:=0 to TS.Count-1 do begin
TH := TS.Infos[i];
if TH.Weight>0 then begin
s := inttostr(i+1) + #9 + IntToStr(TH.Weight);
s := s + #9 + IntToStr(TH.Counter);
s := s + #9 + FloatToStrF( 1.0*TH.Weight/TH.Counter, ffFixed, 7, 2 );
s := s + #9 + TS.Keys[i];
Form1.rtfStat.Lines.Add( s );
end;
end;
end else begin
summsg := 1;
sumdau := 1;
d := -1;
l := 0;
for i:=0 to TS.Count-1 do begin
TH := TS.Infos[i];
if TH.Group<>d then begin
d := TH.Group;
l := 0;
Form1.rtfStat.Lines.Add( '' );
end;
inc( l );
if TH.Group=0 then begin
summsg := TH.Counter;
sumdau := TH.Weight;
s := inttostr(TH.Group)+'.'+inttostr(l) + #9 + IntToStr(TH.Weight);
s := s + #9 + IntToStr(TH.Counter);
s := s + #9 + FloatToStrF( 1.0*TH.Weight/TH.Counter, ffFixed, 7, 2 );
end else begin
if TH.Group=1 then begin
s := inttostr(TH.Group)+'.'+inttostr(l) + #9 + IntToStr(TH.Weight);
s := s + #9 + IntToStr(TH.Counter);
s := s + #9 + FloatToStrF( 100.0*TH.Counter/summsg, ffFixed, 7, 2 )+'%';
end else begin
s := inttostr(TH.Group)+'.'+inttostr(l) + #9 + IntToStr(TH.Weight);
s := s + #9; // + IntToStr(TH.Anz);
s := s + #9 + FloatToStrF( 100.0*TH.Weight/sumdau, ffFixed, 7, 2 )+'%';
end;
end;
s := s + #9 + TS.Keys[i];
Form1.rtfStat.Lines.Add( s );
end;
end;
Form1.rtfStat.Lines.Add( '' );
Application.ProcessMessages;
end;
var TG : TAgtGroupMem;
GrpCnt, DJ: Integer;
gnr,anr: LongInt;
Hdr : String;
GrpTS, SumTS: TStatList;
begin
if not Form1.FindBegin then exit;
Form1.rtfStat.Lines.Clear;
if FromPart='' then Form1.rtfStat.Lines.Add( DAUHeader + '(Ranking)' )
else Form1.rtfStat.Lines.Add( DAUHeader + 'for "'+FromPart+'"' );
Form1.rtfStat.Lines.Add( '(based on msgs with bodies '+StatDayBaseText+', i.e. not killfiled yet ...)' );
Form1.rtfStat.Lines.Add( '' );
Application.ProcessMessages;
SumTS := TStatList.Create;
GrpTS := TStatList.Create;
GrpCnt := 0;
for gnr:=0 to Form1.lstGroups.Items.Count-1 do begin
if not(Form1.Stop) and (Form1.lstGroups.Selected[gnr]) then begin
GrpTS.Clear;
TG := TAgtGroupMem( Form1.lstGroups.Items.Objects[gnr] );
OpenMyArt( Opt.Database.Names[TG.PathIdx], TG.GrpID );
for anr:=0 to AgtArtCount(HArt)-1 do begin
inc( Form1.BalkenCount );
if (Form1.BalkenCount mod 25)=0 then begin
Form1.FindStatus(TG,anr);
Form1.BalkenG.Progress := Form1.BalkenCount;
end;
AgtArtLoadBody( HArt, anr );
if DayOK( AgtArtUnixTime(HArt,0) ) then begin
// AgtArtLoadBody( HArt, anr );
AgtArtSkipOverviewLine( HArt );
ArtTextSize := AgtArtTextLen( HArt );
ArtText := AgtArtTextPtr( HArt );
inc( Form1.FindCount );
if FromPart='' then begin
Hdr := GetArtHeader('From:');
if GroupByName then Hdr := FilterNameOfFrom( Hdr );
DJ := DauJones( ArtText, False, nil, nil );
GrpTS.Add( Hdr, DJ, 0 );
SumTS.Add( Hdr, DJ, 0 );
end else begin
Hdr := LowerCase( GetArtHeader('From:') );
if GroupByName then Hdr := FilterNameOfFrom( Hdr );
if (FromPart='@') or (Pos(LowerCase(FromPart),Hdr)>0) then begin
DauJones( ArtText, True, GrpTS, SumTS );
end;
end;
end;
end;
CloseMyArt;
Application.ProcessMessages;
Report( TG.GrpNam, GrpTS );
inc( GrpCnt );
end;
Application.ProcessMessages;
end;
if GrpCnt > 1 then Report( 'All selected groups', SumTS );
GrpTS.Free;
SumTS.Free;
Form1.FindEnd;
Form1.rtfStat.SelStart := 0;
Form1.rtfStat.SetFocus;
end;
procedure AgtStat_Header( InitHdrNam: String );
var TG : TAgtGroupMem;
i : Integer;
gnr,anr,l,gsum, GrpCnt: LongInt;
s : String;
Hdr, Cmp : String;
TH : TStatInfo;
GrpTS, SumTS: TStatList;
GrpUsers, SumUsers: TStringList;
HdrNam : String;
Special : Byte;
IsRegex : Boolean;
function GetRegExMatch: String;
var Art : TStringList;
Lin, e: Integer;
h : String;
begin
Result := '';
Art := TStringList.Create;
Art.Text := String( ArtText );
for lin:=0 to Art.Count-1 do begin
if Art[lin]='' then break; // end-of-headers
h := Art[lin];
if regex.MatchS( DecodeHeadervalue( h[1], length(h) ) ) then begin
if regex.SubExpCount<=1 then begin
Result := Art[lin];
end else begin
for e:=1 to regex.SubExpCount do begin
Result := Result + copy( Art[lin],
regex.SubExp[e].StartP ,
regex.SubExp[e].Len );
end;
end;
break;
end;
end;
Art.Free;
end;
begin
if InitHdrNam='' then exit;
Special := 0;
IsRegex := False;
if copy(InitHdrNam,1,1)='{' then begin
try
s := InitHdrNam;
System.Delete( s, 1, 1 );
if copy(s,length(s),1)='}' then s:=copy(s,1,length(s)-1);
regex.CompileRO( s, PCRE_CASELESS );
IsRegex := True;
except
on E:Exception do begin
MessageDlg( 'Regex-error:' + #13#10 + E.Message, mtError, [mbOK], 0);
exit;
end;
end;
end else begin
if copy(InitHdrNam,length(InitHdrNam),1)<>':' then InitHdrNam:=InitHdrNam+':';
if InitHdrNam[1] in ['1'..'6'] then begin {[Gruppierte] X-Newsreader}
Special := strtoint(InitHdrNam[1]);
InitHdrNam := copy(InitHdrNam,2,255);
end;
end;
HdrNam := InitHdrNam;
if not Form1.FindBegin then exit;
Form1.rtfStat.Lines.Clear;
case Special of
1: s := 'Header-statistics for: '+ HdrNam + ', X-Mailer:, User-Agent:';
2: s := 'Header-statistics for: Newsreader (grouped, per msg.)';
3: s := 'Header-statistics for: '+ HdrNam + ' (grouped by domain)';
4: s := 'Header-statistics for: '+ HdrNam + ' (grouped by name)';
5: s := 'Header-statistics for: '+ HdrNam + ' (Re:/was: skipped)';
6: s := 'Header-statistics for: Newsreader (grouped, per user)';
else s := 'Header-statistics for: '+ HdrNam;
end;
Form1.rtfStat.Lines.Add( s );
Form1.rtfStat.Lines.Add( '(based on msgs with bodies '+StatDayBaseText+')' );
Form1.rtfStat.Lines.Add( '' );
Application.ProcessMessages;
GrpCnt := 0;
GrpTS := TStatList.Create;
SumTS := TStatList.Create;
GrpUsers := TStringList.Create;
GrpUsers.Sorted := True;
SumUsers := TStringList.Create;
SumUsers.Sorted := True;
for gnr:=0 to Form1.lstGroups.Items.Count-1 do begin
if not(Form1.Stop) and (Form1.lstGroups.Selected[gnr]) then begin
GrpTS.Clear;
GrpUsers.Clear;
TG := TAgtGroupMem( Form1.lstGroups.Items.Objects[gnr] );