Esempio n. 1
0
    def add_category_and_children_keys(categoryKey: str,
                                       valueDictionary: Dict[str, Any],
                                       innerTabs: Dict[str,
                                                       Any], tab: QTabWidget):
        """
        Modifies instance tabs variable with new values from valueDictionary.
        :param categoryKey: Category to modify.
        :param valueDictionary: Dictionary with values to put in.
        :param innerTabs: Inner tabs of tab to tbe modified. E.g. Simulation's inner tabs can be general, averages, etc.
        :param tab: Tab to be modified. For instance, this tab can be the simulation tab.
        """
        innerLayout = QFormLayout()
        innerTabs[categoryKey] = {'tab': QTabWidget()}

        for mainKey in valueDictionary[categoryKey]:
            label = QLabel(get_label_string(str(mainKey)))
            value = QLabel(str(valueDictionary[categoryKey][mainKey]))
            value.setAlignment(QtCore.Qt.AlignRight)

            innerLayout.addRow(label, value)
            innerTabs[categoryKey][mainKey] = {'label': label, 'value': value}

        innerTabs[categoryKey]['tab'].setLayout(innerLayout)
        tab.addTab(innerTabs[categoryKey]['tab'],
                   get_label_string(categoryKey))
Esempio n. 2
0
def test_get_label_string(label: str, expected: str):
    """
    Test get label string functionality.
    :param label: Label to convert.
    :param expected: Expected converted label.
    """
    assert get_label_string(
        label) == expected, f"Expected label string to be: {expected}."
Esempio n. 3
0
    def get_advanced_statistics(self) -> str:
        """
        Returns a lot more statistics from trader object.
        :return: String of huge statistics.
        """
        trader: SimulationTrader = self.gui.trader
        statDict = trader.get_grouped_statistics()

        total = ''

        for categoryKey in statDict:
            total += get_label_string(categoryKey) + ':\n'
            for key in statDict[categoryKey]:
                value = statDict[categoryKey][key]
                total += f'\t\t {get_label_string(key)} : {get_label_string(value)} \n'
        return total
Esempio n. 4
0
    def modify_tab(self, valueDictionary, tabType):
        """
        Modifies tab.
        :param valueDictionary: Dictionary with values.
        :param tabType: Tab type to be modified.
        """
        innerTabs = self.tabs[tabType]['innerTabs']  # live/widgets
        self.set_profit_or_loss_label(valueDictionary=valueDictionary,
                                      innerTabs=innerTabs)

        for key in innerTabs:  # If there's a change in the value dictionary, re-initialize the tab.
            if key not in valueDictionary:
                self.initialize_tab(valueDictionary=valueDictionary,
                                    tabType=tabType)
                break

        for categoryKey in valueDictionary:
            if categoryKey not in innerTabs:
                tab = self.tabs[tabType]['tab']
                self.add_category_and_children_keys(categoryKey,
                                                    valueDictionary, innerTabs,
                                                    tab)
            else:
                innerWidgets = innerTabs[categoryKey]  # live/widgets/general
                for mainKey in valueDictionary[categoryKey]:
                    if mainKey in innerWidgets:
                        innerWidgets[mainKey]['value'].setText(
                            str(valueDictionary[categoryKey][mainKey]))
                    else:
                        label = QLabel(get_label_string(str(mainKey)))
                        value = QLabel(
                            str(valueDictionary[categoryKey][mainKey]))
                        value.setAlignment(QtCore.Qt.AlignRight)

                        layout = innerTabs[categoryKey]['tab'].layout()
                        layout.addRow(label, value)
                        innerWidgets[mainKey] = {
                            'label': label,
                            'value': value
                        }
Esempio n. 5
0
def test_get_label_string(label: str, expected: str):
    assert get_label_string(
        label) == expected, f"Expected label string to be: {expected}."