Exemplo n.º 1
0
def updating_function():
    properties = PropertyManager()
    database = DatabaseManager()
    opc = OPCManager(properties.get_property('opc_name'))
    email_manager = EmailManager(properties.get_property('email'),
                                 properties.get_property('password'),
                                 properties.get_property('server'))
    flowmeters = database.get_all_flowmeters()
    for flowmeter in flowmeters:
        flowmeter = email_manager.update_flowmeter(flowmeter)
        opc.update_flowmeter_in_opc(flowmeter)
        database.update_flowmeter(flowmeter)
        sleep(float(properties.get_property('interval')))
Exemplo n.º 2
0
async def db_manager():
    db_conn_url = DatabaseURL(settings.DATABASE_CONNECTION_URL + '_test')
    database_manager = DatabaseManager(db_conn_url, force_rollback=True)
    _url = str(db_conn_url).split('/')
    _url_str = DatabaseURL('/'.join(_url[:-1] + ['template1']))

    try:
        conn = await asyncpg.connect(str(db_conn_url))
        print('DB exists')
    except asyncpg.InvalidCatalogNameError:
        print('DB doesn\'t exist. Creating new one.')
        # db_conn_url.components.path = 'template1'
        conn = await asyncpg.connect(str(_url_str))
        await conn.execute(F'create database {db_conn_url.database} '
                           F'owner "{db_conn_url.username}"')

    with patch.object(
            settings,
            'DATABASE_CONNECTION_URL',
            str(db_conn_url),
    ):
        alembicArgs = [
            '--raiseerr',
            '-c',
            'alembic.ini',
            'upgrade',
            'head',
        ]
        loop = asyncio.get_running_loop()
        await loop.run_in_executor(
            executor, lambda: alembic.config.main(argv=alembicArgs))
    await database_manager.connect()
    yield database_manager

    await database_manager.disconnect()
    await conn.close()
    conn = await asyncpg.connect(str(_url_str))
    if not os.environ.get('KEEP_TEST_DB'):
        try:
            await conn.execute(F'drop database {db_conn_url.database}')
            print('DB deleted')
        except asyncpg.exceptions.ObjectInUseError:
            print('DB likely opened in your IDE. Delete manually')
    await conn.close()
Exemplo n.º 3
0
def user_info():
    with DatabaseManager() as db:
        users = user.get_users(db.conn)

    return jsonify(users)
Exemplo n.º 4
0
def delete_table_data():
    with DatabaseManager() as db:
        book.delete_sample_data(db.conn)

    return jsonify({'status': 'success'})
Exemplo n.º 5
0
def create_sample_data():
    with DatabaseManager() as db:
        book.insert_sample_data(db.conn)

    return jsonify({'status': 'success'})
Exemplo n.º 6
0
def fetch_books_tree():
    with DatabaseManager() as db:
        books_tree = tree.read(db.conn)

    return jsonify(books_tree)
Exemplo n.º 7
0
 def __init__(self) -> None:
     super().__init__()
     self.__another_window_flag = False
     self.__database = DatabaseManager()
Exemplo n.º 8
0
class Ui_MainWindow(object):

    def __init__(self) -> None:
        super().__init__()
        self.__another_window_flag = False
        self.__database = DatabaseManager()

    def setupUi(self, MainWindow):
        MainWindow.setObjectName("MainWindow")
        icon = QtGui.QIcon()
        icon.addPixmap(QtGui.QPixmap("view\\ico\\Klukeart-Cubes-Box-21-Water-Diamond.ico"), QtGui.QIcon.Normal,
                       QtGui.QIcon.Off)
        MainWindow.setWindowIcon(icon)
        MainWindow.setToolButtonStyle(QtCore.Qt.ToolButtonIconOnly)
        MainWindow.setFixedSize(QtCore.QSize(1500, 550))
        self.centralwidget = QtWidgets.QWidget(MainWindow)
        self.centralwidget.setObjectName("centralwidget")
        self.groupBox = QtWidgets.QGroupBox(self.centralwidget)
        self.groupBox.setGeometry(QtCore.QRect(20, 10, 1461, 491))
        self.groupBox.setObjectName("groupBox")
        self.tableWidget = QtWidgets.QTableWidget(self.groupBox)
        self.tableWidget.setGeometry(QtCore.QRect(5, 21, 1451, 461))
        self.tableWidget.setMinimumSize(QtCore.QSize(1451, 461))
        self.tableWidget.setMaximumSize(QtCore.QSize(1451, 461))
        self.tableWidget.setObjectName("tableWidget")
        self.tableWidget.setColumnCount(13)
        self.tableWidget.setRowCount(0)
        item = QtWidgets.QTableWidgetItem()
        self.tableWidget.setHorizontalHeaderItem(0, item)
        item = QtWidgets.QTableWidgetItem()
        self.tableWidget.setHorizontalHeaderItem(1, item)
        item = QtWidgets.QTableWidgetItem()
        self.tableWidget.setHorizontalHeaderItem(2, item)
        item = QtWidgets.QTableWidgetItem()
        self.tableWidget.setHorizontalHeaderItem(3, item)
        item = QtWidgets.QTableWidgetItem()
        self.tableWidget.setHorizontalHeaderItem(4, item)
        item = QtWidgets.QTableWidgetItem()
        self.tableWidget.setHorizontalHeaderItem(5, item)
        item = QtWidgets.QTableWidgetItem()
        self.tableWidget.setHorizontalHeaderItem(6, item)
        item = QtWidgets.QTableWidgetItem()
        self.tableWidget.setHorizontalHeaderItem(7, item)
        item = QtWidgets.QTableWidgetItem()
        self.tableWidget.setHorizontalHeaderItem(8, item)
        item = QtWidgets.QTableWidgetItem()
        self.tableWidget.setHorizontalHeaderItem(9, item)
        item = QtWidgets.QTableWidgetItem()
        self.tableWidget.setHorizontalHeaderItem(10, item)
        item = QtWidgets.QTableWidgetItem()
        self.tableWidget.setHorizontalHeaderItem(11, item)
        item = QtWidgets.QTableWidgetItem()
        self.tableWidget.setHorizontalHeaderItem(12, item)
        MainWindow.setCentralWidget(self.centralwidget)
        self.menubar = QtWidgets.QMenuBar(MainWindow)
        self.menubar.setGeometry(QtCore.QRect(0, 0, 1512, 26))
        self.menubar.setObjectName("menubar")
        self.menu = QtWidgets.QMenu(self.menubar)
        self.menu.setObjectName("menu")
        self.menu_2 = QtWidgets.QMenu(self.menu)
        self.menu_2.setObjectName("menu_2")
        self.menu_3 = QtWidgets.QMenu(self.menu)
        self.menu_3.setObjectName("menu_3")
        MainWindow.setMenuBar(self.menubar)
        self.statusbar = QtWidgets.QStatusBar(MainWindow)
        self.statusbar.setObjectName("statusbar")
        MainWindow.setStatusBar(self.statusbar)
        self.properties_connection = QtWidgets.QAction(MainWindow)
        self.properties_connection.setObjectName("properties_connection")
        self.properties_connection.triggered.connect(self.__connection_dialog)
        self.properties_program = QtWidgets.QAction(MainWindow)
        self.properties_program.setObjectName("properties_program")
        self.properties_program.triggered.connect(self.__properties_dialog)
        self.properties_router = QtWidgets.QAction(MainWindow)
        self.properties_router.setObjectName("properties_program")
        self.properties_router.triggered.connect(self.__router_dialog)
        self.add_flow = QtWidgets.QAction(MainWindow)
        self.add_flow.setObjectName("add_flow")
        self.remove_flow = QtWidgets.QAction(MainWindow)
        self.add_flow.triggered.connect(self.__add_flowmeter)
        self.remove_flow.setObjectName("remove_flow")
        self.update_flow = QtWidgets.QAction(MainWindow)
        self.update_flow.setObjectName("update_flow")
        self.menu_2.addAction(self.properties_connection)
        self.menu_2.addAction(self.properties_program)
        self.menu_2.addAction(self.properties_router)
        self.menu_3.addAction(self.add_flow)
        self.menu_3.addAction(self.remove_flow)
        self.menu_3.addAction(self.update_flow)
        self.menu.addAction(self.menu_2.menuAction())
        self.menu.addAction(self.menu_3.menuAction())
        self.menubar.addAction(self.menu.menuAction())

        self.retranslateUi(MainWindow)
        QtCore.QMetaObject.connectSlotsByName(MainWindow)

    def retranslateUi(self, MainWindow):
        _translate = QtCore.QCoreApplication.translate
        MainWindow.setWindowTitle(_translate("MainWindow", "Менеджер Данных Mag 8000"))
        self.groupBox.setTitle(_translate("MainWindow", "База Расходомеров"))
        item = self.tableWidget.horizontalHeaderItem(0)
        item.setText(_translate("MainWindow", "ID"))
        item = self.tableWidget.horizontalHeaderItem(1)
        item.setText(_translate("MainWindow", "Имя"))
        item = self.tableWidget.horizontalHeaderItem(2)
        item.setText(_translate("MainWindow", "Почта"))
        item = self.tableWidget.horizontalHeaderItem(3)
        item.setText(_translate("MainWindow", "Телефон"))
        item = self.tableWidget.horizontalHeaderItem(4)
        item.setText(_translate("MainWindow", "Текущий расход"))
        item = self.tableWidget.horizontalHeaderItem(5)
        item.setText(_translate("MainWindow", "Ед."))
        item = self.tableWidget.horizontalHeaderItem(6)
        item.setText(_translate("MainWindow", "Накопленый 1"))
        item = self.tableWidget.horizontalHeaderItem(7)
        item.setText(_translate("MainWindow", "Накопленый 2"))
        item = self.tableWidget.horizontalHeaderItem(8)
        item.setText(_translate("MainWindow", "Накопленый 3"))
        item = self.tableWidget.horizontalHeaderItem(9)
        item.setText(_translate("MainWindow", "Ед."))
        item = self.tableWidget.horizontalHeaderItem(10)
        item.setText(_translate("MainWindow", "Заряд Батареи"))
        item = self.tableWidget.horizontalHeaderItem(11)
        item.setText(_translate("MainWindow", "Обновление"))
        item = self.tableWidget.horizontalHeaderItem(12)
        item.setText(_translate("MainWindow", "Ошибки"))
        self.menu.setTitle(_translate("MainWindow", "Файл"))
        self.menu_2.setTitle(_translate("MainWindow", "Настройки"))
        self.menu_3.setTitle(_translate("MainWindow", "Расходомер"))
        self.properties_connection.setText(_translate("MainWindow", "Почта"))
        self.properties_program.setText(_translate("MainWindow", "Программа"))
        self.properties_router.setText(_translate("MainWindow", "Роутер"))
        self.add_flow.setText(_translate("MainWindow", "Добавить"))
        self.remove_flow.setText(_translate("MainWindow", "Убрать"))
        self.update_flow.setText(_translate("MainWindow", "Изменить"))
        self.__infill_table()

    def __infill_table(self):
        row = 0
        self.tableWidget.setRowCount(row)
        for flowmeter in self.__database.get_all_flowmeters():
            self.tableWidget.insertRow(row)
            self.tableWidget.setItem(row, 0, QTableWidgetItem(str(flowmeter.unique_id)))
            self.tableWidget.setItem(row, 1, QTableWidgetItem(flowmeter.name))
            self.tableWidget.setItem(row, 2, QTableWidgetItem(flowmeter.email))
            self.tableWidget.setItem(row, 3, QTableWidgetItem(flowmeter.phone_number))
            self.tableWidget.setItem(row, 4, QTableWidgetItem(str(flowmeter.current_flow)))
            self.tableWidget.setItem(row, 5, QTableWidgetItem(flowmeter.current_flow_units))
            self.tableWidget.setItem(row, 6, QTableWidgetItem(str(flowmeter.totalizer1)))
            self.tableWidget.setItem(row, 7, QTableWidgetItem(str(flowmeter.totalizer2)))
            self.tableWidget.setItem(row, 8, QTableWidgetItem(str(flowmeter.totalizer3)))
            self.tableWidget.setItem(row, 9, QTableWidgetItem(flowmeter.totalizer_units))
            self.tableWidget.setItem(row, 10, QTableWidgetItem(str(flowmeter.battery_capacity)))
            self.tableWidget.setItem(row, 11, QTableWidgetItem(flowmeter.last_update.strftime('%Y-%m-%d %H:%M:%S')))
            self.tableWidget.setItem(row, 12, QTableWidgetItem(flowmeter.alarms))
            row += 1



    @another_window
    def __connection_dialog(self):
        dialog = QtWidgets.QDialog()
        ui = DialogConnection()
        ui.setupUi(dialog)
        dialog.show()
        dialog.exec_()

    @another_window
    def __properties_dialog(self):
        dialog = QtWidgets.QDialog()
        ui = DialogProgramSettings()
        ui.setupUi(dialog)
        dialog.show()
        dialog.exec_()

    @another_window
    def __router_dialog(self):
        dialog = QtWidgets.QDialog()
        ui = DialogRouter()
        ui.setupUi(dialog)
        dialog.show()
        dialog.exec_()

    @another_window
    def __add_flowmeter(self):
        dialog = QtWidgets.QDialog()
        ui = DialogAddFlowmeter()
        ui.setupUi(dialog)
        dialog.show()
        dialog.exec_()
Exemplo n.º 9
0
 def __generate_properties(self):
     database = DatabaseManager()
     create_matrikon_opc_config(database.get_all_flowmeters())