Verified Commit 2a689877 authored by Elger Jonker's avatar Elger Jonker

[wip] show possible organizations for non-accepted urls

parent b8059ecc
......@@ -85,14 +85,14 @@
<li class="nav-item"><a class="nav-link" href="/game/contests/">Contest</a></li>
<li class="nav-item"><a class="nav-link" href="/game/team/">Teams</a></li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Submit Organization <span class="caret"></span></a>
<a class="nav-link dropdown-toggle" href="/game/submit_organization/" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Submit Organization <span class="caret"></span></a>
<div class="dropdown-menu" aria-labelledby="navbarDropdown">
<a class="dropdown-item" href="/game/submit_organization/">Submit Organization</a>
<a class="dropdown-item" href="/game/submitted_organizations/">Submitted Organizations</a>
</div>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdown2" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Submit Url<span class="caret"></span></a>
<a class="nav-link dropdown-toggle" href="/game/submit_url/" id="navbarDropdown2" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Submit Url<span class="caret"></span></a>
<div class="dropdown-menu" aria-labelledby="navbarDropdown2">
<a class="dropdown-item" href="/game/submit_url/">Submit Url</a>
<a class="dropdown-item" href="/game/submitted_urls/">Submitted Urls</a>
......
......@@ -21,7 +21,26 @@
<table class="table table-sm table-striped table-bordered table-hover"
style="width: 29%; float:left; margin: 20px; box-shadow: 0px 13px 82px -47px rgba(0,0,0,0.75); background-color: {{ score.team_color_soft }}; {% if team.name == score.team %} border: 1px solid lightgreen; {% endif %}">
<tbody>
<tr><td colspan="3" style="font-weight: bold; font-family: impact, sans-serif; font-size: 6em; text-align: center;"><a name="{{ forloop.counter }}"></a># {{ forloop.counter }}</td></tr>
<tr><td colspan="3"
style="font-weight: bold; font-family: impact, sans-serif; font-size: 6em; text-align: center;
{% if forloop.counter == 1 %}
background: radial-gradient(ellipse farthest-corner at right bottom, #FEDB37 0%, #FDB931 8%, #9f7928 30%, #8A6E2F 40%, transparent 80%),
radial-gradient(ellipse farthest-corner at left top, #FFFFFF 0%, #FFFFAC 8%, #D1B464 25%, #5d4a1f 62.5%, #5d4a1f 100%);
{% endif %}
{% if forloop.counter == 2 %}
/* chrome only, and not at all as impressive */
background: conic-gradient(
#d7d7d7, #c3c3c3, #cccccc, #c6c6c6,
#d3d3d3, #d8d8d8, #d5d5d5, #d8d8d8,
#d3d3d3, #c5c5c5, #c0c0c0, #bfbfbf,
#d0d0d0, #d9d9d9, #d1d1d1, #c5c5c5,
#c8c8c8, #d7d7d7, #d5d5d5, #cdcdcd,
#c4c4c4, #d9d9d9, #cecece, #c5c5c5,
#c5c5c5, #cdcdcd, #d8d8d8, #d9d9d9,
#d7d7d7);
{% endif %}
">
<a name="{{ forloop.counter }}"></a># {{ forloop.counter }}</td></tr>
<tr><td colspan="3" style="font-size: 3em; text-align: center; background-color: {{ score.team_color }}; height: 160px; vertical-align: middle;">{{ score.team | truncatechars:24 }}</td></tr>
<tr><td>Total score</td> <td colspan="2" style="text-align: center; font-size: 2em;">{{ score.total_score }}</td></tr>
<tr><td>Organizations</td> <td>{{ score.added_organizations }}</td><td><small>* {{ score.added_organizations_multiplier }} = {{ score.added_organizations_score }}</small></td></tr>
......
......@@ -2,6 +2,7 @@ import logging
from datetime import datetime
import pytz
import simplejson as json
import spectra
from babel import languages
from constance import config
......@@ -261,7 +262,7 @@ def scores(request):
scores.append(score)
# order the scores from high to low.
scores = sorted(scores, key=lambda k: (k['high'], k['medium'], k['low']), reverse=True)
scores = sorted(scores, key=lambda k: (k['total_score'], k['high'], k['medium'], k['low']), reverse=True)
return render(request, 'game/scores.html', {'team': get_team_info(request),
'scores': scores,
......@@ -449,10 +450,11 @@ def contest_map_data(request):
# not relevant for scores.
bare_organizations = list(OrganizationSubmission.objects.all().filter(
has_been_accepted=False,
has_been_rejected=False,
added_by_team__participating_in_contest=contest.pk
))
for bare_organizations in bare_organizations:
features.append(get_bare_organization_feature(bare_organizations))
for bare_organization in bare_organizations:
features.append(get_bare_organization_feature(bare_organization))
# and organizations that have been accepted, but don't have urls yet, thus no scans.
bare_organizations = list(OrganizationSubmission.objects.all().filter(
......@@ -460,8 +462,8 @@ def contest_map_data(request):
organization_in_system__u_many_o_upgrade__url__isnull=True,
added_by_team__participating_in_contest=contest.pk
))
for bare_organizations in bare_organizations:
features.append(get_bare_organization_feature(bare_organizations))
for bare_organization in bare_organizations:
features.append(get_bare_organization_feature(bare_organization))
# organizations that have been accepted, do have urls, but don't have a scan yet
bare_organizations = list(OrganizationSubmission.objects.all().filter(
......@@ -470,9 +472,19 @@ def contest_map_data(request):
organization_in_system__u_many_o_upgrade__endpoint__endpointgenericscan__isnull=True,
added_by_team__participating_in_contest=contest.pk
))
# todo: should be the real deal, we can also get the real coordinates if the organization has been added
# which might be altered during to contest to match reality.
# todo: this can have the real ID... for nicer map transitions? That's done by name right?
for bare_organizations in bare_organizations:
features.append(get_bare_organization_feature(bare_organizations))
for bare_organization in bare_organizations:
features.append(get_bare_organization_feature(bare_organization))
bare_urls = list(UrlSubmission.objects.all().filter(
has_been_accepted=False,
has_been_rejected=False,
added_by_team__participating_in_contest=contest.pk
).prefetch_related('for_organization__coordinate_set'))
for bare_url in bare_urls:
features.append(get_bare_url_feature(bare_url))
# loop over the organizations and calculate the ratings.
# you prefetch all the related objects, which still have to be iterated... damn,
......@@ -486,8 +498,16 @@ def contest_map_data(request):
for scan in url_scans:
features = add_or_update_features(features, scan)
data["features"] = features
# update string features to json type.
# todo: make sure that there are no strings in the database, because of this uglyness
updated_features = []
for feature in features:
if isinstance(feature['geometry']['coordinates'], str):
feature['geometry']['coordinates'] = json.loads(feature['geometry']['coordinates'])
else:
updated_features.append(feature)
data["features"] = updated_features
return JsonResponse(data, encoder=JSEncoder)
......@@ -545,7 +565,8 @@ def get_bare_organization_feature(submitted_organization):
"type": "Feature",
"properties":
{
"organization_id": "pending_%s" % submitted_organization.pk,
# can't use ID of submission, because this does not match per call.
"organization_id": "pending_%s" % submitted_organization.organization_type_name,
"organization_type": submitted_organization.organization_type_name,
"organization_name": submitted_organization.organization_name,
"organization_slug": slugify(submitted_organization.organization_name),
......@@ -570,6 +591,47 @@ def get_bare_organization_feature(submitted_organization):
}
def get_bare_url_feature(submitted_url):
print(submitted_url)
print(submitted_url.for_organization.coordinate_set)
if not submitted_url.for_organization.coordinate_set:
geojsontype = "Point"
area = [0, 0]
else:
coordinate = submitted_url.for_organization.coordinate_set.first()
geojsontype = coordinate.geojsontype
area = coordinate.area
return {
"type": "Feature",
"properties":
{
"organization_id": "%s" % submitted_url.for_organization.pk,
"organization_type": submitted_url.for_organization.type.name,
"organization_name": submitted_url.for_organization.name,
"organization_slug": slugify(submitted_url.for_organization.name),
"overall": 0,
"high": 0,
"medium": 0,
"low": 0,
"data_from": 0,
"color": "pending",
"total_urls": 0,
"high_urls": 0,
"medium_urls": 0,
"low_urls": 0,
},
"geometry":
{
"type": geojsontype,
# Sometimes the data is a string, sometimes it's a list. The admin
# interface might influence this.
"coordinates": area
}
}
def make_new_feature(organization, scan):
# log.debug('Making new feature %s, with scan %s' % (organization, scan))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment