Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Political Memory
memopol
Commits
705915a4
Commit
705915a4
authored
Sep 05, 2016
by
Nicolas Joyard
Browse files
Add PositionScore model for position score decay
parent
391b04aa
Changes
6
Hide whitespace changes
Inline
Side-by-side
memopol/tests/test_representative_positions.py
View file @
705915a4
...
...
@@ -6,9 +6,10 @@ class RepresentativePositionsTest(RepresentativeBaseTest):
"""
- One for positions
- One for related themes
- One for position scores
- One for position themes
"""
queries
=
RepresentativeBaseTest
.
queries
+
2
queries
=
RepresentativeBaseTest
.
queries
+
3
def
test_queries
(
self
):
self
.
do_query_test
()
...
...
memopol/views/representative_detail_positions.py
View file @
705915a4
...
...
@@ -19,7 +19,8 @@ class RepresentativeDetailPositions(RepresentativeDetailBase):
queryset
=
Position
.
objects
.
filter
(
published
=
True
)
.
order_by
(
'-datetime'
,
'pk'
)
),
'positions__themes'
'positions__themes'
,
'positions__positionscore'
)
return
qs
...
...
memopol/views/theme_detail_positions.py
View file @
705915a4
...
...
@@ -8,7 +8,8 @@ class ThemeDetailPositions(ThemeDetailBase):
def
get_queryset
(
self
):
qs
=
super
(
ThemeDetailPositions
,
self
).
get_queryset
()
qs
=
qs
.
prefetch_related
(
'positions__representative'
)
qs
=
qs
.
prefetch_related
(
'positions__representative'
,
'positions__positionscore'
)
return
qs
def
get_context_data
(
self
,
**
kwargs
):
...
...
representatives_positions/migrations/0006_positionscore.py
0 → 100644
View file @
705915a4
# -*- coding: utf-8 -*-
from
__future__
import
unicode_literals
from
django.db
import
migrations
,
models
class
Migration
(
migrations
.
Migration
):
dependencies
=
[
(
'representatives_positions'
,
'0005_set_title'
),
(
'representatives_recommendations'
,
'0007_fix_underflow'
),
]
operations
=
[
migrations
.
CreateModel
(
name
=
'PositionScore'
,
fields
=
[
(
'id'
,
models
.
AutoField
(
verbose_name
=
'ID'
,
serialize
=
False
,
auto_created
=
True
,
primary_key
=
True
)),
(
'score'
,
models
.
FloatField
(
default
=
0
)),
],
options
=
{
'db_table'
:
'representatives_positions_positionscore'
,
'managed'
:
False
,
},
),
migrations
.
RunSQL
(
"""
CREATE OR REPLACE VIEW "representatives_positions_positionscore"
AS SELECT
"representatives_positions_position"."id" AS "id",
"representatives_positions_position"."id" AS "position_id",
"representatives_positions_position"."representative_id" AS "representative_id",
decay_score(
"representatives_positions_position"."score",
"representatives_positions_position"."datetime",
"decay_num"."value",
"decay_denom"."value",
"exponent"."value",
"decimals"."value"
) AS "score"
FROM "representatives_positions_position"
JOIN (SELECT CAST(TO_NUMBER(value, '99999') AS NUMERIC) AS value FROM memopol_settings_setting WHERE key = 'SCORE_DECAY_NUM') decay_num ON 1=1
JOIN (SELECT CAST(TO_NUMBER(value, '99999') AS NUMERIC) AS value FROM memopol_settings_setting WHERE key = 'SCORE_DECAY_DENOM') decay_denom ON 1=1
JOIN (SELECT CAST(TO_NUMBER(value, '99999') AS NUMERIC) AS value FROM memopol_settings_setting WHERE key = 'SCORE_EXPONENT') exponent ON 1=1
JOIN (SELECT CAST(TO_NUMBER(value, '99999') AS INTEGER) AS value FROM memopol_settings_setting WHERE key = 'SCORE_DECIMALS') decimals ON 1=1;
"""
),
]
representatives_positions/models.py
View file @
705915a4
...
...
@@ -37,3 +37,15 @@ class Position(models.Model):
def
unpublish
(
self
):
self
.
published
=
False
class
PositionScore
(
models
.
Model
):
position
=
models
.
OneToOneField
(
Position
,
related_name
=
'positionscore'
,
on_delete
=
models
.
DO_NOTHING
)
representative
=
models
.
ForeignKey
(
Representative
,
related_name
=
'positionscores'
)
score
=
models
.
FloatField
(
default
=
0
)
class
Meta
:
managed
=
False
db_table
=
'representatives_positions_positionscore'
templates/blocks/_position_list.html
View file @
705915a4
...
...
@@ -45,7 +45,7 @@
<div
class=
"text-center"
>
{{ position.datetime|naturalday }}
</div>
{% include "blocks/_themetags.html" with themes=position.themes.all exclude=theme.pk %}
{{ position.score|score_badge }}
{{ position.
positionscore.
score|score_badge }}
</button>
<div
class=
"modal fade"
id=
"position-modal-{{ position.pk }}"
tabindex=
"-1"
role=
"dialog"
aria-labelledby=
"position-button-{{ position.pk }}"
>
...
...
@@ -90,7 +90,7 @@
<dt>
{% trans "Score" %}
</dt>
<dd>
{{ position.score|score_badge }}
{{ position.
positionscore.
score|score_badge }}
</dd>
</dl>
</div>
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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