diff --git a/component/button.py b/component/button.py index aaf6760..d771e46 100644 --- a/component/button.py +++ b/component/button.py @@ -1,8 +1,4 @@ -from PyQt6.QtWidgets import QPushButton,QApplication,QPushButton, QLabel, QVBoxLayout, QApplication -from PyQt6.QtCore import QSize,Qt -from PyQt6.QtGui import QIcon -from PyQt6.QtCore import QSize - +from PyQt6.QtWidgets import QPushButton,QPushButton, QLabel, QVBoxLayout class SquareButton(QPushButton): def __init__(self, icon, text, parent=None): @@ -17,11 +13,4 @@ def __init__(self, icon, text, parent=None): layout = QVBoxLayout() layout.addWidget(self.icon_label) layout.addWidget(self.text_label) - self.setLayout(layout) - - # def sizeHint(self): - # screen = QApplication.screens()[0] - # screen_size = screen.availableGeometry() - # # Calculate the button size based on screen size - # button_size = screen_size.width() / 10 - # return QSize(button_size, button_size) \ No newline at end of file + self.setLayout(layout) \ No newline at end of file diff --git a/component/field/user_infor.py b/component/field/user_infor.py new file mode 100644 index 0000000..d49feae --- /dev/null +++ b/component/field/user_infor.py @@ -0,0 +1,25 @@ +from PyQt6.QtWidgets import QLineEdit + +class UserInfo: + def __init__(self, parent=None): + self.chinese_name = QLineEdit(parent) + self.english_name = QLineEdit(parent) + self.gender = QLineEdit(parent) + self.birth_year = QLineEdit(parent) + self.education_level = QLineEdit(parent) + self.native_language = QLineEdit(parent) + self.family_language = QLineEdit(parent) + self.friend_language = QLineEdit(parent) + + def get_data(self)->dict: + return { + "中文姓名": self.chinese_name.text(), + "英文姓名": self.english_name.text(), + "性別": self.gender.text(), + "出生年": self.birth_year.text(), + "教育程度": self.education_level.text(), + "母語": self.native_language.text(), + "跟家人常說語言": self.family_language.text(), + "跟朋友常說語言": self.friend_language.text() + } + \ No newline at end of file diff --git a/component/screen/end_screen.py b/component/screen/end_screen.py index dcecd5a..485af55 100644 --- a/component/screen/end_screen.py +++ b/component/screen/end_screen.py @@ -17,9 +17,7 @@ def __init__(self,navigator,screen_height,screen_width, result): self.result = result self.initUI() - if(result is not None): - self.saveResult(result) - + def initUI(self): layout = QVBoxLayout(self) @@ -43,15 +41,4 @@ def initUI(self): quit_btn.setStyleSheet("background-color: red; color: white; font-size: 20px; padding: 10px;") layout.addWidget(quit_btn) - self.setLayout(layout) - - - def saveResult(self,history): - user_df = dataHandaler.get_user() - user_df = user_df.drop(user_df.index) - new_history_value = pd.DataFrame([element.to_dict() for element in history]) - new_history_value['participate_number'] = dataHandaler.get_new_sessionId() - new_history_value = new_history_value.sort_values(by='question') - user_df = pd.concat([user_df, pd.DataFrame([{"participantID":dataHandaler.get_new_sessionId()}])], ignore_index=True) - dataHandaler.append_history_data(new_history_value) - dataHandaler.append_user_data(user_df) \ No newline at end of file + self.setLayout(layout) \ No newline at end of file diff --git a/component/screen/test_screen.py b/component/screen/test_screen.py index 44e96b0..4528319 100644 --- a/component/screen/test_screen.py +++ b/component/screen/test_screen.py @@ -1,7 +1,7 @@ from component.button import SquareButton -from component.model import Answer import os +from model.answer import Answer from storage.localStorage import dataHandaler import random from PyQt6.QtWidgets import QWidget, QLabel, QPushButton, QVBoxLayout,QProgressBar,QSizePolicy,QHBoxLayout,QSpacerItem, QGridLayout @@ -15,6 +15,8 @@ from config.constant import pofomopo_consonants,similarity_list from pydub import AudioSegment from config.dir import volume_icon +import pandas as pd +from model.session import currentSession # TestScreen class TestScreen(QWidget): @@ -183,7 +185,21 @@ def submit_test(self): question.set_answer(pofomopo_consonants[question.get_answer()] if question.get_answer()!= -1 else -1) question.set_similarity(similarity_list[question.get_similarity()] if question.get_similarity()!=-1 else -1) - + new_user_value = currentSession.get_user_info() + new_user_value["participantID"]=dataHandaler.get_new_sessionId() + + new_history_value = pd.DataFrame([element.to_dict() for element in self.answerList]) + new_history_value['participate_number'] = dataHandaler.get_new_sessionId() + new_history_value = new_history_value.sort_values(by='question') + + + dataHandaler.append_history_data(new_history_value) + print(new_user_value) + dataHandaler.append_user_data(pd.DataFrame([new_user_value])) + + def submit_session(self): + pass + def updateProcess(self): # Update the progress label self.progress_label.setText(f"Test Number: {self.current_index + 1}/{len(self.answerList)}") diff --git a/component/screen/user_information_screen.py b/component/screen/user_information_screen.py index a46c2b1..b4618b5 100644 --- a/component/screen/user_information_screen.py +++ b/component/screen/user_information_screen.py @@ -1,7 +1,9 @@ +from component.field.user_infor import UserInfo from component.modal import ConfirmDialog -from PyQt6.QtWidgets import QWidget, QLabel, QPushButton, QVBoxLayout,QLineEdit,QDialog +from PyQt6.QtWidgets import QWidget, QLabel, QPushButton, QVBoxLayout,QHBoxLayout,QDialog import logging +from model.session import currentSession class UserInformationScreen(QWidget): def __init__(self,navigator,screen_height:int,screen_width:int): @@ -16,20 +18,17 @@ def __init__(self,navigator,screen_height:int,screen_width:int): def initUI(self)->None: logging.info("Setting up UI for StartScreen") layout = QVBoxLayout() - self.fields = { - "中文姓名": QLineEdit(self), - "英文姓名": QLineEdit(self), - "性別": QLineEdit(self), - "出生年": QLineEdit(self), - "教育程度": QLineEdit(self), - "母語": QLineEdit(self), - "跟家人常說語言": QLineEdit(self), - "跟朋友常說語言": QLineEdit(self) - } - - for label, edit in self.fields.items(): - layout.addWidget(QLabel(label)) - layout.addWidget(edit) + self.user_info_fields = UserInfo(self) + + layout.addLayout(self.create_labeled_field("中文姓名", self.user_info_fields.chinese_name)) + layout.addLayout(self.create_labeled_field("英文姓名", self.user_info_fields.english_name)) + layout.addLayout(self.create_labeled_field("性別", self.user_info_fields.gender)) + layout.addLayout(self.create_labeled_field("出生年", self.user_info_fields.birth_year)) + layout.addLayout(self.create_labeled_field("教育程度", self.user_info_fields.education_level)) + layout.addLayout(self.create_labeled_field("母語", self.user_info_fields.native_language)) + layout.addLayout(self.create_labeled_field("跟家人常說語言", self.user_info_fields.family_language)) + layout.addLayout(self.create_labeled_field("跟朋友常說語言", self.user_info_fields.friend_language)) + # Save button save_btn = QPushButton('Save', self) @@ -41,8 +40,8 @@ def initUI(self)->None: self.setWindowTitle('User Information') def save_data(self): - user_info = {label: edit.text() for label, edit in self.fields.items()} - print("User Info Saved:", user_info) + user_info = self.user_info_fields.get_data() + currentSession.set_user_info(user_info) def show_confirm_dialog(self): dialog = ConfirmDialog("save the information?",self) @@ -53,4 +52,13 @@ def show_confirm_dialog(self): self.save_data() self.navigator.navigate_to_test_screen() else: - print("Save cancelled") \ No newline at end of file + print("Save cancelled") + + + + def create_labeled_field(self, label_text: str, field: QWidget) -> QHBoxLayout: + labeled_field_layout = QHBoxLayout() + label = QLabel(label_text) + labeled_field_layout.addWidget(label) + labeled_field_layout.addWidget(field) + return labeled_field_layout \ No newline at end of file diff --git a/model/__init__.py b/model/__init__.py new file mode 100644 index 0000000..75901de --- /dev/null +++ b/model/__init__.py @@ -0,0 +1,3 @@ +from model.session import Session + +currentSession = Session() \ No newline at end of file diff --git a/component/model.py b/model/answer.py similarity index 100% rename from component/model.py rename to model/answer.py diff --git a/model/session.py b/model/session.py new file mode 100644 index 0000000..33b4ff3 --- /dev/null +++ b/model/session.py @@ -0,0 +1,12 @@ + +class Session: + def __init__(self): + self.user_info = None + + def set_user_info(self, info:dict): + self.user_info = info + + def get_user_info(self)->dict: + return self.user_info + +currentSession = Session() \ No newline at end of file diff --git a/model/user.py b/model/user.py new file mode 100644 index 0000000..e69de29 diff --git a/storage/localStorage.py b/storage/localStorage.py index 12eb551..104c4b7 100644 --- a/storage/localStorage.py +++ b/storage/localStorage.py @@ -29,6 +29,7 @@ def append_data(self,new_df): class DataHandaler: def __init__(self): + self.user_data_handaler =xlsxHandler(dir=user_dir) self.history_data_handaler =xlsxHandler(dir=history_dir) self.exam_data_handler = xlsxHandler(dir=exam_dir)