@@ -451,10 +451,10 @@ def print_stream(*values, end='\n'):
451
451
def calculate_points (self , results ):
452
452
points = 0
453
453
for group , result in results .items ():
454
- if group != 0 and group not in self .config [ " scores" ] :
454
+ if group != 0 and group not in self .scores :
455
455
util .exit_with_error (f'Group { group } doesn\' t have points specified in config file.' )
456
456
if result == "OK" and group != 0 :
457
- points += self .config [ " scores" ] [group ]
457
+ points += self .scores [group ]
458
458
return points
459
459
460
460
@@ -647,6 +647,46 @@ def validate_arguments(self, args):
647
647
648
648
return compilers , timetool_path
649
649
650
+ def set_scores (self ):
651
+ self .tests = package_util .get_tests (self .args .tests )
652
+ self .groups = list (sorted (set ([self .get_group (test ) for test in self .tests ])))
653
+ self .scores = collections .defaultdict (int )
654
+
655
+ if 'scores' not in self .config .keys ():
656
+ print (util .warning ('Scores are not defined in config.yml. Points will be assigned equally to all groups.' ))
657
+ num_groups = len (self .groups )
658
+ self .scores = {}
659
+ if self .groups [0 ] == 0 :
660
+ num_groups -= 1
661
+ self .scores [0 ] = 0
662
+
663
+ points_per_group = 100 // num_groups
664
+ for group in self .groups :
665
+ if group == 0 :
666
+ continue
667
+ self .scores [group ] = points_per_group
668
+
669
+ if points_per_group * num_groups != 100 :
670
+ self .scores [self .groups [- 1 ]] += 100 - points_per_group * num_groups
671
+
672
+ print ("Points will be assigned as follows:" )
673
+ total_score = 0
674
+ for group in self .scores :
675
+ print ("%2d: %3d" % (group , self .scores [group ]))
676
+ total_score += self .scores [group ]
677
+ print ()
678
+ else :
679
+ total_score = 0
680
+ for group in self .config ["scores" ]:
681
+ self .scores [group ] = self .config ["scores" ][group ]
682
+ total_score += self .scores [group ]
683
+
684
+ if total_score != 100 :
685
+ print (util .warning ("WARN: Scores sum up to %d instead of 100." % total_score ))
686
+ print ()
687
+
688
+ self .possible_score = self .get_possible_score (self .groups )
689
+
650
690
def run (self , args ):
651
691
if not util .check_if_project ():
652
692
print (util .warning ('You are not in a project directory (couldn\' t find config.yml in current directory).' ))
@@ -665,8 +705,6 @@ def run(self, args):
665
705
util .exit_with_error ('Time limit was not defined in config.yml.' )
666
706
if not 'memory_limit' in self .config .keys ():
667
707
util .exit_with_error ('Memory limit was not defined in config.yml.' )
668
- if not 'scores' in self .config .keys ():
669
- util .exit_with_error ('Scores were not defined in config.yml.' )
670
708
671
709
self .compilers , self .timetool_path = self .validate_arguments (args )
672
710
@@ -687,18 +725,8 @@ def run(self, args):
687
725
else :
688
726
print (f'Memory limit: { self .memory_limit } kB' ,
689
727
util .warning (("[originally was %.1f kb]" % config_memory_limit )))
690
- self .scores = collections .defaultdict (int )
691
- print ("Scores:" )
692
- total_score = 0
693
- for group in self .config ["scores" ]:
694
- self .scores [group ] = self .config ["scores" ][group ]
695
- print ("%2d: %3d" % (group , self .scores [group ]))
696
- total_score += self .scores [group ]
697
- if total_score != 100 :
698
- print (util .warning ("WARN: Scores sum up to %d (instead of 100)." % total_score ))
699
- print ()
700
728
701
- self .tests = package_util . get_tests ( args . tests )
729
+ self .set_scores ( )
702
730
703
731
if len (self .tests ) > 0 :
704
732
print (util .bold ('Tests that will be run:' ), ' ' .join ([self .extract_file_name (test ) for test in self .tests ]))
@@ -709,9 +737,6 @@ def run(self, args):
709
737
else :
710
738
print (util .warning ('There are no tests to run.' ))
711
739
712
- self .groups = list (sorted (set ([self .get_group (test ) for test in self .tests ])))
713
- self .possible_score = self .get_possible_score (self .groups )
714
-
715
740
solutions = self .get_solutions (self .args .solutions )
716
741
results = self .compile_and_run (solutions )
717
742
validation_results = self .validate_expected_scores (results )
0 commit comments