Example #1
0
 def post(self):
     graph_type = self['graph_type']
     model_type = self['model_type']
     filters = []
     filter_ids = ''
     if len(self['filters']) > 0:
         filters = self.get_filters(self['filters'])
         count = 0
         for t in filters:
             count += 1
             filter_ids=filter_ids+t[0]
             if count < len(filters):
                 filter_ids += ','
     dimensions = self['dimensions']
     model = model_list[model_type]
     graph_model = view_to_graphmodel_mapping[graph_type]
     aggregator_index = self['agg_idx'] if self['agg_idx'] else aggregator_strategy_list.keys()[0]
     time_strategy_index = self['time_strategy'] if self['time_strategy'] else time_strategy_list.keys()[0]
     time_dim_strategy_index = self['time_as_dimension_strategy'] if self['time_as_dimension_strategy'] else time_strategy_list.keys()[0]
     aggregator_strategy = aggregator_strategy_list[aggregator_index] if aggregator_index else None
     time_strategy = time_strategy_list[time_strategy_index] if time_strategy_index else None
     time_as_dim_strategy = time_strategy_list[time_dim_strategy_index] if time_dim_strategy_index else None
     curr_graph = {'model':model,'graph_model':graph_model,'dimension_ids':dimensions,'filter_ids':filter_ids,'graph_view':graph_type,'aggregator_strategy':aggregator_strategy,'time_strategy':time_strategy,'time_dim_strategy':time_as_dim_strategy}
     graph_view = get_graph_view(curr_graph)
     dimension_id = graph_view.graph_model.xaxis_id
     metric_id = graph_view.graph_model.yaxis_id
     model_class = get_class(model)
     dimension = model_class.property_titles[dimension_id]
     metric = model_class.property_titles[metric_id]
     chart_data_json = {'chart_data':graph_view.translate_to_json(filters),
                        'chart_type':curr_graph['graph_view'],
                        'dimension':dimension,
                        'metric':metric}
     self.write(json.dumps(chart_data_json))
Example #2
0
 def get_options_for(self, req_type):
     options = None
     if req_type == 'graph_types':
         options = [graph_type for graph_type in view_to_graphmodel_mapping]
         html = self.get_rendered_html('marketers/graphs/graph_types_area.html', {'types' : options})
     elif req_type == 'models':
         options = [model for model in model_list]
         html = self.get_rendered_html('marketers/graphs/models_area.html', {'types' : options})
     elif req_type == 'dimensions':
         model = model_list[self['model']]
         model_objs = get_model_objs_for(model)
         graph_type = self['graph_type']
         graph_model_name = view_to_graphmodel_mapping[graph_type]
         graph_model_obj = get_class(graph_model_name)()
         name, params = graph_model_obj.get_dimensions_html_for(get_class(model), model_objs)
         html = self.get_rendered_html(name, params)
     return {req_type : html}
Example #3
0
 def post(self):
     graph_type = self['graph_type']
     model_type = self['model_type']
     filters = []
     filter_ids = ''
     if len(self['filters']) > 0:
         filters = self.get_filters(self['filters'])
         count = 0
         for t in filters:
             count += 1
             filter_ids = filter_ids + t[0]
             if count < len(filters):
                 filter_ids += ','
     dimensions = self['dimensions']
     model = model_list[model_type]
     graph_model = view_to_graphmodel_mapping[graph_type]
     aggregator_index = self['agg_idx'] if self[
         'agg_idx'] else aggregator_strategy_list.keys()[0]
     time_strategy_index = self['time_strategy'] if self[
         'time_strategy'] else time_strategy_list.keys()[0]
     time_dim_strategy_index = self['time_as_dimension_strategy'] if self[
         'time_as_dimension_strategy'] else time_strategy_list.keys()[0]
     aggregator_strategy = aggregator_strategy_list[
         aggregator_index] if aggregator_index else None
     time_strategy = time_strategy_list[
         time_strategy_index] if time_strategy_index else None
     time_as_dim_strategy = time_strategy_list[
         time_dim_strategy_index] if time_dim_strategy_index else None
     curr_graph = {
         'model': model,
         'graph_model': graph_model,
         'dimension_ids': dimensions,
         'filter_ids': filter_ids,
         'graph_view': graph_type,
         'aggregator_strategy': aggregator_strategy,
         'time_strategy': time_strategy,
         'time_dim_strategy': time_as_dim_strategy
     }
     graph_view = get_graph_view(curr_graph)
     dimension_id = graph_view.graph_model.xaxis_id
     metric_id = graph_view.graph_model.yaxis_id
     model_class = get_class(model)
     dimension = model_class.property_titles[dimension_id]
     metric = model_class.property_titles[metric_id]
     chart_data_json = {
         'chart_data': graph_view.translate_to_json(filters),
         'chart_type': curr_graph['graph_view'],
         'dimension': dimension,
         'metric': metric
     }
     self.write(json.dumps(chart_data_json))
Example #4
0
 def translate_to_json(self, filters):
     chart_data = []
     model_name = self.graph_model.lines_map[
         self.graph_model.lines_map.keys()[0]][0].model.__class__.__name__
     dimension_idx = self.graph_model.xaxis_id
     model_cls = get_class('platforms_graphs.model.' + model_name)
     time_dim_strategy = None
     if self.graph_model.property_titles[
             self.graph_model.xaxis_id] == 'Time':
         time_dim_strategy = self.time_as_dimension_strategy if self.time_as_dimension_strategy else time_horizon
     lines_map = {}
     for curr_dim, pvals in self.graph_model.lines_map.items():
         dim = time_dim_strategy(
             curr_dim) if time_dim_strategy else curr_dim
         if time_dim_strategy:
             for d in dim:
                 if d not in lines_map:
                     lines_map[d] = []
                 for pval in pvals:
                     lines_map[d].append(pval)
         else:
             if dim not in lines_map:
                 lines_map[dim] = []
             for pval in pvals:
                 lines_map[dim].append(pval)
     sorted_lines_map = sorted(
         lines_map.items(),
         key=lambda (k, v): model_cls.get_sort_value(
             dimension_idx, k, time_dim_strategy.__name__
         )) if time_dim_strategy else sorted(
             lines_map.items(),
             key=lambda (k, v): model_cls.get_sort_value(dimension_idx, k))
     for (curr_dimension, plot_vals) in sorted_lines_map:
         matches = self.find_matches_in(plot_vals, filters)
         data_row = {'dimension1': curr_dimension}
         for co_ord in matches:
             key = co_ord[0]
             if self.graph_model.property_titles[
                     self.graph_model.additional_xaxis_id] == 'Time':
                 times = self.time_strategy(
                     key) if self.time_strategy else time_horizon(key)
                 for time in times:
                     data_row[time] = co_ord[1]
             else:
                 data_row[co_ord[0]] = co_ord[1]
         chart_data.append(data_row)
     return chart_data
Example #5
0
 def translate_to_json(self, filters):
     chart_data = []
     model_name = self.graph_model.lines_map[self.graph_model.lines_map.keys()[0]][0].model.__class__.__name__
     dimension_idx = self.graph_model.xaxis_id
     model_cls = get_class('platforms_graphs.model.'+model_name)
     time_dim_strategy = None
     if self.graph_model.property_titles[self.graph_model.xaxis_id] == 'Time':
         time_dim_strategy = self.time_as_dimension_strategy if self.time_as_dimension_strategy else time_horizon
     lines_map = {}
     for curr_dim, pvals in self.graph_model.lines_map.items():
         dim = time_dim_strategy(curr_dim) if time_dim_strategy else curr_dim
         if time_dim_strategy:
             for d in dim:
                 if d not in lines_map:
                     lines_map[d] = []
                 for pval in pvals:
                     lines_map[d].append(pval)
         else:
             if dim not in lines_map:
                 lines_map[dim] = []
             for pval in pvals:
                     lines_map[dim].append(pval)
     sorted_lines_map = sorted(lines_map.items(), key=lambda (k,v):model_cls.get_sort_value(dimension_idx, k, time_dim_strategy.__name__)) if time_dim_strategy else sorted(lines_map.items(), key=lambda (k,v):model_cls.get_sort_value(dimension_idx, k))
     for (curr_dimension, plot_vals) in sorted_lines_map:
         matches = self.find_matches_in(plot_vals, filters)
         data_row = {'dimension1':curr_dimension}
         for co_ord in matches:
             key = co_ord[0]
             if self.graph_model.property_titles[self.graph_model.additional_xaxis_id] == 'Time':
                 times = self.time_strategy(key) if self.time_strategy else time_horizon(key)
                 for time in times:
                     data_row[time] = co_ord[1]
             else:
                 data_row[co_ord[0]] = co_ord[1]
         chart_data.append(data_row)
     return chart_data
Example #6
0
def get_model_obj_for(model_name):
    return get_class(model_name)()
Example #7
0
def get_model_records_for(model_name):
    model_records = []
    model_cls = get_class(model_name)
    with open(model_cls.file_name) as f:
        model_records = f.readlines()
    return model_records