Ejemplo n.º 1
0
    def export_to_plotly(self):
        if len(self.tracking_data['Key']) == 0:
            raise ValueError('There is no issues to show')

        header_values = [['<b>{}</b>'.format(head)]
                         for head in self.tracking_data.keys()
                         ] + [['<b>Deadline</b>']]
        cells_values = [value if key != 'Key' else
                        list(map(lambda el:'<a href="https://jira.billing.ru/browse/{0}">{0}</a>'.format(el), value))
                        for key, value in self.tracking_data.items()]\
            + [[deadline(cr, 2) if pr == 'Critical' else deadline(cr, 1) for cr, pr
                in zip(self.created_dict, self.tracking_data['Priority'])]]
        data = [
            go.Table(domain=dict(x=[0, 1], y=[0, 0.7]),
                     columnorder=[1, 2, 3, 4, 5, 6, 7, 8, 9],
                     columnwidth=[3, 10, 3, 2, 2, 2, 2, 2, 2.5],
                     header=dict(values=header_values,
                                 fill=dict(color=['grey']),
                                 font=dict(color='white'),
                                 line=dict(width=1, color='grey'),
                                 align='center'),
                     cells=dict(
                         values=cells_values,
                         align=[
                             'center', 'left', 'center', 'center', 'center',
                             'center', 'center'
                         ],
                         fill=dict(color=alert_action(
                             keys=self.tracking_data['Key'],
                             days=self.tracking_data['Days in progress'],
                             priorities=self.tracking_data['Priority'],
                             olds=self.old_list)),
                         height=25,
                         line=dict(width=1, color='grey'))),
            go.Bar(x=list(self.pivot_data.keys()),
                   y=[value['On track'] for value in self.pivot_data.values()],
                   xaxis='x1',
                   yaxis='y1',
                   name='On track',
                   showlegend=False,
                   text=list(
                       map(lambda el: 'On track: <b>{}</b> '.format(el), [
                           value['On track']
                           for value in self.pivot_data.values()
                       ])),
                   textposition='inside',
                   marker=dict(color='rgb(163,204,163)',
                               line=dict(color='grey', width=1))),
            go.Bar(x=list(self.pivot_data.keys()),
                   y=[value['Overdue'] for value in self.pivot_data.values()],
                   xaxis='x1',
                   yaxis='y1',
                   name='Overdue',
                   showlegend=False,
                   text=list(
                       map(
                           lambda el, link:
                           '<a href = "{}">Overdue: <b>{}</b> </a>'.format(
                               link, el), [
                                   value['Overdue']
                                   for value in self.pivot_data.values()
                               ], self.overdue_data.values())),
                   textposition='outside',
                   marker=dict(color='rgb(255,204,204)',
                               line=dict(color='grey', width=1))),
            go.Bar(x=list(self.all_bugs.keys()),
                   y=[value['On track'] for value in self.all_bugs.values()],
                   xaxis='x2',
                   yaxis='y2',
                   name='On track',
                   showlegend=False,
                   text=list(
                       map(lambda el: 'On track: <b>{}</b> '.format(el), [
                           value['On track']
                           for value in self.all_bugs.values()
                       ])),
                   textposition='inside',
                   marker=dict(color='rgb(163,204,163)',
                               line=dict(color='grey', width=1))),
            go.Bar(
                x=list(self.all_bugs.keys()),
                y=[value['Overdue'] for value in self.all_bugs.values()],
                xaxis='x2',
                yaxis='y2',
                name='Overdue',
                showlegend=False,
                text=list(
                    map(
                        lambda el: '<a href = "{}">Overdue: <b>{}</b> </a>'.
                        format(self.jql_all, el),
                        [value['Overdue']
                         for value in self.all_bugs.values()])),
                textposition='outside',
                marker=dict(color='rgb(255,204,204)',
                            line=dict(color='grey', width=1)))
        ]

        title = self.dashboard_name
        html_file = '//billing.ru/dfs/incoming/ABryntsev/' + "{0}.html".format(
            title)

        axis = dict()
        max_dmn = max([sum(pd.values()) for pd in self.pivot_data.values()])
        max_all = max([sum(pd.values()) for pd in self.all_bugs.values()])
        layout = go.Layout(
            hovermode='closest',
            plot_bgcolor='white',
            title=dict(
                text='<b>{} ({})</b>'.format(
                    title,
                    datetime.datetime.now().strftime("%d.%m.%y %H:%M")) +
                ('<sup> in cloud</sup>' if self.repository == 'online' else '')
                + '<br><i>SLA: Blockers - 1 day, Criticals - 2 days</i>',
                x=0.5),
            font=dict(family='Oswald, sans-serif', size=12),
            shapes=[
                dict(type='rect',
                     xref='paper',
                     yref='paper',
                     x0=0,
                     y0=0.72,
                     x1=0.88,
                     y1=1,
                     line=dict(color='rgb(0,0,0)', width=0.5)),
                dict(type='rect',
                     xref='paper',
                     yref='paper',
                     x0=0.89,
                     y0=0.72,
                     x1=1,
                     y1=1,
                     line=dict(color='rgb(0,0,0)', width=0.5))
            ],
            xaxis1=dict(
                axis,
                **dict(showline=True,
                       domain=[0.02, 0.86],
                       anchor='y1',
                       linecolor='black',
                       showgrid=False)),
            yaxis1=dict(axis,
                        **dict(showline=True,
                               domain=[0.75, 0.97],
                               anchor='x1',
                               gridcolor='rgb(232,232,232)',
                               ticks='outside',
                               ticklen=5,
                               tickcolor='rgba(0,0,0,0)'),
                        range=[0, 1.1 * max_dmn]),
            xaxis2=dict(
                axis,
                **dict(showline=True,
                       domain=[0.91, 0.98],
                       anchor='y2',
                       linecolor='black',
                       showgrid=False)),
            yaxis2=dict(axis,
                        **dict(showline=True,
                               domain=[0.75, 0.97],
                               anchor='x2',
                               gridcolor='rgb(232,232,232)',
                               ticks='outside',
                               ticklen=5,
                               tickcolor='rgba(0,0,0,0)'),
                        range=[0, 1.1 * max_all]),
            barmode='stack')

        fig = go.Figure(data=data, layout=layout)
        if self.repository == 'offline':
            plotly.offline.plot(fig,
                                filename=html_file,
                                auto_open=self.auto_open)
        elif self.repository == 'citrix':
            plotly.offline.plot(fig,
                                image_filename=title,
                                image='png',
                                image_height=1080,
                                image_width=1920)
            plotly.offline.plot(fig,
                                filename=html_file,
                                auto_open=self.auto_open)
            time.sleep(5)
            shutil.move(
                'C:/Users/{}/Downloads/{}.png'.format(self.local_user, title),
                './files/{}.png'.format(title))
            citrix = CitrixShareFile(
                hostname=self.citrix_token['hostname'],
                client_id=self.citrix_token['client_id'],
                client_secret=self.citrix_token['client_secret'],
                username=self.citrix_token['username'],
                password=self.citrix_token['password'])
            citrix.upload_file(
                folder_id='fofd8511-6564-44f3-94cb-338688544aac',
                local_path='./files/{}.png'.format(title))
            citrix.upload_file(
                folder_id='fofd8511-6564-44f3-94cb-338688544aac',
                local_path=html_file)
    def export_to_plotly(self):
        trace_dict, xticks = {label: [] for label in self.all_spent.keys()}, {}
        for label in self.all_spent.keys():
            xticks[label] = [self.start_date]
            while xticks[label][-1] != self.end_date[label]:
                xticks[label].append(xticks[label][-1] +
                                     datetime.timedelta(days=1))
            trace_dict[label].append(
                go.Scatter(x=list(self.all_spent[label].keys()),
                           y=list(self.all_spent[label].values()),
                           name='Spent',
                           mode='lines+markers',
                           line=dict(
                               width=2,
                               color='rgb(31,119,180)',
                           ),
                           marker=dict(
                               size=1,
                               color='rgb(31,119,180)',
                           ),
                           showlegend=True if label == list(
                               self.all_spent.keys())[0] else False))
            trace_dict[label].append(
                go.Scatter(x=list(self.all_remain[label].keys()),
                           y=list(self.all_remain[label].values()),
                           name='Remain',
                           mode='lines+markers',
                           line=dict(
                               width=2,
                               color='rgb(255,127,14)',
                           ),
                           marker=dict(
                               size=1,
                               color='rgb(255,127,14)',
                           ),
                           showlegend=True if label == list(
                               self.all_spent.keys())[0] else False))
            try:
                trace_dict[label].append(
                    go.Scatter(
                        x=[
                            min(self.all_remain[label].keys()),
                            self.end_date[label]
                        ],
                        y=[
                            max([
                                math.fabs(rmn)
                                for rmn in self.all_remain[label].values()
                            ]), 0
                        ],
                        name='',
                        mode='lines',
                        line=dict(color='rgb(200,200,200)',
                                  width=2,
                                  dash='dash'),
                        showlegend=False))
            except ValueError:
                pass
        cols = math.ceil(len(self.all_spent.keys()) / 2)
        fig = subplots.make_subplots(rows=2,
                                     cols=cols,
                                     subplot_titles=list(
                                         self.all_spent.keys()))
        for traces, i, label in zip(trace_dict.values(),
                                    range(len(trace_dict.keys())),
                                    trace_dict.keys()):
            row, col = int(i // cols + 1), int(i % cols + 1)
            for trace in traces:
                fig.append_trace(trace, row, col)
            xaxis, yaxis = 'xaxis{}'.format(i + 1), 'yaxis{}'.format(i + 1)
            fig["layout"][xaxis].update(
                linecolor='black',
                type='date',
                dtick=86400000,
                showline=True,
                showticklabels=True,
                showgrid=False,
                tickvals=xticks[label],
                ticktext=[
                    xticks[label][i].strftime('%d.%m.%y') if not i % 10 else ''
                    for i in range(len(xticks[label]))
                ],
                autorange=True)
            fig["layout"][yaxis].update(linecolor='black',
                                        showline=True,
                                        gridcolor='rgb(232,232,232)',
                                        autorange=True)

        title = '{} specific works'.format(self.dashboard_name)
        # html_file = self.png_dir + "{0}.html".format(title)
        html_file = '//billing.ru/dfs/incoming/ABryntsev/' + "{0}.html".format(
            title)

        fig['layout']['title'].update(text='{0} as of {1}'.format(
            title,
            datetime.datetime.now().strftime("%d.%m.%y %H:%M")),
                                      x=0.5)
        fig["layout"].update(hovermode='closest',
                             legend=dict(orientation='h'),
                             plot_bgcolor='white')
        for annotation in fig['layout']['annotations']:
            annotation['font'] = dict(size=14)

        if self.repository == 'offline':
            plotly.offline.plot(fig,
                                filename=html_file,
                                auto_open=self.auto_open)
        elif self.repository == 'citrix':
            plotly.offline.plot(fig,
                                image_filename=title,
                                image='png',
                                image_height=1080,
                                image_width=1920)
            plotly.offline.plot(fig,
                                filename=html_file,
                                auto_open=self.auto_open)
            time.sleep(5)
            shutil.move(
                'C:/Users/{}/Downloads/{}.png'.format(self.local_user, title),
                './files/{}.png'.format(title))
            citrix = CitrixShareFile(
                hostname=self.citrix_token['hostname'],
                client_id=self.citrix_token['client_id'],
                client_secret=self.citrix_token['client_secret'],
                username=self.citrix_token['username'],
                password=self.citrix_token['password'])
            citrix.upload_file(
                folder_id='fofd8511-6564-44f3-94cb-338688544aac',
                local_path='./files/{}.png'.format(title))
            citrix.upload_file(
                folder_id='fofd8511-6564-44f3-94cb-338688544aac',
                local_path=html_file)
    def export_to_plotly(self):
        if len(self.name_list) == 0:
            raise ValueError('There is no issues to show')

        trace_avg = go.Bar(x=list(self.days_dict.keys()),
                           y=self.average_list,
                           text=self.average_list,
                           name='average',
                           textposition='auto',
                           marker=dict(
                               color='rgb(126,135,215)',
                               line=dict(color='black', width=1),
                           ),
                           insidetextfont=dict(family='sans-serif',
                                               size=18,
                                               color='white'))
        trace_median = go.Bar(x=list(self.days_dict.keys()),
                              y=self.median_list,
                              text=self.median_list,
                              name='median',
                              textposition='auto',
                              marker=dict(
                                  color='rgb(254,210,92)',
                                  line=dict(color='black', width=1),
                              ),
                              insidetextfont=dict(family='sans-serif',
                                                  size=18,
                                                  color='black'))

        trace_max = go.Bar(x=list(self.days_dict.keys()),
                           y=self.max_list,
                           text=self.max_list,
                           name='max',
                           textposition='auto',
                           marker=dict(
                               color='pink',
                               line=dict(color='black', width=1),
                           ),
                           insidetextfont=dict(family='sans-serif',
                                               size=18,
                                               color='black'))
        traces = [trace_median, trace_avg]

        plan_fact_str = "pf"

        title = self.dashboard_name + (self.priority.strip() if self.labels == '' else 'Showstoppers')\
            + (' created by QC' if self.creators != '' else '')
        file_name = title + ' ' + plan_fact_str
        # html_file = self.png_dir + "{0}.html".format(file_name)
        html_file = '//billing.ru/dfs/incoming/ABryntsev/' + "{0}.html".format(
            title)

        annotations = [
            dict(x=1.05,
                 y=1.03,
                 xref='paper',
                 yref='paper',
                 text='Duration',
                 showarrow=False,
                 font=dict(family='sans-serif', size=16, color='black'))
        ]
        for i in range(len(self.days_dict.keys())):
            annotations.append(
                dict(x=list(self.days_dict.keys())[i],
                     y=self.average_list[i] + max(self.average_list) / 20,
                     xref='x',
                     yref='y',
                     text='Bugs number: <b>' + str(self.count_list[i]) +
                     '</b><br>Max duration: <b>' + str(self.max_list[i]) +
                     '</b>',
                     showarrow=False,
                     font=dict(family='sans-serif', size=16, color='black'),
                     bordercolor='black',
                     borderwidth=1,
                     borderpad=5,
                     bgcolor='white',
                     opacity=1))
        layout = go.Layout(
            annotations=annotations,
            legend=dict(x=1,
                        y=1,
                        traceorder='normal',
                        font=dict(family='sans-serif', size=16, color='#000')),
            showlegend=True,
            margin=dict(t=50, b=50, r=100, l=36),
            autosize=True,
            font=dict(size=12, color='black'),
            barmode='group',
            title=title +
            (' <sup>in cloud</sup>' if self.repository == 'online' else ''),
            plot_bgcolor='white',
            yaxis=dict(
                rangemode="tozero",
                autorange=True,
                showgrid=True,
                zeroline=True,
                showline=True,
                ticks='',
                showticklabels=True,
                tickangle=0,
                title='Days between creation and resolution',
                titlefont=dict(family='sans-serif', size=12, color='black'),
                # title=dict(
                #     text='Days between creation and resolution',
                #     font=dict(
                #         family='sans-serif',
                #         size=12,
                #         color='black'
                #     )
                # ),
                tickfont=dict(family='sans-serif', size=16, color='black'),
            ),
            xaxis=dict(
                rangemode="tozero",
                autorange=True,
                showgrid=True,
                zeroline=True,
                showline=True,
                ticks='',
                tickangle=0,
                showticklabels=True,
                tickfont=dict(family='sans-serif', size=16, color='black'),
                title='Domains',
                titlefont=dict(family='sans-serif', size=12, color='black')
                # title=dict(
                #     text='Domains',
                #     font=dict(
                #         family='sans-serif',
                #         size=12,
                #         color='black'
                #     )
                # )
            ))

        fig = go.Figure(data=traces, layout=layout)
        if self.repository == 'offline':
            plotly.offline.plot(fig,
                                filename=html_file,
                                auto_open=self.auto_open)
        elif self.repository == 'citrix':
            plotly.offline.plot(fig,
                                image_filename=title,
                                image='png',
                                image_height=1080,
                                image_width=1920)
            plotly.offline.plot(fig,
                                filename=html_file,
                                auto_open=self.auto_open)
            time.sleep(5)
            shutil.move(
                'C:/Users/{}/Downloads/{}.png'.format(self.local_user, title),
                './files/{}.png'.format(title))
            citrix = CitrixShareFile(
                hostname=self.citrix_token['hostname'],
                client_id=self.citrix_token['client_id'],
                client_secret=self.citrix_token['client_secret'],
                username=self.citrix_token['username'],
                password=self.citrix_token['password'])
            citrix.upload_file(
                folder_id='fofd8511-6564-44f3-94cb-338688544aac',
                local_path='./files/{}.png'.format(title))
            citrix.upload_file(
                folder_id='fofd8511-6564-44f3-94cb-338688544aac',
                local_path=html_file)
Ejemplo n.º 4
0
    def export_to_plotly(self):
        if len(self.sprint_distribution.keys()) == 0:
            raise ValueError('There is no issues to show')

        data = [
            go.Bar(x=list(self.sprint_distribution.keys()),
                   y=list(self.sprint_distribution.values()),
                   showlegend=False,
                   text=[
                       round(val, 2)
                       for val in list(self.sprint_distribution.values())
                   ],
                   textposition='inside',
                   marker=dict(color='rgba(29,137,49,0.4)',
                               line=dict(color='rgb(29,137,49)', width=2)))
        ]

        title = self.dashboard_name
        html_file = '//billing.ru/dfs/incoming/ABryntsev/' + "{0}.html".format(
            title)

        layout = go.Layout(
            hovermode='closest',
            plot_bgcolor='white',
            title=dict(text='<b>{} as of {}</b>'.format(
                title,
                datetime.datetime.now().strftime("%d.%m.%y %H:%M")),
                       x=0.5),
            xaxis=dict(title='Sprints',
                       automargin=True,
                       tickvals=list(self.sprint_distribution.keys()),
                       linecolor='black',
                       showgrid=False,
                       ticktext=[
                           tick if len(tick) < 16 else '<br>'.join(
                               textwrap.wrap(tick, 17))
                           for tick in list(self.sprint_distribution.keys())
                       ]),
            yaxis=dict(title='Man-days',
                       linecolor='black',
                       gridcolor='rgb(232,232,232)'))

        fig = go.Figure(data=data, layout=layout)
        if self.repository == 'offline':
            plotly.offline.plot(fig,
                                filename=html_file,
                                auto_open=self.auto_open)
        elif self.repository == 'citrix':
            plotly.offline.plot(fig,
                                image_filename=title,
                                image='png',
                                image_height=1080,
                                image_width=1920)
            plotly.offline.plot(fig,
                                filename=html_file,
                                auto_open=self.auto_open)
            time.sleep(5)
            shutil.move(
                'C:/Users/{}/Downloads/{}.png'.format(self.local_user, title),
                './files/{}.png'.format(title))
            citrix = CitrixShareFile(
                hostname=self.citrix_token['hostname'],
                client_id=self.citrix_token['client_id'],
                client_secret=self.citrix_token['client_secret'],
                username=self.citrix_token['username'],
                password=self.citrix_token['password'])
            citrix.upload_file(
                folder_id='fofd8511-6564-44f3-94cb-338688544aac',
                local_path='./files/{}.png'.format(title))
            citrix.upload_file(
                folder_id='fofd8511-6564-44f3-94cb-338688544aac',
                local_path=html_file)
Ejemplo n.º 5
0
    def export_to_plotly(self):
        jira = JIRA(server='https://jira.billing.ru',
                    basic_auth=(self.user, self.password))

        date, end, dates, xaxis = datetime.datetime.strptime(self.start_date, '%d.%m.%y').date(),\
            datetime.datetime.strptime(self.end_date, '%d.%m.%y').date(), [], []
        while date <= end:
            if date <= datetime.datetime.now().date():
                dates.append(date)
            xaxis.append(date)
            date += datetime.timedelta(days=7)

        bugs = self.upload_bugs(jira=jira, dates=dates)
        readiness, count_dict, done_dict = self.upload_sprint(
            jira=jira, sprint=self.sprint, dates=dates)

        data = [
            go.Scatter(x=list(readiness.keys()),
                       y=list(readiness.values()),
                       name='Readiness',
                       xaxis='x1',
                       yaxis='y1',
                       text=list(readiness.values()),
                       textposition='top left',
                       mode='lines+markers+text',
                       line=dict(width=2, color='rgb(158,244,82)'),
                       marker=dict(size=5, color='rgb(158,244,82)'),
                       showlegend=False),
            go.Bar(x=list(bugs.keys()),
                   y=list(bugs.values()),
                   name='Bugs',
                   xaxis='x2',
                   yaxis='y2',
                   text=list(bugs.values()),
                   textposition='inside',
                   marker=dict(color='rgba(97,100,223,0.4)',
                               line=dict(color='rgb(97,100,223)', width=2)),
                   showlegend=False),
            go.Bar(x=list(done_dict.keys()),
                   y=list(done_dict.values()),
                   name='Done count',
                   xaxis='x3',
                   yaxis='y3',
                   text=list(done_dict.values()),
                   textposition='inside',
                   marker=dict(color='rgba(82,162,218,0.4)',
                               line=dict(color='rgb(82,162,218)', width=2)),
                   showlegend=False),
            go.Scatter(x=list(count_dict.keys()),
                       y=list(count_dict.values()),
                       name='Total count',
                       xaxis='x4',
                       yaxis='y4',
                       text=list(count_dict.values()),
                       textposition='top left',
                       mode='lines+markers+text',
                       line=dict(width=2, color='rgb(75,223,156)'),
                       marker=dict(size=5, color='rgb(75,223,156)'),
                       showlegend=False)
        ]

        title = self.dashboard_name
        layout = go.Layout(
            hovermode='closest',
            plot_bgcolor='white',
            title=dict(text=title, x=0.5),
            xaxis1=dict(showline=True,
                        domain=[0, 0.45],
                        anchor='y1',
                        type='date',
                        dtick=604800000,
                        title='Dates',
                        range=[
                            xaxis[0] - timedelta(days=3),
                            xaxis[-1] + timedelta(days=3)
                        ],
                        tickvals=xaxis,
                        ticktext=[
                            datetime.datetime.strftime(tick, '%d.%m.%y')
                            for tick in xaxis
                        ],
                        ticks='outside',
                        ticklen=5,
                        tickcolor='rgba(0,0,0,0)',
                        linecolor='black',
                        gridcolor='rgb(232,232,232)'),
            xaxis2=dict(showline=True,
                        domain=[0.55, 1],
                        anchor='y2',
                        type='date',
                        dtick=604800000,
                        title='Dates',
                        range=[
                            xaxis[0] - timedelta(days=7),
                            xaxis[-1] + timedelta(days=7)
                        ],
                        tickvals=xaxis,
                        ticktext=[
                            datetime.datetime.strftime(tick, '%d.%m.%y')
                            for tick in xaxis
                        ],
                        ticks='outside',
                        ticklen=5,
                        tickcolor='rgba(0,0,0,0)',
                        linecolor='black',
                        gridcolor='rgb(232,232,232)'),
            xaxis3=dict(showline=True,
                        domain=[0, 0.45],
                        anchor='y3',
                        type='date',
                        dtick=604800000,
                        title='Dates',
                        range=[
                            xaxis[0] - timedelta(days=7),
                            xaxis[-1] + timedelta(days=7)
                        ],
                        tickvals=xaxis,
                        ticktext=[
                            datetime.datetime.strftime(tick, '%d.%m.%y')
                            for tick in xaxis
                        ],
                        ticks='outside',
                        ticklen=5,
                        tickcolor='rgba(0,0,0,0)',
                        linecolor='black',
                        gridcolor='rgb(232,232,232)'),
            xaxis4=dict(showline=True,
                        domain=[0.55, 1],
                        anchor='y4',
                        type='date',
                        dtick=604800000,
                        title='Dates',
                        range=[
                            xaxis[0] - timedelta(days=3),
                            xaxis[-1] + timedelta(days=3)
                        ],
                        tickvals=xaxis,
                        ticktext=[
                            datetime.datetime.strftime(tick, '%d.%m.%y')
                            for tick in xaxis
                        ],
                        ticks='outside',
                        ticklen=5,
                        tickcolor='rgba(0,0,0,0)',
                        linecolor='black',
                        gridcolor='rgb(232,232,232)'),
            yaxis1=dict(domain=[0.55, 1],
                        title='Sprint scope readiness, %',
                        showline=True,
                        anchor='x1',
                        ticks='outside',
                        ticklen=5,
                        tickcolor='rgba(0,0,0,0)',
                        linecolor='black',
                        gridcolor='rgb(232,232,232)',
                        range=[0, 105]),
            yaxis2=dict(domain=[0.55, 1],
                        title='Count of closed and resolved bugs',
                        showline=True,
                        anchor='x2',
                        ticks='outside',
                        ticklen=5,
                        tickcolor='rgba(0,0,0,0)',
                        linecolor='black',
                        gridcolor='rgb(232,232,232)'),
            yaxis3=dict(domain=[0, 0.45],
                        title='Count of closed and resolved issues',
                        showline=True,
                        anchor='x3',
                        ticks='outside',
                        ticklen=5,
                        tickcolor='rgba(0,0,0,0)',
                        linecolor='black',
                        gridcolor='rgb(232,232,232)'),
            yaxis4=dict(domain=[0, 0.45],
                        title='Count of issues in sprint scope',
                        showline=True,
                        anchor='x4',
                        ticks='outside',
                        ticklen=5,
                        tickcolor='rgba(0,0,0,0)',
                        linecolor='black',
                        gridcolor='rgb(232,232,232)'))

        html_file = '//billing.ru/dfs/incoming/ABryntsev/{}.html'.format(title)
        fig = go.Figure(data=data, layout=layout)
        if self.repository == 'offline':
            plotly.offline.plot(fig,
                                filename=html_file,
                                auto_open=self.auto_open)
        elif self.repository == 'citrix':
            plotly.offline.plot(fig,
                                image_filename=title,
                                image='png',
                                image_height=1080,
                                image_width=1920)
            plotly.offline.plot(fig,
                                filename=html_file,
                                auto_open=self.auto_open)
            time.sleep(5)
            shutil.move(
                'C:/Users/{}/Downloads/{}.png'.format(self.local_user, title),
                './files/{}.png'.format(title))
            citrix = CitrixShareFile(
                hostname=self.citrix_token['hostname'],
                client_id=self.citrix_token['client_id'],
                client_secret=self.citrix_token['client_secret'],
                username=self.citrix_token['username'],
                password=self.citrix_token['password'])
            citrix.upload_file(
                folder_id='fofd8511-6564-44f3-94cb-338688544aac',
                local_path='./files/{}.png'.format(title))
            citrix.upload_file(
                folder_id='fofd8511-6564-44f3-94cb-338688544aac',
                local_path=html_file)
    def export_to_plotly(self):
        if len(self.feature_dict.keys()) == 0:
            raise ValueError('There is no issues to show')

        for pt, estimates, spents, info, dd, readiness in zip(
                self.feature_dict.keys(), self.feature_dict.values(),
                self.spent_dict.values(), self.info.values(),
                self.due_dates.values(), self.readiness_dict.values()):
            estimates = {
                key: value
                for key, value in zip(reversed(list(estimates.keys())),
                                      reversed(list(estimates.values())))
            }
            spents = {
                key: value
                for key, value in zip(reversed(list(spents.keys())),
                                      reversed(list(spents.values())))
            }
            info = list(reversed(info))
            dd = {
                key: value
                for key, value in zip(reversed(list(dd.keys())),
                                      reversed(list(dd.values())))
            }
            readiness = {
                key: value
                for key, value in zip(reversed(list(readiness.keys())),
                                      reversed(list(readiness.values())))
            }
            print(info)
            data, base = [], [0] * len(spents.keys())
            for dmn in estimates[list(estimates.keys())[0]].keys():
                spent_color, due_color = [], []
                for ft in list(spents.keys()):
                    if dmn in self.wrong_estimates[ft]:
                        spent_color.append('rgba(222,110,110,0.6)')
                    else:
                        spent_color.append('rgba(200,200,200,0.6)')
                for d, ft in zip(dd.values(), readiness.keys()):
                    if len(d[dmn]) == 0:
                        if readiness[ft][dmn] < 1:
                            due_color.append('rgb(230,0,0)')
                        else:
                            due_color.append('rgb(0,0,0)')
                    else:
                        if max(d[dmn]) > self.end_date:
                            due_color.append('rgb(230,0,0)')
                        elif max(d[dmn]) < datetime.now().date():
                            if readiness[ft][dmn] < 1:
                                due_color.append('rgb(230,0,0)')
                            else:
                                due_color.append('rgb(0,0,0)')
                        else:
                            due_color.append('rgb(0,0,0)')
                data.append(
                    go.Bar(
                        orientation='h',
                        y=list(estimates.keys()),
                        x=[est[dmn] for est in estimates.values()],
                        name=dmn,
                        showlegend=False,
                        # text=[dmn]*len(estimates.keys()),
                        text=[
                            dmn + ': {}'.format(max(d[dmn]).strftime('%d.%m'))
                            if len(d[dmn]) > 0 else dmn + ': empty'
                            for d in dd.values()
                        ],
                        textposition='inside',
                        insidetextfont=dict(color=due_color),
                        marker=dict(color='rgb(250,250,250)',
                                    opacity=0.5,
                                    line=dict(color='rgb(0,0,0)', width=2)),
                        base=base,
                        offset=-0.4,
                        width=0.8))
                data.append(
                    go.Bar(orientation='h',
                           y=list(spents.keys()),
                           x=[spent[dmn] for spent in spents.values()],
                           name=dmn,
                           showlegend=False,
                           text='',
                           textposition='inside',
                           marker=dict(color=spent_color),
                           base=base,
                           offset=-0.39,
                           width=0.78))
                base = [
                    bs + cnt for bs, cnt in zip(
                        base, [est[dmn] for est in estimates.values()])
                ]

            title = '{} Features ({})'.format(self.dashboard_name, pt)
            # html_file = self.png_dir + "{0}.html".format(title)
            html_file = '//billing.ru/dfs/incoming/ABryntsev/' + "{0}.html".format(
                title)

            for el in [
                    '<a href="https://jira.billing.ru/browse/{0}">{0}</a>{1}'.
                    format(key, inf)
                    for key, inf in zip(list(estimates.keys()), info)
            ]:
                print(el)

            layout = dict(
                title=dict(text='<b>{0} as of {1}</b>'.format(
                    title,
                    datetime.now().strftime("%d.%m.%y %H:%M")) +
                           (' <sup>in cloud</sup>'
                            if self.repository == 'online' else ''),
                           x=0.5),
                yaxis=dict(
                    automargin=True,
                    tickvals=list(estimates.keys()),
                    ticktext=[
                        '<a href="https://jira.billing.ru/browse/{0}">{0}</a>{1}'
                        .format(key, inf)
                        for key, inf in zip(list(estimates.keys()), info)
                    ],
                    ticks='outside',
                    ticklen=10,
                    tickcolor='rgba(0,0,0,0)',
                    tickfont=dict(size=10),
                    linecolor='black',
                    gridcolor='rgb(232,232,232)'),
                xaxis=dict(linecolor='black', gridcolor='rgb(232,232,232)'),
                hovermode='closest',
                plot_bgcolor='white')

            fig = go.Figure(data=data, layout=layout)
            if self.repository == 'offline':
                plotly.offline.plot(fig,
                                    filename=html_file,
                                    auto_open=self.auto_open)
            elif self.repository == 'citrix':
                plotly.offline.plot(fig,
                                    image_filename=title,
                                    image='png',
                                    image_height=1080,
                                    image_width=1920)
                plotly.offline.plot(fig,
                                    filename=html_file,
                                    auto_open=self.auto_open)
                time.sleep(5)
                shutil.move(
                    'C:/Users/{}/Downloads/{}.png'.format(
                        self.local_user, title),
                    './files/{}.png'.format(title))
                citrix = CitrixShareFile(
                    hostname=self.citrix_token['hostname'],
                    client_id=self.citrix_token['client_id'],
                    client_secret=self.citrix_token['client_secret'],
                    username=self.citrix_token['username'],
                    password=self.citrix_token['password'])
                citrix.upload_file(
                    folder_id='fofd8511-6564-44f3-94cb-338688544aac',
                    local_path='./files/{}.png'.format(title))
                citrix.upload_file(
                    folder_id='fofd8511-6564-44f3-94cb-338688544aac',
                    local_path=html_file)
    def export_to_plotly(self):
        if len(self.all_spent.keys()) == 0:
            raise ValueError('There is no issues to show')

        data = [
            go.Scatter(
                x=list(self.all_spent.keys()),
                y=list(self.all_spent.values()),
                xaxis='x1',
                yaxis='y1',
                name='Spent',
                text=[str(round(sp, 1)) for sp in self.all_spent.values()],
                textposition='top left',
                textfont=dict(size=8),
                mode='lines+markers+text',
                line=dict(width=2, color='rgb(31,119,180)', dash='dash'),
                marker=dict(
                    size=5,
                    color='rgb(31,119,180)',
                )),
            go.Scatter(
                x=list(self.all_remain.keys()),
                y=list(self.all_remain.values()),
                xaxis='x1',
                yaxis='y1',
                name='Remain',
                text=[str(round(sp, 1)) for sp in self.all_remain.values()],
                textposition='top right',
                textfont=dict(size=8),
                mode='lines+markers+text',
                line=dict(
                    width=2,
                    color='rgb(31,119,180)',
                ),
                marker=dict(
                    size=5,
                    color='rgb(31,119,180)',
                )),
            go.Scatter(x=[self.start_date, self.end_date],
                       y=[max(self.all_remain.values()), 0],
                       xaxis='x1',
                       yaxis='y1',
                       name='',
                       mode='lines',
                       line=dict(color='rgba(31,119,180,0.4)',
                                 width=1,
                                 dash='dot'),
                       showlegend=False),
            go.Scatter(
                x=list(self.pp1_all_spent.keys()),
                y=list(self.pp1_all_spent.values()),
                xaxis='x1',
                yaxis='y1',
                name='Spent (Pilot 1.0)',
                text=[str(round(sp, 1)) for sp in self.pp1_all_spent.values()],
                textposition='top left',
                textfont=dict(size=8),
                mode='lines+markers+text',
                line=dict(width=2, color='rgb(255,127,14)', dash='dash'),
                marker=dict(
                    size=5,
                    color='rgb(255,127,14)',
                )),
            go.Scatter(x=list(self.pp1_all_remain.keys()),
                       y=list(self.pp1_all_remain.values()),
                       xaxis='x1',
                       yaxis='y1',
                       name='Remain (Pilot 1.0)',
                       text=[
                           str(round(sp, 1))
                           for sp in self.pp1_all_remain.values()
                       ],
                       textposition='top right',
                       textfont=dict(size=8),
                       mode='lines+markers+text',
                       line=dict(
                           width=2,
                           color='rgb(255,127,14)',
                       ),
                       marker=dict(
                           size=5,
                           color='rgb(255,127,14)',
                       )),
            go.Scatter(
                x=list(self.pp2_all_spent.keys()),
                y=list(self.pp2_all_spent.values()),
                xaxis='x1',
                yaxis='y1',
                name='Spent (Pilot 2.0)',
                text=[str(round(sp, 1)) for sp in self.pp2_all_spent.values()],
                textposition='top left',
                textfont=dict(size=8),
                mode='lines+markers+text',
                line=dict(width=2, color='rgb(0,204,150)', dash='dash'),
                marker=dict(
                    size=5,
                    color='rgb(0,204,150)',
                )),
            go.Scatter(x=list(self.pp2_all_remain.keys()),
                       y=list(self.pp2_all_remain.values()),
                       xaxis='x1',
                       yaxis='y1',
                       name='Remain (Pilot 2.0)',
                       text=[
                           str(round(sp, 1))
                           for sp in self.pp2_all_remain.values()
                       ],
                       textposition='top right',
                       textfont=dict(size=8),
                       mode='lines+markers+text',
                       line=dict(
                           width=2,
                           color='rgb(0,204,150)',
                       ),
                       marker=dict(
                           size=5,
                           color='rgb(0,204,150)',
                       ))
        ]

        try:
            data.append(
                go.Scatter(x=[self.start_date, self.end_date],
                           y=[max(self.pp1_all_remain.values()), 0],
                           xaxis='x1',
                           yaxis='y1',
                           name='',
                           mode='lines',
                           line=dict(color='rgba(255,127,14,0.4)',
                                     width=1,
                                     dash='dot'),
                           showlegend=False))
        except ValueError:
            pass

        try:
            data.append(
                go.Scatter(x=[self.start_date, self.end_date],
                           y=[max(self.pp2_all_remain.values()), 0],
                           xaxis='x1',
                           yaxis='y1',
                           name='',
                           mode='lines',
                           line=dict(color='rgba(0,204,150,0.4)',
                                     width=1,
                                     dash='dot'),
                           showlegend=False))
        except ValueError:
            pass

        title = self.dashboard_name
        # html_file = self.png_dir + "{0}.html".format(title)
        html_file = '//billing.ru/dfs/incoming/ABryntsev/' + "{0}.html".format(
            title)

        layout = go.Layout(
            hovermode='closest',
            plot_bgcolor='white',
            xaxis1=dict(linecolor='black',
                        gridcolor='rgb(232,232,232)',
                        anchor='y1',
                        type='date',
                        dtick=86400000,
                        title='Date',
                        titlefont=dict(size=12),
                        tickfont=dict(size=16),
                        tickangle=45,
                        showline=True,
                        range=[
                            self.start_date - datetime.timedelta(days=1),
                            self.end_date + datetime.timedelta(days=1)
                        ]),
            yaxis1=dict(linecolor='black',
                        gridcolor='rgb(232,232,232)',
                        anchor='x1',
                        showline=True,
                        title='Man-days',
                        titlefont=dict(size=12),
                        tickfont=dict(size=16),
                        range=[0, max(self.all_remain.values()) + 100]),
            title=dict(
                text=title +
                '<br><b>Total ({} features):</b> spent - {} md, original estimate - {} md. <b>Readiness:</b> {}%'
                .format(*map(round, [
                    self.readiness['features'], self.readiness['spent'], self.
                    readiness['original estimate'], self.readiness['spent'] /
                    self.readiness['original estimate'] *
                    100 if self.readiness['spent'] <= self.
                    readiness['original estimate'] else 100
                ])) +
                '<br><b>Pilot 1.0 ({} features):</b> spent - {} md, original estimate - {} md. <b>Readiness:</b> {}%'
                .format(*map(round, [
                    self.pp1_readiness['features'],
                    self.pp1_readiness['spent'],
                    self.pp1_readiness['original estimate'],
                    (self.pp1_readiness['spent'] /
                     self.pp1_readiness['original estimate'] *
                     100 if self.pp1_readiness['spent'] <= self.
                     pp1_readiness['original estimate'] else 100
                     ) if self.pp1_readiness['original estimate'] else 0
                ])) +
                '<br><b>Pilot 2.0 ({} features):</b> spent - {} md, original estimate - {} md. <b>Readiness:</b> {}%'
                .format(*map(round, [
                    self.pp2_readiness['features'],
                    self.pp2_readiness['spent'],
                    self.pp2_readiness['original estimate'],
                    (self.pp2_readiness['spent'] /
                     self.pp2_readiness['original estimate'] *
                     100 if self.pp2_readiness['spent'] <= self.
                     pp2_readiness['original estimate'] else 100
                     ) if self.pp2_readiness['original estimate'] else 0
                ])),
                x=0.5),
            legend=dict(orientation='h'))

        fig = go.Figure(data=data, layout=layout)
        if self.repository == 'offline':
            plotly.offline.plot(fig,
                                filename=html_file,
                                auto_open=self.auto_open)
        elif self.repository == 'citrix':
            plotly.offline.plot(fig,
                                image_filename=title,
                                image='png',
                                image_height=1080,
                                image_width=1920)
            plotly.offline.plot(fig,
                                filename=html_file,
                                auto_open=self.auto_open)
            time.sleep(5)
            shutil.move(
                'C:/Users/{}/Downloads/{}.png'.format(self.local_user, title),
                './files/{}.png'.format(title))
            citrix = CitrixShareFile(
                hostname=self.citrix_token['hostname'],
                client_id=self.citrix_token['client_id'],
                client_secret=self.citrix_token['client_secret'],
                username=self.citrix_token['username'],
                password=self.citrix_token['password'])
            citrix.upload_file(
                folder_id='fofd8511-6564-44f3-94cb-338688544aac',
                local_path='./files/{}.png'.format(title))
            citrix.upload_file(
                folder_id='fofd8511-6564-44f3-94cb-338688544aac',
                local_path=html_file)
Ejemplo n.º 8
0
    def export_to_plotly(self):
        if len(self.domain_dict.keys()) == 1:
            raise ValueError('There is no issues to show')

        data = []
        for status in self.domain_dict[list(self.domain_dict)[0]].keys():
            data.append(
                go.Bar(orientation='v',
                       x=[dmn for dmn in self.bssbox_dict if dmn != 'BSSBox'],
                       y=[
                           self.bssbox_dict[dmn][status]
                           for dmn in self.bssbox_dict if dmn != 'BSSBox'
                       ],
                       text=[
                           self.bssbox_dict[dmn][status]
                           for dmn in self.bssbox_dict if dmn != 'BSSBox'
                       ],
                       name=status,
                       textposition='auto',
                       marker=dict(color=color_for_status(status),
                                   line=dict(color='black', width=1)),
                       xaxis='x1',
                       yaxis='y1',
                       showlegend=True))
            data.append(
                go.Bar(orientation='v',
                       x=['BSSBox'],
                       y=[self.bssbox_dict['BSSBox'][status]],
                       text=[self.bssbox_dict['BSSBox'][status]],
                       name=status,
                       textposition='auto',
                       marker=dict(color=color_for_status(status),
                                   line=dict(color='black', width=1)),
                       xaxis='x2',
                       yaxis='y2',
                       showlegend=False))
            data.append(
                go.Bar(orientation='v',
                       x=[dmn for dmn in self.domain_dict if dmn != 'Total'],
                       y=[
                           self.domain_dict[dmn][status]
                           for dmn in self.domain_dict if dmn != 'Total'
                       ],
                       text=[
                           self.domain_dict[dmn][status]
                           for dmn in self.domain_dict if dmn != 'Total'
                       ],
                       name=status,
                       textposition='auto',
                       marker=dict(color=color_for_status(status),
                                   line=dict(color='black', width=1)),
                       xaxis='x3',
                       yaxis='y3',
                       showlegend=False))
            data.append(
                go.Bar(orientation='v',
                       x=['Total'],
                       y=[self.domain_dict['Total'][status]],
                       text=[self.domain_dict['Total'][status]],
                       name=status,
                       textposition='auto',
                       marker=dict(color=color_for_status(status),
                                   line=dict(color='black', width=1)),
                       xaxis='x4',
                       yaxis='y4',
                       showlegend=False))

        title = self.dashboard_name
        html_file = '//billing.ru/dfs/incoming/ABryntsev/' + "{0}.html".format(
            title)

        layout = dict(
            hovermode='closest',
            plot_bgcolor='white',
            title=dict(text='<b>{0} as of {1}</b>'.format(
                self.dashboard_name,
                datetime.now().strftime("%d.%m.%y %H:%M")) +
                       (' <sup>in cloud</sup>'
                        if self.repository == 'online' else ''),
                       x=0.5),
            barmode='stack',
            xaxis1=dict(
                domain=[0.065, 0.555],
                anchor='y1',
                ticks='outside',
                ticklen=4,
                tickcolor='rgba(0,0,0,0)',
                automargin=True,
                tickangle=-90,
                showgrid=False,
                linecolor='black',
                tickvals=[dmn for dmn in self.bssbox_dict if dmn != 'BSSBox'],
                ticktext=[
                    dmn if len(dmn) < 8 else '<br>'.join(textwrap.wrap(dmn, 9))
                    for dmn in self.bssbox_dict if dmn != 'BSSBox'
                ]),
            yaxis1=dict(domain=[0, 1],
                        anchor='x1',
                        ticks='outside',
                        ticklen=8,
                        tickcolor='rgba(0,0,0,0)',
                        gridcolor='rgb(232,232,232)'),
            xaxis2=dict(
                domain=[0, 0.035],
                anchor='y2',
                tickangle=-90,
                showgrid=False,
                linecolor='black',
            ),
            yaxis2=dict(domain=[0, 1],
                        anchor='x2',
                        ticks='outside',
                        ticklen=8,
                        tickcolor='rgba(0,0,0,0)',
                        gridcolor='rgb(232,232,232)'),
            xaxis3=dict(
                domain=[0.585, 0.935],
                anchor='y3',
                ticks='outside',
                ticklen=4,
                tickcolor='rgba(0,0,0,0)',
                automargin=True,
                tickangle=-90,
                showgrid=False,
                linecolor='black',
            ),
            yaxis3=dict(domain=[0, 1],
                        anchor='x3',
                        ticks='outside',
                        ticklen=8,
                        tickcolor='rgba(0,0,0,0)',
                        gridcolor='rgb(232,232,232)'),
            xaxis4=dict(domain=[0.965, 1],
                        anchor='y4',
                        tickangle=-90,
                        showgrid=False,
                        linecolor='black'),
            yaxis4=dict(domain=[0, 1],
                        anchor='x4',
                        ticks='outside',
                        ticklen=8,
                        tickcolor='rgba(0,0,0,0)',
                        gridcolor='rgb(232,232,232)'),
            legend=dict(x=0.39, y=1.04, orientation='h'))

        fig = go.Figure(data=data, layout=layout)
        if self.repository == 'offline':
            plotly.offline.plot(fig,
                                filename=html_file,
                                auto_open=self.auto_open)
        elif self.repository == 'citrix':
            plotly.offline.plot(fig,
                                image_filename=title,
                                image='png',
                                image_height=1080,
                                image_width=1920)
            plotly.offline.plot(fig,
                                filename=html_file,
                                auto_open=self.auto_open)
            time.sleep(5)
            shutil.move(
                'C:/Users/{}/Downloads/{}.png'.format(self.local_user, title),
                './files/{}.png'.format(title))
            citrix = CitrixShareFile(
                hostname=self.citrix_token['hostname'],
                client_id=self.citrix_token['client_id'],
                client_secret=self.citrix_token['client_secret'],
                username=self.citrix_token['username'],
                password=self.citrix_token['password'])
            citrix.upload_file(
                folder_id='fofd8511-6564-44f3-94cb-338688544aac',
                local_path='./files/{}.png'.format(title))
            citrix.upload_file(
                folder_id='fofd8511-6564-44f3-94cb-338688544aac',
                local_path=html_file)
Ejemplo n.º 9
0
    def export_to_plotly(self):
        if len(self.status_list) == 0:
            raise ValueError('There is no issues to show')

        bugs_statuses_progress = {
            'Open': [],
            'In Fix': [],
            'Resolved': [],
            'Closed': []
        }
        dates = []
        with open(os.path.abspath(
                '//billing.ru/dfs/incoming/ABryntsev/bugs_progress.csv'),
                  'r',
                  newline='\n') as csvfile:
            data = csv.reader(csvfile, delimiter=';')
            next(data)
            for row in data:
                dates.append(row[0])
                bugs_statuses_progress['Open'].append(row[1])
                bugs_statuses_progress['In Fix'].append(row[2])
                bugs_statuses_progress['Resolved'].append(row[3])
                bugs_statuses_progress['Closed'].append(row[4])
        print(dates, bugs_statuses_progress)
        data = []
        for status in bugs_statuses_progress.keys():
            data.append(
                go.Bar(x=dates,
                       y=bugs_statuses_progress[status],
                       text=bugs_statuses_progress[status],
                       name=status,
                       textposition='auto',
                       marker=dict(color=color_for_status(status),
                                   line=dict(color='black', width=1)),
                       xaxis='x1',
                       yaxis='y1',
                       legendgroup='group1'))
            data.append(
                go.Scatter(x=dates,
                           y=bugs_statuses_progress[status],
                           name=status,
                           text=bugs_statuses_progress[status],
                           textposition='top center',
                           mode='lines+markers+text',
                           line=dict(color=color_for_status(status), width=2),
                           marker=dict(color=color_for_status(status), size=3),
                           xaxis='x2',
                           yaxis='y2',
                           legendgroup='group2'))

        title = self.dashboard_name
        html_file = '//billing.ru/dfs/incoming/ABryntsev/' + "{0}.html".format(
            title)

        layout = go.Layout(
            hovermode='closest',
            plot_bgcolor='white',
            xaxis1=dict(domain=[0, 1],
                        type='date',
                        dtick=86400000,
                        title='Date',
                        anchor='y1',
                        linecolor='black',
                        gridcolor='rgb(232,232,232)'),
            yaxis1=dict(domain=[0.57, 1],
                        anchor='x1',
                        showline=True,
                        title='Number of bugs',
                        linecolor='black',
                        gridcolor='rgb(232,232,232)'),
            xaxis2=dict(
                domain=[0, 1],
                type='date',
                dtick=86400000,
                title='Date',
                anchor='y2',
                # range=[dates[0], dates[-1]]
                autorange=True,
                linecolor='black',
                gridcolor='rgb(232,232,232)'),
            yaxis2=dict(
                range=[0, int(max(bugs_statuses_progress['Open'])) + 50],
                domain=[0, 0.43],
                anchor='x2',
                showline=True,
                title='Number of bugs',
                linecolor='black',
                gridcolor='rgb(232,232,232)'),
            legend=dict(y=0.5),
            barmode='stack',
            title=dict(text=title, x=0.5))

        fig = go.Figure(data=data, layout=layout)
        if self.repository == 'offline':
            plotly.offline.plot(fig,
                                filename=html_file,
                                auto_open=self.auto_open)
        elif self.repository == 'citrix':
            plotly.offline.plot(fig,
                                image_filename=title,
                                image='png',
                                image_height=1080,
                                image_width=1920)
            plotly.offline.plot(fig,
                                filename=html_file,
                                auto_open=self.auto_open)
            time.sleep(5)
            shutil.move(
                'C:/Users/{}/Downloads/{}.png'.format(self.local_user, title),
                './files/{}.png'.format(title))
            citrix = CitrixShareFile(
                hostname=self.citrix_token['hostname'],
                client_id=self.citrix_token['client_id'],
                client_secret=self.citrix_token['client_secret'],
                username=self.citrix_token['username'],
                password=self.citrix_token['password'])
            citrix.upload_file(
                folder_id='fofd8511-6564-44f3-94cb-338688544aac',
                local_path='./files/{}.png'.format(title))
            citrix.upload_file(
                folder_id='fofd8511-6564-44f3-94cb-338688544aac',
                local_path=html_file)
Ejemplo n.º 10
0
    def export_to_plotly(self):
        if len(self.iot_dict[list(self.iot_dict.keys())[0]].keys()) == 0:
            raise ValueError('There is no issues to show')

        data, xtitle = [], {'AEP': None, 'CMP': None}
        for prj, i in zip(self.iot_dict.keys(),
                          range(len(self.iot_dict.keys()))):
            xtitle[prj] = '<b><i>IOT{} Project:</i></b><br>Plan estimate: {}, Fact estimate: {}, Spent time: {}'.\
                format(prj, round(sum([e['Plan estimate'] for epic, e in self.iot_dict[prj].items()
                                       if epic not in set(self.nis)])),
                       round(sum([e['Fact estimate'] for epic, e in self.iot_dict[prj].items()
                                  if epic not in set(self.nis)]), 1),
                       round(sum([e['Spent time'] for e in self.iot_dict[prj].values()])), 1)
            for est in self.iot_dict[prj][list(
                    self.iot_dict[prj].keys())[0]].keys():
                data.append(
                    go.Bar(y=[
                        epic for epic in self.iot_dict[prj].keys()
                        if self.iot_dict[prj][epic]['Spent time'] >= 0
                    ],
                           x=[
                               e[est]
                               for epic, e in self.iot_dict[prj].items()
                               if self.iot_dict[prj][epic]['Spent time'] >= 0
                           ],
                           xaxis='x{}'.format(i + 1),
                           yaxis='y{}'.format(i + 1),
                           orientation='h',
                           name=est,
                           showlegend=True if i == 1 else False,
                           text=[
                               round(e[est], 1)
                               for epic, e in self.iot_dict[prj].items()
                               if self.iot_dict[prj][epic]['Spent time'] >= 0
                           ],
                           textposition='auto',
                           marker=dict(color=color_for_est(est),
                                       line=dict(width=1))))

        title = self.dashboard_name
        # html_file = self.png_dir + "{0}.html".format(title)
        html_file = '//billing.ru/dfs/incoming/ABryntsev/' + "{0}.html".format(
            title)

        axis = dict()
        layout = dict(
            hovermode='closest',
            title='<b>{0} as of {1}</b>'.format(
                self.dashboard_name,
                datetime.datetime.now().strftime("%d.%m.%y %H:%M")) +
            (' <sup>in cloud</sup>' if self.repository == 'online' else ''),
            xaxis1=dict(
                axis,
                **dict(domain=[0, 0.49],
                       anchor='y1',
                       showgrid=True,
                       title=xtitle['AEP'])),
            yaxis1=dict(
                axis,
                **dict(
                    domain=[0, 1],
                    anchor='x1',
                    showline=True,
                    showgrid=True,
                    automargin=True,
                    tickvals=list(self.iot_dict['AEP'].keys()),
                    ticktext=[
                        '<a href="https://jira.billing.ru/browse/{0}">{0}<br></a>'
                        .format(epic) + ('<a href="{}">{}</a>'.format(
                            self.jql_nis['AEP'][epic],
                            ('{}...'.format(text[:25]) if len(text) > 25 else
                             text)) if epic in set(self.nis) else
                                         ('{}...'.format(text[:25])
                                          if len(text) > 25 else text))
                        if epic != 'Empty' else '<a href="{}">{}</a>'.format(
                            self.jql_empty['AEP'], epic) for epic, text in zip(
                                list(self.iot_dict['AEP'].keys()),
                                self.ticktext['AEP'])
                    ]),
                ticks='outside',
                ticklen=10,
                tickcolor='rgba(0,0,0,0)'),
            xaxis2=dict(
                axis,
                **dict(domain=[0.51, 1],
                       anchor='y2',
                       showgrid=True,
                       title=xtitle['CMP'],
                       range=[
                           max([
                               max(e.values())
                               for e in self.iot_dict['CMP'].values()
                           ]), 0
                       ])),
            yaxis2=dict(
                axis,
                **dict(
                    domain=[0, 1],
                    anchor='x2',
                    showline=True,
                    showgrid=True,
                    automargin=True,
                    tickvals=list(self.iot_dict['CMP'].keys()),
                    ticktext=[
                        '<a href="https://jira.billing.ru/browse/{0}">{0}<br></a>'
                        .format(epic) + (('<a href="{}">{}</a>'.format(
                            self.jql_nis['CMP'][epic],
                            ('{}...'.format(text[:25]) if len(text) > 25 else
                             text)) if epic in set(self.nis) else
                                          ('{}...'.format(text[:25])
                                           if len(text) > 25 else text)))
                        if epic != 'Empty' else '<a href="{}">{}</a>'.format(
                            self.jql_empty['CMP'], epic) for epic, text in zip(
                                list(self.iot_dict['CMP'].keys()),
                                self.ticktext['CMP'])
                    ],
                    side='right'),
                ticks='outside',
                ticklen=10,
                tickcolor='rgba(0,0,0,0)'),
            legend=dict(orientation='h', x=0.38, y=1.04))

        fig = go.Figure(data=data, layout=layout)
        if self.repository == 'offline':
            plotly.offline.plot(fig,
                                filename=html_file,
                                auto_open=self.auto_open)
        elif self.repository == 'citrix':
            plotly.offline.plot(fig,
                                image_filename=title,
                                image='png',
                                image_height=1080,
                                image_width=1920)
            plotly.offline.plot(fig,
                                filename=html_file,
                                auto_open=self.auto_open)
            time.sleep(5)
            shutil.move(
                'C:/Users/{}/Downloads/{}.png'.format(self.local_user, title),
                './files/{}.png'.format(title))
            citrix = CitrixShareFile(
                hostname=self.citrix_token['hostname'],
                client_id=self.citrix_token['client_id'],
                client_secret=self.citrix_token['client_secret'],
                username=self.citrix_token['username'],
                password=self.citrix_token['password'])
            citrix.upload_file(
                folder_id='fofd8511-6564-44f3-94cb-338688544aac',
                local_path='./files/{}.png'.format(title))
            citrix.upload_file(
                folder_id='fofd8511-6564-44f3-94cb-338688544aac',
                local_path=html_file)
Ejemplo n.º 11
0
    def export_to_plotly(self):
        if len(self.name_list) == 0:
            raise ValueError('There is no issues to show')

        data, annotations = [], []
        start_date = str((datetime.now() - timedelta(days=8)).date())
        end_date = str((datetime.now() + timedelta(days=22)).date())
        for i in range(len(self.assignee_list)):
            for j in range(len(self.assignee_list[i])):
                data.append(go.Scatter(
                    x=[self.duedate_list[i][j]],
                    y=[self.assignee_list[i][j]],
                    mode='markers',
                    marker=dict(
                        size=12,
                        color='rgb(255,100,100)'
                        if datetime.strptime(self.duedate_list[i][j][:11].strip(),
                                             '%Y-%m-%d').date() < datetime.now().date() else 'rgb(254,210,92)'
                    )
                ))
            data.append(go.Scatter(
                x=[start_date, end_date],
                y=[self.assignee_list[i][0], self.assignee_list[i][0]],
                mode='lines',
                line=dict(
                    color='rgb(115,115,115)',
                    width=1,
                    dash='dash'),
                opacity=0.4
            ))

        for i in range(len(self.assignee_list)):
            for j in range(len(self.assignee_list[i])):
                annotations.append(dict(
                    x=self.duedate_list[i][j],
                    y=self.assignee_list[i][j],
                    xref='x',
                    yref='y',
                    xanchor='center',
                    text=self.key_list[i][j][8:] + ': ' + self.name_list[i][j][:30] + '...',
                    showarrow=True,
                    arrowwidth=0.5,
                    arrowcolor='rgb(115,115,115)',
                    arrowhead=0,
                    ax=-80,
                    # ay=-40 - 20 * (self.duedate_list[i][:j].count(self.duedate_list[i][j]))
                    ay=-25 - 18.5 * j,
                    font=dict(
                        size=12,
                        color=issue_color(self.issuetype_list[i][j], 'font')
                    ),
                    bordercolor=issue_color(self.issuetype_list[i][j], 'border'),
                    borderwidth=1,
                    borderpad=1,
                    bgcolor=issue_color(self.issuetype_list[i][j], 'background'),
                    opacity=0.8
                ))
        annotations.append(dict(
            xref='x',
            yref='paper',
            xanchor='left',
            x=datetime.now().date(),
            y=0,
            # text=datetime.strftime(datetime.now(), '%b %d'),
            text='Today',
            showarrow=False,
            font=dict(
                color='rgb(255,100,100)'
            )
        ))

        title = self.dashboard_name
        # html_file = self.png_dir + "{0}.html".format(title)
        html_file = '//billing.ru/dfs/incoming/ABryntsev/' + "{0}.html".format(title)

        layout = go.Layout(
            barmode='group',
            annotations=annotations,
            showlegend=False,
            title=title,
            autosize=True,
            xaxis=dict(
                type='date',
                range=[start_date, end_date],
                dtick=86400000,
                tickfont=dict(
                    size=14
                )
                # rangeslider=dict(
                #     visible=True
                # )
            ),
            yaxis=dict(
                automargin=True,
                tickfont=dict(
                    size=14
                )
            ),
            shapes=[dict(
                type='line',
                xref='x',
                yref='paper',
                x0=datetime.now().date(),
                y0=0,
                x1=datetime.now().date(),
                y1=1,
                line=dict(
                    color='rgb(255,100,100)',
                    width=1.5
                )
            )]
        )

        fig = dict(data=data, layout=layout)
        if self.repository == 'offline':
            plotly.offline.plot(fig, filename=html_file, auto_open=self.auto_open)
        elif self.repository == 'citrix':
            plotly.offline.plot(fig, image_filename=title, image='png', image_height=1080, image_width=1920)
            plotly.offline.plot(fig, filename=html_file, auto_open=self.auto_open)
            time.sleep(5)
            shutil.move('C:/Users/{}/Downloads/{}.png'.format(self.local_user, title), './files/{}.png'.format(title))
            citrix = CitrixShareFile(hostname=self.citrix_token['hostname'], client_id=self.citrix_token['client_id'],
                                     client_secret=self.citrix_token['client_secret'],
                                     username=self.citrix_token['username'], password=self.citrix_token['password'])
            citrix.upload_file(folder_id='fofd8511-6564-44f3-94cb-338688544aac',
                               local_path='./files/{}.png'.format(title))
            citrix.upload_file(folder_id='fofd8511-6564-44f3-94cb-338688544aac',
                               local_path=html_file)