コード例 #1
0
    def draw(self):
        colors = choice_colors(len(self._datas.keys()))
        user_color = {}
        for user in self._datas.keys():
            user_color[user] = colors.pop()

        val_min = int(time.mktime(time.strptime(self.val_min, '%Y-%m-%d')))
        val_max = int(time.mktime(time.strptime(self.val_max, '%Y-%m-%d')))

        plots = []
        for product_id in self._datas:
            f = fill_style.Plain()
            f.bgcolor = user_color[user]
            datas = self._datas[product_id].items()
            datas = map(
                lambda x:
                (int(time.mktime(time.strptime(x[0], '%Y-%m-%d'))), x[1]),
                datas)
            datas.sort()
            datas2 = []
            val = 0
            for d in datas:
                val += d[1]

                if len(datas2):
                    d2 = d[0] - 60 * 61 * 24
                    if datas2[-1][0] < d2 - 1000:
                        datas2.append((d2, datas2[-1][1]))
                datas2.append((d[0], val))
            if len(datas2) and datas2[-1][0] < val_max - 100:
                datas2.append((val_max, datas2[-1][1]))
            if len(datas2) == 1:
                datas2.append((datas2[0][0] + 100, datas2[0][1]))
            st = line_style.T()
            st.color = user_color[product_id]
            st.width = 1
            st.cap_style = 1
            st.join_style = 1
            plot = line_plot.T(label=self._names[product_id],
                               data=datas2,
                               line_style=st)
            plots.append(plot)

        interval = max((val_max - val_min) / 15, 86400)
        x_axis = axis.X(format=lambda x: '/a60{}' + time.strftime(
            '%Y-%m-%d', time.gmtime(x)),
                        tic_interval=interval,
                        label=None)
        # For add the report header on the top of the report.
        tb = text_box.T(loc=(300, 500),
                        text="/hL/15/bStock Level Forecast",
                        line_style=None)
        tb.draw()
        ar = area.T(size=(620, 435),
                    x_range=(val_min, val_max + 1),
                    y_axis=axis.Y(format="%d", label="Virtual Stock (Unit)"),
                    x_axis=x_axis)
        for plot in plots:
            ar.add_plot(plot)
        ar.draw(self._canvas)
コード例 #2
0
ファイル: stock_graph.py プロジェクト: kevin8909/xjerp
    def draw(self):
        print '********oh,begin*********'
        colors = choice_colors(len(self._datas.keys()))
        user_color = {}
        for user in self._datas.keys():
            user_color[user] = colors.pop()

        val_min = int(time.mktime(time.strptime(self.val_min,'%Y-%m-%d')))
        val_max = int(time.mktime(time.strptime(self.val_max,'%Y-%m-%d')))

        plots = []
        for product_id in self._datas:
            f = fill_style.Plain()
            f.bgcolor = user_color[user]
            datas = self._datas[product_id].items()
            datas = map(lambda x: (int(time.mktime(time.strptime(x[0],'%Y-%m-%d'))),x[1]), datas)
            datas.sort()
            datas2 = []
            val = 0
            for d in datas:
                val+=d[1]

                if len(datas2):
                    d2 = d[0]-60*61*24
                    if datas2[-1][0]<d2-1000:
                        datas2.append((d2,datas2[-1][1]))
                datas2.append((d[0],val))
            if len(datas2) and datas2[-1][0]<val_max-100:
                datas2.append((val_max, datas2[-1][1]))
            if len(datas2)==1:
                datas2.append( (datas2[0][0]+100, datas2[0][1]) )
            st = line_style.T()
            st.color = user_color[product_id]
            st.width = 1
            st.cap_style=1
            st.join_style=1
            plot = line_plot.T(label=self._names[product_id], data=datas2, line_style=st)
            plots.append(plot)

        interval = max((val_max-val_min)/15, 86400)
        x_axis = axis.X(format=lambda x:'/a60{}'+time.strftime('%Y-%m-%d',time.gmtime(x)), tic_interval=interval, label=None)
        # For add the report header on the top of the report.
        tb = text_box.T(loc=(300, 500), text="/hL/15/bStock Level Forecast", line_style=None)
        tb.draw()
        ar = area.T(size = (620,435), x_range=(val_min,val_max+1), y_axis = axis.Y(format="%d", label="Virtual Stock (Unit)"), x_axis=x_axis)
        for plot in plots:
            ar.add_plot(plot)
        print '*********oh,yes*********'
        ar.draw(self._canvas)
コード例 #3
0
ファイル: workcenter_load.py プロジェクト: ccdos/OpenERP
    def create(self, cr, uid, ids, datas, context=None):
        assert len(ids), 'You should provide some ids!'
        colors = choice_colors(len(ids))
        cr.execute(
            "SELECT MAX(mrp_production.date_planned) AS stop,MIN(mrp_production.date_planned) AS start "\
            "FROM mrp_workcenter, mrp_production, mrp_production_workcenter_line "\
            "WHERE mrp_production_workcenter_line.production_id=mrp_production.id "\
            "AND mrp_production_workcenter_line.workcenter_id=mrp_workcenter.id "\
            "AND mrp_production.state NOT IN ('cancel','done') "\
            "AND mrp_workcenter.id IN %s",(tuple(ids),))
        res = cr.dictfetchone()
        if not res['stop']:
            res['stop'] = time.strftime('%Y-%m-%d %H:%M:%S')
        if not res['start']:
            res['start'] = time.strftime('%Y-%m-%d %H:%M:%S')
        dates = self._compute_dates(datas['form']['time_unit'], res['start'][:10], res['stop'][:10])
        dates_list = dates.keys()
        dates_list.sort()
        x_index = []
        for date in dates_list:
            x_index.append((dates[date]['name'], date))
        pdf_string = StringIO.StringIO()
        can = canvas.init(fname=pdf_string, format='pdf')
        can.set_title("Work Center Loads")
        chart_object.set_defaults(line_plot.T, line_style=None)
        if datas['form']['measure_unit'] == 'cycles':
            y_label = "Load (Cycles)"
        else:
            y_label = "Load (Hours)"

        # For add the report header on the top of the report.
        tb = text_box.T(loc=(300, 500), text="/hL/15/bWork Center Loads", line_style=None)
        tb.draw()
        ar = area.T(legend = legend.T(),
                    x_grid_style = line_style.gray70_dash1,
                    x_axis = axis.X(label="Periods", format="/a90/hC%s"),
                    x_coord = category_coord.T(x_index, 0),
                    y_axis = axis.Y(label=y_label),
                    y_range = (0, None),
                    size = (640,480))
        bar_plot.fill_styles.reset();
        # select workcenters
        cr.execute(
            "SELECT mw.id, rs.name FROM mrp_workcenter mw, resource_resource rs " \
            "WHERE mw.id IN %s and mw.resource_id=rs.id " \
            "ORDER BY mw.id" ,(tuple(ids),))
        workcenters = cr.dictfetchall()

        data = []
        for date in dates_list:
            vals = []
            for workcenter in workcenters:
                cr.execute("SELECT SUM(mrp_production_workcenter_line.hour) AS hours, SUM(mrp_production_workcenter_line.cycle) AS cycles, \
                                resource_resource.name AS name, mrp_workcenter.id AS id \
                            FROM mrp_production_workcenter_line, mrp_production, mrp_workcenter, resource_resource \
                            WHERE (mrp_production_workcenter_line.production_id=mrp_production.id) \
                                AND (mrp_production_workcenter_line.workcenter_id=mrp_workcenter.id) \
                                AND (mrp_workcenter.resource_id=resource_resource.id) \
                                AND (mrp_workcenter.id=%s) \
                                AND (mrp_production.date_planned BETWEEN %s AND %s) \
                            GROUP BY mrp_production_workcenter_line.workcenter_id, resource_resource.name, mrp_workcenter.id \
                            ORDER BY mrp_workcenter.id", (workcenter['id'], dates[date]['start'] + ' 00:00:00', dates[date]['stop'] + ' 23:59:59'))
                res = cr.dictfetchall()
                if not res:
                    vals.append(0.0)
                else:
                    if datas['form']['measure_unit'] == 'cycles':
                        vals.append(res[0]['cycles'] or 0.0)
                    else:
                        vals.append(res[0]['hours'] or 0.0)

            toto = [dates[date]['name']]
            for val in vals:
                toto.append(val)
            data.append(toto)

        workcenter_num = 0
        for workcenter in workcenters:
            f = fill_style.Plain()
            f.bgcolor = colors[workcenter_num]
            ar.add_plot(bar_plot.T(label=workcenter['name'], data=data, fill_style=f, hcol=workcenter_num+1, cluster=(workcenter_num, len(res))))
            workcenter_num += 1

        if (not data) or (len(data[0]) <= 1):
            ar = self._empty_graph(time.strftime('%Y-%m-%d'))
        ar.draw(can)
        # close canvas so that the file is written to "disk"
        can.close()
        self.obj = external_pdf(pdf_string.getvalue())
        self.obj.render()
        pdf_string.close()
        return (self.obj.pdf, 'pdf')
コード例 #4
0
ファイル: workcenter_load.py プロジェクト: amhosni/odoo3
    def create(self, cr, uid, ids, datas, context=None):
        assert len(ids), 'You should provide some ids!'
        colors = choice_colors(len(ids))
        cr.execute(
            "SELECT MAX(mrp_production.date_planned) AS stop,MIN(mrp_production.date_planned) AS start "\
            "FROM mrp_workcenter, mrp_production, mrp_production_workcenter_line "\
            "WHERE mrp_production_workcenter_line.production_id=mrp_production.id "\
            "AND mrp_production_workcenter_line.workcenter_id=mrp_workcenter.id "\
            "AND mrp_production.state NOT IN ('cancel','done') "\
            "AND mrp_workcenter.id IN %s",(tuple(ids),))
        res = cr.dictfetchone()
        if not res['stop']:
            res['stop'] = time.strftime('%Y-%m-%d %H:%M:%S')
        if not res['start']:
            res['start'] = time.strftime('%Y-%m-%d %H:%M:%S')
        dates = self._compute_dates(datas['form']['time_unit'],
                                    res['start'][:10], res['stop'][:10])
        dates_list = list(dates.keys())
        dates_list.sort()
        x_index = []
        for date in dates_list:
            x_index.append((dates[date]['name'], date))
        pdf_string = io.StringIO()
        can = canvas.init(fname=pdf_string, format='pdf')
        can.set_title("Work Center Loads")
        chart_object.set_defaults(line_plot.T, line_style=None)
        if datas['form']['measure_unit'] == 'cycles':
            y_label = "Load (Cycles)"
        else:
            y_label = "Load (Hours)"

        # For add the report header on the top of the report.
        tb = text_box.T(loc=(300, 500),
                        text="/hL/15/bWork Center Loads",
                        line_style=None)
        tb.draw()
        ar = area.T(legend=legend.T(),
                    x_grid_style=line_style.gray70_dash1,
                    x_axis=axis.X(label="Periods", format="/a90/hC%s"),
                    x_coord=category_coord.T(x_index, 0),
                    y_axis=axis.Y(label=y_label),
                    y_range=(0, None),
                    size=(640, 480))
        bar_plot.fill_styles.reset()
        # select workcenters
        cr.execute(
            "SELECT mw.id, rs.name FROM mrp_workcenter mw, resource_resource rs " \
            "WHERE mw.id IN %s and mw.resource_id=rs.id " \
            "ORDER BY mw.id" ,(tuple(ids),))
        workcenters = cr.dictfetchall()

        data = []
        for date in dates_list:
            vals = []
            for workcenter in workcenters:
                cr.execute(
                    "SELECT SUM(mrp_production_workcenter_line.hour) AS hours, SUM(mrp_production_workcenter_line.cycle) AS cycles, \
                                resource_resource.name AS name, mrp_workcenter.id AS id \
                            FROM mrp_production_workcenter_line, mrp_production, mrp_workcenter, resource_resource \
                            WHERE (mrp_production_workcenter_line.production_id=mrp_production.id) \
                                AND (mrp_production_workcenter_line.workcenter_id=mrp_workcenter.id) \
                                AND (mrp_workcenter.resource_id=resource_resource.id) \
                                AND (mrp_workcenter.id=%s) \
                                AND (mrp_production.date_planned BETWEEN %s AND %s) \
                            GROUP BY mrp_production_workcenter_line.workcenter_id, resource_resource.name, mrp_workcenter.id \
                            ORDER BY mrp_workcenter.id",
                    (workcenter['id'], dates[date]['start'] + ' 00:00:00',
                     dates[date]['stop'] + ' 23:59:59'))
                res = cr.dictfetchall()
                if not res:
                    vals.append(0.0)
                else:
                    if datas['form']['measure_unit'] == 'cycles':
                        vals.append(res[0]['cycles'] or 0.0)
                    else:
                        vals.append(res[0]['hours'] or 0.0)

            toto = [dates[date]['name']]
            for val in vals:
                toto.append(val)
            data.append(toto)

        workcenter_num = 0
        for workcenter in workcenters:
            f = fill_style.Plain()
            f.bgcolor = colors[workcenter_num]
            ar.add_plot(
                bar_plot.T(label=workcenter['name'],
                           data=data,
                           fill_style=f,
                           hcol=workcenter_num + 1,
                           cluster=(workcenter_num, len(res))))
            workcenter_num += 1

        if (not data) or (len(data[0]) <= 1):
            ar = self._empty_graph(time.strftime('%Y-%m-%d'))
        ar.draw(can)
        # close canvas so that the file is written to "disk"
        can.close()
        self.obj = external_pdf(pdf_string.getvalue())
        self.obj.render()
        pdf_string.close()
        return (self.obj.pdf, 'pdf')