-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6a52919
commit 8cd156e
Showing
5 changed files
with
153 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
from component.text import TextElement | ||
from component.button import ButtonElement | ||
import psychopy.visual.line | ||
from psychopy.visual.rect import Rect | ||
from config.constant import color_dict | ||
|
||
class ConfirmationModal: | ||
def __init__(self, win, text,confirm_action=None,cancel_action=None): | ||
self.win = win | ||
self.text = TextElement(win, text, pos=(0, 0), color=color_dict["white"],) | ||
self.confirm_button = ButtonElement(win, "Confirm", pos=(-0.3, -0.5), width=0.3, height=0.2, color="green", action=confirm_action) | ||
self.cancel_button = ButtonElement(win, "Cancel", pos=(0.3, -0.5), width=0.3, height=0.2, color="red", action=cancel_action) | ||
self.background_rect = Rect(win, width=1.2, height=0.9, fillColor=(0, 0, 0, 1.0), pos=(0, -0.2)) | ||
self.buttons = [self.confirm_button, self.cancel_button] | ||
self.visible = False | ||
|
||
def draw(self): | ||
if self.visible: | ||
self.background_rect.draw() | ||
self.text.draw() | ||
for element in self.buttons: | ||
element.draw() | ||
|
||
def containMouse(self, mouse): | ||
if(self.visible)==False: | ||
return False | ||
return self.confirm_button.containMouse(mouse) or self.cancel_button.containMouse(mouse) | ||
|
||
def action(self, mouse): | ||
for button_element in self.buttons: | ||
if button_element.containMouse(mouse): | ||
return button_element.action(mouse) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
from component.button import ButtonElement, ButtonList | ||
from component.modal import ConfirmationModal | ||
|
||
clickable_list:list = [ButtonList,ButtonElement, ConfirmationModal] | ||
|
||
def is_instance_of_class(variable, class_list=clickable_list): | ||
""" | ||
Check if a variable is an instance of any class in the class_list. | ||
Args: | ||
variable: The variable to be checked. | ||
class_list: A list of class names or classes. | ||
Returns: | ||
True if the variable is an instance of any class in the class_list, False otherwise. | ||
""" | ||
for cls in class_list: | ||
if isinstance(variable, cls): | ||
return True | ||
return False |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,62 @@ | ||
import pandas | ||
from config.dir import user_dir,history_dir,exam_dir | ||
|
||
class csvHandler: | ||
|
||
@staticmethod | ||
def get_new_sessionId(): | ||
user_df = pandas.read_excel(user_dir) | ||
class xlsxHandler: | ||
|
||
def __init__(self,dir): | ||
self.dir = dir | ||
|
||
def readData(self): | ||
return pandas.read_excel(self.dir) | ||
|
||
def readStructure(self): | ||
return pandas.read_excel(self.dir, nrows=1) | ||
|
||
def dumpd_data(self): | ||
history_dir.to_excel(self.dir, index=False) | ||
|
||
def truncate(self): | ||
df = pandas.read_excel(self.dir) | ||
df = pandas.DataFrame(columns=df.columns) | ||
df.to_excel(self.dir, index=False) | ||
|
||
def append_data(self,new_df): | ||
df_excel = pandas.read_excel(self.dir) | ||
result = pandas.concat([df_excel, new_df], ignore_index=True) | ||
print(result) | ||
result.to_excel(self.dir, index=False) | ||
|
||
|
||
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) | ||
|
||
def get_new_sessionId(self): | ||
user_df = self.user_data_handaler.readData() | ||
if user_df.empty: | ||
return 1 | ||
max_value = user_df['participantID'].max() | ||
return int(max_value) + 1 | ||
|
||
@staticmethod | ||
def get_exam(): | ||
def get_exam(self): | ||
return pandas.read_excel(exam_dir) | ||
|
||
@staticmethod | ||
def get_user(): | ||
return pandas.read_excel(user_dir) | ||
def get_user(self): | ||
return self.user_data_handaler.readData() | ||
|
||
@staticmethod | ||
def append_history_data(new_df): | ||
csvHandler.append_data(new_df,history_dir) | ||
|
||
@staticmethod | ||
def append_user_data(new_df): | ||
csvHandler.append_data(new_df,user_dir) | ||
def append_history_data(self,new_df): | ||
self.history_data_handaler.append_data(new_df=new_df) | ||
|
||
@staticmethod | ||
def append_data(new_df,path,sheet_name='Sheet1'): | ||
df_excel = pandas.read_excel(path) | ||
result = pandas.concat([df_excel, new_df], ignore_index=True) | ||
result.to_excel(path, index=False) | ||
|
||
@staticmethod | ||
def dumpd_data(): | ||
history_df = pandas.read_excel(history_dir) | ||
history_dir.to_excel('history.xlsx', index=False) | ||
|
||
@staticmethod | ||
def readStructure_user(): | ||
return csvHandler.readStructure(user_dir) | ||
def append_user_data(self,new_df): | ||
self.user_data_handaler.append_data(new_df=new_df) | ||
|
||
def readStructure_user(self): | ||
return self.user_data_handaler.readStructure() | ||
|
||
def resetHistory(self): | ||
self.user_data_handaler.truncate() | ||
self.history_data_handaler.truncate() | ||
|
||
@staticmethod | ||
def readStructure(dir): | ||
return pandas.read_excel(dir, nrows=1) | ||
dataHandaler= DataHandaler() |