def create_challenge( title, start_date, end_date, host_team, participant_host_team, anon_leaderboard=False, is_featured=False, ): """ Creates a challenge. """ evaluation_script = open( os.path.join( settings.BASE_DIR, "examples", "example1", "sample_evaluation_script.zip", ), "rb", ) queue = "".join(random.choice(string.ascii_letters) for _ in range(75)) year = datetime.date.today().year # add UUID here uuid_stamp = uuid.uuid4().hex[0:10] slug = "{t}-{y}-{z}".format(t=title, y=year, z=uuid_stamp) slug = slug.lower().replace(" ", "-")[:198] image_file = ContentFile(get_file_content(CHALLENGE_IMAGE_PATH, "rb"), "logo.png") challenge = Challenge( title=title, short_description=fake.paragraph(), description=fake.paragraph(), terms_and_conditions=fake.paragraph(), submission_guidelines=fake.paragraph(), evaluation_details=fake.paragraph(), evaluation_script=SimpleUploadedFile(evaluation_script.name, evaluation_script.read()), approved_by_admin=True, leaderboard_description=fake.paragraph(), creator=host_team, published=True, enable_forum=True, anonymous_leaderboard=anon_leaderboard, start_date=start_date, end_date=end_date, queue=queue, featured=is_featured, image=image_file, ) challenge.save() challenge.slug = slug challenge.participant_teams.add(participant_host_team) challenge.save() print( "Challenge created with title: {} creator: {} start_date: {} end_date: {}" .format(title, host_team.team_name, start_date, end_date))
def create_challenge_template(challenge_config_path): """ Creates a challenge template Arguments: challenge_config_path {str}: path to the challenge config location having the config files and zip """ title = "{} template".format(fake.first_name()) template_file = open( os.path.join( challenge_config_path, "test_zip_file.zip", ), "rb", ) challenge_config_yaml_file_path = os.path.join(challenge_config_path, "test_zip_file", "zip_challenge.yaml") with open(challenge_config_yaml_file_path, "r") as stream: yaml_file_data = yaml.safe_load(stream) challenge_image_file_path = os.path.join(challenge_config_path, "test_zip_file", yaml_file_data["image"]) image_file = ContentFile(get_file_content(challenge_image_file_path, "rb"), "logo.png") dataset = fake.first_name() phases = len(yaml_file_data["challenge_phases"]) splits = len(yaml_file_data["dataset_splits"]) year = datetime.date.today().year uuid_stamp = uuid.uuid4().hex[0:10] slug = "{t}-{y}-{z}".format(t=title, y=year, z=uuid_stamp) challenge_template = ChallengeTemplate.objects.create( title=title, template_file=SimpleUploadedFile(template_file.name, template_file.read()), is_active=True, image=image_file, dataset=dataset, eval_metrics=["Accuracy", "F1"], phases=phases, splits=splits, slug=slug, ) challenge_template.save() print("Challenge template {} created.".format(challenge_template.title)) return challenge_template
def test_get_file_content(self): test_file_content = get_file_content(self.test_file_path, 'rb') expected = '1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n' self.assertEqual(test_file_content, expected)
def test_get_file_content(self): test_file_content = get_file_content(self.test_file_path, "rb") expected = "1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n" self.assertEqual(test_file_content.decode(), expected)