def _visualize(self, args, cache_directory = None): self.visualizations = [] indicators_to_visualize = {} interface = IndicatorFrameworkInterface(self.project) not_visualized = [] #get common years years = set([]) for indicator in self.indicators: years |= set(indicator['years']) source_data_objs = {} for indicator in self.indicators: indicator_name = indicator['indicator_name'] source_data_name = indicator['source_data_name'] dataset_name = indicator['dataset_name'] if (self.indicator_type == 'mapnik_map' or self.indicator_type == 'mapnik_animated_map') and dataset_name not in self.spatial_datasets: not_visualized.append(indicator) continue if source_data_name not in source_data_objs: source_data = interface.get_source_data( source_data_name = source_data_name, years = list(years), cache_directory = cache_directory ) source_data_objs[source_data_name] = source_data else: source_data = source_data_objs[source_data_name] indicator = interface.get_indicator( indicator_name = indicator_name, dataset_name = dataset_name) computed_indicator = interface.get_computed_indicator(indicator = indicator, source_data = source_data, dataset_name = dataset_name) computed_indicator.gui_indicator_name = indicator_name ##################### #hack to get plausible primary keys... cache_directory = source_data.cache_directory _storage_location = os.path.join(cache_directory, 'indicators', '_stored_data', repr(source_data.years[0])) storage = StorageFactory().get_storage( type = 'flt_storage', storage_location = _storage_location) cols = storage.get_column_names( table_name = dataset_name) primary_keys = [col for col in cols if col.find('_id') != -1] computed_indicator.primary_keys = primary_keys ################## name = computed_indicator.get_file_name( suppress_extension_addition = True) indicators_to_visualize[name] = computed_indicator viz_args = {} if self.indicator_type == 'mapnik_map': viz_type = self.indicator_type elif self.indicator_type == 'mapnik_animated_map': viz_type = self.indicator_type elif self.indicator_type == 'matplotlib_chart': viz_type = self.indicator_type elif self.indicator_type == 'tab': viz_type = 'table' if 'output_style' not in viz_args: viz_args['output_style'] = Table.ALL viz_args['output_type'] = 'tab' elif self.indicator_type == 'table_esri': viz_type = 'table' if 'output_style' not in viz_args: viz_args['output_style'] = Table.ALL viz_args['output_type'] = 'esri' elif self.indicator_type == 'table_per_year': viz_type = 'table' if 'output_style' not in viz_args: viz_args['output_style'] = Table.PER_YEAR viz_args['output_type'] = 'tab' elif self.indicator_type == 'table_per_attribute': viz_type = 'table' if 'output_style' not in viz_args: viz_args['output_style'] = Table.PER_ATTRIBUTE viz_args['output_type'] = 'tab' viz_args.update(self.kwargs) viz_args.update(args) # try: # import pydevd;pydevd.settrace() # except: # pass viz_factory = VisualizationFactory() self.visualizations = viz_factory.visualize( indicators_to_visualize = indicators_to_visualize.keys(), computed_indicators = indicators_to_visualize, visualization_type = viz_type, **viz_args) if self.visualizations is None: self.visualizations = [] return not_visualized