Пример #1
0
    def test_display_challenge_details(self):
        table = BeautifulTable(max_width=200)
        attributes = [
            "description", "submission_guidelines", "evaluation_details",
            "terms_and_conditions"
        ]
        column_attributes = [
            "Start Date", "End Date", "Description", "Submission Guidelines",
            "Evaluation Details", "Terms and Conditions"
        ]
        table.column_headers = column_attributes
        values = []
        start_date = convert_UTC_date_to_local(
            self.challenge_data["start_date"]).split(" ")[0]
        end_date = convert_UTC_date_to_local(
            self.challenge_data["end_date"]).split(" ")[0]
        values.extend([start_date, end_date])
        values.extend(
            list(
                map(lambda item: clean_data(self.challenge_data[item]),
                    attributes)))
        table.append_row(values)
        expected = str(table)

        runner = CliRunner()
        result = runner.invoke(challenge, ["1"])
        response = result.output.strip()
        assert response == expected
Пример #2
0
def pretty_print_challenge_details(challenge):
    table = BeautifulTable(max_width=200)
    attributes = [
        "description",
        "submission_guidelines",
        "evaluation_details",
        "terms_and_conditions",
    ]
    table.column_headers = [
        "Start Date",
        "End Date",
        "Description",
        "Submission Guidelines",
        "Evaluation Details",
        "Terms and Conditions",
    ]
    values = []
    start_date = convert_UTC_date_to_local(
        challenge["start_date"]).split(" ")[0]
    end_date = convert_UTC_date_to_local(challenge["end_date"]).split(" ")[0]
    values.extend([start_date, end_date])
    values.extend(
        list(map(lambda item: clean_data(challenge[item]), attributes)))
    table.append_row(values)
    echo(table)
Пример #3
0
def pretty_print_challenge_data(challenges):
    """
    Function to print the challenge data
    """
    table = BeautifulTable(max_width=200)
    attributes = ["id", "title", "short_description"]
    columns_attributes = [
        "ID",
        "Title",
        "Short Description",
        "Creator",
        "Start Date",
        "End Date",
    ]
    table.column_headers = columns_attributes
    for challenge in reversed(challenges):
        values = list(map(lambda item: challenge[item], attributes))
        creator = challenge["creator"]["team_name"]
        start_date = convert_UTC_date_to_local(challenge["start_date"])
        end_date = convert_UTC_date_to_local(challenge["end_date"])
        values.extend([creator, start_date, end_date])
        table.append_row([
            colored(values[0], 'white'),
            colored(values[1], 'yellow'),
            colored(values[2], 'cyan'),
            colored(values[3], 'white'),
            colored(values[4], 'green'),
            colored(values[5], 'red'),
        ])

    echo(table, color='yes')
Пример #4
0
    def setup(self):

        challenge_data = json.loads(challenge_response.challenges)

        url = "{}{}"
        responses.add(responses.GET,
                      url.format("https://evalapi.cloudcv.org",
                                 URLS.challenge_list.value),
                      json=challenge_data,
                      status=200)

        self.output = ""
        challenge_data = challenge_data["results"]
        table = BeautifulTable(max_width=200)
        attributes = ["id", "title", "short_description"]
        columns_attributes = [
            "ID", "Title", "Short Description", "Creator", "Start Date",
            "End Date"
        ]
        table.column_headers = columns_attributes
        for challenge_json in reversed(challenge_data):
            values = list(map(lambda item: challenge_json[item], attributes))
            creator = challenge_json["creator"]["team_name"]
            start_date = convert_UTC_date_to_local(
                challenge_json["start_date"])
            end_date = convert_UTC_date_to_local(challenge_json["end_date"])
            values.extend([creator, start_date, end_date])
            table.append_row(values)
        self.output = str(table)
Пример #5
0
    def setup(self):

        challenge_data = json.loads(challenge_response.challenges)
        host_team_data = json.loads(challenge_response.challenge_host_teams)
        participant_team_data = json.loads(
            challenge_response.challenge_participant_teams)

        url = "{}{}"
        responses.add(
            responses.GET,
            url.format(API_HOST_URL, URLS.participant_teams.value),
            json=participant_team_data,
            status=200,
        )

        responses.add(
            responses.GET,
            url.format(API_HOST_URL, URLS.host_teams.value),
            json=host_team_data,
            status=200,
        )

        responses.add(
            responses.GET,
            url.format(API_HOST_URL,
                       URLS.participant_challenges.value).format("3"),
            json=challenge_data,
            status=200,
        )

        responses.add(
            responses.GET,
            url.format(API_HOST_URL, URLS.host_challenges.value).format("2"),
            json=challenge_data,
            status=200,
        )

        challenges_json = challenge_data["results"]

        table = BeautifulTable(max_width=200)
        attributes = ["id", "title", "short_description"]
        columns_attributes = [
            "ID",
            "Title",
            "Short Description",
            "Creator",
            "Start Date",
            "End Date",
        ]
        table.column_headers = columns_attributes
        for challenge_data in reversed(challenges_json):
            values = list(map(lambda item: challenge_data[item], attributes))
            creator = challenge_data["creator"]["team_name"]
            start_date = convert_UTC_date_to_local(
                challenge_data["start_date"])
            end_date = convert_UTC_date_to_local(challenge_data["end_date"])
            values.extend([creator, start_date, end_date])
            table.append_row(values)
        self.output = str(table)
Пример #6
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
Пример #7
0
def pretty_print_submission_details(submission):
    """
    Function to print details of a submission
    """
    team_name = "\n{}".format(
        style(submission["participant_team_name"], bold=True, fg="green")
    )
    sid = "Submission ID: {}\n".format(
        style(str(submission["id"]), bold=True, fg="blue")
    )
    team_name = "{} {}".format(team_name, sid)

    status = style(
        "\nSubmission Status : {}\n".format(submission["status"]), bold=True
    )
    execution_time = style(
        "\nExecution Time (sec) : {}\n".format(submission["execution_time"]),
        bold=True,
    )

    date = convert_UTC_date_to_local(submission["submitted_at"])
    submitted_at = style("\nSubmitted At : {}\n".format(date), bold=True)
    submission = "{}{}{}{}".format(
        team_name, status, execution_time, submitted_at
    )
    echo(submission)
Пример #8
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)
Пример #9
0
def pretty_print_challenge_data(challenges):
    """
    Function to print the challenge data
    """
    table = BeautifulTable(max_width=200)
    attributes = ["id", "title", "short_description"]
    columns_attributes = [
        "ID",
        "Title",
        "Short Description",
        "Creator",
        "Start Date",
        "End Date",
    ]
    table.column_headers = columns_attributes
    for challenge in reversed(challenges):
        values = list(map(lambda item: challenge[item], attributes))
        creator = challenge["creator"]["team_name"]
        start_date = convert_UTC_date_to_local(challenge["start_date"])
        end_date = convert_UTC_date_to_local(challenge["end_date"])
        values.extend([creator, start_date, end_date])
        table.append_row(values)
    echo_via_pager(table)
Пример #10
0
def pretty_print_leaderboard_data(attributes, results):
    """
    Pretty print the leaderboard for a particular CPS.
    """
    leaderboard_table = BeautifulTable(max_width=150)
    attributes = ["Rank", "Participant Team"] + attributes + ["Last Submitted"]
    attributes = list(map(lambda item: str(item), attributes))
    leaderboard_table.column_headers = attributes

    for rank, result in enumerate(results, start=1):
        name = result["submission__participant_team__team_name"]
        scores = result["result"]

        last_submitted = convert_UTC_date_to_local(
            result["submission__submitted_at"])

        leaderboard_row = [rank, name] + scores + [last_submitted]
        leaderboard_table.append_row(leaderboard_row)
    echo(leaderboard_table)
Пример #11
0
    def test_display_leaderboard(self):
        attributes = self.leaderboard[0]["leaderboard__schema"]["labels"]

        table = BeautifulTable(max_width=150)
        attributes = ["Rank", "Participant Team"
                      ] + attributes + ["Last Submitted"]
        attributes = list(map(lambda item: str(item), attributes))
        table.column_headers = attributes

        for rank, result in enumerate(self.leaderboard, start=1):
            name = result['submission__participant_team__team_name']
            scores = result['result']
            last_submitted = convert_UTC_date_to_local(
                result['submission__submitted_at'])

            value = [rank, name] + scores + [last_submitted]
            table.append_row(value)

        output = str(table).rstrip()

        runner = CliRunner()
        result = runner.invoke(challenge, ['2', 'leaderboard', '1'])
        response = result.output.rstrip()
        assert response == output
    def setup(self):

        challenge_data = json.loads(challenge_response.challenges)

        url = "{}{}"
        responses.add(
            responses.GET,
            url.format(API_HOST_URL, URLS.challenge_list.value),
            json=challenge_data,
            status=200,
        )

        responses.add(
            responses.GET,
            url.format(API_HOST_URL, URLS.past_challenge_list.value),
            json=challenge_data,
            status=200,
        )

        responses.add(
            responses.GET,
            url.format(API_HOST_URL, URLS.challenge_list.value),
            json=challenge_data,
            status=200,
        )

        responses.add(
            responses.GET,
            url.format(API_HOST_URL, URLS.future_challenge_list.value),
            json=challenge_data,
            status=200,
        )

        challenges_json = challenge_data["results"]

        self.output = ""

        table = BeautifulTable(max_width=200)
        attributes = ["id", "title", "short_description"]
        columns_attributes = [
            "ID",
            "Title",
            "Short Description",
            "Creator",
            "Start Date",
            "End Date",
        ]
        table.column_headers = columns_attributes
        for challenge_data in reversed(challenges_json):
            values = list(map(lambda item: challenge_data[item], attributes))
            creator = challenge_data["creator"]["team_name"]
            start_date = convert_UTC_date_to_local(
                challenge_data["start_date"])
            end_date = convert_UTC_date_to_local(challenge_data["end_date"])
            values.extend([creator, start_date, end_date])
            table.append_row([
                colored(values[0], 'white'),
                colored(values[1], 'yellow'),
                colored(values[2], 'cyan'),
                colored(values[3], 'white'),
                colored(values[4], 'green'),
                colored(values[5], 'red'),
            ])
        self.output = str(table)