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(
|
||||
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)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -1,4 +1,8 @@
|
|||
{
|
||||
"name": "steam-navigation",
|
||||
"collected_data_url": "http://127.0.0.1:8000/rest/university/recherche/survey/",
|
||||
|
||||
"surveys": {
|
||||
"text-welcome": {
|
||||
"type": "text",
|
||||
"title": "Bienvenue !",
|
||||
|
@ -38,4 +42,7 @@
|
|||
"type": "question-text",
|
||||
"title": "Qu'avez vous pensé de l'interface de Steam ?"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue