From 1f3ee947e0e181086fd9a2f4ff94fbb7001b7725 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B0=D0=BA=D0=B0=D1=80=20=D0=97=D0=B0=D1=80=D1=87?= =?UTF-8?q?=D1=83=D0=BA=D0=BE=D0=B2?= Date: Sun, 21 Jun 2020 00:56:13 +0500 Subject: [PATCH] added plots and currency info --- poetry.lock | 48 +++++++++++++++++++++++- pyproject.toml | 1 + src/view/currency_window.py | 75 +++++++++++++++++++++++++++++++++++++ src/view/main_window.py | 7 +++- ui/currency.py | 3 +- 5 files changed, 130 insertions(+), 4 deletions(-) diff --git a/poetry.lock b/poetry.lock index bbb3b33..b6d0098 100644 --- a/poetry.lock +++ b/poetry.lock @@ -172,6 +172,14 @@ optional = false python-versions = "*" version = "0.4.3" +[[package]] +category = "main" +description = "NumPy is the fundamental package for array computing with Python." +name = "numpy" +optional = false +python-versions = ">=3.5" +version = "1.18.5" + [[package]] category = "dev" description = "Utility library for gitignore style pattern matching of file paths." @@ -243,6 +251,17 @@ optional = false python-versions = ">=3.5" version = "12.8.0" +[[package]] +category = "main" +description = "Scientific Graphics and GUI Library for Python" +name = "pyqtgraph" +optional = false +python-versions = "*" +version = "0.11.0" + +[package.dependencies] +numpy = ">=1.8.0" + [[package]] category = "dev" description = "Alternative regular expression module, to replace re." @@ -342,7 +361,7 @@ python-versions = "*" version = "1.12.1" [metadata] -content-hash = "b391c3c1821ad3ba68bff85ce27c4e643982ceb74b3d0f317e23728cd7c3b539" +content-hash = "893eb159a82896e5e6cbc4b012568db3e71ce5057eaf202e50c9396d27812740" python-versions = "^3.8" [metadata.files] @@ -440,6 +459,29 @@ mypy-extensions = [ {file = "mypy_extensions-0.4.3-py2.py3-none-any.whl", hash = "sha256:090fedd75945a69ae91ce1303b5824f428daf5a028d2f6ab8a299250a846f15d"}, {file = "mypy_extensions-0.4.3.tar.gz", hash = "sha256:2d82818f5bb3e369420cb3c4060a7970edba416647068eb4c5343488a6c604a8"}, ] +numpy = [ + {file = "numpy-1.18.5-cp35-cp35m-macosx_10_9_intel.whl", hash = "sha256:e91d31b34fc7c2c8f756b4e902f901f856ae53a93399368d9a0dc7be17ed2ca0"}, + {file = "numpy-1.18.5-cp35-cp35m-manylinux1_i686.whl", hash = "sha256:7d42ab8cedd175b5ebcb39b5208b25ba104842489ed59fbb29356f671ac93583"}, + {file = "numpy-1.18.5-cp35-cp35m-manylinux1_x86_64.whl", hash = "sha256:a78e438db8ec26d5d9d0e584b27ef25c7afa5a182d1bf4d05e313d2d6d515271"}, + {file = "numpy-1.18.5-cp35-cp35m-win32.whl", hash = "sha256:a87f59508c2b7ceb8631c20630118cc546f1f815e034193dc72390db038a5cb3"}, + {file = "numpy-1.18.5-cp35-cp35m-win_amd64.whl", hash = "sha256:965df25449305092b23d5145b9bdaeb0149b6e41a77a7d728b1644b3c99277c1"}, + {file = "numpy-1.18.5-cp36-cp36m-macosx_10_9_x86_64.whl", hash = "sha256:ac792b385d81151bae2a5a8adb2b88261ceb4976dbfaaad9ce3a200e036753dc"}, + {file = "numpy-1.18.5-cp36-cp36m-manylinux1_i686.whl", hash = "sha256:ef627986941b5edd1ed74ba89ca43196ed197f1a206a3f18cc9faf2fb84fd675"}, + {file = "numpy-1.18.5-cp36-cp36m-manylinux1_x86_64.whl", hash = "sha256:f718a7949d1c4f622ff548c572e0c03440b49b9531ff00e4ed5738b459f011e8"}, + {file = "numpy-1.18.5-cp36-cp36m-win32.whl", hash = "sha256:4064f53d4cce69e9ac613256dc2162e56f20a4e2d2086b1956dd2fcf77b7fac5"}, + {file = "numpy-1.18.5-cp36-cp36m-win_amd64.whl", hash = "sha256:b03b2c0badeb606d1232e5f78852c102c0a7989d3a534b3129e7856a52f3d161"}, + {file = "numpy-1.18.5-cp37-cp37m-macosx_10_9_x86_64.whl", hash = "sha256:a7acefddf994af1aeba05bbbafe4ba983a187079f125146dc5859e6d817df824"}, + {file = "numpy-1.18.5-cp37-cp37m-manylinux1_i686.whl", hash = "sha256:cd49930af1d1e49a812d987c2620ee63965b619257bd76eaaa95870ca08837cf"}, + {file = "numpy-1.18.5-cp37-cp37m-manylinux1_x86_64.whl", hash = "sha256:b39321f1a74d1f9183bf1638a745b4fd6fe80efbb1f6b32b932a588b4bc7695f"}, + {file = "numpy-1.18.5-cp37-cp37m-win32.whl", hash = "sha256:cae14a01a159b1ed91a324722d746523ec757357260c6804d11d6147a9e53e3f"}, + {file = "numpy-1.18.5-cp37-cp37m-win_amd64.whl", hash = "sha256:0172304e7d8d40e9e49553901903dc5f5a49a703363ed756796f5808a06fc233"}, + {file = "numpy-1.18.5-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:e15b382603c58f24265c9c931c9a45eebf44fe2e6b4eaedbb0d025ab3255228b"}, + {file = "numpy-1.18.5-cp38-cp38-manylinux1_i686.whl", hash = "sha256:3676abe3d621fc467c4c1469ee11e395c82b2d6b5463a9454e37fe9da07cd0d7"}, + {file = "numpy-1.18.5-cp38-cp38-manylinux1_x86_64.whl", hash = "sha256:4674f7d27a6c1c52a4d1aa5f0881f1eff840d2206989bae6acb1c7668c02ebfb"}, + {file = "numpy-1.18.5-cp38-cp38-win32.whl", hash = "sha256:9c9d6531bc1886454f44aa8f809268bc481295cf9740827254f53c30104f074a"}, + {file = "numpy-1.18.5-cp38-cp38-win_amd64.whl", hash = "sha256:3dd6823d3e04b5f223e3e265b4a1eae15f104f4366edd409e5a5e413a98f911f"}, + {file = "numpy-1.18.5.zip", hash = "sha256:34e96e9dae65c4839bd80012023aadd6ee2ccb73ce7fdf3074c62f301e63120b"}, +] pathspec = [ {file = "pathspec-0.8.0-py2.py3-none-any.whl", hash = "sha256:7d91249d21749788d07a2d0f94147accd8f845507400749ea19c1ec9054a12b0"}, {file = "pathspec-0.8.0.tar.gz", hash = "sha256:da45173eb3a6f2a5a487efba21f050af2b41948be6ab52b6a1e3ff22bb8b7061"}, @@ -501,6 +543,10 @@ pyqt5-sip = [ {file = "PyQt5_sip-12.8.0-cp38-cp38-win_amd64.whl", hash = "sha256:1d65ce08a56282fb0273dd06585b8927b88d4fba71c01a54f8e2ac87ac1ed387"}, {file = "PyQt5_sip-12.8.0.tar.gz", hash = "sha256:0a34b6596bdd28d52da3a51fa8d9bb0b287bcb605c2512aa3251b9028cc71f4d"}, ] +pyqtgraph = [ + {file = "pyqtgraph-0.11.0-py3-none-any.whl", hash = "sha256:234d78f266d7c44d80e3bb735043e102d446842ef12e60f62f157f1fa5146411"}, + {file = "pyqtgraph-0.11.0.tar.gz", hash = "sha256:ca0a6715882579c46c80df18d9b260a09fce0e086521bfb6fc1f4027f938b35c"}, +] regex = [ {file = "regex-2020.6.8-cp27-cp27m-win32.whl", hash = "sha256:fbff901c54c22425a5b809b914a3bfaf4b9570eee0e5ce8186ac71eb2025191c"}, {file = "regex-2020.6.8-cp27-cp27m-win_amd64.whl", hash = "sha256:112e34adf95e45158c597feea65d06a8124898bdeac975c9087fe71b572bd938"}, diff --git a/pyproject.toml b/pyproject.toml index dfffcf0..8d83f20 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -10,6 +10,7 @@ pydantic = "^1.4" pyqt5 = "^5.15.0" unify = "^0.5" requests = "^2.24.0" +pyqtgraph = "^0.11.0" [tool.poetry.scripts] start_gui = "src.view.main:main" diff --git a/src/view/currency_window.py b/src/view/currency_window.py index 7a35c15..d21e637 100644 --- a/src/view/currency_window.py +++ b/src/view/currency_window.py @@ -1,10 +1,29 @@ +from datetime import date +from decimal import Decimal + +import pyqtgraph as pg from PyQt5.QtCore import Qt from PyQt5.QtWidgets import QMainWindow from ui.currency import Ui_CurrencyWindow +selling_prices = [1.337, 1.488, 1.556, 1.246, 1.889] +buying_prices = [2.534, 2.679, 2.365, 2.456, 2.345] +time = [ + date(2020, 5, 1), + date(2020, 5, 2), + date(2020, 5, 3), + date(2020, 5, 4), + date(2020, 5, 5), +] + +time_dict = dict(enumerate(time)) + class CurrencyWindow(Ui_CurrencyWindow, QMainWindow): + + '''Вернуть parent''' + def __init__(self, parent): super().__init__(parent, Qt.WindowCloseButtonHint | Qt.WindowMinimizeButtonHint) self.setupUi(self) @@ -12,6 +31,61 @@ def __init__(self, parent): self.buyButton.clicked.connect(self.buy) self.sellButton.clicked.connect(self.sell) + self.set_text_info(selling_prices[-1], buying_prices[-1], Decimal('3.0012')) + + def set_text_info(self, selling_price, buying_price, account): + self.buyingPrice.setText('Cтоимость покупки: ' + str(selling_price) + ' у.е.') + self.sellingPrice.setText('Стоимость продажи: ' + str(buying_price) + ' у.е.') + self.account.setText('На счёте: ' + str(account) + ' у.е.') + + def draw_graphs(self): + pg.setConfigOptions(antialias=True) + + self.graphicsView.setBackground('w') + + self.graphicsView.addLegend() + + time_axis = pg.AxisItem(orientation='bottom') + time_axis.setTicks([time_dict.items()]) + self.graphicsView.setAxisItems(axisItems={'bottom': time_axis}) + + self.graphicsView.setLabel('left', 'Цена') + self.graphicsView.setLabel('bottom', 'Время') + + self.graphicsView.showGrid(x=True, y=True) + + self.plot( + list(time_dict.keys()), + buying_prices, + 'Цена покупки', + (0, 220, 0), + 1.5, + 'o', + 5, + ) + + self.plot( + list(time_dict.keys()), + selling_prices, + 'Цена продажи', + (255, 0, 0), + 1.5, + 'o', + 5, + ) + + def plot(self, x, y, plot_name, color, width, symbol, symbol_size): + pen = pg.mkPen(color=color, width=width) + self.graphicsView.plot( + x, + y, + name=plot_name, + pen=pen, + symbol=symbol, + symbolSize=symbol_size, + symbolBrush=color, + ) + def buy(self): pass @@ -19,4 +93,5 @@ def sell(self): pass def init(self): + self.draw_graphs() self.show() diff --git a/src/view/main_window.py b/src/view/main_window.py index 86e7476..d5a77b0 100644 --- a/src/view/main_window.py +++ b/src/view/main_window.py @@ -1,4 +1,3 @@ - from PyQt5 import QtWidgets from PyQt5.QtCore import Qt from PyQt5.QtWidgets import QMainWindow, QPushButton, QTableWidgetItem @@ -94,7 +93,11 @@ def fill_operations(self): self.operationsTable.setRowCount(row + 1) self.operationsTable.setItem( - row, 0, QTableWidgetItem('Покупка' if i.operation_type == OperationType.BUY else 'Продажа') + row, + 0, + QTableWidgetItem( + 'Покупка' if i.operation_type == OperationType.BUY else 'Продажа' + ), ) self.operationsTable.setItem(row, 1, QTableWidgetItem(i.currency_name)) self.operationsTable.setItem(row, 2, QTableWidgetItem((str(i.amount)))) diff --git a/ui/currency.py b/ui/currency.py index 16d14bd..ee626f1 100644 --- a/ui/currency.py +++ b/ui/currency.py @@ -9,6 +9,7 @@ from PyQt5 import QtCore, QtGui, QtWidgets +from pyqtgraph import PlotWidget class Ui_CurrencyWindow(object): @@ -19,7 +20,7 @@ def setupUi(self, MainWindow): self.centralwidget.setObjectName("centralwidget") self.gridLayout = QtWidgets.QGridLayout(self.centralwidget) self.gridLayout.setObjectName("gridLayout") - self.graphicsView = QtWidgets.QGraphicsView(self.centralwidget) + self.graphicsView = PlotWidget(self.centralwidget) self.graphicsView.setObjectName("graphicsView") self.gridLayout.addWidget(self.graphicsView, 3, 2, 1, 1) self.buyAndSell = QtWidgets.QWidget(self.centralwidget)