Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set the correct range for Y-axis of the token balance graph #6668

Merged
merged 2 commits into from
Dec 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file.
104 changes: 104 additions & 0 deletions src/tribler-gui/tribler_gui/tests/gui_test_data.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
# Test data for token balance history

negative_token_balance_history = [
{'timestamp': 1639989682705, 'balance': -4242445126},
{'timestamp': 1639989682715, 'balance': -4242942932},
{'timestamp': 1639989682725, 'balance': -4243010528},
{'timestamp': 1639989836725, 'balance': -4243010528},
{'timestamp': 1639989836756, 'balance': -4243010528},
{'timestamp': 1639989837713, 'balance': -4242920753},
{'timestamp': 1639989838040, 'balance': -4242920753},
{'timestamp': 1639989838050, 'balance': -4242920753},
{'timestamp': 1639989865600, 'balance': -4243183609},
{'timestamp': 1639989865600, 'balance': -4243364423},
{'timestamp': 1639989865615, 'balance': -4243542847},
{'timestamp': 1639989865615, 'balance': -4243706616},
{'timestamp': 1639989865631, 'balance': -4243826841},
{'timestamp': 1639989865647, 'balance': -4243891015},
{'timestamp': 1639989904528, 'balance': -4243891015},
{'timestamp': 1639989921434, 'balance': -4243891015},
{'timestamp': 1639989921450, 'balance': -4243891015},
{'timestamp': 1639989921997, 'balance': -4243891015},
{'timestamp': 1639989921997, 'balance': -4243891015},
{'timestamp': 1639989931318, 'balance': -4244475952},
{'timestamp': 1639989931334, 'balance': -4244704214},
{'timestamp': 1639989931334, 'balance': -4244732128},
{'timestamp': 1639989931350, 'balance': -4244758963},
{'timestamp': 1639989931365, 'balance': -4244781725},
{'timestamp': 1639989931365, 'balance': -4244806208},
{'timestamp': 1639990014979, 'balance': -4245061842},
{'timestamp': 1639990014995, 'balance': -4245120697},
{'timestamp': 1639990014995, 'balance': -4245168539},
{'timestamp': 1639990015010, 'balance': -4245216358},
{'timestamp': 1639990015010, 'balance': -4245221001},
{'timestamp': 1639990015026, 'balance': -4245225659},
{'timestamp': 1639990193728, 'balance': -4245241816},
{'timestamp': 1639990250821, 'balance': -4245243295},
{'timestamp': 1639990448300, 'balance': -4245243295},
{'timestamp': 1639990454609, 'balance': -4245243295},
{'timestamp': 1639991174571, 'balance': -4245852308},
{'timestamp': 1639991174587, 'balance': -4245986649},
{'timestamp': 1639991174587, 'balance': -4246441060},
{'timestamp': 1639991174602, 'balance': -4248106527},
{'timestamp': 1639991174602, 'balance': -4249141793},
{'timestamp': 1639991174618, 'balance': -4249402255},
{'timestamp': 1639991279504, 'balance': -4249454759},
{'timestamp': 1639991279519, 'balance': -4249569078},
{'timestamp': 1639991279519, 'balance': -4249804508},
{'timestamp': 1639991279535, 'balance': -4249919744},
{'timestamp': 1639991279582, 'balance': -4249927169},
{'timestamp': 1639991279598, 'balance': -4249939590},
{'timestamp': 1639991355956, 'balance': -4250162322},
{'timestamp': 1639991355971, 'balance': -4250284312},
{'timestamp': 1639991355971, 'balance': -4250512181},
{'timestamp': 1639991355987, 'balance': -4250567205},
{'timestamp': 1639991355987, 'balance': -4250726076},
{'timestamp': 1639991356003, 'balance': -4251008765},
{'timestamp': 1639991356003, 'balance': -4251491838},
{'timestamp': 1639991484789, 'balance': -4251490530},
{'timestamp': 1639991484789, 'balance': -4251491838},
{'timestamp': 1639991491322, 'balance': -4251493162},
{'timestamp': 1639991491338, 'balance': -4251497771},
{'timestamp': 1639991491338, 'balance': -4251498931},
{'timestamp': 1639991491353, 'balance': -4251501656},
{'timestamp': 1639991491369, 'balance': -4251502083},
{'timestamp': 1639991491385, 'balance': -4251502510},
{'timestamp': 1639991901542, 'balance': -4251500986},
{'timestamp': 1639991948147, 'balance': -4253313336},
{'timestamp': 1639991948162, 'balance': -4253442797},
{'timestamp': 1639991948162, 'balance': -4253643279},
{'timestamp': 1639991948162, 'balance': -4257892944},
{'timestamp': 1639991948178, 'balance': -4260661821},
{'timestamp': 1639991948188, 'balance': -4261099251},
{'timestamp': 1639992013196, 'balance': -4261261311},
{'timestamp': 1639992013206, 'balance': -4261438136},
{'timestamp': 1639992013216, 'balance': -4261805891},
{'timestamp': 1639992013216, 'balance': -4262175431},
{'timestamp': 1639992013236, 'balance': -4262246474},
{'timestamp': 1639992013236, 'balance': -4262542764},
{'timestamp': 1639992111113, 'balance': -4262590904},
{'timestamp': 1639992111128, 'balance': -4262657779},
{'timestamp': 1639992111144, 'balance': -4262720033},
{'timestamp': 1639992111144, 'balance': -4262831837},
{'timestamp': 1639992111160, 'balance': -4262832264},
{'timestamp': 1639992111160, 'balance': -4262832691},
{'timestamp': 1639992534358, 'balance': -4262824219},
{'timestamp': 1639992597448, 'balance': -4262825830},
{'timestamp': 1639992740444, 'balance': -4262820880},
{'timestamp': 1639992740447, 'balance': -4262822860},
{'timestamp': 1639992740728, 'balance': -4262822860},
{'timestamp': 1639992863178, 'balance': -4457312394},
{'timestamp': 1639992863194, 'balance': -4526475834},
{'timestamp': 1639992863213, 'balance': -4640392288},
{'timestamp': 1639992863222, 'balance': -4806582573},
{'timestamp': 1639992863232, 'balance': -4929355104},
{'timestamp': 1639992863490, 'balance': -4929355104},
{'timestamp': 1639992863513, 'balance': -4815438650},
{'timestamp': 1639992863517, 'balance': -4815438650},
{'timestamp': 1639992863604, 'balance': -4929355104},
{'timestamp': 1639992866229, 'balance': -4929355104},
{'timestamp': 1639992868239, 'balance': -5008495201},
{'timestamp': 1639992868395, 'balance': -5008495201},
{'timestamp': 1639992883269, 'balance': -5008495201},
{'timestamp': 1639992883456, 'balance': -5008495201},
]
10 changes: 10 additions & 0 deletions src/tribler-gui/tribler_gui/tests/test_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import tribler_gui
from tribler_gui.dialogs.feedbackdialog import FeedbackDialog
from tribler_gui.dialogs.new_channel_dialog import NewChannelDialog
from tribler_gui.tests.gui_test_data import negative_token_balance_history
from tribler_gui.tribler_app import TriblerApplication
from tribler_gui.tribler_window import TriblerWindow
from tribler_gui.utilities import connect
Expand Down Expand Up @@ -564,6 +565,15 @@ def test_trust_page(window):
screenshot(window, name="trust_page_values")


@pytest.mark.guitest
def test_big_negative_token_balance(window):
QTest.mouseClick(window.token_balance_widget, Qt.LeftButton)
wait_for_variable(window, "trust_page.history")
window.trust_page.history = negative_token_balance_history
window.trust_page.plot_absolute_values()
screenshot(window, name="big_negative_token_balance")


@pytest.mark.guitest
def test_close_dialog_with_esc_button(window):
QTest.mouseClick(window.left_menu_button_new_channel, Qt.LeftButton)
Expand Down
13 changes: 11 additions & 2 deletions src/tribler-gui/tribler_gui/widgets/trustpage.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from tribler_common.sentry_reporter.sentry_mixin import AddBreadcrumbOnShowMixin

from tribler_gui.defs import GB, PB
from tribler_gui.defs import PB, TB
from tribler_gui.dialogs.trustexplanationdialog import TrustExplanationDialog
from tribler_gui.tribler_request_manager import TriblerNetworkRequest
from tribler_gui.utilities import connect
Expand All @@ -18,7 +18,7 @@ def __init__(self, parent, **kargs):
]
super().__init__(parent, 'Token balance over time', series, **kargs)
self.setLabel('left', 'Data', units='B')
self.setLimits(yMin=-GB, yMax=PB)
self.setLimits(yMin=-TB, yMax=PB)


class TrustPage(AddBreadcrumbOnShowMixin, QWidget):
Expand Down Expand Up @@ -83,6 +83,15 @@ def plot_absolute_values(self) -> None:
"""
Plot the evolution of the token balance.
"""
if self.history:
min_balance = min(item['balance'] for item in self.history)
max_balance = max(item['balance'] for item in self.history)
half = (max_balance - min_balance) / 2
min_limit = min(-TB, min_balance - half)
max_limit = max(PB, max_balance + half)
self.trust_plot.setLimits(yMin=min_limit, yMax=max_limit)
self.trust_plot.setYRange(min_balance, max_balance)

# Convert all dates to a datetime object
for history_item in self.history:
timestamp = history_item["timestamp"] // 1000
Expand Down