Example #1
0
    def charts(self):
        chart = PNAMultiBarChart(None, Axis('Location'), Axis('Percent', format='.2f'))
        chart.height = 550
        chart.marginBottom = 150
        chart.rotateLabels = -45
        chart.showControls = False
        chart.forceY = [0, 100]

        def get_data_for_graph():
            com = []
            rows = self.calculate_rows()
            for row in rows:
                #-1 removes % symbol for cast to float
                y = row[-1]['html'][:-1]
                try:
                    y = float(y)
                except ValueError:
                    y = 0
                com.append({"x": row[0]['html'], "y": y})

            return [
                {
                    'key':
                        'Méthode de calcul: Nombre total de produits PNA perdus '
                        '(non compris les produits périmés) sur PNA stock final',
                    'values': com
                },
            ]

        chart.data = get_data_for_graph()
        return [chart]
    def charts(self):
        chart = PNAMultiBarChart(None, Axis('Location'), Axis('Percent', format='.2f'))
        chart.height = 550
        chart.marginBottom = 150
        chart.rotateLabels = -45
        chart.showControls = False
        chart.forceY = [0, 100]

        def get_data_for_graph():
            com = []
            sorted_products, rows = self.calculate_rows(for_chart=True)
            for product in sorted_products:
                y = float(rows[product]['percent'][:-1])
                com.append({"x": product, "y": y})

            return [
                {
                    'key':
                        'Méthode de calcul: Nombre total de produits PNA perdus '
                        '(non compris les produits périmés) sur PNA stock final',
                    'values': com
                },
            ]

        chart.data = get_data_for_graph()
        return [chart]
Example #3
0
    def charts(self):
        chart = PNAMultiBarChart(None, Axis('Location'),
                                 Axis('Percent', format='.2f'))
        chart.height = 550
        chart.marginBottom = 150
        chart.forceY = [0, 100]
        chart.rotateLabels = -45
        chart.showControls = False

        def get_data_for_graph():
            com = []
            sorted_products, rows = self.calculate_rows(for_chart=True)
            for product in sorted_products:
                y = float(rows[product]['percent'][:-1])
                com.append({"x": product, "y": y})

            return [
                {
                    'key': 'valeur péremption sur valeur totale ',
                    'values': com
                },
            ]

        chart.data = get_data_for_graph()
        return [chart]
Example #4
0
    def charts(self):
        chart = PNAMultiBarChart(None, Axis('Location'),
                                 Axis('Percent', format='.2f'))
        chart.height = 550
        chart.marginBottom = 150
        chart.forceY = [0, 100]
        chart.rotateLabels = -45
        chart.showControls = False

        def get_data_for_graph():
            com = []
            rows = self.calculate_rows()
            for row in rows:
                #-1 removes % symbol for cast to float
                y = row[-1]['html'][:-1]
                try:
                    y = float(y)
                except ValueError:
                    y = 0
                com.append({"x": row[0]['html'], "y": y})

            return [
                {
                    'key': 'valeur péremption sur valeur totale ',
                    'values': com
                },
            ]

        chart.data = get_data_for_graph()
        return [chart]
Example #5
0
    def charts(self):
        x_axis = 'Product' if self.selected_location_type != 'PPS' else 'Location'
        chart = PNAMultiBarChart(None, Axis(x_axis), Axis('Percent', format='.2f'))
        chart.height = 550
        chart.marginBottom = 150
        chart.forceY = [0, 100]
        chart.rotateLabels = -45
        chart.showControls = False

        def data_to_chart(stocks_list):
            stocks_to_return = []
            products_data = []
            added_products = []

            for stock in stocks_list:
                location_id = stock['location_id']
                location_name = stock['location_name']
                for product in stock['products']:
                    product_id = product['product_id']
                    product_name = product['product_name']
                    in_ppses = product['in_ppses']
                    all_ppses = product['all_ppses']
                    if product_id not in added_products:
                        added_products.append(product_id)
                        product_dict = {
                            'product_id': product_id,
                            'product_name': product_name,
                            'location_id': location_id,
                            'location_name': location_name,
                            'in_ppses': in_ppses,
                            'all_ppses': all_ppses,
                        }
                        products_data.append(product_dict)
                    else:
                        for product_data in products_data:
                            if product_data['product_id'] == product_id:
                                product_data['in_ppses'] += in_ppses
                                product_data['all_ppses'] += all_ppses

            products = sorted(products_data, key=lambda x: x['product_name'])
            if self.selected_location_type != 'PPS':
                for product in products:
                    product_name = product['product_name']
                    in_ppses = product['in_ppses']
                    all_ppses = product['all_ppses']
                    percent = (in_ppses / float(all_ppses)) * 100 if all_ppses != 0 else 0
                    stocks_to_return.append([
                        product_name,
                        {
                            'html': '{}'.format(percent),
                            'sort_key': percent
                        }
                    ])
            else:
                added_locations = []
                availability_for_ppses = {}
                for product in products:
                    location_id = product['location_id']
                    location_name = product['location_name']
                    in_ppses = product['in_ppses']
                    all_ppses = product['all_ppses']
                    if location_id not in added_locations:
                        added_locations.append(location_id)
                        availability_for_ppses[location_id] = {
                            'location_name': location_name,
                            'in_ppses': in_ppses,
                            'all_ppses': all_ppses,
                        }
                    else:
                        availability_for_ppses[location_id]['in_ppses'] += in_ppses
                        availability_for_ppses[location_id]['all_ppses'] += all_ppses

                for location_id, location_info in availability_for_ppses.items():
                    location_name = location_info['location_name']
                    in_ppses = location_info['in_ppses']
                    all_ppses = location_info['all_ppses']
                    percent = (in_ppses / float(all_ppses)) * 100 if all_ppses != 0 else 0
                    stocks_to_return.append([
                        location_name,
                        {
                            'html': '{}'.format(percent),
                            'sort_key': percent
                        }
                    ])

            return stocks_to_return

        def get_data_for_graph():
            com = []
            rows = data_to_chart(self.clean_rows)
            for row in rows:
                com.append({"x": row[0], "y": row[1]['sort_key']})

            return [
                {
                    "key": 'Taux de disponibilité de la Gamme des produits',
                    'values': com
                },
            ]

        chart.data = get_data_for_graph()
        return [chart]
Example #6
0
    def charts(self):
        chart = PNAMultiBarChart(None, Axis('Location'),
                                 Axis('Percent', format='.2f'))
        chart.height = 550
        chart.marginBottom = 150
        chart.rotateLabels = -45
        chart.showControls = False
        chart.forceY = [0, 100]

        def data_to_chart(quantities_list):
            quantities_to_return = []
            locations_data = {}
            added_locations = []

            for quantity in quantities_list:
                location_name = quantity['location_name']
                location_id = quantity['location_id']
                for product in quantity['products']:
                    amt_delivered_convenience = product[
                        'amt_delivered_convenience']
                    ideal_topup = product['ideal_topup']
                    if location_id not in added_locations:
                        added_locations.append(location_id)
                        locations_data[location_id] = {
                            'location_name': location_name,
                            'amt_delivered_convenience':
                            amt_delivered_convenience,
                            'ideal_topup': ideal_topup,
                        }
                    else:
                        locations_data[location_id][
                            'amt_delivered_convenience'] += amt_delivered_convenience
                        locations_data[location_id][
                            'ideal_topup'] += ideal_topup

            sorted_locations_data_values = sorted(
                locations_data.values(), key=lambda x: x['location_name'])
            for location_info in sorted_locations_data_values:
                location_name = location_info['location_name']
                amt_delivered_convenience = location_info[
                    'amt_delivered_convenience']
                ideal_topup = location_info['ideal_topup']
                percent = (amt_delivered_convenience / float(ideal_topup) * 100) \
                    if ideal_topup != 0 else 0
                quantities_to_return.append([
                    location_name, {
                        'html': '{:.2f} %'.format(percent),
                        'sort_key': percent
                    }
                ])

            return quantities_to_return

        def get_data_for_graph():
            com = []
            rows = data_to_chart(self.clean_rows)
            for row in rows:
                com.append({"x": row[0], "y": row[1]['sort_key']})

            return [
                {
                    "key": 'Taux de Satisfaction des produits',
                    'values': com
                },
            ]

        chart.data = get_data_for_graph()
        return [chart]