def get_orders_units_info(self, plottype, group_arg):
        if group_arg == 'quarter':
            orders = self.orders_dataframe.groupby('Quarter').size()
        elif group_arg == 'year':
            orders = self.orders_dataframe.groupby('Year').size()
        elif group_arg == 'month':
            orders_aux = self.orders_dataframe
            max_date = orders_aux['Date'].max()
            """Here we take the max_date to the last day of the previous month"""
            max_date -= dt.timedelta(days=max_date.day)
            """Here we compute the min_date as max_date minus a year"""
            min_date = max_date - dt.timedelta(days=365)
            """Here we select orders in that date range"""
            orders_aux = orders_aux[(orders_aux['Date'] > min_date)
                                    & (orders_aux['Date'] <= max_date)]
            orders_aux.set_index('Date', inplace=True)
            #orders=orders_aux.groupby([(orders_aux.index.year),(orders_aux.index.month)])['Total Vendido'].sum()
            orders = orders_aux.groupby([(orders_aux.index.year),
                                         (orders_aux.index.month)]).size()
        elif group_arg == 'employee':
            orders = self.orders_dataframe.groupby(
                'Employee').size().sort_values(ascending=False)
        elif group_arg == 'country':
            orders = self.orders_dataframe.groupby(
                'Country').size().sort_values(ascending=False)
        fig_size1 = 8
        fig_size2 = 6
        fig_title = "Orders by " + current_app.config['GROUP_ARGS'][group_arg]
        indextype = 'N'
        xlabel = current_app.config['GROUP_ARGS'][group_arg]
        ylabel = "Quantity"
        spines = ['top', 'bottom', 'left', 'right']
        rotation = 90
        bgcolor = "#8cb1cf"
        serie_01 = {
            'data': orders,
            'dp_shape_color': 'o-g',
            'lw': 1,
            'legend': 'Orders',
            'edgecolor': '#60A0D0',
            'color': '#FFFFFF',
            'annotate': 'y',
            'color_highest': 'y',
            'color_shortest': 'y'
        }
        general_params = (fig_size1, fig_size2, fig_title, orders.index,
                          indextype, xlabel, ylabel, spines, rotation, bgcolor)
        data_params = list([])
        data_params.append(serie_01)

        if plottype == 'line':
            png_figure = hp.plot_lines(general_params, data_params)
        elif plottype == 'bar':
            png_figure = hp.plot_bars(general_params, data_params)
        else:
            #data_params[0]['dp_shape_color']='o-r'
            png_figure = hp.plot_combined(general_params, data_params)

        orders = pd.DataFrame(orders).rename(columns={0: 'Quantity'})
        return orders, png_figure
示例#2
0
    def get_products_revenues_info(self,plottype):
        revenues=self.order_details_dataframe.groupby('Product')['Total $'].sum().sort_values(ascending=False)

        fig_size1=8
        fig_size2=6
        fig_title="Total Sold by PRODUCT (top 20)"
        indextype='S'
        xlabel="PRODUCT"
        ylabel="Total Sold [$]"
        spines=['top','bottom','left','right']
        rotation=90
        bgcolor="#8cb1cf"
        serie_01={'data': revenues.head(20),
                  'dp_shape_color': '-g',
                  'lw':1,
                  'legend':'Product Revenues',
                  'edgecolor': '#60A0D0',
                  'color': '#FFFFFF',
                  'annotate': 'f',
                  'color_highest': 'y',
                  'color_shortest': 'y'}
        general_params=(fig_size1,
                        fig_size2,
                        fig_title,
                        revenues.index[0:20],
                        indextype,
                        xlabel,
                        ylabel,
                        spines,
                        rotation,
                        bgcolor)
        data_params=list([])
        data_params.append(serie_01)

        if plottype=='line':
            png_figure=hp.plot_lines(general_params,data_params)
        elif plottype=='bar':
            png_figure=hp.plot_bars(general_params,data_params)
        else:
            #data_params[0]['dp_shape_color']='o-r'
            png_figure=hp.plot_combined(general_params,data_params)

        revenues=pd.DataFrame(revenues).rename(columns={0: 'Total Sold'})
        return  revenues.head(20),png_figure