コード例 #1
0
    def mouse_moved(self, evt):
        """
        method for moving the vertical lines based on mouse placement

        """
        pos = evt[0]
        if self.plot_widget_1.sceneBoundingRect().contains(pos) or \
                self.plot_widget_2.sceneBoundingRect().contains(pos):
            x_val_1, y_val_1, x_val_2, y_val_2, limits = self.move_vertical_lines(pos)

            x_label_idx = where(array(self.x_1) == x_val_1)[0]
            x_label_1 = self.x_time[x_label_idx.item()] + self.units[0] if \
                self.x_time and x_label_idx.size != 0 else \
                Amount(str(x_val_1)).amount + self.units[0]
            y_label_1 = Amount(str(y_val_1)).amount + self.units[1]

            x_label_2 = self.x_time[x_label_idx.item()] + self.units[0] if \
                self.x_time and x_label_idx.size != 0 else \
                Amount(str(x_val_2)).amount + self.units[2]
            y_label_2 = Amount(str(y_val_2)).amount + self.units[3]

            if limits:
                self.label_1.setHtml('<div style="text-align: center">'
                                     '<span style="font-size: 10pt">{}</span><br>'
                                     '<span style="font-size: 10pt">{}</span><br>'
                                     '<span style="font-size: 10pt">({})</span>'
                                     '</div>'.format(self.labels[0], x_label_1, y_label_1))
                self.label_2.setHtml('<div style="text-align: center">'
                                     '<span style="font-size: 10pt">{}</span><br>'
                                     '<span style="font-size: 10pt">{}</span><br>'
                                     '<span style="font-size: 10pt">({})</span>'
                                     '</div>'.format(self.labels[1], x_label_2, y_label_2))
コード例 #2
0
ファイル: test_amount.py プロジェクト: seemir/stressa
    def test_adding_method(self, amount):
        """
        Testing adding two amounts together

        """
        correct_sum = str(Decimal(self.amount.amount.replace(" ", "")) + Decimal(amount))
        assert (self.amount + Amount(amount)).replace(" ", "") == correct_sum
コード例 #3
0
ファイル: finn_stat.py プロジェクト: seemir/stressa
    def extract_sqm_price(self, sql_price_statistics: dict, info: dict):
        """
        method for extracting square meter price

        Parameters
        ----------
        sql_price_statistics : dict
                               dictionary with square meter price
        info                 : dict
                               dictionary to store results

        """
        Assertor.assert_data_types([sql_price_statistics, info], [dict, dict])
        for prop, value in sql_price_statistics.items():
            if prop.lower() == 'props':
                for pro, val in value.items():
                    if pro.lower() == 'pageprops':
                        for pr_name, vl_name in val.items():
                            if pr_name.lower() == 'areasales':
                                for name, inf in vl_name.items():
                                    if isinstance(
                                            inf,
                                        (int,
                                         float)) and name.lower() == 'price':
                                        info.update({
                                            'sqm_price':
                                            Amount(str(inf)).amount + " kr/m²"
                                        })
        return info
コード例 #4
0
ファイル: finn_stat.py プロジェクト: seemir/stressa
    def extract_view_statistics(self, total_view_statistics: dict, info: dict):
        """
        method for extracting the total view statistics

        Parameters
        ----------
        total_view_statistics   : dict
                                  dictionary with view statistics
        info                    : dict
                                  dictionary to store results

        Returns
        -------
        out                     : dict
                                  dictionary with results

        """
        Assertor.assert_data_types([total_view_statistics, info], [dict, dict])
        for prop, value in total_view_statistics.items():
            if prop.lower() == 'props':
                for pro, val in value.items():
                    if pro.lower() == 'pageprops':
                        for pr_name, vl_name in val.items():
                            if isinstance(
                                    vl_name,
                                (int,
                                 float)) and pr_name.lower() == 'totalclicks':
                                info.update(
                                    {"views": Amount(str(vl_name)).amount})
        return info
コード例 #5
0
ファイル: test_amount.py プロジェクト: seemir/stressa
    def test_division_by_zero(self):
        """
        Test that dividing Amount object by zero throws ZeroDivisionError exception

        """
        with pt.raises(ZeroDivisionError):
            assert self.amount / Amount("0")
コード例 #6
0
ファイル: test_amount.py プロジェクト: seemir/stressa
    def test_true_division_method(self, amount):
        """
        Test the division method of Amount object

        """
        correct_mul = str(Decimal(self.amount.amount.replace(" ", "")) / Decimal(amount))
        assert (self.amount / Amount(amount)).replace(" ", "") == correct_mul
コード例 #7
0
ファイル: test_amount.py プロジェクト: seemir/stressa
    def test_multiplication_method(self, amount):
        """
        Test the multiplication method of Amount object

        """
        correct_mul = str(Decimal(self.amount.amount.replace(" ", "")) * Decimal(amount))
        assert (self.amount * Amount(amount)).replace(" ", "") == correct_mul
コード例 #8
0
ファイル: test_amount.py プロジェクト: seemir/stressa
    def test_subtracting_method(self, amount):
        """
        Testing subtracting two amounts together

        """
        correct_sub = str(Decimal(self.amount.amount.replace(" ", "")) - Decimal(amount))
        assert (self.amount - Amount(amount)).replace(" ", "") == correct_sub
コード例 #9
0
ファイル: test_amount.py プロジェクト: seemir/stressa
    def test_amount_throws_type_error_for_invalid_argument_types(self, invalid_amount_type):
        """
        Test that TypeError is thrown if invalid type, i.e. not str is passed to Amount object

        """
        with pt.raises(TypeError):
            Amount(invalid_amount_type)
        with pt.raises(TypeError):
            self.amount.amount = invalid_amount_type
コード例 #10
0
ファイル: test_amount.py プロジェクト: seemir/stressa
    def test_validate_amount_method(self, invalid_amount):
        """
        Test the static method validate_amount method

        """
        with pt.raises(TrackingError):
            Amount(invalid_amount)
        with pt.raises(TrackingError):
            self.amount.amount = invalid_amount
        with pt.raises(TrackingError):
            self.amount.validate_amount(invalid_amount)
コード例 #11
0
ファイル: change_bar_chart.py プロジェクト: seemir/stressa
    def mouse_moved(self, evt):
        """
        method for moving the vertical lines based on mouse placement

        """
        pos = evt[0]
        x_val, y_val = self.move_vertical_lines(pos)

        x_label_idx = where(array(self.x) == x_val)[0]
        x_label = self.x_time[x_label_idx.item()] if \
            self.x_time and x_label_idx.size != 0 else \
            Amount(str(x_val)).amount + self.units[0]
        y_label = str(y_val) + self.units[1]

        if min(self.x) <= x_val <= max(self.x):
            self.label.setHtml('<div style="text-align: center">'
                               '<span style="font-size: 10pt">{}</span><br>'
                               '<span style="font-size: 10pt">{}</span><br>'
                               '<span style="font-size: 10pt">({})</span>'
                               '</div>'.format(self.labels, x_label, y_label))
コード例 #12
0
ファイル: ratio_chart.py プロジェクト: seemir/stressa
    def mouse_moved(self, evt):
        """
        method for moving the vertical lines based on mouse placement

        """
        pos = evt[0]
        if self.graphics_view.sceneBoundingRect().contains(pos):
            x_val, y_val = self.move_vertical_lines(pos)

            percent = Percent(
                str(y_val / 100).replace("[", "").replace("]", ""))

            if min(self.x) <= x_val <= max(self.x):
                self.label.setHtml(
                    '<div style="text-align: center">'
                    '<span style="font-size: 10pt">{}</span><br>'
                    '<span style="font-size: 10pt">{} {}</span><br>'
                    '<span style="font-size: 10pt">({})</span>'
                    '</div>'.format(self.labels,
                                    Amount(str(x_val)).amount, self.units[0],
                                    percent.value))
コード例 #13
0
ファイル: finn_stat.py プロジェクト: seemir/stressa
    def calculate_average(self, elements: dict):
        """
        method for calculating the average

        Parameters
        ----------
        elements      : dict
                        dictionary of prices

        Returns
        -------
        out           : str
                        string with results

        """
        products = []
        sums = 0
        for price, num in elements.items():
            products.append(int(price) * num)
            sums += num
        average = Amount(str(round(sum(products) /
                                   sums))).amount if sums != 0 else "0"
        return average
コード例 #14
0
ファイル: test_amount.py プロジェクト: seemir/stressa
    def test_amount_value_object_equal(self):
        """
        Testing that two Amount Value objects are equal when all properties are equal

        """
        assert self.amount == Amount("90210")
コード例 #15
0
ファイル: finn_stat.py プロジェクト: seemir/stressa
    def extract_area_sales_statistics(self, areal_sales_statistics: dict,
                                      info: dict):
        """
        method for extracting the detail view statistics

        Parameters
        ----------
        areal_sales_statistics  : dict
                                  dictionary with area sales statistics
        info                    : dict
                                  dictionary to store results

        Returns
        -------
        out                     : dict
                                  dictionary with results

        """
        Assertor.assert_data_types([areal_sales_statistics, info],
                                   [dict, dict])
        historical_data_names = [
            "hist_data_city_area", "hist_data_municipality"
        ]
        location_name = ["city_area", "municipality"]
        for prop, value in areal_sales_statistics.items():
            if prop.lower() == 'props':
                for pro, val in value.items():
                    if pro.lower() == 'pageprops':
                        for pr_name, vl_name in val.items():
                            if pr_name.lower() == 'locationhistory':
                                for i, data in enumerate(vl_name):
                                    if len(areal_sales_statistics) == 3:
                                        if i == 0:
                                            continue
                                        i -= 1
                                    for prop_val, value_name in data.items():
                                        if prop_val.lower(
                                        ) == "locationdetails":
                                            if value_name:
                                                if "name" in value_name[0]:
                                                    info.update({
                                                        location_name[i]:
                                                        value_name[0]["name"]
                                                    })
                                        elif prop_val.lower() == "histdata":
                                            historical_values = {}
                                            for ke_val, va_name in value_name.items(
                                            ):
                                                historical_values.update({
                                                    int(ke_val):
                                                    int(va_name)
                                                })
                                            info.update({
                                                historical_data_names[i]:
                                                historical_values
                                            })
                                            info.update({
                                                historical_data_names[i] + "_count":
                                                Amount(
                                                    str(
                                                        sum(historical_values.
                                                            values()))).amount
                                            })
        if all(name in info.keys() for name in historical_data_names):
            self.harmonize_data_sets(info)
        return info
コード例 #16
0
ファイル: test_amount.py プロジェクト: seemir/stressa
    def test_amount_value_object_not_equal(self):
        """
        Testing that two Amount Value objects are equal when some properties are not equal

        """
        assert self.amount != Amount("90211")
コード例 #17
0
ファイル: test_amount.py プロジェクト: seemir/stressa
    def setup(cls):
        """
        Executed before all tests

        """
        cls.amount = Amount("90210")
コード例 #18
0
ファイル: statistics_model.py プロジェクト: seemir/stressa
    def add_dist_chart(self,
                       prefix: str,
                       postfix: str,
                       key: str,
                       plot_name_1: str,
                       plot_name_2: str,
                       table_name: str,
                       dist_name: str,
                       dist_var_1: str,
                       dist_var_2: str,
                       ignore_total: bool = True):
        """
        method for adding distribution chart to the statistics model

        Parameters
        ----------
        prefix      : str
                      name of prefix, i.e. "graphics"
        postfix     : str
                      index if used in naming of line_edits
        key         : str
                      name of label to change
        plot_name_1 : str
                      name of first plot
        plot_name_2 : str
                      name of second plot
        table_name  : str
                      name of table
        dist_name   : str
                      name of distribution variable
        dist_var_1  : str
                      name of instance variable for distribution
        dist_var_2  : str
                      name of second instance variable for distribution
        ignore_total: str
                      boolean for handling total values

        """
        Assertor.assert_data_types([
            prefix, postfix, key, plot_name_1, plot_name_2, table_name,
            dist_name, dist_var_1, dist_var_2, ignore_total
        ], [str, str, str, str, str, str, str, str, str, bool])
        BarChart.clear_graphics(getattr(self.parent.ui, prefix + plot_name_1))
        BarChart.clear_graphics(getattr(self.parent.ui, prefix + plot_name_2))
        if key + postfix in self.data.keys() and self.data[key + postfix]:
            dist = self.data[key + postfix]
            city_area_dist = dist["Nabolag"][:-2] if ignore_total else dist[
                "Nabolag"]
            city_dist = dist["By"][:-2] if ignore_total else dist["By"]
            dist_range = list(range(len(city_area_dist)))
            if "info" + postfix in self.data.keys():
                if self.data["info" + postfix]["neighborhood"]:
                    neighbourhood = self.data["info" + postfix]["neighborhood"]["name"] \
                        .replace("-", " - ")
                    city = self.data["info" + postfix]["neighborhood"]["city"]
                else:
                    neighbourhood = self.data["info" +
                                              postfix]["census"].replace(
                                                  "-", " - ")
                    city = self.data["info" + postfix]["city"].replace(
                        "-", " - ")
            else:
                neighbourhood = ""
                city = ""

            if "city_area" + postfix in self.data.keys():
                city_area = self.data["city_area" + postfix]
            else:
                city_area = ""

            if sum(city_area_dist) != 0:
                dist_df = {"Gruppe": [], "Nabolag": [], "By": []}
                for keys, values in dist.items():
                    if keys == "Gruppe":
                        dist_df[keys] = values
                    else:
                        if ignore_total:
                            dist_df[keys] = [
                                Percent(str(val / 100)).value
                                if i not in (len(values) - 1, len(values) -
                                             2) else Amount(str(val)).amount
                                for i, val in enumerate(values)
                            ]
                        else:
                            dist_df[keys] = [
                                Percent(str(val / 100)).value
                                for i, val in enumerate(values)
                            ]

                table_model = TableModel(DataFrame(dist_df))
                getattr(self.parent.ui, table_name).setModel(table_model)
                getattr(self.parent.ui,
                        table_name).horizontalHeader().setSectionResizeMode(
                            QHeaderView.Stretch)

                setattr(
                    self, dist_var_1,
                    BarChartWithLine(
                        dist_range,
                        city_area_dist,
                        getattr(self.parent.ui, prefix + plot_name_1),
                        getattr(self.parent.ui, table_name),
                        width=0.5,
                        reverse=False,
                        legend='<div style="text-align: center">'
                        '<span style="font-size: 10pt">{}:</span><br>'
                        '<span style="font-size: 10pt">{}</span><br>'
                        '<span style="font-size: 10pt">({})</span><br>'
                        '</div>'.format(dist_name, neighbourhood, city_area)))

                setattr(
                    self, dist_var_2,
                    BarChartWithLine(
                        dist_range,
                        city_dist,
                        getattr(self.parent.ui, prefix + plot_name_2),
                        getattr(self.parent.ui, table_name),
                        width=0.5,
                        reverse=False,
                        legend='<div style="text-align: center">'
                        '<span style="font-size: 10pt">{}:</span><br>'
                        '<span style="font-size: 10pt">{}</span><br>'
                        '</div>'.format(dist_name, city)))

                getattr(self, dist_var_1).table_view_mapping()
                getattr(self, dist_var_2).table_view_mapping()