Beispiel #1
0
def pending_task_count_dataview(request, name=None):
    """ Return the number of pending DispatchedTasks for each defined task.  An 
        optional filter and/or exclude may be provided in the POST data as a 
        json query.  The return value is a json dicitonary with task names as 
        the keys.
    """
    name = _resolve_name(name)
    json_request = _json_from_post(request, allow_empty=True) or {}
    tasknames = get_defined_tasks()
    
    filterexp = [['state', 'PENDING']]
    if name:
        filterexp.append(['name', name])
    segmentize = {'field': 'taskname', 'method': ['values', tasknames], }
    aggregate = [{'field': 'count'}]
    
    json_request = _update_json_request(json_request, filter=filterexp, 
                                        segmentize=segmentize, 
                                        aggregate=aggregate)
    
    xyquery = JsonXYQuery(JsonTaskModelMap(), json_request)
    json_result = xyquery.do_query()
    
    d = json_result['data']
    
    #r = dict((row[0], row[1]['count']) for row in d)
    r = dict((row[0], row[1][0]['methods'][0]['value']) for row in d)
    
    return _json_response(r)
Beispiel #2
0
 def test_simple_variance(self):
     if not self.has_variance():
         print '\nThis database does not support computing Variance.  Skipping test.'
         return
     input = {
         'segmentize': {
             'field': 'enumval',
             'method': ['all'],
             },
         'aggregate': [
             { 'field': 'floatval', 
               'methods': ['variance'] }
             ]
         }
     expected_output = {
         'data': [
             (u'A',[{ 'fieldname':'floatval', 'methods': [{'name':'variance', 'value': 5.0}] }] ),
             (u'B',[{ 'fieldname':'floatval', 'methods': [{'name':'variance', 'value': 4.0}] }] ),
             (u'C',[{ 'fieldname':'floatval', 'methods': [{'name':'variance', 'value': 88.0}] }] ),
             ]
         }
     query = JsonXYQuery(TestModelModelMap(), input)
     output = query.do_query()
     output = sort_result(output)
     self.assertEquals('variance', output['data'][0][1]['methods'][0]['name'])
     self.assertEquals('variance', output['data'][1][1]['methods'][0]['name'])
     self.assertEquals('variance', output['data'][2][1]['methods'][0]['name'])
Beispiel #3
0
 def test_simple_all(self):
     input = {
         'segmentize': {
             'field': 'enumval',
             'method': ['all'],
             },
         'aggregate': [
             { 'field': 'count', }
             ]
         }
     expected_output = {
         'data': [
             (u'A',[{ 'fieldname':'count', 'methods': [{'name':'count', 'value': 3}] }] ),
             (u'B',[{ 'fieldname':'count', 'methods': [{'name':'count', 'value': 2}] }] ),
             (u'C',[{ 'fieldname':'count', 'methods': [{'name':'count', 'value': 1}] }] ),
             ]
         }
     #expected_output = {
     #    'data': [
     #        [x, {'field': {'method': ''} } ],
     #        ]
     #    }
     query = JsonXYQuery(TestModelModelMap(), input)
     output = query.do_query()
     output = sort_result(output)
     self.assertEquals(expected_output, output)
Beispiel #4
0
 def test_date_each(self):
     D = date_timestamp
     input = {
         "segmentize": {
             "field":"date",
             "method": ["each"],
             },
         "aggregate": [
             { "field":"count", }
             ]
         }
     expected_output = {
         'data': [
             (D(2010,1,4),  [{ 'fieldname':'count', 'methods': [{'name':'count', 'value': 1}] }] ),
             (D(2010,1,4),  [{ 'fieldname':'count', 'methods': [{'name':'count', 'value': 1}] }] ),
             (D(2010,1,11), [{ 'fieldname':'count', 'methods': [{'name':'count', 'value': 1}] }] ),
             (D(2010,1,13), [{ 'fieldname':'count', 'methods': [{'name':'count', 'value': 1}] }] ),
             (D(2010,1,20), [{ 'fieldname':'count', 'methods': [{'name':'count', 'value': 1}] }] ),
             (D(2010,1,24), [{ 'fieldname':'count', 'methods': [{'name':'count', 'value': 1}] }] ),
             ]
         }
     
     query = JsonXYQuery(TestModelModelMap(), input)
     output = query.do_query()
     output = sort_result(output)
     self.assertEquals(expected_output, output)
Beispiel #5
0
 def test_date_values(self):
     D = date_timestamp
     input = {
         "segmentize": {
             "field":"date",
             "method": ["values", [D(2010,1,1), D(2010,1,4), D(2010,1,13),]],
             },
         "aggregate": [
             { "field":"count", }
             ]
         }
     expected_output = {
         'data': [
             (D(2010,1,1), [{ 'fieldname':'count', 'methods': [{'name':'count', 'value': 0}] }] ),
             (D(2010,1,4), [{ 'fieldname':'count', 'methods': [{'name':'count', 'value': 2}] }] ),
             (D(2010,1,13),[{ 'fieldname':'count', 'methods': [{'name':'count', 'value': 1}] }] ),
             ]
         }
     
     query = JsonXYQuery(TestModelModelMap(), input)
     ##print 'filter args:  {0}\n'.format(query.filter.filter_args)
     ##print 'exclude args: {0}\n'.format(query.filter.exclude_args)
     output = query.do_query()
     output = sort_result(output)
     self.assertEquals(expected_output, output)
Beispiel #6
0
def task_xy_dataview(request):
    """ Performs a database query and returns the results of that query.  The 
        result is formatted as json.  The query must be contained in the 
        request's POST content and it must be fin json format.  
        
        See the docs directory form more information on the format of the query 
        and result.
    """
    json_request = _json_from_post(request)
    
    xyquery = JsonXYQuery(JsonTaskModelMap(), json_request)
    json_result = xyquery.do_query()
    
    ##import pprint
    ##pprint.pprint(json_result)
    
    ##print jsonutil.dumps(json_result)
    
    return _json_response(json_result)
Beispiel #7
0
 def test_simple_range(self):
     input = {
         'segmentize': {
             'field': 'intval',
             'method': ['range', {'min': 1, 'max':8, 'interval':3}],
             },
         'aggregate': [
             { 'field': 'count', }
             ]
         }
     expected_output = {
         'data': [
             (2,[{ 'fieldname':'count', 'methods': [{'name':'count', 'value': 2}] }] ),
             (5,[{ 'fieldname':'count', 'methods': [{'name':'count', 'value': 3}] }] ),
             (8,[{ 'fieldname':'count', 'methods': [{'name':'count', 'value': 1}] }] ),
             ]
         }
     query = JsonXYQuery(TestModelModelMap(), input)
     output = query.do_query()
     output = sort_result(output)
     self.assertEquals(expected_output, output)
Beispiel #8
0
 def test_simple_enumerate(self):
     input = {
         'segmentize': {
             'field': 'enumval',
             'method': ['all'],
             },
         'aggregate': [
             { 'field': 'floatval', 
               'methods': ['enumerate'] }
             ]
         }
     expected_output = {
         'data': [
             (u'A',[{ 'fieldname':'floatval', 'methods': [{'name':'enumerate', 'value': {4.0: 2, 7.0: 1}}] }] ),
             (u'B',[{ 'fieldname':'floatval', 'methods': [{'name':'enumerate', 'value': {3.0: 1, 5.0: 1}}] }] ),
             (u'C',[{ 'fieldname':'floatval', 'methods': [{'name':'enumerate', 'value': {88.0: 1}       }] }] ),
             ]
         }
     query = JsonXYQuery(TestModelModelMap(), input)
     output = query.do_query()
     output = sort_result(output)
     self.assertEquals(expected_output, output)
Beispiel #9
0
 def test_date_range(self):
     D = datetime_timestamp
     input = {
         "segmentize": {
             "field":"datetime",
             "method": ["range", {"min": D(2010,1,10,12), "max": D(2010,1,22,12), "interval": timedelta_ms(days=6)}]
             },
         "aggregate": [
             { "field":"count",
               "methods":["enumerate"] }
             ]
         }
     expected_output = {
         'data': [
             (D(2010,1,13,12), [{ 'fieldname':'count', 'methods': [{'name':'count', 'value': 2}] }] ),
             (D(2010,1,19,12), [{ 'fieldname':'count', 'methods': [{'name':'count', 'value': 1}] }] ),
             ]
         }
     
     query = JsonXYQuery(TestModelModelMap(), input)
     output = query.do_query()
     output = sort_result(output)
     self.assertEquals(expected_output, output)
Beispiel #10
0
 def test_date_all(self):
     D = datetime_timestamp
     input = {
         'segmentize': {
             'field': 'datetime',
             'method': ['all'],
             },
         'aggregate': [
             { 'field': 'count', }
             ]
         }
     expected_output = {
         'data': [
             (D(2010,1,4,12), [{ 'fieldname':'count', 'methods': [{'name':'count', 'value': 2}] }] ),
             (D(2010,1,11,12),[{ 'fieldname':'count', 'methods': [{'name':'count', 'value': 1}] }] ),
             (D(2010,1,13,12),[{ 'fieldname':'count', 'methods': [{'name':'count', 'value': 1}] }] ),
             (D(2010,1,20,12),[{ 'fieldname':'count', 'methods': [{'name':'count', 'value': 1}] }] ),
             (D(2010,1,24,12),[{ 'fieldname':'count', 'methods': [{'name':'count', 'value': 1}] }] ),
             ]
         }
     query = JsonXYQuery(TestModelModelMap(), input)
     output = query.do_query()
     output = sort_result(output)
     self.assertEquals(expected_output, output)