Ejemplo n.º 1
0
    def test_display_my_submission_details_with_end_date_and_start_date(self):
        table = BeautifulTable(max_width=100)
        attributes = [
            "id", "participant_team_name", "execution_time", "status"
        ]
        columns_attributes = [
            "ID", "Participant Team", "Execution Time(sec)", "Status",
            "Submitted At", "Method Name"
        ]
        table.column_headers = columns_attributes

        start_date = datetime.strptime('6/5/18', "%m/%d/%y")
        end_date = datetime.strptime('6/9/18', "%m/%d/%y")
        for submission in self.submissions:
            date = validate_date_format(submission['submitted_at'])
            if (date >= start_date and date <= end_date):
                # Check for empty method name
                date = convert_UTC_date_to_local(submission['submitted_at'])
                method_name = submission["method_name"] if submission[
                    "method_name"] else "None"
                values = list(map(lambda item: submission[item], attributes))
                values.append(date)
                values.append(method_name)
                table.append_row(values)
        output = str(table).rstrip()
        runner = CliRunner()
        result = runner.invoke(
            challenge,
            ['3', 'phase', '7', 'submissions', '-s', '6/5/18', '-e', '6/9/18'])
        response = result.output.rstrip()
        assert response == output
Ejemplo n.º 2
0
def pretty_print_my_submissions_data(submissions, start_date, end_date):
    """
    Function to print the submissions for a particular challenge.
    """
    table = BeautifulTable(max_width=100)
    attributes = ["id", "participant_team_name", "execution_time", "status"]
    columns_attributes = [
        "ID",
        "Participant Team",
        "Execution Time(sec)",
        "Status",
        "Submitted At",
        "Method Name",
    ]
    table.column_headers = columns_attributes
    if len(submissions) == 0:
        echo(
            style(
                "\nSorry, you have not made any submissions to this challenge phase.\n",
                bold=True,
                fg="red",
            )
        )
        sys.exit(1)

    if not start_date:
        start_date = datetime.min

    if not end_date:
        end_date = datetime.max

    for submission in submissions:
        date = validate_date_format(submission["submitted_at"])
        if date >= start_date and date <= end_date:
            # Check for empty method name
            date = convert_UTC_date_to_local(submission["submitted_at"])
            method_name = (
                submission["method_name"]
                if submission["method_name"]
                else "None"
            )
            values = list(map(lambda item: submission[item], attributes))
            values.append(date)
            values.append(method_name)
            table.append_row(values)
    if len(table) == 0:
        echo(
            style(
                "\nSorry, no submissions were made during this time period.\n",
                bold=True,
                fg="red",
            )
        )
        sys.exit(1)
    echo(table)
Ejemplo n.º 3
0
def display_participated_or_hosted_challenges(is_host=False,
                                              is_participant=False):
    """
    Function to display the participated or hosted challenges by a user
    """

    challenges = []

    if is_host:
        team_url = "{}{}".format(get_host_url(), URLS.host_teams.value)
        challenge_url = "{}{}".format(get_host_url(),
                                      URLS.host_challenges.value)

        teams = get_participant_or_host_teams(team_url)
        challenges = get_participant_or_host_team_challenges(
            challenge_url, teams)
        echo(style("\nHosted Challenges\n", bold=True))

        if len(challenges) != 0:
            pretty_print_challenge_data(challenges)
        else:
            echo("Sorry, no challenges found.")

    if is_participant:
        team_url = "{}{}".format(get_host_url(), URLS.participant_teams.value)
        challenge_url = "{}{}".format(get_host_url(),
                                      URLS.participant_challenges.value)

        teams = get_participant_or_host_teams(team_url)
        challenges = get_participant_or_host_team_challenges(
            challenge_url, teams)

        if len(challenges) != 0:

            # Filter out past/unapproved/unpublished challenges.
            challenges = list(
                filter(
                    lambda challenge: validate_date_format(challenge[
                        "end_date"]) > datetime.now() and challenge[
                            "approved_by_admin"] and challenge["published"],
                    challenges,
                ))
            if challenges:
                echo(style("\nParticipated Challenges\n", bold=True))
                pretty_print_challenge_data(challenges)
            else:
                echo("Sorry, no challenges found.")
        else:
            echo("Sorry, no challenges found.")
Ejemplo n.º 4
0
def display_ongoing_challenge_list():
    """
    Displays the list of ongoing challenges from the backend
    """
    url = "{}{}".format(get_host_url(), URLS.challenge_list.value)

    header = get_request_header()
    try:
        response = requests.get(url, headers=header)
        response.raise_for_status()
    except requests.exceptions.HTTPError as err:
        if response.status_code == 401:
            validate_token(response.json())
        echo(style(err, fg="red", bold=True))
        sys.exit(1)
    except requests.exceptions.RequestException:
        echo(
            style(
                "\nCould not establish a connection to EvalAI."
                " Please check the Host URL.\n",
                bold=True,
                fg="red",
            ))
        sys.exit(1)

    response = response.json()
    challenges = response["results"]

    # Filter out past/unapproved/unpublished challenges.
    challenges = list(
        filter(
            lambda challenge: validate_date_format(challenge["end_date"]) >
            datetime.now() and challenge["approved_by_admin"] and challenge[
                "published"],
            challenges,
        ))

    if len(challenges) != 0:
        pretty_print_challenge_data(challenges)
    else:
        echo(style(
            "Sorry, no challenges found.",
            fg="red",
            bold=True,
        ))