-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCheckSchedule.py
1547 lines (1355 loc) · 76.9 KB
/
CheckSchedule.py
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 copy
import time
import math
import argparse
import statistics
from collections import Counter
from GlobalConstants import *
from GeneralFunctions import *
def get_spacing_data(match_schedule, specific_team_number, in_blocks=False):
number_of_teams = get_number_of_teams_from_schedule(match_schedule, in_blocks)
#get_match_spacing()
present_match_numbers = []
counter = 0
half_counter = 0
if in_blocks:
for league_block in match_schedule:
for match in league_block:
if specific_team_number in match:
present_match_numbers.append(counter)
half_counter += 1
if half_counter == NUMBER_OF_ARENAS:
counter += 1
half_counter = 0
else:
for match in match_schedule:
if specific_team_number in match:
present_match_numbers.append(counter)
half_counter += 1
if half_counter == NUMBER_OF_ARENAS:
counter += 1
half_counter = 0
#analyse_match_spacing()
spacings_data = []
n = 0
while n < len(present_match_numbers)-1:
spacings_data.append(present_match_numbers[n+1]-present_match_numbers[n]-1)
n += 1
return spacings_data
def min_value_from_list(list):
min_value = list[0]
for value in list:
if value < min_value:
min_value = value
return min_value
def min_value_from_dict(dict):
min_value = dict[next(iter(dict))]
for value in dict.values():
if value < min_value:
min_value = value
return min_value
def max_value_from_list(list):
max_value = list[0]
for value in list:
if value > max_value:
max_value = value
return max_value
def max_value_from_dict(dict):
max_value = dict[next(iter(dict))]
for value in dict.values():
if value > max_value:
max_value = value
return max_value
def av_value_from_list(list):
sum = 0
for value in list:
sum += value
return sum/len(list)
def av_value_from_dict(dict):
sum = 0
for value in dict.values():
sum += value
return sum/len(dict.keys())
def spacing_check(match_schedule, summary_of_checks, exclude_teams_list, detailed=False):
number_of_teams = get_number_of_teams_from_schedule(match_schedule)-len(exclude_teams_list)
output_text = "\n## Spacings\n"
output_text += "\n#### This looks at the spacing between matches for each team."
if INCREMENT_SPACING_CHECK:
output_text += "\n#### Spacing is given as the difference between the two match numbers. E.g. a spacing of 4 is (on, off, off, off, on).\n"
else:
output_text += "\n#### Spacing is given as the gap between two matches. E.g. a spacing of 3 is (on, off, off, off, on).\n"
min_spacings_list = {}
av_spacings_list = {}
max_spacings_list = {}
spacings_data_all = {}
list_of_team_numbers = get_list_of_team_numbers_from_schedule(match_schedule)
number_of_teams_per_match = get_number_of_teams_per_match_from_schedule(match_schedule)
for team_number in list_of_team_numbers:
if not team_number in exclude_teams_list:
spacings_data = get_spacing_data(match_schedule, team_number)
if INCREMENT_SPACING_CHECK:
n = 0
while n < len(spacings_data):
spacings_data[n] += 1
n += 1
spacings_data_all[team_number] = spacings_data
min_spacings_list[team_number] = min_value_from_list(spacings_data)
max_spacings_list[team_number] = max_value_from_list(spacings_data)
av_spacings_list[team_number] = round(av_value_from_list(spacings_data), 2)
# min_spacings_list.append(min_value_from_list(spacings_data))
# max_spacings_list.append(max_value_from_list(spacings_data))
# av_spacings_list.append(round(av_value_from_list(spacings_data), 2))
strong_alert_level_low = 0
medium_alert_level_low = 1
weak_alert_level_low = 2
target_spacing = number_of_teams/number_of_teams_per_match - 1
weak_alert_level_high = target_spacing*2+1
medium_alert_level_high = target_spacing*3
weak_alert_level_high_count = 0
medium_alert_level_high_count = 0
strong_alert_low_text, medium_alert_low_text, weak_alert_low_text = "", "", ""
if INCREMENT_SPACING_CHECK:
strong_alert_level += 1
medium_alert_level += 1
weak_alert_level += 1
weak_alert_level_high += 1
medium_alert_level_high += 1
min_spacing_summary_list = []
max_spacing_summary_list = []
av_spacing_summary_list = []
min_spacing_summary_list.append(min_value_from_dict(min_spacings_list))
min_spacing_summary_list.append(av_value_from_dict(min_spacings_list))
min_spacing_summary_list.append(max_value_from_dict(min_spacings_list))
max_spacing_summary_list.append(min_value_from_dict(max_spacings_list))
max_spacing_summary_list.append(av_value_from_dict(max_spacings_list))
max_spacing_summary_list.append(max_value_from_dict(max_spacings_list))
av_spacing_summary_list.append(min_value_from_dict(av_spacings_list))
av_spacing_summary_list.append(av_value_from_dict(av_spacings_list))
av_spacing_summary_list.append(max_value_from_dict(av_spacings_list))
top_line_text = " min av max"
min_spacing_output_text = f"Minimum Spacings: {min_spacing_summary_list[0]:4.1f} {min_spacing_summary_list[1]:4.1f} {min_spacing_summary_list[2]:4.1f}"
av_spacing_output_text = f"Average Spacings: {av_spacing_summary_list[0]:4.1f} {av_spacing_summary_list[1]:4.1f} {av_spacing_summary_list[2]:4.1f}"
max_spacing_output_text = f"Maximum Spacings: {max_spacing_summary_list[0]:4.1f} {max_spacing_summary_list[1]:4.1f} {max_spacing_summary_list[2]:4.1f}"
output_text += f"\n{top_line_text}\n{min_spacing_output_text}\n{av_spacing_output_text}\n{max_spacing_output_text}\n"
min_spacings_count_list = []
min_spacing_list_totals = Counter(min_spacings_list.values())
total = 0
n = 0
while n < 99:
number_of_n = min_spacing_list_totals[n]
min_spacings_count_list.append(number_of_n)
total += number_of_n
if total == number_of_teams:
break
n += 1
max_spacings_count_list = []
ax_spacing_list_totals = Counter(max_spacings_list.values())
total = 0
n = 0
while n < 99:
number_of_n = ax_spacing_list_totals[n]
max_spacings_count_list.append(number_of_n)
total += number_of_n
if total == number_of_teams:
break
n += 1
min_spacings_count_text = "Number of teams with each minimum spacing:\n"
n = 0
while n < len(min_spacings_count_list):
if min_spacings_count_list[n] > 0:
text_to_add = f"Min spacing of {n:>2}: {min_spacings_count_list[n]:>3} teams"
if n == strong_alert_level_low:
colour_for_text = "red"
text = f"{min_spacings_count_list[n]:>3} teams have a minimum spacing of {strong_alert_level_low}."
strong_alert_low_text = f"{colour_text(text, 'red')} This spacing is impossible for a physical competition as it would result in consecutive matches (on, on)."
add_team_numbers = True
summary_of_checks[0].append(["minimum spacing", strong_alert_low_text])
elif n == medium_alert_level_low:
colour_for_text = "orange"
text = f"{min_spacings_count_list[n]:>3} teams have a minimum spacing of {medium_alert_level_low}."
medium_alert_low_text = f"{colour_text(text, 'orange')} This spacing is very tight for a physical competition as it would result in almost consecutive matches (on, off, on)."
add_team_numbers = True
summary_of_checks[1].append(["minimum spacing", medium_alert_low_text])
elif n == weak_alert_level_low:
colour_for_text = "yellow"
text = f"{min_spacings_count_list[n]:>3} teams have a minimum spacing of {weak_alert_level_low}."
weak_alert_low_text = f"{colour_text(text, 'yellow')} This spacing is a bit close for a physical competition, but still very usable (on, off, off, on)."
add_team_numbers = True
summary_of_checks[2].append(["minimum spacing", weak_alert_low_text])
else:
colour_for_text = None
add_team_numbers = False
if add_team_numbers:
team_list_text = get_team_list_text_when_number_matches_dict(min_spacings_list, n)
else:
team_list_text = ""
min_spacings_count_text += f"{colour_text(text_to_add, colour_for_text)}{team_list_text}\n"
n += 1
min_spacings_count_text = min_spacings_count_text[:-1]
output_text = f"{output_text}\n{min_spacings_count_text}\n"
max_spacings_count_text = "Number of teams with each maximum spacing:\n"
n = 0
while n < len(max_spacings_count_list):
if max_spacings_count_list[n] > 0:
text_to_add = f"Max spacing of {n:>2}: {max_spacings_count_list[n]:>3} teams"
if n > medium_alert_level_high:
colour_for_text = "orange"
medium_alert_level_high_count += max_spacings_count_list[n]
add_team_numbers = True
elif n > weak_alert_level_high:
colour_for_text = "yellow"
weak_alert_level_high_count += max_spacings_count_list[n]
add_team_numbers = True
else:
colour_for_text = None
add_team_numbers = False
if add_team_numbers:
team_list_text = get_team_list_text_when_number_matches_dict(max_spacings_list, n)
else:
team_list_text = ""
max_spacings_count_text += f"{colour_text(text_to_add, colour_for_text)}{team_list_text}\n"
n += 1
max_spacings_count_text = max_spacings_count_text[:-1]
output_text = f"{output_text}\n{max_spacings_count_text}\n"
if strong_alert_low_text != "":
output_text += f"\n{strong_alert_low_text}"
output_text += "\n"
if medium_alert_low_text != "":
output_text += f"\n{medium_alert_low_text}"
output_text += "\n"
if weak_alert_low_text != "":
output_text += f"\n{weak_alert_low_text}"
output_text += "\n"
if medium_alert_level_high_count > 0:
text = f"{medium_alert_level_high_count:>3} teams have a maximum spacing larger than {math.floor(medium_alert_level_high):>2}."
medium_alert_level_high_text = f"{colour_text(text, 'orange')} This spacing is very large for a competition."
summary_of_checks[1].append(["maximum spacing", medium_alert_level_high_text])
output_text += f"\n{medium_alert_level_high_text}"
output_text += "\n"
if weak_alert_level_high_count > 0:
text = f"{weak_alert_level_high_count+medium_alert_level_high_count:>3} teams have a maximum spacing larger than {math.floor(weak_alert_level_high):>2}."
weak_alert_level_high_text = f"{colour_text(text, 'yellow')} This spacing is quite large for a competition, but still very usable."
summary_of_checks[2].append(["maximum spacing", weak_alert_level_high_text])
output_text += f"\n{weak_alert_level_high_text}"
output_text += "\n"
output_text += "\n"
if detailed:
separated = False
if separated:
#Minimum stuff: [team_num, min_spacing, count]
output_text += "\n Team Min Count"
min_spacing_detailed_list = []
for n, spacings_data in spacings_data_all.items():
min_spacing = min_spacings_list[n]
spacing_count = spacings_data.count(min_spacing)
add_array = [n+1, min_spacing, spacing_count, 100*min_spacing-spacing_count]
min_spacing_detailed_list.append(add_array)
min_spacing_detailed_list = order_array_list(min_spacing_detailed_list, 3)
for row in min_spacing_detailed_list:
text_to_add = f"\n {row[0]:>3} {row[1]:>2} {row[2]:>2}"
if row[1] == strong_alert_level_low:
colour = "red"
elif row[1] == medium_alert_level_low:
colour = "orange"
elif row[1] == weak_alert_level_low:
colour = "yellow"
else:
colour = None
output_text += colour_text(text_to_add, colour)
output_text += "\n"
#Average stuff: [team_num, average_spacing]
output_text += "\n Team Av"
closest_to_target = 999999
n = 0
while n < len(av_spacings_list):
if abs(target_spacing-av_spacings_list[n]) < closest_to_target:
closest_to_target = abs(target_spacing-av_spacings_list[n])
n += 1
closest_to_target = round(closest_to_target, 2)
av_spacing_detailed_list = []
for n, spacings_data in spacings_data_all.items():
av_spacing = av_value_from_list(spacings_data)
add_array = [n+1, round(av_spacing,5)]
av_spacing_detailed_list.append(add_array)
av_spacing_detailed_list = order_array_list(av_spacing_detailed_list, 1, False)
for row in av_spacing_detailed_list:
text_to_add = f"\n {row[0]:>3} {row[1]:3.1f}"
if round(abs(target_spacing-round(row[1],2)),2) == closest_to_target:
colour = "dark green"
else:
colour = None
output_text += colour_text(text_to_add, colour)
output_text += "\n"
#Maximum stuff: [team_num, max_spacing, count]
output_text += "\n Team Max Count"
max_spacing_detailed_list = []
for n, spacings_data in spacings_data_all.items():
max_spacing = max_spacings_list[n]
spacing_count = spacings_data.count(max_spacing)
add_array = [n+1, max_spacing, spacing_count, 100*max_spacing+spacing_count]
max_spacing_detailed_list.append(add_array)
max_spacing_detailed_list = order_array_list(max_spacing_detailed_list, 3, True)
for row in max_spacing_detailed_list:
text_to_add = f"\n {row[0]:>3} {row[1]:>2} {row[2]:>2}"
if row[1] > medium_alert_level_high:
colour = "orange"
elif row[1] > weak_alert_level_high:
colour = "yellow"
else:
colour = None
output_text += colour_text(text_to_add, colour)
output_text += "\n"
#Spacing stuff: [team_num, list_of_spacings]
output_text += "\n Team Spacings"
for n, spacings_data in enumerate(spacings_data_all):
text_to_add = f"\n {n+1:>3} "
for spacing in spacings_data:
text_to_add += f"{spacing:>2}, "
text_to_add = text_to_add[:-2]
output_text += text_to_add
else:
#Minimum stuff: [team_num, min_spacing, count]
min_spacing_detailed_list = []
for n, spacings_data in spacings_data_all.items():
min_spacing = min_spacings_list[n]
spacing_count = spacings_data.count(min_spacing)
add_array = [n, min_spacing, spacing_count, 100*min_spacing-spacing_count]
min_spacing_detailed_list.append(add_array)
min_spacing_detailed_list_sorted_by_team = min_spacing_detailed_list.copy()
min_spacing_detailed_list = order_array_list(min_spacing_detailed_list.copy(), 3)
#Average stuff: [team_num, average_spacing]
closest_to_target = 999999
for value in av_spacings_list.values():
if abs(target_spacing-value) < closest_to_target:
closest_to_target = abs(target_spacing-value)
closest_to_target = round(closest_to_target, 2)
av_spacing_detailed_list = []
for n, spacings_data in spacings_data_all.items():
av_spacing = av_value_from_list(spacings_data)
add_array = [n, round(av_spacing,5)]
av_spacing_detailed_list.append(add_array)
av_spacing_detailed_list_sorted_by_team = av_spacing_detailed_list.copy()
av_spacing_detailed_list = order_array_list(av_spacing_detailed_list.copy(), 1, False)
#Maximum stuff: [team_num, max_spacing, count]
max_spacing_detailed_list = []
for n, spacings_data in spacings_data_all.items():
max_spacing = max_spacings_list[n]
spacing_count = spacings_data.count(max_spacing)
add_array = [n, max_spacing, spacing_count, 100*max_spacing+spacing_count]
max_spacing_detailed_list.append(add_array)
max_spacing_detailed_list_sorted_by_team = max_spacing_detailed_list.copy()
max_spacing_detailed_list = order_array_list(max_spacing_detailed_list.copy(), 3, True)
gap_between_sections = " "
min_spacing_text_top_row = f"{colour_text('Team','blue')} Min Count"
av_spacing_text_top_row = f"{colour_text('Team','blue')} Av"
max_spacing_text_top_row = f"{colour_text('Team','blue')} Max Count"
output_text += f"\n {min_spacing_text_top_row} {av_spacing_text_top_row} {max_spacing_text_top_row}"
for n, row in enumerate(min_spacing_detailed_list):
min_spacing_team_num = min_spacing_detailed_list[n][0]
min_spacing = min_spacing_detailed_list[n][1]
min_spacing_count = min_spacing_detailed_list[n][2]
if min_spacing == strong_alert_level_low:
colour = "red"
elif min_spacing == medium_alert_level_low:
colour = "orange"
elif min_spacing == weak_alert_level_low:
colour = "yellow"
else:
colour = None
min_spacing_team_num = colour_text(f"{min_spacing_team_num:>3}",'blue')
min_spacing = colour_text(f"{min_spacing:>2}",colour)
min_spacing_count = f"{min_spacing_count:>2}"
min_spacing_text = f"{min_spacing_team_num} {min_spacing} {min_spacing_count}"
av_spacing_team_num = av_spacing_detailed_list[n][0]
av_spacing = av_spacing_detailed_list[n][1]
if round(abs(target_spacing-round(av_spacing,2)),2) == closest_to_target:
colour = "dark green"
else:
colour = None
av_spacing_team_num = colour_text(f"{av_spacing_team_num:>3}",'blue')
av_spacing = colour_text(f"{av_spacing:3.1f}",colour)
av_spacing_text = f"{av_spacing_team_num} {av_spacing}"
max_spacing_team_num = max_spacing_detailed_list[n][0]
max_spacing = max_spacing_detailed_list[n][1]
max_spacing_count = max_spacing_detailed_list[n][2]
if max_spacing > medium_alert_level_high:
colour = "orange"
elif max_spacing > weak_alert_level_high:
colour = "yellow"
else:
colour = None
max_spacing_team_num = colour_text(f"{max_spacing_team_num:>3}",'blue')
max_spacing = colour_text(f"{max_spacing:>2}",colour)
max_spacing_count = f"{max_spacing_count:>2}"
max_spacing_text = f"{max_spacing_team_num} {max_spacing} {max_spacing_count}"
text_to_add = f"\n {min_spacing_text}{gap_between_sections}{av_spacing_text}{gap_between_sections}{max_spacing_text}"
output_text += text_to_add
output_text += "\n"
gap_between_sections = " "
# output_text += f"\n {colour_text('Team','blue')} Min Count Av Max Count"
output_text += f"\n {colour_text('Team','blue')} Min Av Max Spacings" #For when count is in brackets.
for n, row in enumerate(min_spacing_detailed_list_sorted_by_team):
team_number = min_spacing_detailed_list_sorted_by_team[n][0]
min_spacing = min_spacing_detailed_list_sorted_by_team[n][1]
min_spacing_count = min_spacing_detailed_list_sorted_by_team[n][2]
if min_spacing == strong_alert_level_low:
colour = "red"
elif min_spacing == medium_alert_level_low:
colour = "orange"
elif min_spacing == weak_alert_level_low:
colour = "yellow"
else:
colour = None
min_spacing = colour_text(f"{min_spacing:>2}",colour)
min_spacing_count = f"({min_spacing_count})"
min_spacing_text = f"{min_spacing} {min_spacing_count}"
min_spacing_text = f"{min_spacing} {min_spacing_count:>4}" #For when count is in brackets
av_spacing = av_spacing_detailed_list_sorted_by_team[n][1]
if round(abs(target_spacing-round(av_spacing,2)),2) == closest_to_target:
colour = "dark green"
else:
colour = None
av_spacing = colour_text(f"{av_spacing:3.1f}",colour)
av_spacing_text = f"{av_spacing}"
max_spacing = max_spacing_detailed_list_sorted_by_team[n][1]
max_spacing_count = max_spacing_detailed_list_sorted_by_team[n][2]
if max_spacing > medium_alert_level_high:
colour = "orange"
elif max_spacing > weak_alert_level_high:
colour = "yellow"
else:
colour = None
max_spacing = colour_text(f"{max_spacing:>2}",colour)
max_spacing_count = f"({max_spacing_count})"
max_spacing_text = f"{max_spacing} {max_spacing_count}"
max_spacing_text = f"{max_spacing} {max_spacing_count:>4}" #For when count is in brackets
spacings_data = spacings_data_all[team_number]
spacing_text = ""
for spacing in spacings_data:
spacing_text += f"{spacing:>2}, "
spacing_text = spacing_text[:-2]
team_number_text = colour_text(f"{team_number:>3}", 'blue')
text_to_add = f"\n {team_number_text} {min_spacing_text}{gap_between_sections}{av_spacing_text}{gap_between_sections}{max_spacing_text}{gap_between_sections}{spacing_text}"
output_text += text_to_add
#Spacing stuff: [team_num, list_of_spacings]
#output_text += "\n Team Spacings"
# for n, spacings_data in enumerate(spacings_data_all):
# text_to_add = f"\n {n+1:>3} "
# for spacing in spacings_data:
# text_to_add += f"{spacing:>2}, "
# text_to_add = text_to_add[:-2]
# output_text += text_to_add
output_text += "\n\n"
return output_text, summary_of_checks
def get_facings_data(match_schedule, specific_team_number, in_blocks=False):
list_of_team_numbers = get_list_of_team_numbers_from_schedule(match_schedule, in_blocks)
number_of_appearances = get_appearances_from_schedule(match_schedule, in_blocks)
#get_facings_data()
facings_data = {}
for team_number in list_of_team_numbers:
facings_data[team_number] = 0
if in_blocks:
for league_block in match_schedule:
for match in league_block:
if specific_team_number in match:
for team_number in list_of_team_numbers:
if team_number in match:
facings_data[team_number] += 1
else:
for match in match_schedule:
if specific_team_number in match:
for team_number in list_of_team_numbers:
if team_number in match:
facings_data[team_number] += 1
#analyse_facings_data()
facing_repeats_data = [0] #Accounts for facing a team 0 times.
for n in range(number_of_appearances):
facing_repeats_data.append(0) #Accounts for facing a team up to the number of appearances times.
for team_number in list_of_team_numbers:
if team_number != specific_team_number:
facing_repeats_data[facings_data[team_number]] += 1
return facing_repeats_data
def get_appearances_data(match_schedule, specific_team_number, in_blocks=False):
number_of_teams = get_number_of_teams_from_schedule(match_schedule, in_blocks)
appearances = 0
if in_blocks:
for league_block in match_schedule:
for match in league_block:
if specific_team_number in match:
appearances += 1
else:
for match in match_schedule:
if specific_team_number in match:
appearances += 1
return appearances
def facings_check(match_schedule, summary_of_checks, exclude_teams_list, detailed=False):
number_of_teams = get_number_of_teams_from_schedule(match_schedule)
number_of_appearances = get_appearances_from_schedule(match_schedule)
output_text = "\n## Facings\n"
output_text += "\n#### This looks at whether a team has faced another team and how often they have done so.\n"
facings_data_all = {}
list_of_team_numbers = get_list_of_team_numbers_from_schedule(match_schedule)
list_of_team_numbers_for_repeats = get_list_of_team_numbers_from_schedule(match_schedule)
for team_number in list_of_team_numbers:
if not team_number in exclude_teams_list:
facings_data = get_facings_data(match_schedule, team_number)
# print(f"{team_number}: {facings_data}")
# facings_data_all.append(facings_data)
facings_data_all[team_number] = facings_data
number_of_teams_per_match = get_number_of_teams_per_match_from_schedule(match_schedule)
best_faces = number_of_appearances*(number_of_teams_per_match-1)
if best_faces > number_of_teams-1:
best_faces = number_of_teams-1
output_text += f"\nNumber of teams that have a specific 'faces (misses)'"
text_to_add = f"faces {best_faces} ({number_of_teams-1-best_faces})"
output_text += f" ({colour_text(text_to_add, 'dark green')} is best):"
strong_alert_level = best_faces-10
medium_alert_level = best_faces-6
weak_alert_level = best_faces-4
strong_alert_level_count, medium_alert_level_count, weak_alert_level_count = 0, 0, 0
n = best_faces
while n >= 0:
total_teams = 0
total_teams_list = []
for m in facings_data_all.keys():
facings_data = facings_data_all[m]
total_non_zero = 0
for q in range(number_of_appearances):
total_non_zero += facings_data[q+1]
if total_non_zero == n:
total_teams += 1
total_teams_list.append(m)
if total_teams > 0:
text_to_add = f" faces {n:>3} {f'({number_of_teams-1-n})':>5}: {total_teams:>3} teams"
if n == best_faces and total_teams == number_of_teams:
text_to_add = colour_text(text_to_add, "green")
checks_text_to_add = f"{total_teams:>3} teams face {n:>3} {f'({number_of_teams-1-n})':>5}."
summary_of_checks[3].append(["facings", f"{colour_text(checks_text_to_add, 'green')} This means all the teams have a perfect facing."])
add_team_numbers = False
elif n == best_faces:
text_to_add = colour_text(text_to_add, "dark green")
add_team_numbers = False
elif n < strong_alert_level:
text_to_add = colour_text(text_to_add, "red")
strong_alert_level_count += total_teams
add_team_numbers = True
elif n < medium_alert_level:
text_to_add = colour_text(text_to_add, "orange")
medium_alert_level_count += total_teams
add_team_numbers = True
elif n < weak_alert_level:
text_to_add = colour_text(text_to_add, "yellow")
weak_alert_level_count += total_teams
add_team_numbers = True
else:
add_team_numbers = False
if add_team_numbers:
team_list_text = tidy_list_of_team_numbers(total_teams_list)
else:
team_list_text = ""
output_text += f"\n{text_to_add}{team_list_text}"
n -= 1
output_text += "\n"
if strong_alert_level_count > 0:
text = f"{strong_alert_level_count:>3} teams have a facing more than {best_faces-strong_alert_level} away from the best possible facing."
strong_alert_level_text = f"{colour_text(text, 'red')} These teams miss facing a lot ({number_of_teams-strong_alert_level}) of teams."
summary_of_checks[0].append(["facings", strong_alert_level_text])
output_text += f"\n{strong_alert_level_text}"
output_text += "\n"
if medium_alert_level_count > 0:
text = f"{strong_alert_level_count+medium_alert_level_count:>3} teams have a facing more than {best_faces-medium_alert_level} away from the best possible facing."
medium_alert_level_text = f"{colour_text(text, 'orange')} These teams miss facing quite a few ({number_of_teams-medium_alert_level}) teams."
summary_of_checks[1].append(["facings", medium_alert_level_text])
output_text += f"\n{medium_alert_level_text}"
output_text += "\n"
if weak_alert_level_count > 0:
text = f"{strong_alert_level_count+medium_alert_level_count+weak_alert_level_count:>3} teams have a facing more than {best_faces-weak_alert_level} away from the best possible facing."
weak_alert_level_text = f"{colour_text(text, 'yellow')} These teams miss facing a few ({number_of_teams-weak_alert_level}) teams."
summary_of_checks[2].append(["facings", weak_alert_level_text])
output_text += f"\n{weak_alert_level_text}"
output_text += "\n"
output_text += "\nRepeats:"
target_repeats = number_of_appearances*(number_of_teams_per_match-1)/number_of_teams
strong_alert_level_repeats = target_repeats+4
medium_alert_level_repeats = target_repeats+2
weak_alert_level_repeats = target_repeats+1
strong_alert_level_repeats_count, medium_alert_level_repeats_count, weak_alert_level_repeats_count = 0, 0, 0
for team_number in exclude_teams_list:
list_of_team_numbers_for_repeats.remove(team_number)
for q in range(number_of_appearances+1):
number_of_teams_at_q = 0
list_of_teams_at_q = []
for m in facings_data_all.keys():
if facings_data_all[m][q] > 0:
number_of_teams_at_q += 1
list_of_teams_at_q.append(m)
if number_of_teams_at_q > 0:
if q > strong_alert_level_repeats:
colour = "red"
add_team_numbers = True
strong_alert_level_repeats_count += number_of_teams_at_q
elif q > medium_alert_level_repeats:
colour = "orange"
add_team_numbers = True
medium_alert_level_repeats_count += number_of_teams_at_q
elif q > weak_alert_level_repeats:
colour = "yellow"
add_team_numbers = True
weak_alert_level_repeats_count += number_of_teams_at_q
else:
colour = None
add_team_numbers = False
text_to_add = colour_text(f" {number_of_teams_at_q:>3} teams face at least 1 team {q:>2} times", colour)
if add_team_numbers:
if number_of_teams_at_q == number_of_teams-len(exclude_teams_list):
team_list_text = " (All teams)"
elif number_of_teams_at_q > number_of_teams-len(exclude_teams_list)-5:
opposite_list = get_team_numbers_not_in_list(list_of_team_numbers_for_repeats, list_of_teams_at_q)
team_list_text = f" (All except: {tidy_list_of_team_numbers(opposite_list)[2:]}"
else:
team_list_text = tidy_list_of_team_numbers(list_of_teams_at_q)
else:
team_list_text = ""
output_text += f"\n{text_to_add}{team_list_text}"
output_text += "\n"
if strong_alert_level_repeats_count > 0:
text = f"{strong_alert_level_repeats_count:>3} teams play at least one team more than {math.floor(strong_alert_level_repeats)} times."
strong_alert_level_text = f"{colour_text(text, 'red')} Playing the same team(s) a lot of times is repetitive and can be unfair."
summary_of_checks[0].append(["repeats", strong_alert_level_text])
output_text += f"\n{strong_alert_level_text}"
output_text += "\n"
if medium_alert_level_repeats_count > 0:
text = f"{medium_alert_level_repeats_count:>3} teams play at least one team more than {math.floor(medium_alert_level_repeats)} times."
medium_alert_level_text = f"{colour_text(text, 'orange')} Playing the same team(s) many times times is repetitive and can be unfair."
summary_of_checks[1].append(["repeats", medium_alert_level_text])
output_text += f"\n{medium_alert_level_text}"
output_text += "\n"
if weak_alert_level_repeats_count > 0:
text = f"{weak_alert_level_repeats_count:>3} teams play at least one team more than {math.floor(weak_alert_level_repeats)} times."
weak_alert_level_text = f"{colour_text(text, 'yellow')} Playing the same team(s) a few times is repetitive and can be unfair."
summary_of_checks[2].append(["repeats", weak_alert_level_text])
output_text += f"\n{weak_alert_level_text}"
output_text += "\n"
if detailed:
output_text += "\nFacings more detailed:\n"
facings_info_array = []
for n, facings_data in facings_data_all.items():
total_non_zero = 0
for q in range(number_of_appearances):
total_non_zero += facings_data[q+1]
facings_info_array.append([n, total_non_zero, number_of_teams-1-total_non_zero])
facings_info_array = order_array_list(facings_info_array, 1, False)
for row in facings_info_array:
if row[1] == best_faces:
colour = "dark green"
elif row[1] < strong_alert_level:
colour = "red"
elif row[1] < medium_alert_level:
colour = "orange"
elif row[1] < weak_alert_level:
colour = "yellow"
else:
colour = None
facings_part_text = f"faces {row[1]:>3}, misses {row[2]:>3}"
output_text += f"\n {row[0]:>3} {colour_text(facings_part_text, colour)}"
output_text += "\n"
for m in range(number_of_appearances+1):
if m > strong_alert_level_repeats:
colour = "red"
elif m > medium_alert_level_repeats:
colour = "orange"
elif m > weak_alert_level_repeats:
colour = "yellow"
else:
colour = None
facings_repeats_array = []
all_zero = True
for n, facings_data in facings_data_all.items():
if facings_data[m] > 0:
all_zero = False
facings_repeats_array.append([n, facings_data[m]])
facings_repeats_array = order_array_list(facings_repeats_array, 1, True)
if not all_zero:
output_text += f"\nTeams and the number of teams they play {m} times:\n"
for row in facings_repeats_array:
if row[1] == 0:
colour = None
output_text += colour_text(f"\n {row[0]:>3} faces {row[1]:>2} teams {m} times", colour)
output_text += "\n"
return output_text, summary_of_checks
def appearances_check(match_schedule, summary_of_checks, exclude_teams_list, detailed=False):
list_of_team_numbers = get_list_of_team_numbers_from_schedule(match_schedule)
number_of_teams = get_number_of_teams_from_schedule(match_schedule)-len(exclude_teams_list)
appearances_list = {}
output_text = "\n## Appearances\n"
output_text += "\n#### This looks at how many matches a team has. Every team should play the same number of matches.\n"
output_text += "\nNumber of appearances for each team:\n"
for team_number in list_of_team_numbers:
if not team_number in exclude_teams_list:
appearances_list[team_number] = get_appearances_data(match_schedule, team_number)
# appearances_list.append(get_appearances_data(match_schedule, team_number))
list_of_appearance_numbers = []
for appearance_count in appearances_list.values():
if not appearance_count in list_of_appearance_numbers:
list_of_appearance_numbers.append(appearance_count)
appearances_and_team_count = []
red_appearances = False
appearances_list_totals = Counter(appearances_list.values())
for appearance_count in list_of_appearance_numbers:
appearances_and_team_count.append([appearance_count, appearances_list_totals[appearance_count]])
if len(appearances_and_team_count) == 1 and appearances_and_team_count[0][1] == number_of_teams:
text_to_add = f" {appearances_and_team_count[0][0]:>2} appearances: {appearances_and_team_count[0][1]:>3} teams"
output_text += colour_text(text_to_add, "green")
checks_text_to_add = f" {appearances_and_team_count[0][1]:>3} teams have an appearance of {appearances_and_team_count[0][0]:>2}."
summary_of_checks[3].append(["appearances", f"{colour_text(checks_text_to_add, 'green')} All the teams have the same number of appearances."])
else:
max_team_count = order_array_list(appearances_and_team_count, 1)[-1][1]
sorted_list = order_array_list(appearances_and_team_count, 0)
n = len(sorted_list)-1
while n >= 0:
item = sorted_list[n]
text_to_add = f" {item[0]:>2} appearances: {item[1]:>3} teams"
if item[1] == max_team_count:
colour = "orange"
team_list_text = ""
else:
colour = "red"
team_list_text = get_team_list_text_when_number_matches_dict(appearances_list, item[0])
output_text += colour_text(f"{text_to_add}", colour)
output_text += f"{team_list_text}\n"
red_appearances = True
n -= 1
if red_appearances:
text_to_add = "Not all teams have the same number of appearances. All teams should have the same number of matches."
summary_of_checks[0].append(["appearances", f"{colour_text(text_to_add, 'red')} Note that unequal appearances may have resulted in errors elsewhere in the checks."])
output_text += "\n"
return output_text, summary_of_checks
def get_number_of_non_four_robot_matches(match_schedule):
list_of_team_numbers = get_list_of_team_numbers_from_schedule(match_schedule)
number_of_three_robot_matches = 0
number_of_two_robot_matches = 0
number_of_one_robot_matches = 0
teams_in_three_robots_matches = {}
for team_number in list_of_team_numbers:
teams_in_three_robots_matches[team_number] = 0
for match in match_schedule:
teams_in_match = 0
for team_number in list_of_team_numbers:
if team_number in match:
teams_in_match += 1
if teams_in_match == 3:
number_of_three_robot_matches += 1
for team_number in list_of_team_numbers:
if team_number in match:
teams_in_three_robots_matches[team_number] += 1
elif teams_in_match == 2:
number_of_two_robot_matches += 1
elif teams_in_match == 1:
number_of_one_robot_matches += 1
return number_of_three_robot_matches, number_of_two_robot_matches, number_of_one_robot_matches, teams_in_three_robots_matches
def non_four_robot_match_check(match_schedule, summary_of_checks, exclude_teams_list, detailed=False):
output_text = "\n## Matches that do not contain 4 Robots\n"
output_text += "\n#### Sometimes matches containing only 3 robots are required to fill the schedule. This checks that there are not more of these matches than are required."
output_text += "\n#### However, 1 or 2 robot matches should never be required or aimed for (use 3 robot matches instead), so this also checks to see if any of those are present.\n"
number_of_teams_per_match = get_number_of_teams_per_match_from_schedule(match_schedule)
list_of_team_numbers = get_list_of_team_numbers_from_schedule(match_schedule)
number_of_teams = get_number_of_teams_from_schedule(match_schedule)-len(exclude_teams_list)
number_of_appearances = get_appearances_from_schedule(match_schedule)
if number_of_teams*number_of_appearances % 4 == 0:
fake_teams_to_add = 0
else:
fake_teams_to_add = 4 - number_of_teams*number_of_appearances % 4
number_of_three_robot_matches, number_of_two_robot_matches, number_of_one_robot_matches, teams_in_three_robots_matches = get_number_of_non_four_robot_matches(match_schedule)
if number_of_three_robot_matches == 1:
add_s = ""
else:
add_s = "es"
if number_of_teams_per_match == 2:
if number_of_one_robot_matches == 1:
add_s = ""
else:
add_s = "es"
text_to_add = f"\n Number of 1 robot matches: {number_of_one_robot_matches:>2} match{add_s}"
checks_text_to_add = f"The number of 1 robot matches is {number_of_one_robot_matches} match{add_s}."
if number_of_one_robot_matches == 0:
output_text += colour_text(text_to_add, "green")
alert_text_one_robot = ""
summary_of_checks[3].append(["1 robot matches", f"{colour_text(checks_text_to_add, 'green')} This is the ideal number of 1 robot matches."])
else:
output_text += colour_text(text_to_add, "red")
alert_text_one_robot = "\nThe ideal number of 1 robot matches is 0 matches."
summary_of_checks[0].append(["1 robot matches", f"{colour_text(checks_text_to_add, 'red')} The ideal number of 1 robot matches is 0 matches."])
output_text += f"\n{alert_text_one_robot}"
else:
text_to_add = f"\n Number of 3 robot matches: {number_of_three_robot_matches:>2} match{add_s}"
if number_of_three_robot_matches == fake_teams_to_add:
output_text += colour_text(text_to_add, "green")
alert_text_three_robot = ""
checks_text_to_add = f"The number of 3 robot matches is {number_of_three_robot_matches} match{add_s}."
summary_of_checks[3].append(["3 robot matches", f"{colour_text(checks_text_to_add, 'green')} This is the lowest number of 3 robot matches posssible for this number of teams and appearances."])
else:
output_text += colour_text(text_to_add, "orange")
checks_text_to_add = f"The number of 3 robot matches is {number_of_three_robot_matches} match{add_s}."
if fake_teams_to_add == 1:
add_s = ""
else:
add_s = "es"
alert_text_three_robot = f"\nThe ideal number of 3 robot matches is {fake_teams_to_add} match{add_s}."
summary_of_checks[1].append(["3 robot matches", f"{colour_text(checks_text_to_add, 'orange')} The ideal number of 3 robot matches for this number of teams and appearances is {fake_teams_to_add} match{add_s}"])
if number_of_two_robot_matches == 1:
add_s = ""
else:
add_s = "es"
text_to_add = f"\n Number of 2 robot matches: {number_of_two_robot_matches:>2} match{add_s}"
checks_text_to_add = f"The number of 2 robot matches is {number_of_two_robot_matches} match{add_s}."
if number_of_two_robot_matches == 0:
output_text += colour_text(text_to_add, "green")
alert_text_two_robot = ""
summary_of_checks[3].append(["2 robot matches", f"{colour_text(checks_text_to_add, 'green')} This is the ideal number of 2 robot matches."])
else:
output_text += colour_text(text_to_add, "red")
alert_text_two_robot = "\nThe ideal number of 2 robot matches is 0 matches."
summary_of_checks[0].append(["2 robot matches", f"{colour_text(checks_text_to_add, 'red')} The ideal number of 2 robot matches is 0 matches."])
if number_of_one_robot_matches == 1:
add_s = ""
else:
add_s = "es"
text_to_add = f"\n Number of 1 robot matches: {number_of_one_robot_matches:>2} match{add_s}"
checks_text_to_add = f"The number of 1 robot matches is {number_of_one_robot_matches} match{add_s}."
if number_of_one_robot_matches == 0:
output_text += colour_text(text_to_add, "green")
alert_text_one_robot = ""
summary_of_checks[3].append(["1 robot matches", f"{colour_text(checks_text_to_add, 'green')} This is the ideal number of 1 robot matches."])
else:
output_text += colour_text(text_to_add, "red")
alert_text_one_robot = "\nThe ideal number of 1 robot matches is 0 matches."
summary_of_checks[0].append(["1 robot matches", f"{colour_text(checks_text_to_add, 'red')} The ideal number of 1 robot matches is 0 matches."])
output_text += f"\n{alert_text_three_robot}{alert_text_two_robot}{alert_text_one_robot}"
if alert_text_three_robot == "" and alert_text_two_robot == "" and alert_text_one_robot == "":
output_text += "\n"
else:
output_text += "\n\n"
if detailed:
output_text += "\nNumber of times each team is present in 3 robot matches:"
info_array = []
for team_number in list_of_team_numbers:
if not team_number in exclude_teams_list:
info_array.append([team_number, teams_in_three_robots_matches[team_number]])
info_array = order_array_list(info_array, 1, True)
for row in info_array:
text_to_add = f"\n {row[0]:>3}: {row[1]:>2} times"
if row[1] == 0:
colour = None
elif row[1] == 1:
colour = "orange"
else:
colour = "red"
output_text += colour_text(text_to_add, colour)
output_text += "\n\n"
return output_text, summary_of_checks
def get_teams_in_match_multiple_times_data(match_schedule):
list_of_team_numbers = get_list_of_team_numbers_from_schedule(match_schedule)
output = []
for n, match in enumerate(match_schedule):
if len(match) != len(set(match)):
check_missing = 0
for team_num in match:
if team_num > 0:
check_missing += 1
if check_missing >= 3:
output.append(n)
return output
def get_overlap_data(match_schedule, in_blocks=False):
#get_overlap_data()
match_list_3_all = []
match_list_4_all = []
match_list_3_unique = set()
match_list_4_unique = set()
match_list_3_match_num = []