Giter VIP home page Giter VIP logo

mariya's People

Contributors

delagreen avatar

Watchers

 avatar

mariya's Issues

Async (Теоретически)

Итак...до меня вроде как наконец-то дошло как писать асинхронно, по крайней мере с использованием библиотеки AsyncIO.
UI интерфейс будет основной таской, от запуска до её завершения. В tuple в которой лежит таска на запуск UI-ки, будем append-ить таски на другие процессы.

report_module

'''
Пример реализации на PANDAS
'''
def creating_a_pd_template():
row_in_dataframe = 0
col = ['ИНН', 'Индекс формы', 'Наименование формы', 'Периодичность формы', 'Срок сдачи формы',
'Отчетный период','Комментарий', 'ОКУД', 'Дата актуализации перечня форм']
new_data = pd.DataFrame(columns = col)

def write_in_pd_data(row_in_dataframe, data):
col = ['ИНН', 'Индекс формы', 'Наименование формы', 'Периодичность формы', 'Срок сдачи формы',
'Отчетный период','Комментарий', 'ОКУД', 'Дата актуализации перечня форм']
new_data = pd.DataFrame(columns = col)
new_data.at[row_in_dataframe, 'ИНН'] = data['inn']
new_data.at[row_in_dataframe, 'Индекс формы'] = data['index']
new_data.at[row_in_dataframe, 'Наименование формы'] = data['name']
new_data.at[row_in_dataframe, 'Периодичность формы'] = data['form_period']
new_data.at[row_in_dataframe, 'Срок сдачи формы'] = data['end_time']
new_data.at[row_in_dataframe, 'Отчетный период'] = data['reported_period']
new_data.at[row_in_dataframe, 'Комментарий'] = data['comment']
new_data.at[row_in_dataframe, 'ОКУД'] = data['okud']
row_in_dataframe +=1
return new_data

dictr= {'inn': 'inn',
'index': 'index',
'name': 'name',
'form_period':'form_period',
'end_time': 'end_time',
'reported_period': 'reported_period',
'comment':'comment',
'okud': 'okud'}

creating_a_pd_template()
print(write_in_pd_data(2, dictr))

Classes

Итак, надо наконец добить классы, переписать всё то что можно переписать =_=
Рефакторинг...... Рефакторинг...... рефакт.....

UI interphase for example

from PySide6.QtWidgets import (QApplication, QMainWindow, QPushButton, QPlainTextEdit,
QVBoxLayout, QWidget, QProgressBar)
from PySide6.QtCore import QProcess
import sys
import re

A regular expression, to extract the % complete.

progress_re = re.compile("Total complete: (\d+)%")

def simple_percent_parser(output):
"""
Matches lines using the progress_re regex,
returning a single integer for the % progress.
"""
m = progress_re.search(output)
if m:
pc_complete = m.group(1)
return int(pc_complete)

class MainWindow(QMainWindow):

def __init__(self):
    super().__init__()

    self.p = None

    self.btn = QPushButton("Execute")
    self.btn.pressed.connect(self.start_process)
    self.text = QPlainTextEdit()
    self.text.setReadOnly(True)

    self.progress = QProgressBar()
    self.progress.setRange(0, 100)

    l = QVBoxLayout()
    l.addWidget(self.btn)
    l.addWidget(self.progress)
    l.addWidget(self.text)

    w = QWidget()
    w.setLayout(l)

    self.setCentralWidget(w)

def message(self, s):
    self.text.appendPlainText(s)

def start_process(self):
    if self.p is None:  # No process running.
        self.message("Executing process")
        self.p = QProcess()  # Keep a reference to the QProcess (e.g. on self) while it's running.
        self.p.readyReadStandardOutput.connect(self.handle_stdout)
        self.p.readyReadStandardError.connect(self.handle_stderr)
        self.p.stateChanged.connect(self.handle_state)
        self.p.finished.connect(self.process_finished)  # Clean up once complete.
        self.p.start("python3", ['dummy_script.py'])

def handle_stderr(self):
    data = self.p.readAllStandardError()
    stderr = bytes(data).decode("utf8")
    # Extract progress if it is in the data.
    progress = simple_percent_parser(stderr)
    if progress:
        self.progress.setValue(progress)
    self.message(stderr)

def handle_stdout(self):
    data = self.p.readAllStandardOutput()
    stdout = bytes(data).decode("utf8")
    self.message(stdout)

def handle_state(self, state):
    states = {
        QProcess.NotRunning: 'Not running',
        QProcess.Starting: 'Starting',
        QProcess.Running: 'Running',
    }
    state_name = states[state]
    self.message(f"State changed: {state_name}")

def process_finished(self):
    self.message("Process finished.")
    self.p = None

app = QApplication(sys.argv)

w = MainWindow()
w.show()

app.exec_()

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.