コード例 #1
0
def submit_pit_scouting_data(request):
    if request.method != "POST":
        return HttpResponse(status=403)

    else:
        data = json.loads(str(request.POST.get('data')))
        if request.POST.get('image_data'):
            image_data = json.loads(str(request.POST.get('image_data')))
        else:
            image_data = "nope"
        data_object = PitScoutData(scout=request.user,
                                   location=Location.objects.get(id=request.session.get('location_id')),
                                   pitscout_name=request.user.first_name + " " + request.user.last_name[:1],
                                   pitscout_team=request\
                                   .user\
                                   .userprofile\
                                   .team\
                                   .team_number)
        for name in data:
            setattr(data_object, name, data.get(name))

        if image_data != "nope":
            data_object.image_id = image_data['data']['id']
            data_object.image_link = image_data['data']['link']
            data_object.image_type = image_data['data']['type']

        try:
            param = str("team/frc%i" % data.get('team_number'))

            json_decoded = make_tba_request(param)

            setattr(data_object, 'team_name', json_decoded.get('nickname'))
            setattr(data_object, 'team_website', json_decoded.get('website'))

        except ValueError:
            pass 

        try:
            data_object.save()
        except (ValueError, IntegrityError):
            return HttpResponse(status=400)

        return HttpResponse(status=200)
コード例 #2
0
def submit_pit_scouting_data(request):
    if request.method != "POST":
        return HttpResponse(status=403)

    else:
        data = json.loads(str(request.POST.get("data")))
        if request.POST.get("image_data"):
            image_data = json.loads(str(request.POST.get("image_data")))
        else:
            image_data = "nope"
        data_object = PitScoutData(
            scout=request.user,
            location=Location.objects.get(id=request.session.get("location_id")),
            pitscout_name=request.user.first_name + " " + request.user.last_name[:1],
            pitscout_team=request.user.userprofile.team.team_number,
        )
        for name in data:
            setattr(data_object, name, data.get(name))

        if image_data != "nope":
            data_object.image_id = image_data["data"]["id"]
            data_object.image_link = image_data["data"]["link"]
            data_object.image_type = image_data["data"]["type"]

        try:
            param = str("team/frc%i" % data.get("team_number"))

            json_decoded = make_tba_request(param)

            setattr(data_object, "team_name", json_decoded.get("nickname"))
            setattr(data_object, "team_website", json_decoded.get("website"))

        except ValueError:
            pass

        try:
            data_object.save()
        except (ValueError, IntegrityError):
            return HttpResponse(status=400)

        return HttpResponse(status=200)
コード例 #3
0
def submit_pit_scouting_data(request):
    if request.method != "POST":
        return HttpResponse(status=403)

    else:
        data = json.loads(request.POST.get('data'))
        image_data = json.loads(request.POST.get('image_data'))

        data_object = PitScoutData(scout=request.user,
                                   location=Location.objects.get(id=request.session.get('location_id')),
                                   pitscout_name=request.user.first_name + " " + request.user.last_name[:1],
                                   pitscout_team_number=request.user.userprofile.team.team_number)
        for name in data:
            setattr(data_object, name, data.get(name))

        if image_data.get('data'):
            data_object.image_id = image_data['data']['id']
            data_object.image_link = image_data['data']['link']
            data_object.image_type = image_data['data']['type']

        try:
            param = str("team/frc%i" % data.get('team_number'))

            json_decoded = make_tba_request(param)

            setattr(data_object, 'team_name', json_decoded.get('nickname'))
            setattr(data_object, 'team_website', json_decoded.get('website'))

        except ValueError:
            pass

        try:
            data_object.save()
        except (ValueError, IntegrityError):
            return HttpResponse(status=400)

        return HttpResponse(status=200)
コード例 #4
0
def view_team_profile(request, team_number=None):

    if not team_number:
        team_number = request.user.userprofile.team.team_number

    elif int(team_number) < 1:
        return HttpResponse("Team numbers cannot be less than 1.", status=400)

    # oh boy here we go
    statistics = {}

    matches = Match.objects.filter(team_number=team_number).exclude(
        location__name="TEST"
    )  # only take matches for this team
    if matches is not None:
        # iterate over possible match fields
        for field in Match._meta.fields:
            value = None
            # field_type = IntegerField, BooleanField, etc.
            field_type = str(field.__class__).split("'")[1].split(".")[4]
            # field_name = tele_picked_up_yellow_crates_blah, etc.
            field_name = str(field).split(".")[2]
            if field_type == "IntegerField":
                # if it's an integer and not a special field
                if field_name != "team_number" and field_name != "match_number" and field_name != "scout_team_number":
                    # then calculate the average of it

                    m = matches.aggregate(Avg(field_name))[field_name + "__avg"]

                    if m is not None:
                        # value = str("%.2f" % matches.aggregate(Avg(field_name))[field_name+"__avg"])
                        value = str("%.2f" % matches.aggregate(Avg(field_name))[field_name + "__avg"])
                    else:
                        value = None
                else:
                    # if it's special, skip it
                    continue
            elif field_type == "BooleanField":
                # if it's a boolean, calculate the % that has true (but not if matches.count()  == 0)
                try:
                    value = str("%.2f" % (matches.filter(**{str(field_name): True}).count() / matches.count() * 100))
                except ZeroDivisionError:
                    pass
            else:
                # otherwise, skip it
                continue
            # put it in the hash -- much simpler than the crazy wacko system of before
            statistics[field_name] = value

            if statistics[field_name] == None:
                statistics[field_name] = "—"

    pit_scout_data = PitScoutData.objects.filter(team_number=team_number).order_by("id").exclude(location__name="TEST")

    aggregate_data = PitScoutData(team_number=team_number)

    for data in pit_scout_data:
        for field in PitScoutData._meta.fields:
            if getattr(data, field.name):
                setattr(aggregate_data, field.name, getattr(data, field.name))

    self_scouted = PitScoutData.objects.filter(
        team_number=team_number, scout__userprofile__team__team_number=team_number
    ).order_by("id")

    for data in self_scouted:
        for field in PitScoutData._meta.fields:
            if getattr(data, field.name):
                setattr(aggregate_data, field.name, getattr(data, field.name))

    # then pass all the sections/data to the context
    pitdatas = PitScoutData.objects.filter(team_number=team_number).count()

    try:
        param = str("team/frc%i" % int(team_number))
        json_decoded = make_tba_request(param)

    except ValueError:
        json_decoded = None

    context = {
        "has_pit_data": pitdatas,
        "aggregate_data": model_to_dict(aggregate_data),
        "team_number": team_number,
        "statistics": statistics,
        "nav_title": str(team_number),
        "matches": matches,
        "tba_data": json_decoded,
    }
    if pitdatas == 1:
        context["scout_name"] = PitScoutData.objects.get(team_number=team_number).scout.first_name

    return render(request, "frc_scout/profiles/profile.html", context)
コード例 #5
0
ファイル: profile_views.py プロジェクト: eukota/frc-scout
def view_team_profile(request, team_number=None):

    if not team_number:
        team_number = request.user.userprofile.team.team_number

    elif int(team_number) < 1:
        return HttpResponse("Team numbers cannot be less than 1.", status=400)

    # oh boy here we go
    statistics = {}

    matches = Match.objects.filter(team_number=team_number).exclude(
        location__name="TEST")  # only take matches for this team
    if matches is not None:
        # iterate over possible match fields
        for field in Match._meta.fields:
            value = None
            # field_type = IntegerField, BooleanField, etc.
            field_type = str(field.__class__).split("'")[1].split('.')[4]
            # field_name = tele_picked_up_yellow_crates_blah, etc.
            field_name = str(field).split('.')[2]
            if field_type == "IntegerField":
                # if it's an integer and not a special field
                if field_name != "team_number" and field_name != "match_number" and field_name != "scout_team_number":
                    # then calculate the average of it

                    m = matches.aggregate(Avg(field_name))[field_name +
                                                           "__avg"]

                    if m is not None:
                        #value = str("%.2f" % matches.aggregate(Avg(field_name))[field_name+"__avg"])
                        value = str("%.2f" % matches.aggregate(
                            Avg(field_name))[field_name + "__avg"])
                    else:
                        value = None
                else:
                    # if it's special, skip it
                    continue
            elif field_type == "BooleanField":
                # if it's a boolean, calculate the % that has true (but not if matches.count()  == 0)
                try:
                    value = str("%.2f" % (matches.filter(**{
                        str(field_name): True
                    }).count() / matches.count() * 100))
                except ZeroDivisionError:
                    pass
            else:
                # otherwise, skip it
                continue
            # put it in the hash -- much simpler than the crazy wacko system of before
            statistics[field_name] = value

            if statistics[field_name] == None:
                statistics[field_name] = "—"

    pit_scout_data = PitScoutData.objects.filter(
        team_number=team_number).order_by('id').exclude(location__name="TEST")

    aggregate_data = PitScoutData(team_number=team_number)

    for data in pit_scout_data:
        for field in PitScoutData._meta.fields:
            if getattr(data, field.name):
                setattr(aggregate_data, field.name, getattr(data, field.name))

    self_scouted = PitScoutData.objects.filter\
        (team_number=team_number, scout__userprofile__team__team_number=team_number).order_by('id')

    for data in self_scouted:
        for field in PitScoutData._meta.fields:
            if getattr(data, field.name):
                setattr(aggregate_data, field.name, getattr(data, field.name))

    # then pass all the sections/data to the context
    pitdatas = PitScoutData.objects.filter(team_number=team_number).count()

    try:
        param = str("team/frc%i" % int(team_number))
        json_decoded = make_tba_request(param)

    except ValueError:
        json_decoded = None

    context = {
        'has_pit_data': pitdatas,
        'aggregate_data': model_to_dict(aggregate_data),
        'team_number': team_number,
        'statistics': statistics,
        'nav_title': str(team_number),
        'matches': matches,
        'tba_data': json_decoded
    }
    if pitdatas == 1:
        context['scout_name'] = PitScoutData.objects.get(
            team_number=team_number).scout.first_name

    return render(request, 'frc_scout/profiles/profile.html', context)
コード例 #6
0
def view_team_profile(request, team_number=None):

    if not team_number:
        team_number = request.user.userprofile.team.team_number

    elif int(team_number) < 1:
        return HttpResponse("Team numbers cannot be less than 1.", status=400)

    # oh boy here we go
    statistics = {}

    matches = Match.objects.filter(team_number=team_number).exclude(location__name="TEST") # only take matches for this team
    if matches is not None:
        # iterate over possible match fields
        for field in Match._meta.fields:
            value = None
            # field_type = IntegerField, BooleanField, etc.
            field_type = str(field.__class__).split("'")[1].split('.')[4]
            # field_name = tele_picked_up_yellow_crates_blah, etc.
            field_name = str(field).split('.')[2]
            if field_type == "IntegerField":
                # if it's an integer and not a special field
                if field_name != "team_number" and field_name != "match_number" and field_name != "scout_team_number":
                    # then calculate the average of it

                    m = matches.aggregate(Avg(field_name))[field_name+"__avg"]

                    if m is not None:
                        #value = str("%.2f" % matches.aggregate(Avg(field_name))[field_name+"__avg"])
                        value = str("%.2f" % matches.aggregate(Avg(field_name))[field_name+"__avg"])
                    else:
                        value = None
                else:
                    # if it's special, skip it
                    continue
            elif field_type == "BooleanField":
                # if it's a boolean, calculate the % that has true (but not if matches.count()  == 0)
                try:
                    value = str("%.2f" % (matches.filter(**{str(field_name): True}).count() / matches.count() * 100))
                except ZeroDivisionError:
                    pass
            else:
                # otherwise, skip it
                continue
            # put it in the hash -- much simpler than the crazy wacko system of before
            statistics[field_name] = value

            if statistics[field_name] == None:
                statistics[field_name] = "—"

        if (statistics['match_final_score'] != "—") and (statistics['match_final_score'] != 0):
            # exclude things that have a 0
            statistics['match_final_score'] = matches.exclude(match_final_score=0).aggregate(
                Avg('match_final_score'))['match_final_score__avg']
            if statistics['match_final_score'] is None:
                statistics['match_final_score'] = 0

        # calculate some special stats
        print(statistics['auto_step_center_acquired_containers'])
        if (statistics['auto_step_center_acquired_containers'] != "—") and (statistics['auto_ground_acquired_containers'] != "—"):
            statistics['auto_total_acquired_containers'] = str("%.2f" %
                (float(statistics['auto_step_center_acquired_containers']) + float(statistics['auto_ground_acquired_containers'])))
        else:
            statistics['auto_total_acquired_containers'] = "—"
        if (statistics['tele_picked_up_ground_upright_totes'] != "—") and (statistics['tele_picked_up_upside_down_totes'] != "—") and (
            statistics['tele_picked_up_sideways_totes'] != "—") and (statistics['tele_picked_up_human_station_totes'] != "—"):
            statistics['tele_picked_up_total_totes'] = str("%.2f" %
                (float(statistics['tele_picked_up_ground_upright_totes']) + float(statistics['tele_picked_up_upside_down_totes'])
                 + float(statistics['tele_picked_up_sideways_totes']) + float(statistics['tele_picked_up_human_station_totes'])))
        else:
            statistics['tele_picked_up_total_totes'] = "—"
        if (statistics['tele_picked_up_sideways_containers'] != "—") and (statistics['tele_picked_up_upright_containers'] != "—") and (
            statistics['tele_picked_up_center_step_containers'] != "—"):
            statistics['tele_picked_up_total_containers'] = str("%.2f" %
                 (float(statistics['tele_picked_up_sideways_containers']) + float(statistics['tele_picked_up_upright_containers'])
                 + float(statistics['tele_picked_up_center_step_containers'])))
        else:
            statistics['tele_picked_up_total_containers'] = "—"
        # aggregate totestacks, yay!
        stacks = ToteStack.objects.filter(match__team_number=team_number, coop_stack=False)
        if (len(stacks) != 0) and (stacks != None):
            statistics['tele_average_stack_height'] = str("%.2f" % stacks.aggregate(Avg('start_height'))['start_height__avg'])
            statistics['tele_average_totes_stacked'] = str("%.2f" % stacks.aggregate(Avg('totes_added'))['totes_added__avg'])
            # I'm pretty proud of this -- it's the averages of the sum per match
            match_stacks = stacks.values('match').annotate(total_totes=Sum('totes_added'))
            statistics['tele_average_totes_stacked_per_match'] = str("%.2f" % match_stacks.aggregate(Avg('total_totes'))['total_totes__avg'])
        else:
            statistics['tele_average_stack_height'] = "—"
            statistics['tele_average_totes_stacked'] = "—"
            statistics['tele_average_totes_stacked_per_match'] = "—"
        coop_stacks = ToteStack.objects.filter(match__team_number=team_number, coop_stack=True)
        if (len(coop_stacks) != 0) and (coop_stacks != None):
            match_coop_stacks = coop_stacks.values('match').annotate(total_totes=Sum('totes_added'))
            statistics['tele_average_coop_totes_stacked_per_match'] = str("%.2f" % match_coop_stacks.aggregate(Avg('total_totes'))['total_totes__avg'])
        else:
            statistics['tele_average_coop_totes_stacked_per_match'] = "—"

        # aggregate containerstacks
        containers = ContainerStack.objects.filter(match__team_number=team_number)
        if (len(containers) != 0) and (containers != None):
            statistics['tele_average_container_height'] = str("%.2f" % containers.aggregate(Avg('height'))['height__avg'])
            match_containers = containers.values('match').annotate(total_containers=Count('containers_added'))
            statistics['tele_average_containers_stacked_per_match'] = str("%.2f" %
                    match_containers.aggregate(Avg('total_containers'))['total_containers__avg'])
        else:
            statistics['tele_average_container_height'] = "—"
            statistics['tele_average_containers_stacked_per_match'] = "—"

        # match scores -- I moved the thing from the 'edit match' screen into its own function
        # because it's pretty useful and recyclable
        match_scores = [match_score(m) for m in matches]
        auto_scores = [m[0] for m in match_scores]
        tele_scores = [m[1] for m in match_scores]
        if len(auto_scores) > 0:
            statistics['auto_average_score'] = str("%.2f" % (sum(auto_scores) / len(auto_scores)))
            statistics['tele_average_score'] = str("%.2f" % (sum(tele_scores) / len(tele_scores)))
            statistics['total_average_score'] = str("%.2f" %
                (float(statistics['auto_average_score']) + float(statistics['tele_average_score'])))
        else:
            statistics['auto_average_score'] = "—"
            statistics['tele_average_score'] = "—"
            statistics['total_average_score'] = "—"
        if statistics['match_final_score'] != "—":
            try:
                statistics['total_score_proportion'] = str("%.2f" %
                    (float(statistics['total_average_score']) / float(statistics['match_final_score']) * 100))
            except ZeroDivisionError:
                statistics['total_score_proportion'] = "?"
        else:
            statistics['total_score_proportion'] = "—"

    pit_scout_data = PitScoutData.objects.filter(team_number=team_number).order_by('id').exclude(location__name="TEST")

    aggregate_data = PitScoutData(team_number=team_number)

    for data in pit_scout_data:
        for field in PitScoutData._meta.fields:
            if getattr(data, field.name):
                setattr(aggregate_data, field.name, getattr(data, field.name))

    self_scouted = PitScoutData.objects.filter\
        (team_number=team_number, scout__userprofile__team__team_number=team_number).order_by('id')

    for data in self_scouted:
        for field in PitScoutData._meta.fields:
            if getattr(data, field.name):
                setattr(aggregate_data, field.name, getattr(data, field.name))

    # then pass all the sections/data to the context
    pitdatas = PitScoutData.objects.filter(team_number=team_number).count()

    try:
        param = str("team/frc%i" % int(team_number))
        json_decoded = make_tba_request(param)

    except ValueError:
        json_decoded = None

    context = {
        'has_pit_data': pitdatas,
        'aggregate_data': model_to_dict(aggregate_data),
        'team_number': team_number,
        'statistics': statistics,
        'nav_title': str(team_number),
        'matches': matches,
        'tba_data': json_decoded
    }
    if pitdatas == 1:
        context['scout_name'] = PitScoutData.objects.get(team_number=team_number).scout.first_name

    return render(request, 'frc_scout/profiles/profile.html', context)