Skip to content

Commit 67f0ced

Browse files
committed
Fix ending pauses
1 parent 4e2430d commit 67f0ced

File tree

9 files changed

+121
-11
lines changed

9 files changed

+121
-11
lines changed

datasetatoms.csv

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
,Replica,Id,Student,SetOfTasks,Tasks,Technique,Trials,Time,Minutes
2+
1,41,1,paulo,ST1,AV1.2:CO1.2:DE1.2,Without Atom,1,14.0,14.0
3+
1,41,1,paulo,ST2,AV2.1:CO2.1:DE2.1,With Atom,1,19.0,19.0
4+
1,41,2,Romário,ST1,AV1.1:CO1.1:DE1.1,With Atom,1,27.0,27.0
5+
1,41,2,Romário,ST2,AV2.2:CO2.2:DE2.2,Without Atom,1,22.0,22.0
6+
2,42,1,Igor,ST1,AV1.2:CO1.2:DE1.2,Without Atom,1,18.0,18.0
7+
2,42,1,Igor,ST2,AV2.1:CO2.1:DE2.1,With Atom,1,40.0,40.0
8+
2,42,2,Hyago,ST1,AV1.1:CO1.1:DE1.1,With Atom,1,20.0,20.0
9+
2,42,2,Hyago,ST2,AV2.2:CO2.2:DE2.2,Without Atom,1,32.0,32.0
10+
3,43,1,,ST1,AV1.2:CO1.2:DE1.2,Without Atom,1,19.0,19.0
11+
3,43,1,,ST2,AV2.1:CO2.1:DE2.1,With Atom,1,53.0,53.0
12+
3,43,2,,ST1,AV1.1:CO1.1:DE1.1,With Atom,1,21.0,21.0
13+
3,43,2,,ST2,AV2.2:CO2.2:DE2.2,Without Atom,1,20.0,20.0
14+
4,44,1,,ST1,AV1.2:CO1.2:DE1.2,Without Atom,1,9.0,9.0
15+
4,44,1,,ST2,AV2.1:CO2.1:DE2.1,With Atom,1,25.0,25.0
16+
4,44,2,,ST1,AV1.1:CO1.1:DE1.1,With Atom,1,17.0,17.0
17+
4,44,2,,ST2,AV2.2:CO2.2:DE2.2,Without Atom,1,30.0,30.0
18+
5,45,1,Matheus Costa,ST1,AV1.1:CO1.1:DE1.1,With Atom,1,27.0,27.0
19+
5,45,1,Matheus Costa,ST2,AV2.2:CO2.2:DE2.2,Without Atom,1,39.0,39.0
20+
5,45,2,Davi Jose,ST1,AV1.2:CO1.2:DE1.2,Without Atom,1,8.0,8.0
21+
5,45,2,Davi Jose,ST2,AV2.1:CO2.1:DE2.1,With Atom,1,18.0,18.0
22+
6,46,1,Marlon Lúcio,ST1,AV1.1:CO1.1:DE1.1,With Atom,1,35.0,35.0
23+
6,46,1,Marlon Lúcio,ST2,AV2.2:CO2.2:DE2.2,Without Atom,1,36.0,36.0
24+
6,46,2,Jackson Barbosa da Silva,ST1,AV1.2:CO1.2:DE1.2,Without Atom,1,13.0,13.0
25+
6,46,2,Jackson Barbosa da Silva,ST2,AV2.1:CO2.1:DE2.1,With Atom,1,40.0,40.0
26+
7,47,1,Allan,ST1,AV1.2:CO1.2:DE1.2,Without Atom,1,19.0,19.0
27+
7,47,1,Allan,ST2,AV2.1:CO2.1:DE2.1,With Atom,1,55.0,55.0
28+
7,47,2,Dielson Sales de Carvalho,ST1,AV1.1:CO1.1:DE1.1,With Atom,1,22.0,22.0
29+
7,47,2,Dielson Sales de Carvalho,ST2,AV2.2:CO2.2:DE2.2,Without Atom,1,25.0,25.0
30+
8,48,1,Thiago,ST1,AV1.1:CO1.1:DE1.1,With Atom,1,16.0,16.0
31+
8,48,1,Thiago,ST2,AV2.2:CO2.2:DE2.2,Without Atom,1,15.0,15.0
32+
8,48,2,,ST1,AV1.2:CO1.2:DE1.2,Without Atom,1,27.0,27.0
33+
8,48,2,,ST2,AV2.1:CO2.1:DE2.1,With Atom,1,78.0,78.0

experiments/management/__init__.py

Whitespace-only changes.

experiments/management/commands/__init__.py

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# -*- coding: utf-8 -*-
2+
3+
import csv
4+
from django.core.management.base import BaseCommand, CommandError
5+
from django.db.models import Q
6+
from experiments.models import LatinSquare, Execution
7+
8+
9+
class Command(BaseCommand):
10+
help = 'Generate a new CSV file to be used as dataset on rstudio script'
11+
12+
def handle(self, *args, **options):
13+
latin_squares = LatinSquare.objects.filter(experiment_id=2) \
14+
.exclude(Q(row1__participant_id__isnull=True) | Q(row2__participant_id__isnull=True))
15+
16+
with open('datasetatoms.csv', 'wb') as csvfile:
17+
filewriter = csv.writer(csvfile, delimiter=',', quotechar='|', quoting=csv.QUOTE_MINIMAL)
18+
filewriter.writerow(["","Replica","Id","Student","SetOfTasks","Tasks","Technique","Trials","Time","Minutes"])
19+
20+
for index, latin_square in enumerate(latin_squares, start=1):
21+
descriptions_row1_cell1 = [task.description for task in latin_square.row1.cell1.tasks.all()]
22+
tasks_row1_cell1 = ':'.join(descriptions_row1_cell1)
23+
descriptions_row1_cell2 = [task.description for task in latin_square.row1.cell2.tasks.all()]
24+
tasks_row1_cell2 = ':'.join(descriptions_row1_cell2)
25+
26+
descriptions_row2_cell1 = [task.description for task in latin_square.row2.cell1.tasks.all()]
27+
tasks_row2_cell1 = ':'.join(descriptions_row2_cell1)
28+
descriptions_row2_cell2 = [task.description for task in latin_square.row2.cell2.tasks.all()]
29+
tasks_row2_cell2 = ':'.join(descriptions_row2_cell2)
30+
31+
row1_cell1_type = ""
32+
row1_cell2_type = ""
33+
row2_cell1_type = ""
34+
row2_cell2_type = ""
35+
36+
if latin_square.frame_sequence[:2] == [1,2]:
37+
row1_cell1_type = "With Atom"
38+
row1_cell2_type = "Without Atom"
39+
row2_cell1_type = "Without Atom"
40+
row2_cell2_type = "With Atom"
41+
else:
42+
row1_cell1_type = "Without Atom"
43+
row1_cell2_type = "With Atom"
44+
row2_cell1_type = "With Atom"
45+
row2_cell2_type = "Without Atom"
46+
47+
duration_row1_cell_1 = self.duration_for_cell(latin_square.row1.cell1, latin_square.row1.participant)
48+
duration_row1_cell_2 = self.duration_for_cell(latin_square.row1.cell2, latin_square.row1.participant)
49+
duration_row2_cell_1 = self.duration_for_cell(latin_square.row2.cell1, latin_square.row2.participant)
50+
duration_row2_cell_2 = self.duration_for_cell(latin_square.row2.cell2, latin_square.row2.participant)
51+
52+
# write lines to csv
53+
filewriter.writerow([index, latin_square.id, 1, latin_square.row1.participant.name.encode('utf-8'), "ST1", tasks_row1_cell1, row1_cell1_type, 1, duration_row1_cell_1, duration_row1_cell_1])
54+
filewriter.writerow([index, latin_square.id, 1, latin_square.row1.participant.name.encode('utf-8'), "ST2", tasks_row1_cell2, row1_cell2_type, 1, duration_row1_cell_2, duration_row1_cell_2])
55+
filewriter.writerow([index, latin_square.id, 2, latin_square.row2.participant.name.encode('utf-8'), "ST1", tasks_row2_cell1, row2_cell1_type, 1, duration_row2_cell_1, duration_row2_cell_1])
56+
filewriter.writerow([index, latin_square.id, 2, latin_square.row2.participant.name.encode('utf-8'), "ST2", tasks_row2_cell2, row2_cell2_type, 1, duration_row2_cell_2, duration_row2_cell_2])
57+
58+
def duration_for_cell(self, cell, participant):
59+
total_duration = 0
60+
61+
for task in cell.tasks.all():
62+
execution = Execution.objects.get(task=task, participant=participant)
63+
total_duration += execution.duration_in_seconds()
64+
65+
return total_duration

experiments/models.py

+19-7
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,19 @@ class Participant(models.Model):
2525
created_at = models.DateTimeField(auto_now_add=True)
2626
updated_at = models.DateTimeField(auto_now=True)
2727

28-
def finish_all_pauses(self):
28+
def finish_last_pause_for_each_execution(self):
2929
for execution in self.execution_set.all():
30-
execution.pause_set.all().update(end_time=datetime.now())
30+
last_pause = Pause.objects.filter(execution=execution).order_by('-pk')
31+
32+
if len(last_pause) > 0:
33+
last_pause = last_pause[0]
34+
if last_pause.end_time is None:
35+
last_pause.end_time = datetime.now()
36+
last_pause.save()
37+
38+
#def finish_all_pauses(self):
39+
# for execution in self.execution_set.all():
40+
# execution.pause_set.all().update(end_time=datetime.now())
3141

3242
def __unicode__(self):
3343
return self.name
@@ -68,13 +78,15 @@ class Execution(models.Model):
6878
number_of_errors = models.IntegerField(default=0)
6979

7080
def duration_in_seconds(self):
71-
pauses_duration = 0
72-
for pause in self.pause_set.all():
73-
pauses_duration += pause.duration_in_seconds()
81+
# pauses_duration = 0
82+
# for pause in self.pause_set.all():
83+
# pauses_duration += pause.duration_in_seconds()
7484

75-
execution_total_duration = self.end - self.start
85+
# execution_total_duration = self.end - self.start
86+
# return execution_total_duration.total_seconds() - pauses_duration
7687

77-
return execution_total_duration.total_seconds() - pauses_duration
88+
duration_in_s = (self.end - self.start).total_seconds()
89+
return divmod(duration_in_s, 60)[0] # return in minutes
7890

7991

8092
class Point(models.Model):

experiments/views/next_task.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ def get(self, request, *args, **kwargs):
1515
experiment = self.__get_experiment(kwargs['experiment_id'])
1616
participant = self.__get_participant(kwargs['participant_id'])
1717

18-
participant.finish_all_pauses()
18+
participant.finish_last_pause_for_each_execution()
1919

2020
if 'previous_execution_id' in self.request.GET:
2121
execution = Execution.objects.get(pk=self.request.GET.get('previous_execution_id'))

experiments/views/pause_execution.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class PauseExecution(TemplateView):
1919
def get(self, request, *args, **kwargs):
2020
# finish previous pauses, this is needed in case of user refresh the screen
2121
execution = Execution.objects.get(pk=kwargs['execution_id'])
22-
execution.participant.finish_all_pauses()
22+
execution.participant.finish_last_pause_for_each_execution()
2323

2424
return super(PauseExecution, self).get(request, args, kwargs)
2525

experiments/views/previous_task.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ def __init__(self, **kwargs):
1515
def get(self, request, *args, **kwargs):
1616
participant = self.__get_participant(kwargs['participant_id'])
1717

18-
participant.finish_all_pauses()
18+
participant.finish_last_pause_for_each_execution()
1919

2020
self.execution = participant.execution_set.all().latest('created_at')
2121

experiments/views/resume_execution.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def date_handler(obj):
1313
raise TypeError
1414

1515
class ResumeExecution(View):
16-
template_name= None
16+
template_name = None
1717
def post(self, request, *args, **kwargs):
1818
pause = self.get_last_pause_for_execution(int(kwargs['execution_id']))
1919
pause.end_time = datetime.now()

0 commit comments

Comments
 (0)