Skip to content

Commit

Permalink
Fix bug when generating heat map
Browse files Browse the repository at this point in the history
  • Loading branch information
nandooliveira committed Dec 6, 2019
1 parent b3607d2 commit d41edf2
Show file tree
Hide file tree
Showing 7 changed files with 127 additions and 14 deletions.
50 changes: 50 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
.PHONY: all help translate test clean update compass collect rebuild

SETTINGS={{ project_name }}.settings
TEST_SETTINGS={{ project_name }}.test_settings

# target: all - Default target. Does nothing.
all:
@echo "Hello $(LOGNAME), nothing to do by default"
@echo "Try 'make help'"

# target: help - Display callable targets.
help:
@egrep "^# target:" [Mm]akefile

# target: translate - calls the "makemessages" django command
translate:
cd {{ project_name }} && django-admin.py makemessages --settings=$(SETTINGS) -i "site-static/*" -a --no-location

# target: test - calls the "test" django command
test:
django-admin.py test --settings=$(TEST_SETTINGS)

# target: clean - remove all ".pyc" files
clean:
django-admin.py clean_pyc --settings=$(SETTINGS)

# target: update - install (and update) pip requirements
update:
pip install -U -r requirements.pip

# target: compass - compass compile all scss files
compass:
cd {{ project_name }}/compass && compass compile

# target: collect - calls the "collectstatic" django command
collect:
django-admin.py collectstatic --settings=$(SETTINGS) --noinput

# target: rebuild - clean, update, compass, collect, then rebuild all data
rebuild: clean update compass collect
django-admin.py reset_db --settings=$(SETTINGS) --router=default --noinput
django-admin.py syncdb --settings=$(SETTINGS) --noinput
django-admin.py migrate --settings=$(SETTINGS)
#django-admin.py loaddata --settings=$(SETTINGS) <your fixtures here>

run:
python manage.py runserver

startenv:
pipenv shell
1 change: 1 addition & 0 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ verify_ssl = true
[dev-packages]
pep8 = "*"
pylint = "<2.0.0"
pycodestyle = "*"

[packages]
django = "*"
Expand Down
25 changes: 17 additions & 8 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 25 additions & 0 deletions experiments/templates/view_task.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<!DOCTYPE html>
<html>
<head>
<title>Run Task</title>
<style type="text/css">
* {
margin: 0;
padding: 0;
}
.imgbox {
display: grid;
height: 100%;
}
.center-fit {
max-width: 100%;
max-height: 100vh;
margin: auto;
}
</style>
</head>
<body>
<img class="center-fit" src="{{ task.image.url }}" alt="Image not found" />
</body>
</html>

17 changes: 11 additions & 6 deletions experiments/views/heat_map.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
from django.views.generic.edit import FormView
from experiments.forms import HeatMapFeedbackForm
from experiments.models import Execution, Point

import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt

from pygazeanalyser.gazeplotter import draw_heatmap

import numpy
Expand All @@ -21,7 +26,7 @@
os.mkdir(PLOTDIR)

# EXPERIMENT SPECS
DISPSIZE = (1440, 900) # (px,px)
DISPSIZE = (1920, 1080) # (px,px)
SCREENSIZE = (39.9,29.9) # (cm,cm)
SCREENDIST = 61.0 # cm
PXPERCM = numpy.mean([DISPSIZE[0]/SCREENSIZE[0], DISPSIZE[1]/SCREENSIZE[1]]) # px/cm
Expand All @@ -44,10 +49,11 @@ def get_initial(self):
initial['execution_id'] = self.kwargs['execution_id']
# execution = self.__execution(245)
execution = self.__execution(self.kwargs['execution_id'])
self.__generate_heat_map(execution)

return initial
if not execution.heatmap:
self.__generate_heat_map(execution)

return initial

def get_context_data(self, **kwargs):
# Call the base implementation first to get a context
Expand All @@ -59,7 +65,6 @@ def get_context_data(self, **kwargs):

return context


def __generate_heat_map(self, execution):
background_image = DIR + "/../.." + execution.task.image.url
points = Point.objects.filter(
Expand Down Expand Up @@ -104,6 +109,7 @@ def __generate_heat_map(self, execution):
execution.heatmap = 'uploads/executions/heatmaps/{0}/heatmap.png'.format(execution.id)
print execution.heatmap
execution.save()
return execution.heatmap.url

def __execution(self, execution_id):
return Execution.objects.get(pk=execution_id)
Expand All @@ -116,5 +122,4 @@ def form_valid(self, form):

self.success_url += '%d/%d/?previous_execution_id=%s' % (
participant.id, experiment.id, heat_map_feedback.execution.id)
return super(HeatMap, self).form_valid(form)

return super(HeatMap, self).form_valid(form)
2 changes: 2 additions & 0 deletions experiments/views/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pipenv shell
python manage.py runserver
21 changes: 21 additions & 0 deletions experiments/views/view_task.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# -*- coding: utf-8 -*-
from datetime import datetime

from django.http import HttpResponseRedirect
from django.views.generic import TemplateView

from experiments.models import Task
from experiments.services.next_task_service import NextTaskService


class ViewTask(TemplateView):
template_name = 'view_task.html'

def get_context_data(self, **kwargs):
# Call the base implementation first to get a context
context = super(ViewTask, self).get_context_data(**kwargs)

task = Task.objects.get(pk=self.kwargs['task_id'])
context['task'] = task

return context

0 comments on commit d41edf2

Please sign in to comment.