Beispiel #1
0
def GetGLineUrl(plot_list, width=600, height=500):
  """Get Google line chart url string.

  Args:
    plot_list: Numeric number list.
               A list also can contain negative value elements.
    width: Image width when it is rendered in web browser.
    height: Image height when it is rendered in web browseor.

  Returns:
    An url string that will create chart image in google chart.
  """
  max_y = max(plot_list)
  min_y = min(plot_list)
  
  gchart = GChart()
  gchart.type('line')
  gchart.dataset(plot_list)
  
  gchart.size(width, height)
  
  gchart.axes.type('y')
  gchart.axes.range(0, min_y, max_y)
  gchart.scale(min_y, max_y)
  
  return str(gchart)
Beispiel #2
0
    def get_context_data(self, **kwargs):
        context = super(RedDetailView, self).get_context_data(**kwargs)
        app_label = 'rtg'
        model = models.get_model(app_label, 'ReservaIp')
        self.admin_object = admin_rtg._registry[model] #IGNORE:protected-access        
        self.admin_object.red_ips = Red_Ips(self.object)

        if self.object.externa:
            ips_activas = "No disponible (red externa)"
        else:
            ips_activas = self.admin_object.red_ips.ips_activas
            
        if self.object.asignacion_ip: #gestionamos las IPs
            ips_asignadas = len(self.admin_object.red_ips.asignadas)
            ips_libres = self.admin_object.red_ips.ips_libres
            self.admin_object.change_list_template = 'rtg/red_detail.django.html'
        else:   #no gestionamos las IPs
            ips_asignadas = 'No se gestionan las IPs de la red'
            ips_libres = ''
            self.admin_object.change_list_template = 'rtg/red_detail_sin_ips.django.html'
            
        hist_asignadas = []
        hist_activas = []                                    
        for i in range(1,13):
            d=HistoricoIpsEnRed.objects.filter(red=self.object).filter(fecha__month=i).aggregate(Max('ips_asignadas'),Max('ips_activas')) #IGNORE:no-member
            hist_asignadas.append(d['ips_asignadas__max'])
            hist_activas.append(d['ips_activas__max'])
        
        hist_libres = deque(map(lambda x:'_' if x==None else str(self.admin_object.red_ips.num_ips-x), hist_asignadas)) #IGNORE:bad-builtin) 
        hist_asignadas = deque(map(lambda x:'_' if x==None else str(x), hist_asignadas)) #IGNORE:bad-builtin
        hist_activas = deque(map(lambda x:'_' if x==None else str(x), hist_activas)) #IGNORE:bad-builtin
        
   
        meses = deque(['Ene','Feb','Mar','Abr','May','Jun','Jul','Ago','Sep','Oct','Nov','Dic'])
        mes_actual = datetime.date.today().month
        
        # rotamos los datos para que apareza en la grafica el mes actual como último mes
        meses.rotate(-mes_actual)
        hist_libres.rotate(-mes_actual)
        hist_asignadas.rotate(-mes_actual)
        hist_activas.rotate(-mes_actual)
        
        #Creamos el GChart pasando el dataset porque no se soporta el parametro t2
        G = GChart(ctype="bvs", chd="t2:" + ','.join(hist_asignadas)+'|'+','.join(hist_libres)+'|'+','.join(hist_activas))
        G.bar('a',1)
        G.size(350,200) 
        G.color('4D89F9','C6D9FD','0000FF')
        G.marker('D','0000FF','2','0','2')
        G.marker('s','0000FF','2','-1','8') 
        G.title('Historico Utilizacion')  #Fallan los acentos
        G.legend('Asignadas','Libres','Activas')
        G['chdlp'] = 'b|l'
        G.scale(0,self.admin_object.red_ips.num_ips) 
        G.margin(0,0,5,0)
        G.axes.type('yx')
        G.axes.label(1,*meses)  #IGNORE:W0142
        G.axes.range(0,0,self.admin_object.red_ips.num_ips)
               
        context.update( { 'model_name': 'red',                         
                          'num_ips': self.admin_object.red_ips.num_ips, 
                          'ips_asignadas': ips_asignadas,
                          'ips_libres': ips_libres,
                          'ips_activas': ips_activas, 
                          'admin_url': get_admin_url(self.request.get_full_path()), 
                          'chart_ips_libres': G,                                       
                         }
                       )
        return context