diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..75197c7 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +/result/ +/venv/ +/idea/ diff --git a/source/survey/WebMission.py b/source/survey/WebMission.py index 2ac4458..604de00 100644 --- a/source/survey/WebMission.py +++ b/source/survey/WebMission.py @@ -96,7 +96,7 @@ class WebMission(BaseSurvey): self._save_event( type="mouse_move", - position=(position.x(), position.y()), + position=[position.x(), position.y()], ) case QEvent.Type.MouseButtonPress: @@ -106,8 +106,8 @@ class WebMission(BaseSurvey): self._save_event( type="mouse_press", - position=(position.x(), position.y()), - button=event.button(), + position=[position.x(), position.y()], + button=event.button().value, ) case QEvent.Type.MouseButtonRelease: @@ -117,8 +117,8 @@ class WebMission(BaseSurvey): self._save_event( type="mouse_release", - position=(position.x(), position.y()), - button=event.button(), + position=[position.x(), position.y()], + button=event.button().value, ) case QEvent.Type.MouseButtonDblClick: @@ -128,7 +128,7 @@ class WebMission(BaseSurvey): self._save_event( type="mouse_double_click", - position=(position.x(), position.y()), + position=[position.x(), position.y()], ) case QEvent.Type.KeyPress: @@ -156,7 +156,7 @@ class WebMission(BaseSurvey): self._save_event( type="resize", - size=(size.width(), size.height()), + size=[size.width(), size.height()], ) return super().eventFilter(obj, event) @@ -197,9 +197,6 @@ class WebMission(BaseSurvey): if self._finished: return - # mark the mission as finished - self._finished = True - # mark the success in the events self._save_event(type="check") @@ -207,6 +204,9 @@ class WebMission(BaseSurvey): if "success" in self.signals: 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 self.browser.web.load(QUrl.fromLocalFile(str(page_success_path.absolute()))) @@ -232,6 +232,10 @@ class WebMission(BaseSurvey): # data collection 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 data["time"] = round(time.time() - self.start_time, 3) self._collected_events.append(data) diff --git a/source/widget/FrameSurvey.py b/source/widget/FrameSurvey.py index eb89a0b..62a325d 100644 --- a/source/widget/FrameSurvey.py +++ b/source/widget/FrameSurvey.py @@ -1,4 +1,6 @@ import json +import time +import uuid from pathlib import Path from PyQt6.QtCore import pyqtSignal @@ -8,6 +10,10 @@ from source.survey.base import BaseSurvey from source.survey import Empty, survey_get +result_path = Path("./result/") +result_path.mkdir(parents=True, exist_ok=True) + + class FrameSurvey(QFrame): signal_abandon = pyqtSignal() signal_skip = pyqtSignal() @@ -22,13 +28,13 @@ class FrameSurvey(QFrame): self.signal_skip.connect(self._on_signal_skip) # 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.current_survey_index = 0 - # prepare the survey collected data - self.collected_datas: dict[str, dict] = {} - # set the layout self._layout = QVBoxLayout() self.setLayout(self._layout) @@ -85,6 +91,9 @@ class FrameSurvey(QFrame): with open(survey_path, encoding="utf-8") as 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 = [ ( 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 @@ -108,7 +117,7 @@ class FrameSurvey(QFrame): # if there is data, get the current survey id survey_id, survey = self.survey_screens[self.current_survey_index] # 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 @@ -139,10 +148,11 @@ class FrameSurvey(QFrame): old_frame_survey.deleteLater() def finish_survey(self): - # TODO: send the collected data as a file somewhere - print(self.collected_datas) + # save the result in a json file + 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): # quit the application by closing and deleting the window diff --git a/surveys.json b/surveys.json index e264074..a7167d3 100644 --- a/surveys.json +++ b/surveys.json @@ -1,41 +1,48 @@ { - "text-welcome": { - "type": "text", - "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 - }, + "name": "steam-navigation", + "collected_data_url": "http://127.0.0.1:8000/rest/university/recherche/survey/", - "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" + "surveys": { + "text-welcome": { + "type": "text", + "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": { + "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 ?" } -} \ No newline at end of file +} + +