示例#1
0
 def get_snapshot(self, name):
     Log.log('d', f'name: {name}')
     snapshot = self.cursor.execute(f"SELECT \
         operations, expressions_count, columns_num, min_num, max_num \
         from history \
         where snapshot_name = '{name}'")
     return snapshot.fetchone()
示例#2
0
 def load_snapshot(self, config: Config):
     Log.log('i', 'Config: ', config.__dict__)
     self.operation_checkbox.set_checked(config.operations)
     self.expressions_count_input.setText(str(config.expressions_count))
     self.columns_input.setText(str(config.columns))
     self.min_number_input.setText(str(config.min_number))
     self.max_number_input.setText(str(config.max_number))
示例#3
0
 def test_add_snapshot(self):
     task = TaskModel(17, 3, ['+', '-'], (10, 49))
     Log.log('d', f'Test format: {task.to_sqlite_format()}')
     name = ''.join([choice(ascii_letters) for _ in range(randint(5, 15))])
     self.hm.add_snaptshot([name, *task.to_sqlite_format()])
     # self.dbm.save()
     Log.log('d', self.hm.get_snapshot_names())
示例#4
0
 def add_snaptshot(self, params):
     Log.log('d', f'add_snapshot params: {params}')
     self.cursor.execute(
         f"INSERT into history \
         (snapshot_name, operations, expressions_count, columns_num, min_num, max_num)\
         values (?,?,?,?,?,?)", params)
     self.conn.commit()
示例#5
0
 def set_checked(self, values):
     from src.logger.logger import Log
     for i in range(self.model().rowCount()):
         item = self.model().item(i)
         Log.log('i', 'Operations item data: ', item.data())
         item.setCheckState(Qt.Checked if item.data() in
                            values else Qt.Unchecked)
 def generate_task_action(self, with_answers=False):
     config = self.validate_task_config()
     Log.log('i', 'with answers: ', with_answers)
     if config:
         task = TaskModel(int(config.expressions_count),
                          int(config.columns), config.operations,
                          (int(config.min_number), int(config.max_number)))
         em = ExportManager(task)
         em.save('Math 1.docx', with_answers)
示例#7
0
    def save(self, file_name, with_answers=False):
        self._fill_table(with_answers)
        self.doc.add_page_break()

        name = open_file(documents_path() + '/' + file_name)
        Log.log('d', 'name: ', name)
        if name[0] == '':
            return
        self.doc.save(name[0])
示例#8
0
 def __init__(self):
     # db_manager = DBManager()
     # self.dbm = db_manager
     # db_manager.init_tables()
     hm = HistoryProvider()
     self.hm = hm
     Log.log('d', hm.get_snapshot_names())
     name = ''.join([choice(ascii_letters) for _ in range(randint(5, 15))])
     hm.add_snaptshot((name, '+, -', 3, 3, 4, 20))
     Log.log('d', hm.get_snapshot_names())
 def generate_example(self):
     op = choice(self._operations)
     a = randint(self._from_num, self._to_num)
     b = randint(self._from_num, self._to_num)
     try:
         Log.log('d', "data: ", a, op, b)
         ret = eval(str(a) + op + str(b))
         Log.log('d', ret)
         ex = ExpressionModel(a, op, b, result=ret)
         return ex
     except Exception:
         return Exception
示例#10
0
    def _fill_table(self, with_answers=False):
        expression_index = 0

        for col_index in range(self.cols):
            for row_index in range(self.rows):
                if expression_index >= self.task.expressions_count:
                    return
                cell = self.table.rows[row_index].cells[col_index]
                expression = self.task.get_field()[expression_index]
                Log.log('d', 'Expression: ', expression.docx_format())
                cell.text = expression.docx_format(with_answers)
                expression_index += 1
示例#11
0
    def show_view(self):
        Log.log('i', 'show_view')
        self.view.show()
        self.view.generate_task_button.clicked.connect(
            self.generate_task_action)

        self.view.generate_task_with_answers_button.clicked.connect(
            lambda: self.generate_task_action(True))

        self.view.table.clicked.connect(self.snapshot_entry_clicked)
        self.view.save_snapshot_button.clicked.connect(self.save_snapshot)
        self.view.delete_snapshot_button.clicked.connect(self.delete_snapshot)
        self.update_snapshot_table()
示例#12
0
 def snapshot_entry_clicked(self, index: QModelIndex):
     config = Config()
     Log.log('i', 'Clicked snaphost entry')
     snapshot = self.history_provider.get_snapshot(index.data())
     Log.log('i', 'Snapshot name: ', index.data())
     if not snapshot:
         return
     config.operations = snapshot[0]
     config.expressions_count = snapshot[1]
     config.columns = snapshot[2]
     config.min_number = snapshot[3]
     config.max_number = snapshot[4]
     self.view.load_snapshot(config)
示例#13
0
 def delete_snapshot(self):
     name, is_pressed = QInputDialog.getText(self.view, "Delete Snapshot",
                                             "Enter name")
     if is_pressed:
         Log.log('d', self.history_provider.get_snapshot(name))
         if self.history_provider.get_snapshot(name):
             self.history_provider.delete_snapshot(name)
             self.update_snapshot_table()
             self.dbm.save()
         else:
             dialog = ErrorDialog(self.view)
             dialog.exec_()
     else:
         return
 def generate_final(self):
     errors = False
     for _ in range(self._task.expressions_count):
         ex = self.generate_example()
         if not ex:
             errors = True
             Log.log('d', 'Cannot generate Example')
             Log.log('d', ex)
             continue
         self._task.add_item(ex)
     if errors:
         Log.log('er', "Table is incomplete")
示例#15
0
 def test_get_snapshot(self):
     ret = self.hm.get_snapshot('test1')
     if not(ret == ('+,-', 17, 3, 10, 49)):
         Log.log('er', f'Not equal {ret}')
     task = TaskModel.from_sqlite_format(ret)
     Log.log('d', task)
示例#16
0
 def delete_snapshot(self, name):
     Log.log('i', f'delete_snapshot(name): {name}')
     self.cursor.execute(
         f"DELETE from history where snapshot_name = '{name}'")
     self.conn.commit()
示例#17
0
 def add_snapshot_entry(self, name):
     Log.log('i', 'Param name: ', name)
     snapshot_item = QTableWidgetItem(name)
     self.table.setRowCount(self.table.rowCount() + 1)
     row = self.table.rowCount() - 1
     self.table.setItem(row, 0, snapshot_item)
示例#18
0
 def close(self):
     hp = HistoryProvider()
     Log.log('d', hp.get_snapshot_names())
     self.conn.close()
示例#19
0
文件: main.py 项目: MlsDmitry/ly_math
 def quit(self):
     Log.log('d', 'quit')
     self.controller.dbm.save()
     self.controller.dbm.close()
示例#20
0
 def update_snapshot_table(self):
     Log.log('i', 'Snapshots: ', self.history_provider.get_snapshot_names())
     self.view.clear_snapshot_table()
     for name in self.history_provider.get_snapshot_names():
         self.view.add_snapshot_entry(name)
示例#21
0
 def test_TaskModel(self):
     Log.log('d', self.task._field)
示例#22
0
 def test_path(self):
     Log.log('d', "Documents path: ", documents_path())
     self.dbm.save()
示例#23
0
 def test_output(self, task):
     eo = ExportManager(task)
     eo.save('test1.beta', True)
     eo.save('test1_with_answers.beta', False)
     Log.log('d', 'saved')
示例#24
0
def documents_path():
    home = os.path.expanduser("~")
    documents_path = os.path.join(home, 'Documents')
    Log.log('d', 'doc path: ', documents_path)
    return documents_path