Skip to content

Commit 142de7d

Browse files
committed
Allow logs without team structure
1 parent 5d4b32a commit 142de7d

File tree

1 file changed

+41
-19
lines changed

1 file changed

+41
-19
lines changed

scoring/score_submissions.py

Lines changed: 41 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,11 @@
1616
import os
1717
import pickle
1818

19-
from absl import app
20-
from absl import flags
21-
from absl import logging
2219
import numpy as np
2320
import pandas as pd
2421
import performance_profile
2522
import scoring_utils
23+
from absl import app, flags, logging
2624
from tabulate import tabulate
2725

2826
flags.DEFINE_string(
@@ -62,6 +60,9 @@
6260
'',
6361
'Optional comma seperated list of names of submissions to exclude from scoring.'
6462
)
63+
flags.DEFINE_boolean('teams_structure',
64+
False,
65+
'Whether the logs are organized by teams.')
6566
FLAGS = flags.FLAGS
6667

6768

@@ -151,6 +152,15 @@ def compute_leaderboard_score(df, normalize=True):
151152
return pd.DataFrame(scores, columns=['score'], index=df.index)
152153

153154

155+
def process_submission_dir(base_dir, submission):
156+
"""Helper function to process a single submission directory."""
157+
if submission in FLAGS.exclude_submissions.split(','):
158+
return None
159+
experiment_path = os.path.join(base_dir, submission)
160+
df = scoring_utils.get_experiment_df(experiment_path)
161+
return df
162+
163+
154164
def main(_):
155165
results = {}
156166
os.makedirs(FLAGS.output_dir, exist_ok=True)
@@ -162,22 +172,34 @@ def main(_):
162172
'rb') as f:
163173
results = pickle.load(f)
164174
else:
165-
for team in os.listdir(FLAGS.submission_directory):
166-
for submission in os.listdir(
167-
os.path.join(FLAGS.submission_directory, team)):
168-
print(submission)
169-
if submission in FLAGS.exclude_submissions.split(','):
170-
continue
171-
experiment_path = os.path.join(FLAGS.submission_directory,
172-
team,
173-
submission)
174-
df = scoring_utils.get_experiment_df(experiment_path)
175-
results[submission] = df
176-
summary_df = get_submission_summary(df)
177-
with open(
178-
os.path.join(FLAGS.output_dir, f'{submission}_summary.csv'),
179-
'w') as fout:
180-
summary_df.to_csv(fout)
175+
if FLAGS.teams_structure:
176+
# Original behavior if logs have a team structure,
177+
# i.e. for the competition logs
178+
for team in os.listdir(FLAGS.submission_directory):
179+
team_path = os.path.join(FLAGS.submission_directory, team)
180+
for submission in os.listdir(team_path):
181+
print(f"Processing {team}/{submission}")
182+
df = process_submission_dir(team_path, submission)
183+
if df is not None:
184+
results[submission] = df
185+
summary_df = get_submission_summary(df)
186+
with open(
187+
os.path.join(FLAGS.output_dir, f'{submission}_summary.csv'),
188+
'w') as fout:
189+
summary_df.to_csv(fout)
190+
else:
191+
# Behavior if the logs have no team structure,
192+
# i.e. for the logs in the rolling leaderboard
193+
for submission in os.listdir(FLAGS.submission_directory):
194+
print(f"Processing {submission}")
195+
df = process_submission_dir(FLAGS.submission_directory, submission)
196+
if df is not None:
197+
results[submission] = df
198+
summary_df = get_submission_summary(df)
199+
with open(
200+
os.path.join(FLAGS.output_dir, f'{submission}_summary.csv'),
201+
'w') as fout:
202+
summary_df.to_csv(fout)
181203

182204
# Optionally save results to filename
183205
if FLAGS.save_results_to_filename:

0 commit comments

Comments
 (0)