result are now saved in a json file in ./result/
This commit is contained in:
parent
b8e2e50b04
commit
445be46cd9
4 changed files with 80 additions and 56 deletions
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
/result/
|
||||||
|
/venv/
|
||||||
|
/idea/
|
|
@ -96,7 +96,7 @@ class WebMission(BaseSurvey):
|
||||||
|
|
||||||
self._save_event(
|
self._save_event(
|
||||||
type="mouse_move",
|
type="mouse_move",
|
||||||
position=(position.x(), position.y()),
|
position=[position.x(), position.y()],
|
||||||
)
|
)
|
||||||
|
|
||||||
case QEvent.Type.MouseButtonPress:
|
case QEvent.Type.MouseButtonPress:
|
||||||
|
@ -106,8 +106,8 @@ class WebMission(BaseSurvey):
|
||||||
|
|
||||||
self._save_event(
|
self._save_event(
|
||||||
type="mouse_press",
|
type="mouse_press",
|
||||||
position=(position.x(), position.y()),
|
position=[position.x(), position.y()],
|
||||||
button=event.button(),
|
button=event.button().value,
|
||||||
)
|
)
|
||||||
|
|
||||||
case QEvent.Type.MouseButtonRelease:
|
case QEvent.Type.MouseButtonRelease:
|
||||||
|
@ -117,8 +117,8 @@ class WebMission(BaseSurvey):
|
||||||
|
|
||||||
self._save_event(
|
self._save_event(
|
||||||
type="mouse_release",
|
type="mouse_release",
|
||||||
position=(position.x(), position.y()),
|
position=[position.x(), position.y()],
|
||||||
button=event.button(),
|
button=event.button().value,
|
||||||
)
|
)
|
||||||
|
|
||||||
case QEvent.Type.MouseButtonDblClick:
|
case QEvent.Type.MouseButtonDblClick:
|
||||||
|
@ -128,7 +128,7 @@ class WebMission(BaseSurvey):
|
||||||
|
|
||||||
self._save_event(
|
self._save_event(
|
||||||
type="mouse_double_click",
|
type="mouse_double_click",
|
||||||
position=(position.x(), position.y()),
|
position=[position.x(), position.y()],
|
||||||
)
|
)
|
||||||
|
|
||||||
case QEvent.Type.KeyPress:
|
case QEvent.Type.KeyPress:
|
||||||
|
@ -156,7 +156,7 @@ class WebMission(BaseSurvey):
|
||||||
|
|
||||||
self._save_event(
|
self._save_event(
|
||||||
type="resize",
|
type="resize",
|
||||||
size=(size.width(), size.height()),
|
size=[size.width(), size.height()],
|
||||||
)
|
)
|
||||||
|
|
||||||
return super().eventFilter(obj, event)
|
return super().eventFilter(obj, event)
|
||||||
|
@ -197,9 +197,6 @@ class WebMission(BaseSurvey):
|
||||||
if self._finished:
|
if self._finished:
|
||||||
return
|
return
|
||||||
|
|
||||||
# mark the mission as finished
|
|
||||||
self._finished = True
|
|
||||||
|
|
||||||
# mark the success in the events
|
# mark the success in the events
|
||||||
self._save_event(type="check")
|
self._save_event(type="check")
|
||||||
|
|
||||||
|
@ -207,6 +204,9 @@ class WebMission(BaseSurvey):
|
||||||
if "success" in self.signals:
|
if "success" in self.signals:
|
||||||
self.signals["success"].emit() # NOQA: emit exist
|
self.signals["success"].emit() # NOQA: emit exist
|
||||||
|
|
||||||
|
# mark the mission as finished
|
||||||
|
self._finished = True
|
||||||
|
|
||||||
# change the content of the page to the success message
|
# change the content of the page to the success message
|
||||||
self.browser.web.load(QUrl.fromLocalFile(str(page_success_path.absolute())))
|
self.browser.web.load(QUrl.fromLocalFile(str(page_success_path.absolute())))
|
||||||
|
|
||||||
|
@ -232,6 +232,10 @@ class WebMission(BaseSurvey):
|
||||||
# data collection
|
# data collection
|
||||||
|
|
||||||
def _save_event(self, **data) -> None:
|
def _save_event(self, **data) -> None:
|
||||||
|
# if the mission is already finished, ignore
|
||||||
|
if self._finished:
|
||||||
|
return
|
||||||
|
|
||||||
# save the data of the event and add the current time
|
# save the data of the event and add the current time
|
||||||
data["time"] = round(time.time() - self.start_time, 3)
|
data["time"] = round(time.time() - self.start_time, 3)
|
||||||
self._collected_events.append(data)
|
self._collected_events.append(data)
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
import json
|
import json
|
||||||
|
import time
|
||||||
|
import uuid
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
from PyQt6.QtCore import pyqtSignal
|
from PyQt6.QtCore import pyqtSignal
|
||||||
|
@ -8,6 +10,10 @@ from source.survey.base import BaseSurvey
|
||||||
from source.survey import Empty, survey_get
|
from source.survey import Empty, survey_get
|
||||||
|
|
||||||
|
|
||||||
|
result_path = Path("./result/")
|
||||||
|
result_path.mkdir(parents=True, exist_ok=True)
|
||||||
|
|
||||||
|
|
||||||
class FrameSurvey(QFrame):
|
class FrameSurvey(QFrame):
|
||||||
signal_abandon = pyqtSignal()
|
signal_abandon = pyqtSignal()
|
||||||
signal_skip = pyqtSignal()
|
signal_skip = pyqtSignal()
|
||||||
|
@ -22,13 +28,13 @@ class FrameSurvey(QFrame):
|
||||||
self.signal_skip.connect(self._on_signal_skip) # NOQA: connect exist
|
self.signal_skip.connect(self._on_signal_skip) # NOQA: connect exist
|
||||||
self.signal_success.connect(self._on_signal_success) # NOQA: connect exist
|
self.signal_success.connect(self._on_signal_success) # NOQA: connect exist
|
||||||
|
|
||||||
# prepare the survey screen data
|
# prepare the survey collected data
|
||||||
|
self.survey_name = None
|
||||||
|
self.collected_data_url = None
|
||||||
|
self.collected_datas: dict[str, dict] = {"time": time.time(), "surveys": {}}
|
||||||
self.survey_screens: list[tuple[str, BaseSurvey]] = []
|
self.survey_screens: list[tuple[str, BaseSurvey]] = []
|
||||||
self.current_survey_index = 0
|
self.current_survey_index = 0
|
||||||
|
|
||||||
# prepare the survey collected data
|
|
||||||
self.collected_datas: dict[str, dict] = {}
|
|
||||||
|
|
||||||
# set the layout
|
# set the layout
|
||||||
self._layout = QVBoxLayout()
|
self._layout = QVBoxLayout()
|
||||||
self.setLayout(self._layout)
|
self.setLayout(self._layout)
|
||||||
|
@ -85,6 +91,9 @@ class FrameSurvey(QFrame):
|
||||||
with open(survey_path, encoding="utf-8") as file:
|
with open(survey_path, encoding="utf-8") as file:
|
||||||
surveys_data = json.load(file)
|
surveys_data = json.load(file)
|
||||||
|
|
||||||
|
self.survey_name = surveys_data.get("name")
|
||||||
|
self.collected_data_url = surveys_data.get("collected_data_url")
|
||||||
|
|
||||||
self.survey_screens = [
|
self.survey_screens = [
|
||||||
(
|
(
|
||||||
survey_id,
|
survey_id,
|
||||||
|
@ -97,7 +106,7 @@ class FrameSurvey(QFrame):
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
for survey_id, survey_data in surveys_data.items()
|
for survey_id, survey_data in surveys_data["surveys"].items()
|
||||||
]
|
]
|
||||||
self.current_survey_index = 0
|
self.current_survey_index = 0
|
||||||
|
|
||||||
|
@ -108,7 +117,7 @@ class FrameSurvey(QFrame):
|
||||||
# if there is data, get the current survey id
|
# if there is data, get the current survey id
|
||||||
survey_id, survey = self.survey_screens[self.current_survey_index]
|
survey_id, survey = self.survey_screens[self.current_survey_index]
|
||||||
# save the response in the data
|
# save the response in the data
|
||||||
self.collected_datas[survey_id] = collected_data
|
self.collected_datas["surveys"][survey_id] = collected_data
|
||||||
|
|
||||||
self.current_survey_index += 1
|
self.current_survey_index += 1
|
||||||
|
|
||||||
|
@ -139,10 +148,11 @@ class FrameSurvey(QFrame):
|
||||||
old_frame_survey.deleteLater()
|
old_frame_survey.deleteLater()
|
||||||
|
|
||||||
def finish_survey(self):
|
def finish_survey(self):
|
||||||
# TODO: send the collected data as a file somewhere
|
# save the result in a json file
|
||||||
print(self.collected_datas)
|
with open(result_path / f"{uuid.uuid4()}.json", "w", encoding="utf-8") as file:
|
||||||
|
json.dump(self.collected_datas, file, ensure_ascii=False)
|
||||||
|
|
||||||
self.window().close()
|
self.quit()
|
||||||
|
|
||||||
def quit(self):
|
def quit(self):
|
||||||
# quit the application by closing and deleting the window
|
# quit the application by closing and deleting the window
|
||||||
|
|
79
surveys.json
79
surveys.json
|
@ -1,41 +1,48 @@
|
||||||
{
|
{
|
||||||
"text-welcome": {
|
"name": "steam-navigation",
|
||||||
"type": "text",
|
"collected_data_url": "http://127.0.0.1:8000/rest/university/recherche/survey/",
|
||||||
"title": "Bienvenue !",
|
|
||||||
"description": "Nous réalisons une étude sur le logiciel Steam afin de déterminer son ergonomie.\nVous serez invité à naviguer sur la plateforme Steam d'une page à l'autre.",
|
|
||||||
"abandonable": true
|
|
||||||
},
|
|
||||||
|
|
||||||
"question-usage": {
|
"surveys": {
|
||||||
"type": "question-choice",
|
"text-welcome": {
|
||||||
"title": "A quel point êtes-vous familier avec Steam ?",
|
"type": "text",
|
||||||
"choices": {
|
"title": "Bienvenue !",
|
||||||
"0": "Ne connait pas",
|
"description": "Nous réalisons une étude sur le logiciel Steam afin de déterminer son ergonomie.\nVous serez invité à naviguer sur la plateforme Steam d'une page à l'autre.",
|
||||||
"1": "Connait de nom",
|
"abandonable": true
|
||||||
"2": "Utilisation rare",
|
},
|
||||||
"3": "Utilisation moyenne",
|
|
||||||
"4": "Utilisation fréquente"
|
"question-usage": {
|
||||||
|
"type": "question-choice",
|
||||||
|
"title": "A quel point êtes-vous familier avec Steam ?",
|
||||||
|
"choices": {
|
||||||
|
"0": "Ne connait pas",
|
||||||
|
"1": "Connait de nom",
|
||||||
|
"2": "Utilisation rare",
|
||||||
|
"3": "Utilisation moyenne",
|
||||||
|
"4": "Utilisation fréquente"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
"web-language": {
|
||||||
|
"type": "mission-web",
|
||||||
|
"title": "Changer la langue en français.",
|
||||||
|
"url": "https://steampowered.com/",
|
||||||
|
"check": "document.getElementsByTagName('html')[0].lang == 'fr'",
|
||||||
|
"skip_time": 60
|
||||||
|
},
|
||||||
|
|
||||||
|
"web-point-shop": {
|
||||||
|
"type": "mission-web",
|
||||||
|
"title": "Rendez-vous sur la boutique des points.",
|
||||||
|
"url": "https://steampowered.com/",
|
||||||
|
"check": "true",
|
||||||
|
"skip_time": 90
|
||||||
|
},
|
||||||
|
|
||||||
|
"question-experience": {
|
||||||
|
"type": "question-text",
|
||||||
|
"title": "Qu'avez vous pensé de l'interface de Steam ?"
|
||||||
}
|
}
|
||||||
},
|
|
||||||
|
|
||||||
"web-language": {
|
|
||||||
"type": "mission-web",
|
|
||||||
"title": "Changer la langue en français.",
|
|
||||||
"url": "https://steampowered.com/",
|
|
||||||
"check": "document.getElementsByTagName('html')[0].lang == 'fr'",
|
|
||||||
"skip_time": 60
|
|
||||||
},
|
|
||||||
|
|
||||||
"web-point-shop": {
|
|
||||||
"type": "mission-web",
|
|
||||||
"title": "Rendez-vous sur la boutique des points.",
|
|
||||||
"url": "https://steampowered.com/",
|
|
||||||
"check": "true",
|
|
||||||
"skip_time": 90
|
|
||||||
},
|
|
||||||
|
|
||||||
"question-experience": {
|
|
||||||
"type": "question-text",
|
|
||||||
"title": "Qu'avez vous pensé de l'interface de Steam ?"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue