Skip to content

Commit

Permalink
feat: database table which named table_info is added
Browse files Browse the repository at this point in the history
  • Loading branch information
Yejining committed Feb 16, 2020
1 parent 9299a21 commit 03db029
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 7 deletions.
13 changes: 13 additions & 0 deletions database/create.sql
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,17 @@ CREATE TABLE `game` (
`average_pupil_diameter` double DEFAULT NULL,
`average_pupil_validity` int(11) DEFAULT NULL,
`is_wandering` int(11) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

CREATE TABLE `info` (
`id` varchar(255) NOT NULL,
`n` int(11) DEFAULT NULL,
`m` int(11) DEFAULT NULL,
`board` varchar(255) DEFAULT NULL,
`seqsize` int(11) DEFAULT NULL,
`sequence` varchar(255) DEFAULT NULL,
`pupil_timer` int(11) DEFAULT NULL,
`seq_timer` int(11) DEFAULT NULL,
`dwell_timer` int(11) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
8 changes: 6 additions & 2 deletions gui/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ def setupUi(self, MainWindow):
self.table.setCornerButtonEnabled(True)
self.table.setObjectName("table")
self.table.setColumnCount(1)
self.table.setRowCount(6)
self.table.setRowCount(7)
item = QtWidgets.QTableWidgetItem()
self.table.setVerticalHeaderItem(0, item)
item = QtWidgets.QTableWidgetItem()
Expand All @@ -401,6 +401,8 @@ def setupUi(self, MainWindow):
item = QtWidgets.QTableWidgetItem()
self.table.setVerticalHeaderItem(5, item)
item = QtWidgets.QTableWidgetItem()
self.table.setVerticalHeaderItem(6, item)
item = QtWidgets.QTableWidgetItem()
self.table.setHorizontalHeaderItem(0, item)
self.gridLayout_6.addWidget(self.table, 0, 0, 1, 1)
self.hLayout_setting = QtWidgets.QHBoxLayout()
Expand Down Expand Up @@ -520,7 +522,9 @@ def retranslateUi(self, MainWindow):
item = self.table.verticalHeaderItem(4)
item.setText(_translate("MainWindow", "CHARSET"))
item = self.table.verticalHeaderItem(5)
item.setText(_translate("MainWindow", "TABLE"))
item.setText(_translate("MainWindow", "TABLE_GAME"))
item = self.table.verticalHeaderItem(6)
item.setText(_translate("MainWindow", "TAGLE_INFO"))
item = self.table.horizontalHeaderItem(0)
item.setText(_translate("MainWindow", "Setting"))
self.pushButton_cancel.setText(_translate("MainWindow", "CANCEL"))
Expand Down
27 changes: 23 additions & 4 deletions src/input/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ def get_dbconn(self):
dbname=self.table.item(3, 0).text(),
dbcharset=self.table.item(4, 0).text()
)
table_game = self.table.item(5, 0).text()
table_info = self.table.item(6, 0).text()
else:
dbconn = MYSQL(
dbhost=dbconstant.HOST,
Expand All @@ -87,8 +89,10 @@ def get_dbconn(self):
dbname=dbconstant.DB_NAME,
dbcharset=dbconstant.CHARSET
)
table_game = dbconstant.TABLE_GAME
table_info = dbconstant.TABLE_INFO

return dbconn
return dbconn, table_game, table_info

def get_id(self):
if self.checkBox_dbid.isChecked() is not True:
Expand All @@ -100,13 +104,13 @@ def is_existing_id(self):
dbconn = self.get_dbconn()

condition = {'id': self.lineEdit_dbid.displayText()}
count = dbconn.count(table=dbconstant.TABLE, condition=condition)
count = dbconn.count(table=dbconstant.TABLE_GAME, condition=condition)
dbconn.close()

return True if count > 0 else False

def save(self, result, parser):
dbconn = self.get_dbconn()
dbconn, table_game, table_info = self.get_dbconn()
width, height = parser.get_card_size()
horizontal_margin, vertical_margin = parser.get_margins()
id = self.get_id()
Expand Down Expand Up @@ -152,9 +156,24 @@ def save(self, result, parser):
'is_wandering': 1 if result.data[i].is_wandering else 0
}

dbconn.insert(table=dbconstant.TABLE, data=tuple)
dbconn.insert(table=table_game, data=tuple)
data_list.append(tuple)

n, m = parser.get_matrix_size()
tuple = {
'id': id,
'n': n,
'm': m,
'board': parser.get_board(),
'seqsize': parser.seqsize(),
'sequence': parser.get_sequence(),
'pupil_timer': int(parser.pupil_time()),
'seq_timer': int(parser.sequence_time()),
'dwell_timer': int(parser.dwell_time())
}

dbconn.insert(table=table_info, data=tuple)

path = "Z:\\paper_workspace\\EuroVis_2020_short\\participant_data_csv\\%s.csv" % id
pandas.DataFrame(data_list).to_csv(path, index=False)

15 changes: 15 additions & 0 deletions src/input/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,21 @@ def get_matrix_size(self):
m = int(self.inputs.lineEdit_boardsizem.displayText())
return n, m

def get_board(self):
board = []
n, m = self.get_matrix_size()
for i in range(m):
for j in range(n):
board.append(self.inputs.sequence.matrix[i][j].displayText())
return ''.join([str(element) for element in board])

def get_sequence(self):
sequence = []
seqsize = self.seqsize()
for i in range(seqsize):
sequence.append(str(self.inputs.sequence.elements[i].displayText()))
return ''.join([str(element) for element in sequence])

def get_time(self, status):
if status == Status.PUPIL:
return self.pupil_time()
Expand Down
7 changes: 6 additions & 1 deletion ui/main.ui
Original file line number Diff line number Diff line change
Expand Up @@ -695,7 +695,12 @@
</row>
<row>
<property name="text">
<string>TABLE</string>
<string>TABLE_GAME</string>
</property>
</row>
<row>
<property name="text">
<string>TAGLE_INFO</string>
</property>
</row>
<column>
Expand Down

0 comments on commit 03db029

Please sign in to comment.