Skip to content

Commit

Permalink
Updated to work with with NaN answers in a more intuitive way
Browse files Browse the repository at this point in the history
  • Loading branch information
u8sand committed Jan 7, 2019
1 parent 0f4189c commit 65699e4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
18 changes: 14 additions & 4 deletions FAIRshakeAPI/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -469,8 +469,8 @@ def save_answer_forms(self, answer_forms):
for answer_form in answer_forms:
if answer_form.is_valid():
answer_form.save()
else:
answer_form.instance.delete()
# else:
# answer_form.instance.delete()
return True

@decorators.action(
Expand Down Expand Up @@ -561,6 +561,16 @@ def save_form(self, request, form):
instance.save()
return instance

def agg_values(values):
values_filtered = [
v for v in values
if v != float('nan') and v is not None
]
if len(values_filtered) > 0:
return sum(values_filtered) / len(values_filtered)
else:
return None

class ScoreViewSet(
mixins.ListModelMixin,
viewsets.GenericViewSet,
Expand Down Expand Up @@ -621,7 +631,7 @@ def list(self, request):
result = {
'scores': {
rubric: {
metric: sum(value)/len(value)
metric: agg_values(value)
for metric, value in score.items()
}
for rubric, score in scores.items()
Expand Down Expand Up @@ -670,7 +680,7 @@ def hist(self, request):
answers = {}
for assessment in self.filter_queryset(self.get_queryset()):
for answer in assessment.answers.all():
answers[answer.answer] = answers.get(answer.answer, 0) + 1
answers[answer.answer] = answers.get(answer.answer, None) + 1
cache.set(key, answers, 60 * 60)

return response.Response(answers)
4 changes: 2 additions & 2 deletions FAIRshakeHub/static/scripts/insignia.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ define(function(require) {
var local_unit = 1 / (scores_sq * summary_sq)

Object.keys(score).forEach(function (summary, j) {
var average = score[summary]
var average = score[summary] === null ? NaN : score[summary]
var local_x = (j % summary_sq) * local_unit
var local_y = Math.floor(j / summary_sq) * local_unit

Expand Down Expand Up @@ -176,7 +176,7 @@ define(function(require) {
results.scores,
{
tooltips: function(rubric, metric, score) {
return 'Score: ' + (score * 100).toFixed(0) + '%<br />' + results.metrics[metric]
return (isNaN(score) ? '' : 'Score: ' + (score * 100).toFixed(0) + '%<br />') + results.metrics[metric]
},
links: function(rubric, metric, score) {
return 'https://fairshake.cloud/metric/' + metric + '/'
Expand Down

0 comments on commit 65699e4

Please sign in to comment.