def __save_sr(match, team, **kargs):

    from Scouting2016.models import ScoreResult

    sr_search = ScoreResult.objects.filter(match=match, team=team)
    if len(sr_search) == 0:
        sr = ScoreResult(match=match, team=team, **kargs)
        sr.save()
        pass
    else:
        sr = sr_search[0]
        for key, value in kargs.iteritems():
            setattr(sr, key, value)
        sr.save()
#         print sr
        pass
Exemplo n.º 2
0
def show_comparison(request):

    context = {}
    context["teams"] = Team.objects.all()

    if len(request.GET) != 0:

        teams = []
        fields = []

        for key in request.GET:
            try:
                team_number = int(key)
                teams.append(team_number)
            except:
                fields.append(key)

        context["selected_team_numbers"] = teams
        context["selected_fields_names"] = [str(x) for x in fields]

    # This would imply that they were on the comparison page, and made a request
    if len(request.GET) != 0:
        context["get"] = request.GET

        annotate_args = {}
        good_fields = []

        valid_fields = []

        # For each available field, check if the GET request has the field AND the field sign
        for score_result_field in ScoreResult.get_fields().values():
            field_name = score_result_field.field_name

            if field_name in request.GET:
                value = request.GET[field_name]

                """
                Grabs whatever field names are requested, and if any fields are requested the
                following command blocks will be used
                """
                if len(value) != 0:

                    valid_fields.append(score_result_field)
                    annotate = __get_annotate_args(score_result_field)

                    annotate_args[annotate[0]] = annotate[1]
                    good_fields.append(score_result_field)

        """
        The filter function will grab score results for all teams requested, exclusively
        all that will be passed on to the page is the teams and fields asked for.
        """
        search_results = Team.objects.filter(teamNumber__in=teams).annotate(**annotate_args)
        context["results"] = __create_filtered_team_metrics(search_results, good_fields)

    return render(request, "Scouting2016/showComparison.html", context)
Exemplo n.º 3
0
def show_add_form(request):

    context = {}
    context["team_number"] = 1
    context["match_number"] = 10
    context["submit_view"] = "/2016/submit_form"
    context["sr"] = {}

    score_result_fields = ScoreResult.get_fields()
    for field_name, value in score_result_fields.iteritems():
        context["sr"][field_name] = value.default

    return render(request, "Scouting2016/inputForm.html", context)
Exemplo n.º 4
0
def __get_create_kargs(request):
    """
    Fill out a list of kargs based on the given request and its POST arguments.
    Will iterate over all of the allowable ScoreResult fields, and will add an
    item into the kargs dicitionary for each one, using the fields default value
    if it is not present in POST.  The result will be a dictionary of
    field_name -> integer value

    @param request: The request containing the POST dictionary

    @return: A dictionary containing field -> value pairs
    """

    kargs = {}

    score_result_fields = ScoreResult.get_fields()

    for field_name in score_result_fields:
        if field_name not in request.POST:
            kargs[field_name] = score_result_fields[field_name].default
        else:
            kargs[field_name] = request.POST[field_name]

    return kargs
Exemplo n.º 5
0
def search_page(request):

    context = {}

    # This would imply that they were on the search page, and made a request
    if len(request.GET) != 0:
        context["get"] = request.GET

        annotate_args = {}
        filter_args = {}
        good_fields = []

        valid_fields = []

        # For each available field, check if the GET request has the field AND the field sign
        for score_result_field in ScoreResult.get_fields().values():
            field_name = score_result_field.field_name
            value_key = field_name + "_value"

            if field_name == "scale_challenge" or field_name == "auto_defense":
                continue
            if field_name in request.GET and value_key in request.GET:
                value = request.GET[field_name]
                sign = request.GET[value_key]

                # If it does have both fields, make sure they are not empty.  If they are empty, they are worthless
                if len(value) != 0 and len(sign) != 0:

                    valid_fields.append(score_result_field)
                    annotate = __get_annotate_args(score_result_field)
                    filter_arg = __get_filter_args(score_result_field, sign, value)

                    annotate_args[annotate[0]] = annotate[1]
                    filter_args[filter_arg[0]] = filter_arg[1]
                    good_fields.append(score_result_field)

        """
        BLACK MAGIC ALERT!!!

        Looking at this by itself makes seemingly no sense, but here is an example of what
        you might run from the command line to get the desired results:

        search_results = Team.objects.all().annotate(HighAuto_MyName=Avg("scoreresult__auto_score_high")).filter(HighAuto_MyName__gte=5)

        The first call, annotate, will create the average results that we will want to filter on.  We can re-name the result
        to "HighAuto_MyName" so that we can use it later.

        The second call, filter, will use the name we created earlier, "HighAuto_MyName" to run a greater-than-or-equal-to comparison,
        and give us a list of the teams that pass the requirements

        search_results now contains a list of the teams that passed the filter.  Furthermore, since we re-named our field during the
        annotate phase, a new, fake field has been added to our team object.  We could do search_results[0].HighAuto_MyName to print
        out how many high auto goals the team scores on average
        """
        search_results = Team.objects.all().annotate(**annotate_args).filter(**filter_args)
        team_numbers = [team_result.teamNumber for team_result in search_results]

        filtered_results = __create_filtered_team_metrics(search_results, good_fields)

        if "scale_challenge" in request.GET:
            filtered_results = search_result_filter(request, team_numbers, filtered_results, "scale_challenge")

        if "auto_defense" in request.GET:
            filtered_results = search_result_filter(request, team_numbers, filtered_results, "auto_defense")

        context["results"] = filtered_results
    return render(request, "Scouting2016/search.html", context)