예제 #1
0
파일: views.py 프로젝트: carljm/datazilla
def graphs(request, project=""):

    ####
    #Load any signals provided in the page
    ####
    signals = []
    timeRanges = DatazillaModel.getTimeRanges()

    for s in SIGNALS:
        if s in request.POST:
            signals.append( { 'value':urllib.unquote( request.POST[s] ),
                              'name':s } )
    ###
    #Get reference data
    ###
    cacheKey = str(project) + '_reference_data'
    jsonData = '{}'
    mc = memcache.Client([settings.DATAZILLA_MEMCACHED], debug=0)
    compressedJsonData = mc.get(cacheKey)

    timeKey = 'days_30'

    ##reference data found in the cache: decompress##
    if compressedJsonData:

        jsonData = zlib.decompress( compressedJsonData )

    else:
        ####
        #reference data has not been cached:
        #serialize, compress, and cache
        ####
        dm = DatazillaModel(project, 'graphs.json')
        refData = dm.getTestReferenceData()
        dm.disconnect()

        refData['time_ranges'] = timeRanges

        jsonData = json.dumps(refData)

        mc.set(str(project) + '_reference_data', zlib.compress( jsonData ) )

    data = { 'username':request.user.username,
             'time_key':timeKey,
             'reference_json':jsonData,
             'signals':signals }

    ####
    #Caller has provided the view parent of the signals, load in page.
    #This occurs when a data view is in its Pane form and is detached
    #to exist on it's own page.
    ####
    parentIndexKey = 'dv_parent_dview_index'
    if parentIndexKey in request.POST:
        data[parentIndexKey] = request.POST[parentIndexKey]

    return render_to_response('graphs.views.html', data)
예제 #2
0
파일: views.py 프로젝트: rhelmer/datazilla
def graphs(request):

   ####
   #Load any signals provided in the page
   ####
   signals = []
   startDate, endDate = _getDateRange()

   for s in SIGNALS:
     if s in request.POST:
        if s == 'start_date':
           startDate = datetime.date( *time.strptime(request.POST[s], '%Y-%m-%d')[0:3] )
        elif s == 'end_date':
           endDate = datetime.date( *time.strptime(request.POST[s], '%Y-%m-%d')[0:3] )
        else:
           signals.append( { 'value':urllib.unquote( request.POST[s] ), 'name':s } )

   ###
   #Get reference data
   ###
   cacheKey = 'reference_data'
   jsonData = '{}'
   mc = memcache.Client([settings.DATAZILLA_MEMCACHED], debug=0)
   compressedJsonData = mc.get(cacheKey)

   ##reference data found in the cache: decompress##
   if compressedJsonData:
      jsonData = zlib.decompress( compressedJsonData )
   else:
      ##reference data has not been cached: serialize, compress, and cache##
      gm = DatazillaModel('graphs.json')
      refData = gm.getTestReferenceData()
      gm.disconnect()

      jsonData = json.dumps(refData)

      mc.set('reference_data', zlib.compress( jsonData ) )

   data = { 'username':request.user.username,
            'start_date':startDate,
            'end_date':endDate,
            'reference_json':jsonData,
            'current_date':datetime.date.today(),
            'signals':signals }

   ####
   #Caller has provided the view parent of the signals, load in page.
   #This occurs when a data view is in its Pane form and is detached
   #to exist on it's own page.
   ####
   parentIndexKey = 'dv_parent_dview_index'
   if parentIndexKey in request.POST:
     data[parentIndexKey] = request.POST[parentIndexKey]

   return render_to_response('graphs.views.html', data)
예제 #3
0
파일: views.py 프로젝트: rhelmer/datazilla
def dataview(request, **kwargs):

   procName = os.path.basename(request.path)
   procPath = "graphs.views."
   ##Full proc name including base path in json file##
   fullProcPath = "%s%s" % (procPath, procName)

   if settings.DEBUG:
      ###
      #Write IP address and datetime to log
      ###
      print "Client IP:%s" % (request.META['REMOTE_ADDR'])
      print "Request Datetime:%s" % (str(datetime.datetime.now()))

   json = ""
   if procName in DATAVIEW_ADAPTERS:
      gm = DatazillaModel('graphs.json')
      if 'adapter' in DATAVIEW_ADAPTERS[procName]:
         json = DATAVIEW_ADAPTERS[procName]['adapter'](procPath, 
                                                       procName, 
                                                       fullProcPath, 
                                                       request,
                                                       gm)
      else:
         if 'fields' in DATAVIEW_ADAPTERS[procName]:
            fields = []
            for f in DATAVIEW_ADAPTERS[procName]['fields']:
               if f in request.POST:
                  fields.append( gm.dhub.escapeString( request.POST[f] ) )
               elif f in request.GET:
                  fields.append( gm.dhub.escapeString( request.GET[f] ) )

            if len(fields) == len(DATAVIEW_ADAPTERS[procName]['fields']):
               json = gm.dhub.execute(proc=fullProcPath,
                                      debug_show=settings.DEBUG,
                                      placeholders=fields,
                                      return_type='table_json')

            else:
               json = '{ "error":"%s fields required, %s provided" }' % (str(len(DATAVIEW_ADAPTERS[procName]['fields'])), 
                                                                         str(len(fields)))

         else:

            json = gm.dhub.execute(proc=fullProcPath,
                                   debug_show=settings.DEBUG,
                                   return_type='table_json')

   else:
      json = '{ "error":"Data view name %s not recognized" }' % procName

   gm.disconnect();

   return HttpResponse(json, mimetype=APP_JS)
예제 #4
0
def cacheTestSummaries():

   gm = DatazillaModel('graphs.json')
   dataIter = gm.getAllSummaryCacheData()

   mc = memcache.Client([os.environ["DATAZILLA_MEMCACHED"]], debug=0)

   for d in dataIter:
      for data in d:
         key = DatazillaModel.getCacheKey( data['item_id'], data['item_data'] )
         rv = mc.set(key, zlib.compress( data['value'] ))
         if not rv:
            sys.stderr.write("ERROR: Failed to store object in memcache: %s, %s\n" % ( str(data['item_id']), data['item_data'] ) ) 

   gm.disconnect()
예제 #5
0
파일: views.py 프로젝트: carljm/datazilla
def setTestData(request):

    jsonData = '{"error":"No POST data found"}'

    if 'data' in request.POST:

        jsonData = request.POST['data']
        unquotedJsonData = urllib.unquote(jsonData)
        data = json.loads( unquotedJsonData )

        dm = DatazillaModel(project, 'graphs.json')
        dm.loadTestData( data, unquotedJsonData )
        dm.disconnect()

        jsonData = json.dumps( { 'loaded_test_pages':len(data['results']) } )

    return HttpResponse(jsonData, mimetype=APP_JS)
예제 #6
0
def loadTestCollection(project):

    gm = DatazillaModel(project, 'graphs.json')

    products = gm.getProducts('id')

    for productName in products:

        if products[ productName ]['product'] and \
           products[ productName ]['version'] and \
           products[ productName ]['branch']:

            name = "%s %s %s" % (products[ productName ]['product'],
                                 products[ productName ]['version'],
                                 products[ productName ]['branch'])

            id = gm.setData('set_test_collection', [ name, "", name ])
            gm.setData('set_test_collection_map', [ id, products[ productName ]['id'] ])

    gm.disconnect()
예제 #7
0
def buildTestSummaries(project):

    gm = DatazillaModel(project, 'graphs.json')

    timeRanges = DatazillaModel.getTimeRanges()

    products = gm.getProducts()

    for productName in products:

        for tr in ['days_7', 'days_30']:

            table = gm.getTestRunSummary(str( timeRanges[tr]['start']),
                                         str( timeRanges[tr]['stop']),
                                         [ products[ productName ] ],
                                         [],
                                         [])

            jsonData = json.dumps( table )

            gm.setSummaryCache( products[ productName ], tr, jsonData )

    gm.disconnect()