Explorar o código

[search] Analytics date range facet graph integration

Romain Rigaux %!s(int64=10) %!d(string=hai) anos
pai
achega
f6f8d04

+ 9 - 5
apps/search/src/search/models.py

@@ -744,17 +744,20 @@ def augment_solr_response(response, collection, query):
         value = response['facets'][name]
         collection_facet = get_facet_field(category, name, collection['facets'])
         print collection_facet
+        counts = response['facets'][name]['buckets']
+        print counts
 
-        if not collection_facet['properties']['facets'] or collection_facet['properties']['facets'][0]['aggregate'] not in ('count', 'unique'):
+        if collection_facet['properties']['isDate']:
+          dimension = 3
+          end = 1
+          counts = [_v for _f in counts for _v in (_f['val'], _f['d2'] if 'd2' in _f else _f['count'])]
+          counts = range_pair(facet['field'], name, selected_values.get(facet['id'], []), counts, end, collection_facet)
+        elif not collection_facet['properties']['facets'] or collection_facet['properties']['facets'][0]['aggregate'] not in ('count', 'unique'):
           dimension = 1
-          counts = response['facets'][name]['buckets']
-          print counts
           # counts":["0",17430,"1000",1949,"2000",671,"3000",404,"4000",243,"5000",165],"gap":1000,"start":0,"end":6000}
           # [{u'count': 5, u'val': u'CT'}, {u'count': 5, u'val': u'NJ'}, {u'count': 5, u'val': u'NY'}]
           counts = [_v for _f in counts for _v in (_f['val'], _f['d2'] if 'd2' in _f else _f['count'])]
-          end = 1
           counts = pairwise2(facet['field'], selected_values.get(facet['id'], []), counts)
-          #counts = range_pair(facet['field'], name, selected_values.get(facet['id'], []), counts, end, collection_facet)
         else:
           dimension = 2
           counts = _augment_stats_2d(name, facet, response['facets'][name]['buckets'], selected_values)
@@ -771,6 +774,7 @@ def augment_solr_response(response, collection, query):
           'type': category,
           'label': collection_facet['label'],
           'counts': counts,
+          'extraSeries': [], # unused?
           'dimension': dimension
         }
 

+ 15 - 0
apps/search/src/search/templates/search.mako

@@ -954,6 +954,21 @@ ${ dashboard.layout_skeleton() }
     </div>
 
     <div data-bind="with: $root.collection.getFacetById($parent.id())">
+      <!-- ko if: properties.isDate -->
+        <span class="facet-field-label">${ _('Chart Type') }</span>
+        <select class="input-small" data-bind="options: $root.timelineChartTypes,
+                       optionsText: 'label',
+                       optionsValue: 'value',
+                       value: properties.timelineChartType">
+        </select>&nbsp;
+        <span class="facet-field-label">${ _('Interval') }</span>
+        <select class="input-small" data-bind="options: $root.intervalOptions,
+                       optionsText: 'label',
+                       optionsValue: 'value',
+                       value: properties.gap">
+        </select>&nbsp;
+      <!-- /ko -->
+    
       <!-- ko if: properties.canRange -->
         <div style="padding-bottom: 10px; text-align: right; padding-right: 20px">
           <span class="facet-field-label">${ _('Zoom') }</span>

+ 3 - 2
apps/search/src/search/views.py

@@ -136,11 +136,11 @@ def search(request):
       try:
         response['error'] = json.loads(e.message)['error']['msg']
       except:
-        response['error'] = force_unicode(str(e))
+        response['error'] = force_unicode(e)
     except Exception, e:
       raise PopupException(e, title=_('Error while accessing Solr'))
 
-      response['error'] = force_unicode(str(e))
+      response['error'] = force_unicode(e)
   else:
     response['error'] = _('There is no collection to search.')
 
@@ -507,6 +507,7 @@ def _create_facet(collection, user, facet_id, facet_label, facet_field, widget_t
       properties['facets_form'] = {'field': '', 'mincount': 1, 'limit': 10, 'aggregate': 'count'}
       properties['facets'] = []
       properties['scope'] = 'stack'
+      properties['timelineChartType'] = 'bar'
 
   if widget_type in ('tree-widget', 'heatmap-widget', 'map-widget'):
     properties['mincount'] = 1