소스 검색

[search] Analytics field facet graph integration

Romain Rigaux 10 년 전
부모
커밋
abfdf87923

+ 1 - 1
apps/beeswax/src/beeswax/server/dbms.py

@@ -509,7 +509,7 @@ class HiveServer2Dbms(object):
     return self.execute_and_watch(query, query_history=query_history)
 
 
-  def execute_and_watch(self, query, design=None, query_history=None):
+  def execute_and_watch(self, query, design=None):
     """
     Run query and return a QueryHistory object in order to see its progress on a Web page.
     """

+ 18 - 1
apps/search/src/search/models.py

@@ -743,8 +743,24 @@ def augment_solr_response(response, collection, query):
       elif category == 'nested' and name in response['facets']:
         value = response['facets'][name]
         collection_facet = get_facet_field(category, name, collection['facets'])
+        print collection_facet
+
+        if 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)
+          print counts
 
-        counts = _augment_stats_2d(name, facet, response['facets'][name]['buckets'], selected_values)
+        print dimension
 
         if collection_facet['properties']['sort'] == 'asc':
           counts.reverse()
@@ -755,6 +771,7 @@ def augment_solr_response(response, collection, query):
           'type': category,
           'label': collection_facet['label'],
           'counts': counts,
+          'dimension': dimension
         }
 
         normalized_facets.append(facet)

+ 3 - 0
apps/search/src/search/static/search/js/search.ko.js

@@ -632,6 +632,7 @@ var Collection = function (vm, collection) {
     });
     return _fields;
   });
+
   self.template.fieldsNames = ko.computed(function () {
     return $.map(self.template.fieldsAttributes(), function(field) {
       return field.name();
@@ -1000,6 +1001,7 @@ var SearchViewModel = function (collection_json, query_json, initial_json) {
           counts: [],
           label: '',
           field: '',
+          dimension: 1,
           extraSeries: []
       });
     }
@@ -1177,6 +1179,7 @@ var SearchViewModel = function (collection_json, query_json, initial_json) {
             facet.counts(new_facet.counts);
             facet.label(new_facet.label);
             facet.field(new_facet.field);
+            facet.dimension(new_facet.dimension);
             facet.extraSeries(typeof new_facet.extraSeries != 'undefined' ? new_facet.extraSeries : []);
             facet.hash(_hash);
             facet.has_data(true);

+ 44 - 9
apps/search/src/search/templates/search.mako

@@ -1005,15 +1005,50 @@ ${ dashboard.layout_skeleton() }
     </div>
 
     <!-- ko if: $root.collection.getFacetById($parent.id()) -->
-    <div data-bind="barChart: {datum: {counts: counts(), widget_id: $parent.id(), label: label()}, stacked: $root.collection.getFacetById($parent.id()).properties.stacked(),
-      isPivot: true,
-      fqs: $root.query.fqs,
-      transformer: pivotChartDataTransformer,
-      onStateChange: function(state){ $root.collection.getFacetById($parent.id()).properties.stacked(state.stacked); },
-      onClick: function(d) {
-        $root.query.togglePivotFacet({facet: d.obj, widget_id: id()});
-      },
-      onComplete: function(){ viewModel.getWidgetById($parent.id()).isLoading(false) } }" />
+      <!-- ko if: dimension() == 1 -->
+        <div data-bind="barChart: {datum: {counts: counts(), widget_id: $parent.id(), label: label()}, stacked: $root.collection.getFacetById($parent.id()).properties.stacked(), field: field, label: label(),
+          fqs: $root.query.fqs,
+          transformer: ($data.type == 'range-up' ? barChartRangeUpDataTransformer : barChartDataTransformer),
+          onStateChange: function(state){ $root.collection.getFacetById($parent.id()).properties.stacked(state.stacked); },
+          onClick: function(d) {
+            if (d.obj.field != undefined) {
+              if ($data.type == 'range-up') {
+                viewModel.query.selectRangeUpFacet({count: d.obj.value, widget_id: d.obj.widget_id, from: d.obj.from, to: d.obj.to, cat: d.obj.field, 'exclude': false, is_up: d.obj.is_up});
+              } else {
+                viewModel.query.selectRangeFacet({count: d.obj.value, widget_id: d.obj.widget_id, from: d.obj.from, to: d.obj.to, cat: d.obj.field});
+              }
+            } else {
+              viewModel.query.toggleFacet({facet: d.obj, widget_id: d.obj.widget_id});
+            }
+          },
+          onSelectRange: function(from, to){ viewModel.collection.selectTimelineFacet({from: from, to: to, cat: field, widget_id: $parent.id()}) },
+          onComplete: function(){ viewModel.getWidgetById($parent.id()).isLoading(false) } }"
+        />
+      <!-- /ko -->
+
+      <!-- ko if: dimension() == 2 -->
+        <div data-bind="barChart: {datum: {counts: counts(), widget_id: $parent.id(), label: label()}, stacked: $root.collection.getFacetById($parent.id()).properties.stacked(),
+          isPivot: true,
+          fqs: $root.query.fqs,
+          transformer: pivotChartDataTransformer,
+          onStateChange: function(state){ $root.collection.getFacetById($parent.id()).properties.stacked(state.stacked); },
+          onClick: function(d) {
+            $root.query.togglePivotFacet({facet: d.obj, widget_id: id()});
+          },
+          onComplete: function(){ viewModel.getWidgetById($parent.id()).isLoading(false) } }"
+        />      
+      <!-- /ko -->
+      
+      <!-- ko if: dimension() == 3 -->
+      <div data-bind="timelineChart: {datum: {counts: counts(), extraSeries: extraSeries(), widget_id: $parent.id(), label: label()}, stacked: $root.collection.getFacetById($parent.id()).properties.stacked(), field: field, label: label(), transformer: timelineChartDataTransformer,
+        type: $root.collection.getFacetById($parent.id()).properties.timelineChartType,
+        fqs: $root.query.fqs,
+        onSelectRange: function(from, to){ $root.collection.selectTimelineFacet({from: from, to: to, cat: field, widget_id: $parent.id()}) },
+        onStateChange: function(state){ $root.collection.getFacetById($parent.id()).properties.stacked(state.stacked); },
+        onClick: function(d){ $root.query.selectRangeFacet({count: d.obj.value, widget_id: $parent.id(), from: d.obj.from, to: d.obj.to, cat: d.obj.field}) },
+        onComplete: function(){ $root.getWidgetById($parent.id()).isLoading(false) }}" />
+      <!-- /ko -->      
+      
     <!-- /ko -->
   </div>
   <!-- /ko -->