Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
H
hypha
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ots
hypha
Commits
f3bec5cd
Commit
f3bec5cd
authored
5 years ago
by
Fredrik Jonsson
Browse files
Options
Downloads
Patches
Plain Diff
Count NA as 0 when calculating review score.
parent
3baf5081
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
opentech/apply/review/forms.py
+4
-2
4 additions, 2 deletions
opentech/apply/review/forms.py
opentech/apply/review/migrations/0020_review_score_calc_update.py
+62
-0
62 additions, 0 deletions
.../apply/review/migrations/0020_review_score_calc_update.py
with
66 additions
and
2 deletions
opentech/apply/review/forms.py
+
4
−
2
View file @
f3bec5cd
...
@@ -84,8 +84,10 @@ class ReviewModelForm(StreamBaseForm, forms.ModelForm, metaclass=MixedMetaClass)
...
@@ -84,8 +84,10 @@ class ReviewModelForm(StreamBaseForm, forms.ModelForm, metaclass=MixedMetaClass)
for
field
in
self
.
instance
.
score_fields
:
for
field
in
self
.
instance
.
score_fields
:
score
=
data
.
get
(
field
.
id
)[
1
]
score
=
data
.
get
(
field
.
id
)[
1
]
if
score
!=
NA
:
# Include NA answers as 0.
scores
.
append
(
score
)
if
score
==
NA
:
score
=
0
scores
.
append
(
score
)
try
:
try
:
return
sum
(
scores
)
/
len
(
scores
)
return
sum
(
scores
)
/
len
(
scores
)
...
...
This diff is collapsed.
Click to expand it.
opentech/apply/review/migrations/0020_review_score_calc_update.py
0 → 100644
+
62
−
0
View file @
f3bec5cd
# Generated by Django 2.0.13 on 2019-08-19 11:10
from
django.db
import
migrations
from
opentech.apply.review.models
import
Review
from
opentech.apply.review.options
import
NA
def
review_score_update
(
apps
,
schema_editor
):
for
review
in
Review
.
objects
.
all
():
# Disable auto_now on "updated_at" field so date is not changed.
for
field
in
review
.
_meta
.
local_fields
:
if
field
.
name
==
'
updated_at
'
:
field
.
auto_now
=
False
# Update the score and save.
scores
=
list
()
for
field
in
review
.
score_fields
:
score
=
review
.
form_data
.
get
(
field
.
id
)[
1
]
# Include NA answers as 0.
if
score
==
NA
:
score
=
0
scores
.
append
(
score
)
try
:
review
.
score
=
sum
(
scores
)
/
len
(
scores
)
except
ZeroDivisionError
:
review
.
score
=
NA
review
.
save
()
def
review_score_revert
(
apps
,
schema_editor
):
for
review
in
Review
.
objects
.
all
():
# Disable auto_now on "updated_at" field so date is not changed.
for
field
in
review
.
_meta
.
local_fields
:
if
field
.
name
==
'
updated_at
'
:
field
.
auto_now
=
False
# Update the score and save.
scores
=
list
()
for
field
in
review
.
score_fields
:
score
=
review
.
form_data
.
get
(
field
.
id
)[
1
]
# Exclude NA answers.
if
score
!=
NA
:
scores
.
append
(
score
)
try
:
review
.
score
=
sum
(
scores
)
/
len
(
scores
)
except
ZeroDivisionError
:
review
.
score
=
NA
review
.
save
()
class
Migration
(
migrations
.
Migration
):
dependencies
=
[
(
'
review
'
,
'
0019_replace_existing_author_field
'
),
]
operations
=
[
migrations
.
RunPython
(
review_score_update
,
review_score_revert
),
]
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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!
Save comment
Cancel
Please
register
or
sign in
to comment