Skip to content

Commit

Permalink
added plots and currency info
Browse files Browse the repository at this point in the history
  • Loading branch information
MakzaR committed Jun 20, 2020
1 parent 93a826c commit 1f3ee94
Show file tree
Hide file tree
Showing 5 changed files with 130 additions and 4 deletions.
48 changes: 47 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
75 changes: 75 additions & 0 deletions src/view/currency_window.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,97 @@
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)

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

def sell(self):
pass

def init(self):
self.draw_graphs()
self.show()
7 changes: 5 additions & 2 deletions src/view/main_window.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

from PyQt5 import QtWidgets
from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import QMainWindow, QPushButton, QTableWidgetItem
Expand Down Expand Up @@ -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))))
Expand Down
3 changes: 2 additions & 1 deletion ui/currency.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@


from PyQt5 import QtCore, QtGui, QtWidgets
from pyqtgraph import PlotWidget


class Ui_CurrencyWindow(object):
Expand All @@ -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)
Expand Down

0 comments on commit 1f3ee94

Please sign in to comment.