parameters: (self, request)
return_statement: return Response(data={'data': {'chart_data': query,
                                         'title': title,
                                         'start': start,
                                         'end': end}})
docstring: Fetch stats for the given time period.
          :param request:
          :return:
docstring_summary: Fetch stats for the given time period.
          :param request:
          :return:
docstring_tokens: Fetch stats for the given time period . : param request : : return :
function: def get(self, request):
          """Fetch stats for the given time period.
          :param request:
          :return:
          """
  
          log.info("stats start: %s", request.data.get('start'))
  
          # Validate GET variables
          ser = self.GetSerializer(data=request.GET)
          if not ser.is_valid():
              return Response(data={'warning': format_errors(ser.errors)})
  
          log.error('request: {}'.format(request.GET))
  
          site_id = ser.validated_data.get('site', None)
          capnode_id = ser.validated_data.get('capture_node', None)
          iface_id = ser.validated_data.get('interface', None)
          end = ser.validated_data.get('end', pytz.UTC.localize(datetime.utcnow()))
          start = ser.validated_data.get('start', end - timedelta(hours=24))
  
          query = Stats.objects.filter(minute__gt=start, minute__lt=end)
  
          # The fields/values we include will determine the 'group by' (how the results are
          # aggregated).
          values = ['minute']
          title = []
          if site_id is not None:
              site = Site.objects.get(id=site_id)
              query = query.filter(capture_node__site_id=site_id)
              values.append('capture_node__site_id')
              title.append(site.name)
  
          if capnode_id is not None:
              try:
                  capnode = CaptureNode.objects.get(id=capnode_id)
                  query = query.filter(capture_node_id=capnode_id)
                  values.append('capture_node_id')
                  title.append(capnode.hostname)
              except CaptureNode.DoesNotExist:
                  log.error("Capture node does not exist. {}".format(capnode_id))
  
          if iface_id is not None:
              try:
                  iface = StatsInterface.objects.get(id=iface_id)
                  query = query.filter(interface_id=iface_id)
                  values.append('interface_id')
                  title.append(iface.name)
              except StatsInterface.DoesNotExist:
                  log.error("Interface does not exist.  {}".format(iface_id))
  
          query = query.order_by('minute')
  
          query = query.values(*values).distinct()
  
          query = query.annotate(
                      capture_size=Sum('capture_size'),
                      received=Sum('received'),
                      dropped=Sum('dropped'),
                      ipv4=Sum('ipv4'),
                      ipv6=Sum('ipv6'),
                      network_other=Sum('network_other'),
                      tcp=Sum('tcp'),
                      udp=Sum('udp'),
                      transport_other=Sum('transport_other')
                  )
  
          if not title:
              title = ['all capture nodes']
  
          title = 'Capture stats for ' + ', '.join(title)
  
          return Response(data={'data': {'chart_data': query,
                                         'title': title,
                                         'start': start,
                                         'end': end}})
function_tokens: def get ( self , request ) : log . info ( "stats start: %s" , request . data . get ( 'start' ) ) # Validate GET variables ser = self . GetSerializer ( data = request . GET ) if not ser . is_valid ( ) : return Response ( data = { 'warning' : format_errors ( ser . errors ) } ) log . error ( 'request: {}' . format ( request . GET ) ) site_id = ser . validated_data . get ( 'site' , None ) capnode_id = ser . validated_data . get ( 'capture_node' , None ) iface_id = ser . validated_data . get ( 'interface' , None ) end = ser . validated_data . get ( 'end' , pytz . UTC . localize ( datetime . utcnow ( ) ) ) start = ser . validated_data . get ( 'start' , end - timedelta ( hours = 24 ) ) query = Stats . objects . filter ( minute__gt = start , minute__lt = end ) # The fields/values we include will determine the 'group by' (how the results are # aggregated). values = [ 'minute' ] title = [ ] if site_id is not None : site = Site . objects . get ( id = site_id ) query = query . filter ( capture_node__site_id = site_id ) values . append ( 'capture_node__site_id' ) title . append ( site . name ) if capnode_id is not None : try : capnode = CaptureNode . objects . get ( id = capnode_id ) query = query . filter ( capture_node_id = capnode_id ) values . append ( 'capture_node_id' ) title . append ( capnode . hostname ) except CaptureNode . DoesNotExist : log . error ( "Capture node does not exist. {}" . format ( capnode_id ) ) if iface_id is not None : try : iface = StatsInterface . objects . get ( id = iface_id ) query = query . filter ( interface_id = iface_id ) values . append ( 'interface_id' ) title . append ( iface . name ) except StatsInterface . DoesNotExist : log . error ( "Interface does not exist.  {}" . format ( iface_id ) ) query = query . order_by ( 'minute' ) query = query . values ( * values ) . distinct ( ) query = query . annotate ( capture_size = Sum ( 'capture_size' ) , received = Sum ( 'received' ) , dropped = Sum ( 'dropped' ) , ipv4 = Sum ( 'ipv4' ) , ipv6 = Sum ( 'ipv6' ) , network_other = Sum ( 'network_other' ) , tcp = Sum ( 'tcp' ) , udp = Sum ( 'udp' ) , transport_other = Sum ( 'transport_other' ) ) if not title : title = [ 'all capture nodes' ] title = 'Capture stats for ' + ', ' . join ( title ) return Response ( data = { 'data' : { 'chart_data' : query , 'title' : title , 'start' : start , 'end' : end } } )