Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
comet
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
16
Issues
16
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Container Registry
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
IGGI students
comet
Commits
c7f768d0
Commit
c7f768d0
authored
Oct 24, 2019
by
Joseph Walton-Rivers
🐦
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'feature-database-performance' into 'master'
Feature database performance See merge request
!9
parents
36d6100f
fd1d4207
Pipeline
#2441
failed with stages
in 3 minutes and 1 second
Changes
6
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
30 additions
and
19 deletions
+30
-19
.gitignore
.gitignore
+1
-0
fg_competitions/filters.py
fg_competitions/filters.py
+1
-0
fg_competitions/models.py
fg_competitions/models.py
+16
-8
fg_competitions/templates/fg_competitions/track_scores.html
fg_competitions/templates/fg_competitions/track_scores.html
+9
-7
fg_competitions/views.py
fg_competitions/views.py
+2
-1
fg_competitions/views_extra.py
fg_competitions/views_extra.py
+1
-3
No files found.
.gitignore
View file @
c7f768d0
*.py[co]
*.swp
db.sqlite3
var/
.venv/
...
...
fg_competitions/filters.py
View file @
c7f768d0
...
...
@@ -8,3 +8,4 @@ class TrackFilter(django_filters.FilterSet):
class
Meta
:
model
=
Track
fields
=
[
"name"
,
"allow_submit"
,
"competition"
]
fg_competitions/models.py
View file @
c7f768d0
from
__future__
import
unicode_literals
from
django.utils.encoding
import
python_2_unicode_compatible
from
django.utils.functional
import
cached_property
from
django.core.exceptions
import
ObjectDoesNotExist
from
django.db
import
models
...
...
@@ -67,8 +68,14 @@ class CompetitionLink(models.Model):
def
__str__
(
self
):
return
self
.
name
class
TrackManager
(
models
.
Manager
):
def
get_queryset
(
self
):
return
super
(
TrackManager
,
self
)
.
get_queryset
()
.
prefetch_related
(
'competition'
)
@
python_2_unicode_compatible
class
Track
(
models
.
Model
):
objects
=
TrackManager
()
"""A variation in the rules of a competition"""
name
=
models
.
CharField
(
max_length
=
100
)
competition
=
models
.
ForeignKey
(
Competition
,
on_delete
=
models
.
CASCADE
)
...
...
@@ -155,14 +162,11 @@ class Submission(models.Model):
curr_upload
=
self
.
current
if
not
curr_upload
:
return
"No submission"
elif
curr_upload
.
status
not
in
(
"BS"
,
"VS"
):
return
curr_upload
.
get_status_display
()
else
:
return
self
.
ranking
return
self
.
ranking
@
property
def
is_valid
(
self
):
return
self
.
current
and
self
.
current
.
status
in
(
'BS'
,
'VS'
)
return
self
.
current
and
self
.
current
.
is_valid
@
property
def
versions
(
self
):
...
...
@@ -173,15 +177,15 @@ class Submission(models.Model):
else
:
raise
ValueError
(
"unknown submission type"
)
@
property
@
cached_
property
def
current_upload
(
self
):
return
self
.
uploads
.
first
()
@
property
@
cached_
property
def
current_text
(
self
):
return
self
.
text_submissions
.
first
()
@
property
@
cached_
property
def
current
(
self
):
if
self
.
submission_type
==
"U"
:
return
self
.
current_upload
...
...
@@ -224,6 +228,10 @@ class BaseSubmission(models.Model):
created
=
models
.
DateTimeField
(
auto_now_add
=
True
)
feedback
=
models
.
TextField
(
blank
=
True
,
null
=
True
)
@
property
def
is_valid
(
self
):
return
self
.
status
in
(
'BS'
,
'VS'
)
def
check_stage
(
self
,
check_stage
):
# check_stage = {upload, build, validate}
# self.status -> current status of the upload {BP, BF, ...}
...
...
fg_competitions/templates/fg_competitions/track_scores.html
View file @
c7f768d0
...
...
@@ -4,7 +4,6 @@
{% block head_title %}{{track}}{% endblock %}
{% block content_tab %}
<h2
class=
"sr-only"
>
Leaderboard
</h2>
<table
class=
"table table-striped"
>
<thead
class=
"thead-light"
>
...
...
@@ -16,17 +15,20 @@
</thead>
<tbody>
{% for submission in
track.submission_set.all
%}
<tr
{%
if
not
submission
.
current
%}
class=
"warning"
{%
endif
%}
>
{% for submission in
submissions
%}
{% with current=submission.current %}
<tr
{%
if
not
current
%}
class=
"warning"
{%
endif
%}
>
<th><a
href=
"{{submission.get_absolute_url}}"
>
{{submission}}
</a>
{% if submission.sample %}
<span
class=
"badge badge-secondary"
>
sample
</span>
{% endif %}
</th>
<td>
{% user_display submission.owner %}
</td>
{% if submission.is_valid %}
<td>
{{ submission.pretty_score|floatformat:3 }}
</td>
{% if not current %}
<td>
No Submission
</td>
{% elif not current.is_valid %}
<td>
{{ current.get_status_display }}
</td>
{% else %}
<td>
{{ submission.pretty_score
}}
</td>
<td>
{{ submission.ranking|floatformat:3
}}
</td>
{% endif %}
</tr>
{% endwith %}
{% empty %}
<tr>
<td
colspan=
"3"
><p
class=
"text-center"
>
There are presently no submissions
</p></td>
...
...
fg_competitions/views.py
View file @
c7f768d0
...
...
@@ -165,7 +165,8 @@ class TrackScoreView(TrackTab, TemplateView):
context
=
super
(
TrackScoreView
,
self
)
.
get_context_data
(
**
kwargs
)
# track
context
[
'track'
]
=
get_object_or_404
(
Track
,
id
=
self
.
kwargs
.
get
(
'track'
))
context
[
'track'
]
=
get_object_or_404
(
Track
.
objects
.
select_related
(
'competition'
),
id
=
self
.
kwargs
.
get
(
'track'
))
context
[
'submissions'
]
=
context
[
'track'
]
.
submission_set
.
all
()
.
select_related
(
'owner'
)
return
context
...
...
fg_competitions/views_extra.py
View file @
c7f768d0
...
...
@@ -2,14 +2,12 @@ from django.shortcuts import get_object_or_404
from
django.views.generic
import
TemplateView
from
.models
import
Competition
,
Track
,
Submission
,
SubmissionUpload
from
fg_portal.models
import
Update
class
Homepage
(
TemplateView
):
template_name
=
"fg_competitions/index.html"
def
get_context_data
(
self
,
**
kwargs
):
context
=
super
(
TemplateView
,
self
)
.
get_context_data
(
**
kwargs
)
context
[
'tracks'
]
=
Track
.
objects
.
order_by
(
'?'
)
.
filter
(
allow_submit
=
True
)[:
3
]
context
[
'news'
]
=
Update
.
objects
.
all
()[:
5
]
context
[
'tracks'
]
=
Track
.
objects
.
order_by
(
'?'
)
.
filter
(
allow_submit
=
True
)
.
select_related
(
'competition'
)[:
3
]
return
context
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment