-
Notifications
You must be signed in to change notification settings - Fork 0
/
EventLogAnalysis.java
executable file
·1567 lines (1326 loc) · 55 KB
/
EventLogAnalysis.java
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
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.TreeMap;
/*********************************************************************
* Class for doing analysis of the data.
*
* @author Duncan A. Buell
* Copyright (c) 2010-2012 Duncan A. Buell
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
**/
public class EventLogAnalysis
{
/*********************************************************************
* Instance variables.
**/
static final String TAG = "ELA: "; // for testing
/*********************************************************************
* Constructor.
**/
public EventLogAnalysis()
{
} // public EventLogAnalysis()
/*********************************************************************
* Accessors and mutators.
**/
/*********************************************************************
* General methods.
**/
/*********************************************************************
* Method to compare closing PEBs in the 152 and PEBs in the 68A.
**/
private void compare152And68APEBS(PrintWriter outFile)
{
boolean noExceptions = true;
// outFile.printf("%s enter compare152And68APEBS%n", TAG);
// outFile.flush();
outFile.printf("%n********** ********** ********** ");
outFile.printf("********** ********** **********%n%n");
outFile.printf("Listing PEBs found only in 68A or in 152 (includes 750+)%n");
outFile.flush();
for(String pebKey: Globals.thePEBs.keySet())
{
OnePEB peb = Globals.thePEBs.get(pebKey);
if(peb.getUsedForClosing() && !peb.getFoundInSystemLog())
{
outFile.printf("PEB %s not in 68A but closed terminals in 152%n",
pebKey);
outFile.flush();
noExceptions = false;
}
}
outFile.printf("%n");
for(String pebKey: Globals.thePEBs.keySet())
{
OnePEB peb = Globals.thePEBs.get(pebKey);
if(!peb.getUsedForClosing() && peb.getFoundInSystemLog())
{
outFile.printf(" PEB %s in 68A but not in the 152 file%n", pebKey);
outFile.flush();
noExceptions = false;
}
}
if(noExceptions)
{
outFile.printf("No exceptions of this type.%n");
outFile.flush();
}
// outFile.printf("%s leave compare152And68APEBS%n%n", TAG);
// outFile.flush();
} // private void compare152And68APEBS(PrintWriter outFile)
/*********************************************************************
* Method to compare terminal serial numbers from the 152 and 155.
**/
private void compareIvos152V155(PrintWriter outFile)
{
boolean noExceptions = true;
// outFile.printf("%s enter compareIvos152V155%n", TAG);
// outFile.flush();
outFile.printf("%n********** ********** ********** ");
outFile.printf("********** ********** **********%n%n");
outFile.printf("Listing terminals found only in 152 or in 155 (includes 750+)%n");
outFile.flush();
for(String termKey: Globals.theTerms.keySet())
{
OneTerminal term = Globals.theTerms.get(termKey);
if(term.getFoundIn152() && !term.getFoundIn155())
{
outFile.printf("%s in 152 but not 155%n", termKey);
outFile.flush();
noExceptions = false;
}
else if(!term.getFoundIn152() && term.getFoundIn155())
{
outFile.printf(" %s in 155 but not 152%n", termKey);
outFile.flush();
noExceptions = false;
}
// The default setting is that a terminal is both absentee and
// not absentee unless we set it otherwise. This means that if
// a terminal is not in the 155 file we will always have the default
// values set.
if(term.getFoundIn155() && term.isAbsentee() && term.isNotAbsentee())
{
outFile.printf("TERMINAL BOTH ABSENTEE AND NOT ABSENTEE: %s%n",
term.getIvoNumber());
outFile.flush();
noExceptions = false;
}
}
if(noExceptions)
{
outFile.printf("No exceptions of this type.%n");
outFile.flush();
}
// outFile.printf("%s leave compareIvos152V155%n%n", TAG);
// outFile.flush();
} // private void compareIvos152V155(PrintWriter outFile)
/*********************************************************************
* Method to compare open and close PEBs.
**/
private void compareOpenAndClosePEB(PrintWriter outFile)
{
boolean noExceptions = true;
// outFile.printf("%s enter compareOpenAndClosePEB%n", TAG);
// outFile.flush();
outFile.printf("%n********** ********** ********** ");
outFile.printf("********** ********** **********%n%n");
outFile.printf("Listing terminals opened and closed with different PEBs (includes 750+)%n");
outFile.printf("This list comes from the 152 file%n");
outFile.flush();
for(String termKey: Globals.theTerms.keySet())
{
OneTerminal term = Globals.theTerms.get(termKey);
if(!term.getOpenPEB().equals(term.getClosePEB()))
{
outFile.printf("%s Opening PEB %s not closing PEB %s: %s%n",
termKey, term.getOpenPEB(), term.getClosePEB(),
term.toStringPcts());
outFile.flush();
noExceptions = false;
}
}
if(noExceptions)
{
outFile.printf("No exceptions of this type.%n");
outFile.flush();
}
noExceptions = true;
outFile.printf("%n");
outFile.printf("Listing precincts with multiple PEBs used for closing (includes 750+)%n");
for(String pctKey: Globals.pctsByNumber.keySet())
{
OnePrecinct pct = Globals.pctsByNumber.get(pctKey);
if(pct.getClosePEBSize() > 1)
{
outFile.printf("%s %s%n", pct.getPctNumber(), pct.getName());
outFile.printf(" %s%n", pct.toStringTerminals());
outFile.printf(" %s %s %n", pct.toStringOpenPEBs(),
pct.toStringClosePEBs());
outFile.flush();
noExceptions = false;
}
}
if(noExceptions)
{
outFile.printf("No exceptions of this type.%n");
outFile.flush();
}
// outFile.printf("%s leave compareOpenAndClosePEB%n%n", TAG);
// outFile.flush();
} // private void compareOpenAndClosePEB(PrintWriter outFile)
/*********************************************************************
* Method to compare the vote totals.
**/
private void compareVoteTotals(PrintWriter outFile)
{
int count152;
int count155;
// outFile.printf("%s enter compareVoteTotals%n", TAG);
// outFile.flush();
count152 = Globals.getBallotCount152();
if(count152 < 0) count152 -= Integer.MIN_VALUE;
outFile.printf("Ballot total in 152: %10d%n", count152);
count155 = Globals.getBallotCount155();
if(count155 < 0) count155 -= Integer.MIN_VALUE;
outFile.printf("Ballot total in 155: %10d%n", count155);
if(count152 != count155)
outFile.printf("BALLOT TOTALS DIFFER%n");
outFile.flush();
// outFile.printf("%s leave compareVoteTotals%n%n", TAG);
// outFile.flush();
} // private void compareVoteTotals(PrintWriter outFile)
/*********************************************************************
* Method to count pairs of events.
**/
private void countEventPairs(PrintWriter outFile)
{
String multKey = "";
String first = "";
String second = "";
TreeMap<String, Integer> pairs = new TreeMap<String, Integer>();
// outFile.printf("%s enter countEventPairs%n", TAG);
// outFile.flush();
outFile.printf("%sListing pairs of successive events (includes 750+)%n", TAG);
outFile.flush();
for(String termKey: Globals.theTerms.keySet())
{
OneTerminal term = Globals.theTerms.get(termKey);
for(int i = 0; i < term.getEventLogSize()-1; ++i)
{
first = term.getEvent(i);
first = OneEvent.getCode(first);
second = term.getEvent(i+1);
second = OneEvent.getCode(second);
if(first.equals("0001510")) continue;
if(second.equals("0001510")) continue;
if(first.equals("0001511")) continue;
if(second.equals("0001511")) continue;
if(first.equals("0001512")) continue;
if(second.equals("0001512")) continue;
// outFile.printf("%s PAIR '%s' '%s'%n", TAG, first, second);
// outFile.flush();
multKey = first + second;
Globals.incrementTreeMap(multKey, pairs, 1);
}
}
ArrayList<String> pairsReverse = new ArrayList<String>();
for(String key: pairs.keySet())
{
// outFile.printf("%s PAIRCOUNT '%s' '%d'%n", TAG,
// key, pairs.get(key));
// outFile.flush();
String ss = String.format("%8d %s", pairs.get(key), key);
pairsReverse.add(ss);
}
Collections.sort(pairsReverse, Collections.reverseOrder());
for(String ss: pairsReverse)
{
if(Integer.valueOf(ss.substring(0,8).trim()) <= 2) continue;
outFile.printf("%s PAIRS '%s'%n", TAG, ss);
first = ss.substring( 9,16);
second = ss.substring(16,23);
outFile.printf("%s '%s' '%s'%n", TAG,
first, Globals.eventTexts.get(first));
outFile.printf("%s '%s' '%s'%n", TAG,
second, Globals.eventTexts.get(second));
outFile.printf("%n");
outFile.flush();
}
// outFile.printf("%s leave countEventPairs%n", TAG);
// outFile.flush();
} // private void countEventPairs(PrintWriter outFile)
/*********************************************************************
* Method to count quadruples of events.
**/
private void countEventQuads(PrintWriter outFile)
{
String multKey = "";
String first = "";
String second = "";
String third = "";
String fourth = "";
TreeMap<String, Integer> quads = new TreeMap<String, Integer>();
// outFile.printf("%s enter countEventQuads%n", TAG);
// outFile.flush();
outFile.printf("%sListing quadruples of successive events (includes 750+)%n", TAG);
outFile.flush();
for(String termKey: Globals.theTerms.keySet())
{
OneTerminal term = Globals.theTerms.get(termKey);
for(int i = 0; i < term.getEventLogSize()-3; ++i)
{
first = term.getEvent(i);
first = OneEvent.getCode(first);
second = term.getEvent(i+1);
second = OneEvent.getCode(second);
third = term.getEvent(i+2);
third = OneEvent.getCode(third);
fourth = term.getEvent(i+3);
fourth = OneEvent.getCode(fourth);
if(first.equals("0001510")) continue;
if(second.equals("0001510")) continue;
if(third.equals("0001510")) continue;
if(fourth.equals("0001510")) continue;
if(first.equals("0001511")) continue;
if(second.equals("0001511")) continue;
if(third.equals("0001511")) continue;
if(fourth.equals("0001510")) continue;
if(first.equals("0001512")) continue;
if(second.equals("0001512")) continue;
if(third.equals("0001512")) continue;
if(fourth.equals("0001510")) continue;
// outFile.printf("%s QUAD '%s' '%s' '%s' '%s'%n", TAG,
// first, second, third, fourth);
// outFile.flush();
multKey = first + second + third + fourth;
Globals.incrementTreeMap(multKey, quads, 1);
}
}
ArrayList<String> quadsReverse = new ArrayList<String>();
for(String key: quads.keySet())
{
// outFile.printf("%s QUADCOUNT '%s' '%d'%n", TAG,
// key, quads.get(key));
// outFile.flush();
String ss = String.format("%8d %s", quads.get(key), key);
quadsReverse.add(ss);
}
Collections.sort(quadsReverse, Collections.reverseOrder());
for(String ss: quadsReverse)
{
if(Integer.valueOf(ss.substring(0,8).trim()) <= 2) continue;
outFile.printf("%s QUADS '%s'%n", TAG, ss);
first = ss.substring( 9,16);
second = ss.substring(16,23);
third = ss.substring(23,30);
fourth = ss.substring(30,37);
outFile.printf("%s '%s' '%s'%n", TAG,
first, Globals.eventTexts.get(first));
outFile.printf("%s '%s' '%s'%n", TAG,
second, Globals.eventTexts.get(second));
outFile.printf("%s '%s' '%s'%n", TAG,
third, Globals.eventTexts.get(third));
outFile.printf("%s '%s' '%s'%n", TAG,
fourth, Globals.eventTexts.get(fourth));
outFile.printf("%n");
outFile.flush();
}
// outFile.printf("%s leave countEventQuads%n", TAG);
// outFile.flush();
} // private void countEventQuads(PrintWriter outFile)
/*********************************************************************
* Method to count triples of events.
**/
private void countEventTriples(PrintWriter outFile)
{
String first = "";
String pairKey = "";
String second = "";
String third = "";
TreeMap<String, Integer> triples = new TreeMap<String, Integer>();
// outFile.printf("%s enter countEventTriples%n", TAG);
// outFile.flush();
outFile.printf("%sListing triples of successive events (includes 750+)%n", TAG);
outFile.flush();
for(String termKey: Globals.theTerms.keySet())
{
OneTerminal term = Globals.theTerms.get(termKey);
for(int i = 0; i < term.getEventLogSize()-2; ++i)
{
first = term.getEvent(i);
first = OneEvent.getCode(first);
second = term.getEvent(i+1);
second = OneEvent.getCode(second);
third = term.getEvent(i+2);
third = OneEvent.getCode(third);
if(first.equals("0001510")) continue;
if(second.equals("0001510")) continue;
if(third.equals("0001510")) continue;
if(first.equals("0001511")) continue;
if(second.equals("0001511")) continue;
if(third.equals("0001511")) continue;
if(first.equals("0001512")) continue;
if(second.equals("0001512")) continue;
if(third.equals("0001512")) continue;
// outFile.printf("%s TRIP '%s' '%s' '%s'%n", TAG, first, second, third);
// outFile.flush();
pairKey = first + second + third;
Globals.incrementTreeMap(pairKey, triples, 1);
}
}
ArrayList<String> triplesReverse = new ArrayList<String>();
for(String key: triples.keySet())
{
// outFile.printf("%s TRIPCOUNT '%s' '%d'%n", TAG,
// key, triples.get(key));
// outFile.flush();
String ss = String.format("%8d %s", triples.get(key), key);
triplesReverse.add(ss);
}
Collections.sort(triplesReverse, Collections.reverseOrder());
for(String ss: triplesReverse)
{
if(Integer.valueOf(ss.substring(0,8).trim()) <= 2) continue;
outFile.printf("%s TRIPS '%s'%n", TAG, ss);
first = ss.substring( 9,16);
second = ss.substring(16,23);
third = ss.substring(23,30);
outFile.printf("%s '%s' '%s'%n", TAG,
first, Globals.eventTexts.get(first));
outFile.printf("%s '%s' '%s'%n", TAG,
second, Globals.eventTexts.get(second));
outFile.printf("%s '%s' '%s'%n", TAG,
third, Globals.eventTexts.get(third));
outFile.printf("%n");
outFile.flush();
}
// outFile.printf("%s leave countEventTriples%n", TAG);
// outFile.flush();
} // private void countEventTriples(PrintWriter outFile)
/*********************************************************************
* Method to count the opening and closing PEBs in each pct.
**/
private void countOpenClosePerPct()
{
FileUtils.logFile.printf("%s enter countOpenClosePerPct%n", TAG);
FileUtils.logFile.flush();
for(String termKey: Globals.theTerms.keySet())
{
OneTerminal term = Globals.theTerms.get(termKey);
TreeMap<String, String> pcts = term.getPcts();
for(String key: pcts.keySet())
{
OnePrecinct pct = Globals.pctsByNumber.get(pcts.get(key));
// FileUtils.logFile.printf("%s PCTKEY %s %s%n", TAG,
// key, pcts.get(key));
// FileUtils.logFile.flush();
pct.setTerm(term.getIvoNumber());
pct.setOpenPEB(term.getOpenPEB());
pct.setClosePEB(term.getClosePEB());
// FileUtils.logFile.printf("%s PCTNOW %s%n", TAG,
// pct.toString());
// FileUtils.logFile.flush();
}
}
FileUtils.logFile.printf("%s leave countOpenClosePerPct%n", TAG);
FileUtils.logFile.flush();
} // private void countOpenClosePerPct()
/*********************************************************************
* Method to count the votes per terminal.
**/
private void countTheVotes()
{
Integer localCount = 0;
String candidate = "";
String contest = "";
String ivo = "";
String keyconcand = "";
String keypctconcand = "";
String keypctivoconcand = "";
String keypctivostylecon = "";
String pct = "";
String style = "";
FileUtils.logFile.printf("%s enter countTheVotes%n", TAG);
FileUtils.logFile.flush();
for(String votesKey: Globals.theVotes.keySet())
{
candidate = Keys.getCandidateFromTheVotesKey(votesKey);
contest = Keys.getContestFromTheVotesKey(votesKey);
ivo = Keys.getIvoFromTheVotesKey(votesKey);
pct = Keys.getPctFromTheVotesKey(votesKey);
style = Keys.getStyleFromTheVotesKey(votesKey);
localCount = Globals.theVotes.get(votesKey);
// add in to the contest-candidate map
keyconcand = Keys.makeKeyForConCand(contest, candidate);
Globals.incrementTreeMap(keyconcand, Globals.conCand, localCount);
// add in to the pct-contest-candidate map
keypctconcand = Keys.makeKeyForPctConCand(pct, contest, candidate);
Globals.incrementTreeMap(keypctconcand, Globals.pctConCand, localCount);
// add in to the pct-ivo-contest-candidate map
keypctivoconcand = Keys.makeKeyForPctIvoConCand(pct, ivo, contest, candidate);
Globals.incrementTreeMap(keypctivoconcand, Globals.pctIvoConCand, localCount);
// add in to the pct-ivo-style-contest map
keypctivostylecon = Keys.makeKeyForPctIvoStyleCon(pct, ivo, style, contest);
Globals.incrementTreeMap(keypctivostylecon, Globals.pctIvoStyleCon, localCount);
}
FileUtils.logFile.printf("%s leave countTheVotes%n", TAG);
FileUtils.logFile.flush();
} // private void countTheVotes()
/*********************************************************************
* Method to do the analysis.
*
* @param prefix the file name prefix
**/
public void doAnalysis(String prefix, String date)
{
FileUtils.logFile.printf("%s enter doAnalysis%n", TAG);
FileUtils.logFile.flush();
//****************************************************************
// The first task is to produce the exceptions list of things
// that should not happen but did.
String exceptionFileName = prefix + "_EXCEPTIONS.txt";
PrintWriter exceptionFile = FileUtils.PrintWriterOpen(exceptionFileName);
exceptionFile.printf("%n%n%n%n%n");
exceptionFile.printf("********** ********** ********** ");
exceptionFile.printf("********** ********** **********%n");
exceptionFile.printf("********** ********** ********** ");
exceptionFile.printf("********** ********** **********%n%n");
exceptionFile.printf("EXCEPTIONS file for %s%n%n", Globals.getCounty());
exceptionFile.flush();
this.compareVoteTotals(exceptionFile);
this.compareIvos152V155(exceptionFile);
this.compareOpenAndClosePEB(exceptionFile);
this.compare152And68APEBS(exceptionFile);
this.findAnomalousOpenCloseTimes(exceptionFile, date);
this.verifyMemoryCardCollection(exceptionFile);
FileUtils.CloseFile(exceptionFile);
//****************************************************************
// Now we do the histograms and statistics on regular things.
String statsFileName = prefix + "_Statistics.txt";
PrintWriter statsFile = FileUtils.PrintWriterOpen(statsFileName);
statsFile.printf("%sProcess statistics file for %s%n%n",
TAG, Globals.getCounty());
statsFile.flush();
this.statisticsProcess(statsFile);
FileUtils.CloseFile(statsFile);
//****************************************************************
// Next we do histos and stats on things we think are anomalous.
String anomalyFileName = prefix + "_StatisticsAnomalies.txt";
PrintWriter anomalyFile = FileUtils.PrintWriterOpen(anomalyFileName);
anomalyFile.printf("%sStatistical anomalies file for %s%n%n",
TAG, Globals.getCounty());
anomalyFile.flush();
this.statisticsAnomalies(anomalyFile);
FileUtils.CloseFile(anomalyFile);
FileUtils.logFile.printf("%s leave doAnalysis%n", TAG);
FileUtils.logFile.flush();
} // public void doAnalysis(String prefix, String date)
/*********************************************************************
* Method to fill out data values from multiple locations and files.
*
* @param prefix the file name prefix
**/
public void fillOutData(String prefix)
{
FileUtils.logFile.printf("%s enter fillOutData%n", TAG);
FileUtils.logFile.flush();
this.process152events();
this.countTheVotes();
this.countOpenClosePerPct();
String combosFileName = prefix + "_EventLogCombos.txt";
PrintWriter combosFile = FileUtils.PrintWriterOpen(combosFileName);
combosFile.printf("%sSuccessive event combinations for %s%n%n",
TAG, Globals.getCounty());
combosFile.flush();
this.countEventPairs(combosFile);
this.countEventTriples(combosFile);
this.countEventQuads(combosFile);
FileUtils.CloseFile(combosFile);
FileUtils.logFile.printf("%s leave fillOutData%n", TAG);
FileUtils.logFile.flush();
} // public void fillOutData(String prefix)
/*********************************************************************
* Method to find anomalous opening and closing times.
**/
private void findAnomalousOpenCloseTimes(PrintWriter outFile, String electionDate)
{
boolean noExceptions = true;
String time = "";
OneTerminal term = null;
// outFile.printf("%s enter anomaloustimes%n", TAG);
// outFile.flush();
String earlyTime = String.format("%s 05:30:00", Globals.getElectionDate());
String lateTime = String.format("%s 19:45:00", Globals.getElectionDate());
outFile.printf("%n********** ********** ********** ");
outFile.printf("********** ********** **********%n%n");
outFile.printf("Listing terminals with anomalous opening/closing times%n");
outFile.printf("Early time means time before %s%n", earlyTime);
outFile.printf("Late time means time after %s%n", lateTime);
// no open time and/or no close time
noExceptions = true;
outFile.printf("%nListing terminals with no opening/closing times (includes 750+)%n");
outFile.printf("All terminals not in the 152 will appear here%n");
outFile.flush();
for(String termKey: Globals.theTerms.keySet())
{
term = Globals.theTerms.get(termKey);
if(term.getOpenDateTime().equals(Globals.DEFAULTTIME))
{
outFile.printf("NO OPENTIME %s %s %s%n",
term.getIvoNumber(), term.getOpenDateTime(),
term.toStringPcts());
outFile.flush();
noExceptions = false;
}
if(term.getCloseDateTime().equals(Globals.DEFAULTTIME))
{
outFile.printf("NO CLOSETIME %s %s %s%n",
term.getIvoNumber(), term.getCloseDateTime(),
term.toStringPcts());
outFile.flush();
noExceptions = false;
}
} // for(String termKey: Globals.theTerms.keySet())
if(noExceptions)
{
outFile.printf("No exceptions of this type.%n");
outFile.flush();
}
// early open time
noExceptions = true;
outFile.printf("%nListing terminals with early opening times (EXCLUDES 750+)%n");
outFile.flush();
for(String termKey: Globals.theTerms.keySet())
{
term = Globals.theTerms.get(termKey);
if(!term.isNotAbsentee()) continue;
time = term.getOpenDateTime();
if((Globals.compareDateTime(time, earlyTime) < 0) &&
(!time.equals(Globals.DEFAULTTIME)))
{
outFile.printf("Early opentime %s %s %s%n",
term.getIvoNumber(), time, term.toStringPcts());
outFile.flush();
noExceptions = false;
}
} // for(String termKey: Globals.theTerms.keySet())
if(noExceptions)
{
outFile.printf("No exceptions of this type.%n");
outFile.flush();
}
// late open time
noExceptions = true;
outFile.printf("%nListing terminals with late opening times (EXCLUDES 750+)%n");
outFile.flush();
for(String termKey: Globals.theTerms.keySet())
{
term = Globals.theTerms.get(termKey);
if(!term.isNotAbsentee()) continue;
time = term.getOpenDateTime();
if((Globals.compareDateTime(time, lateTime) > 0) &&
(!time.equals(Globals.DEFAULTTIME)))
{
outFile.printf("Late opentime %s %s %s%n",
term.getIvoNumber(), time, term.toStringPcts());
outFile.flush();
noExceptions = false;
}
} // for(String termKey: Globals.theTerms.keySet())
if(noExceptions)
{
outFile.printf("No exceptions of this type.%n");
outFile.flush();
}
// early close time
noExceptions = true;
outFile.printf("%nListing terminals with early closing times (EXCLUDES 750+)%n");
outFile.flush();
for(String termKey: Globals.theTerms.keySet())
{
term = Globals.theTerms.get(termKey);
if(!term.isNotAbsentee()) continue;
time = term.getCloseDateTime();
if((Globals.compareDateTime(time, earlyTime) < 0) &&
(!time.equals(Globals.DEFAULTTIME)))
{
outFile.printf("Early closetime %s %s %s%n",
term.getIvoNumber(), time, term.toStringPcts());
outFile.flush();
noExceptions = false;
}
} // for(String termKey: Globals.theTerms.keySet())
if(noExceptions)
{
outFile.printf("No exceptions of this type.%n");
outFile.flush();
}
// late close time
outFile.printf("%nListing terminals with late closing times (EXCLUDES 750+)%n");
outFile.flush();
ArrayList<OneTerminal> lateTerminalList = new ArrayList<OneTerminal>();
outFile.printf("%nListing terminals by serial number (EXCLUDES 750+)%n");
outFile.flush();
for(String termKey: Globals.theTerms.keySet())
{
term = Globals.theTerms.get(termKey);
if(!term.isNotAbsentee()) continue;
time = term.getCloseDateTime();
if((Globals.compareDateTime(time, lateTime) > 0) &&
(!time.equals(Globals.DEFAULTTIME)))
{
outFile.printf("Late closetime %s %s %s%n",
term.getIvoNumber(), time, term.toStringPcts());
outFile.flush();
noExceptions = false;
lateTerminalList.add(term);
}
} // for(String termKey: Globals.theTerms.keySet())
CompareLateClose compareLateClose = new CompareLateClose();
Collections.sort(lateTerminalList, compareLateClose);
outFile.printf("%nListing terminals by late closing time (EXCLUDES 750+)%n");
outFile.flush();
for(int i = 0; i < lateTerminalList.size(); ++i)
{
// outFile.printf("%s%n", lateTerminalList.get(i));
outFile.printf("Late closetime %s %s %s%n",
lateTerminalList.get(i).getIvoNumber(),
lateTerminalList.get(i).getCloseDateTime(),
lateTerminalList.get(i).toStringPcts());
}
if(noExceptions)
{
outFile.printf("No exceptions of this type.%n");
outFile.flush();
}
// outFile.printf("%s leave anomaloustimes%n%n", TAG);
// outFile.flush();
} // private void findAnomalousOpenCloseTimes(PrintWriter outFile)
/*********************************************************************
* Method to process the events in the event log for each terminal.
*
* This counts the number of votes cast and the number of late votes
* and it sets the open and close time and PEB for a given terminal.
**/
private void process152events()
{
FileUtils.logFile.printf("%s enter process152events%n", TAG);
FileUtils.logFile.flush();
for(String termKey: Globals.theTerms.keySet())
{
OneTerminal term = Globals.theTerms.get(termKey);
term.process152events();
}
FileUtils.logFile.printf("%s leave process152events%n", TAG);
FileUtils.logFile.flush();
} // private void process152events()
/*********************************************************************
* Method to do statistics, histograms, etc., of various sorts.
**/
private void statisticsProcess(PrintWriter outFile)
{
ArrayList<ArrayList<String>> labels = null;
ArrayList<String> temp = null;
ArrayList<Integer> numbers = null;
//****************************************************************
// The first stats we do are of votes per terminal
labels = new ArrayList<ArrayList<String>>();
numbers = new ArrayList<Integer>();
outFile.printf("%n********** ********** ********** ");
outFile.printf("********** ********** **********%n%n");
outFile.printf("%sChecking that terminal vote counts are consistent (EXCLUDES 750+)%n", TAG);
outFile.flush();
for(String termKey: Globals.theTerms.keySet())
{
OneTerminal term = Globals.theTerms.get(termKey);
// we test that the term is not a not-absentee term
// because the default is to set both the booleans to true
// so if the terminal isn't in the list then notAbsentee=true
if(!term.isNotAbsentee()) continue;
temp = new ArrayList<String>();
temp.add(term.toStringPcts()); // sort first on pct number(s)
temp.add(term.getIvoNumber()); // then on ivo number
if((term.getVotesCast152() == Globals.DUMMYINT) &&
(term.getVotesCast155() == Globals.DUMMYINT))
{
outFile.printf("%n%s Term %s votes 152=XXXXXX and 155=XXXXXX both dummy values%n",
TAG, term.getIvoNumber());
outFile.flush();
}
else if(term.getVotesCast152() == Globals.DUMMYINT)
{
outFile.printf("%n%s Term %s votes 152=XXXXXX and 155=%d disagree, using 155%n",
TAG, term.getIvoNumber(), term.getVotesCast155());
outFile.flush();
labels.add(temp);
numbers.add(term.getVotesCast155());
}
else if(term.getVotesCast155() == Globals.DUMMYINT)
{
outFile.printf("%n%s Term %s votes 152=%d and 155=XXXXXX disagree, using 152%n",
TAG, term.getIvoNumber(), term.getVotesCast152());
outFile.flush();
labels.add(temp);
numbers.add(term.getVotesCast152());
}
else // if they agree, we use the 155 number
{
labels.add(temp);
numbers.add(term.getVotesCast155());
}
}
outFile.printf("%n%s Histogram of votes per terminal (EXCLUDES 750+)%n", TAG);
outFile.flush();
// silly bubble sort by pct number
for(int i = 0; i < labels.size()-1; ++i)
{
for(int j = i+1; j < labels.size(); ++j)
{
if(labels.get(i).get(0).compareTo(labels.get(j).get(0)) > 0)
{
ArrayList<String> tempList = labels.get(i);
labels.set(i, labels.get(j));
labels.set(j, tempList);
Integer tempInt = numbers.get(i);
numbers.set(i, numbers.get(j));
numbers.set(j, tempInt);
}
}
}
Statistics.doStats(outFile, labels, numbers, 200, 4, true); // last is print
//****************************************************************
// Now we do stats on votes cast after closing
labels = new ArrayList<ArrayList<String>>();
numbers = new ArrayList<Integer>();
for(String termKey: Globals.theTerms.keySet())
{
OneTerminal term = Globals.theTerms.get(termKey);
temp = new ArrayList<String>();
temp.add(term.getIvoNumber());
labels.add(temp);
numbers.add(term.getLateVotesCast152());
}
outFile.printf("%n********** ********** ********** ");
outFile.printf("********** ********** **********%n%n");
outFile.printf("%s Histogram of votes after closing time (EXCLUDES 750+)%n", TAG);
outFile.flush();
Statistics.doStats(outFile, labels, numbers, 50, 1, true); // last is print
//****************************************************************
// Now we do a histo of the closing times themselves
labels = new ArrayList<ArrayList<String>>();
numbers = new ArrayList<Integer>();
for(String termKey: Globals.theTerms.keySet())
{
OneTerminal term = Globals.theTerms.get(termKey);