Пример #1
0
 def __getstate__(self, view=None):
     return {
         "label": self.url,
         "name": parametise_label(self.graph.tile.widget, view, self.label),
         "dynamic_name_display": self.dynamic_label,
         "hyperlink": parametise_label(self.graph.tile.widget, view, self.hyperlink),
     }
Пример #2
0
 def __getstate__(self, view=None):
     state = {
         "label": self.url,
         "name": parametise_label(self.graph.tile.widget, view, self.label),
         "colour": self.colour,
         "hyperlink": parametise_label(self.graph.tile.widget, view, self.hyperlink),
         "dynamic_name_display": self.dynamic_label,
     }
     if self.graph.use_secondary_numeric_axis:
         if self.graph.graph_type == self.graph.LINE:
             state["use_secondary_vertical_axis"] = self.use_secondary_numeric_axis
         else:
             state["use_secondary_numeric_axis"] = self.use_secondary_numeric_axis
     return state
Пример #3
0
 def apply_parametisation(self, obj, val, **kwargs):
     parametisation_or_widget = kwargs.get("parametisation")
     view = kwargs.get("view")
     if view is None and parametisation_or_widget is None:
         raise ImportExportException(
             "Cannot determine which parametisation to use")
     return parametise_label(parametisation_or_widget, view, val)
Пример #4
0
 def __getstate__(self, view=None, parametisation=None):
     state =  {
         "category": self.subcategory.category.name,
         "subcategory": self.subcategory.name,
         "label": self.url,
         "name": parametise_label(parametisation, view, self.label),
         "geom_type": self.geom_types[self.geom_type],
     }
     if self.is_external():
         state["external_url"] = parametise_label(parametisation, view, self.ext_url)
         state["external_type"] = self.ext_type
     else:
         state["properties"] = [ 
                 p.__getstate__() 
                 for p in self.geopropertydefinition_set.all() 
         ]
     return state
Пример #5
0
 def __getstate__(self, view=None):
     return {
         "corner_header": parametise_label(self.tile.widget, view, self.corner_label),
         "show_column_headers": self.show_column_headers,
         "show_row_headers": self.show_row_headers,
         "columns": [ c.__getstate__(view) for c in self.gridcolumn_set.all() ],
         "rows": [ c.__getstate__(view) for c in self.gridrow_set.all() ],
     }
Пример #6
0
 def __getstate__(self, view=None):
     if not self.parametisation:
         view = None
     data = {
         "category": self.subcategory().category.name,
         "category_aspect": self.subcategory().category.category_aspect,
         "subcategory": self.subcategory().name,
         "name": parametise_label(self, view, self.name()),
         "subtitle": parametise_label(self, view, self.family.subtitle),
         "label": self.url(),
         "display": {
             "expansion_hint": self.expansion_hint,
             "deexpansion_hint": self.deexpansion_hint,
             "tiles": [ tile.__getstate__(view) for tile in self.tiledefinition_set.all() ],
         },
         "source_url": parametise_label(self, view, self.source_url()),
         "source_url_text": parametise_label(self, view, self.family.source_url_text),
         "refresh_rate": self.refresh_rate,
         "about": parametise_label(self, view, self.about),
     }
     if self.rawdataset_set.all().count() > 0:
         data["raw_data_sets"] = [ rds.__getstate__(view) for rds in self.rawdataset_set.all() ]
     return data
Пример #7
0
 def __getstate__(self, view=None):
     state = {
         "type": self.tile_types[self.tile_type],
         "expansion": self.expansion,
         "aspect": self.aspect,
     }
     if self.tile_type in (self.NEWSFEED, self.NEWSTICKER, 
                             self.SINGLE_LIST_STAT, self.SINGLE_MAIN_STAT, self.DOUBLE_MAIN_STAT, self.MAIN_STAT,
                             self.PRIORITY_LIST, self.URGENCY_LIST, self.CALENDAR, self.TIME_LINE,
                             self.MULTI_LIST_STAT, self.GRAPH_SINGLE_STAT, self.TEXT_TEMPLATE, 
                             self.TAG_CLOUD):
         state["statistics"] = [ s.__getstate__(view) for s in self.statistic_set.all() ]
     if self.tile_type == self.GRID_SINGLE_STAT:
         state["statistics"] = []
         for s in self.statistic_set.all():
             if s.gridstatistic_set.count() == 0:
                 state["statistics"].append(s.__getstate__(view))
     elif self.tile_type in (self.SINGLE_LIST_STAT, self.PRIORITY_LIST, self.URGENCY_LIST):
         if self.list_label_width:
             state["list_label_width"] = self.list_label_width
         else:
             state["list_label_width"] = 50
     if self.tile_type == self.TEXT_TEMPLATE:
         state["template"] = parametise_label(self.widget, view, self.template)
     if self.tile_type in (self.PRIORITY_LIST, self.URGENCY_LIST, self.MULTI_LIST_STAT, self.SINGLE_LIST_STAT):
         state["columns"] = self.columns
     if self.tile_type in (self.GRAPH, self.GRAPH_SINGLE_STAT):
         GraphDefinition = apps.get_app_config("widget_def").get_model("GraphDefinition")
         g = GraphDefinition.objects.get(tile=self)
         state["graph"] = g.__getstate__(view)
     if self.tile_type == self.MAP:
         state["map"] = {
             "url": self.url,
             "window": self.geo_window.__getstate__(view),
             "layers": [ ds.__getstate__(view=view,parametisation=self.widget.paremetisation) for ds in self.geo_datasets.all() ],
         }
     if self.tile_type in (self.GRID, self.GRID_SINGLE_STAT):
         GridDefinition = apps.get_app_config("widget_def").get_model("GridDefinition")
         state["grid"] = GridDefinition.objects.get(tile=self).__getstate__(view)
     if self.tile_type == self.MAIN_STAT:
         state["main_stat_count"] = self.main_stat_count
     return state
Пример #8
0
 def __getstate__(self, view):
     state = {
         "label": self.url,
         "type": self.stat_types[self.stat_type],
     }
     if self.tile.tile_type != TileDefinition.GRID:
         state["name"] = parametise_label(self.tile.widget, view, self.name)
         state["display_name"] = self.name_as_label
     if self.is_numeric():
         state["precision"] = self.num_precision
         state["unit"] = {}
         if self.unit_prefix:
             state["unit"]["prefix"] = self.unit_prefix 
         if self.unit_suffix:
             state["unit"]["suffix"] = self.unit_suffix 
         if self.unit_underfix:
             state["unit"]["underfix"] = self.unit_underfix 
         if self.unit_signed:
             state["unit"]["signed"] = True
         if self.unit_si_prefix_rounding > 0:
             state["unit"]["si_prefix_rounding"] = self.unit_si_prefix_rounding
     if self.traffic_light_scale:
         state["traffic_light_scale"] = self.traffic_light_scale.__getstate__()
     elif self.traffic_light_automation:
         state["traffic_light_scale"] = self.traffic_light_automation.strategy.scale.__getstate__()
     else:
         state["traffic_light_scale"] = None
     if self.stat_type not in (self.STRING_LIST, self.LONG_STRING_LIST):
         state["trend"] = self.trend
         if self.icon_library:
             state["icon_library"] = self.icon_library.name
         else:
             state["icon_library"] = None
     if self.rotates:
         state["rotates"] = self.rotates
     if self.is_display_list():
         state["numbered_list"] = self.numbered_list
     if self.is_data_list():
         state["hyperlinkable"] = self.hyperlinkable
     state["footer"] = self.footer
     return state
Пример #9
0
 def __getstate__(self, view=None):
     state = {
         "heading": parametise_label(self.widget(), view, self.heading),
         "graph_type": self.graph_types[self.graph_type],
         "label": self.tile.url,
         "display_options": self.graphdisplayoptions.__getstate__(self.graph_type),
     }
     if self.graph_type == self.LINE:
         state["vertical_axis"] = {
             "name": parametise_label(self.widget(), view, self.numeric_axis_label),
             "always_show_zero": self.numeric_axis_always_show_zero,
         }
         if self.use_secondary_numeric_axis:
             state["secondary_vertical_axis"] = {
                 "name": parametise_label(self.widget(), view, self.secondary_numeric_axis_label),
                 "always_show_zero": self.secondary_numeric_axis_always_show_zero,
             }
         state["horizontal_axis"] = {
             "name": parametise_label(self.tile.widget, view, self.horiz_axis_label),
             "type": self.axis_types[self.horiz_axis_type]
         }
         state["line_label"] = self.dataset_label
         state["lines"] = [ d.__getstate__(view) for d in self.graphdataset_set.all() ]
     elif self.graph_type in (self.HISTOGRAM, self.BAR):
         state["numeric_axis"] = {
             "name": parametise_label(self.tile.widget, view, self.numeric_axis_label),
             "always_show_zero": self.numeric_axis_always_show_zero,
         }
         if self.use_secondary_numeric_axis:
             state["secondary_numeric_axis"] = {
                 "name": parametise_label(self.tile.widget, view, self.secondary_numeric_axis_label),
                 "always_show_zero": self.secondary_numeric_axis_always_show_zero,
             }
         state["cluster_label"] = self.cluster_label
         state["bar_label"] = self.dataset_label
         state["dynamic_clusters"] = self.dynamic_clusters
         if not self.dynamic_clusters:
             state["clusters"] = [ c.__getstate__(view) for c in self.graphcluster_set.all() ]
         state["bars"] = [ d.__getstate__(view) for d in self.graphdataset_set.all()]
     elif self.graph_type == self.PIE:
         state["sector_label"] = self.dataset_label
         state["pie_label"] = self.cluster_label
         state["dynamic_pies"] = self.dynamic_clusters
         if not self.dynamic_clusters:
             state["pies"] = [ c.__getstate__(view) for c in self.graphcluster_set.all() ]
         state["sectors"] = [ d.__getstate__(view) for d in self.graphdataset_set.all()]
     return state
Пример #10
0
 def csv(self, view=None):
     """Return a CSV escaped heading for this column"""
     return csv_escape(parametise_label(self.rds.widget, view, self.heading))
Пример #11
0
def api_get_single_graph_data(graph, view, pval=None, verbose=False):
    pval = resolve_pval(graph.widget().parametisation, view=view, pval=pval)
    graph_json = { "data": {} }
    if verbose:
        graph_json["data"] = []
    else:
        if graph.use_clusters():
            for cluster in graph.clusters(pval):
                graph_json["data"][cluster.url] = {}
        else:
            for dataset in graph.graphdataset_set.all():
                graph_json["data"][dataset.url] = []
    numeric_min = None
    numeric_max = None
    numeric2_min = None
    numeric2_max = None
    horiz_min = None
    horiz_max = None
    for gd in graph.get_data(pval=pval):
        if graph.use_numeric_axes():
            if graph.use_secondary_numeric_axis and gd.dataset.use_secondary_numeric_axis:
                (numeric2_min, numeric2_max)=update_maxmin(gd.value, 
                            numeric2_min, numeric2_max)
            else:
                (numeric_min, numeric_max)=update_maxmin(gd.value, 
                            numeric_min, numeric_max)
        if not graph.use_clusters():
            (horiz_min, horiz_max) = update_maxmin(gd.horiz_value(),
                            horiz_min, horiz_max)
        if verbose:
            if graph.use_numeric_axes():
                if gd.dataset.use_secondary_numeric_axis:
                    data_label = graph.secondary_numeric_axis_label
                else:
                    data_label = graph.numeric_axis_label
                data_label = parametise_label(graph.widget(), view, data_label)
            else:
                data_label = "value"
            graph_datum = {
                    parametise_label(graph.widget(), view, graph.dataset_label): parametise_label(graph.widget(), view, get_graph_subset_displayname(gd.dataset,pval)),
                    data_label: gd.value
                    }
            if graph.use_clusters():
                graph_datum[parametise_label(graph.widget(), view, graph.cluster_label)] = parametise_label(graph.widget(), view, gd.get_cluster().label)
            else:
                graph_datum[parametise_label(graph.widget(), view, graph.horiz_axis_label)] = gd.horiz_json_value()
            if gd.dataset.use_error_bars:
                graph_datum[data_label + "_min"] = gd.err_valmin
                graph_datum[data_label + "_max"] = gd.err_valmax
            graph_json["data"].append(graph_datum)
        else:
            if gd.dataset.use_error_bars:
                json_val = {
                            "value": gd.value,
                            "min": gd.err_valmin,
                            "max": gd.err_valmax,
                }
            else:
                json_val = gd.value
            if graph.use_clusters():
                graph_json["data"][gd.get_cluster().url][gd.dataset.url] = json_val
            else:
                if gd.dataset.use_error_bars:
                    json_val["horizontal_value"] = gd.horiz_json_value()
                else:
                    json_val = ( gd.horiz_json_value(), json_val )
                graph_json["data"][gd.dataset.url].append(json_val)
    if graph.use_numeric_axes():
        graph_json["%s_scale" % graph.numeric_axis_name()] = {
                "min": numeric_min,
                "max": numeric_max
        }
        if graph.use_secondary_numeric_axis:
            graph_json["%s_2_scale" % graph.numeric_axis_name()] = {
                    "min": numeric2_min,
                    "max": numeric2_max
            }
    if not graph.use_clusters():
        graph_json["horizontal_axis_scale"] = {
                "min": graph.jsonise_horiz_value(horiz_min),
                "max": graph.jsonise_horiz_value(horiz_max)
        }
    if graph.use_clusters() and graph.dynamic_clusters:
        if graph.is_histogram():
            graph_json["clusters"] = [ c.__getstate__(view) for c in graph.clusters(pval) ]
        else:
            graph_json["pies"] = [ c.__getstate__(view) for c in graph.clusters(pval) ]
    overrides = get_graph_overrides(graph.graphdataset_set, GraphDatasetData, "dataset", pval)
    if overrides:
        graph_json["dataset_name_overrides"] = overrides
    return graph_json
Пример #12
0
 def __getstate__(self, view=None):
     return {
         "header": parametise_label(self.grid.tile.widget, view, self.label),
     }
Пример #13
0
 def __getstate__(self, view=None):
     return {
         "header": parametise_label(self.grid.tile.widget, view, self.label),
         "statistics": [ s.__getstate__(view) for s in self.grid.gridstatistic_set.filter(row=self).order_by("column") ]
     }
Пример #14
0
def api_get_single_graph_data(graph, view, pval=None, verbose=False):
    pval = resolve_pval(graph.widget().parametisation, view=view, pval=pval)
    graph_json = { "data": {} }
    if verbose:
        graph_json["data"] = []
    else:
        if graph.use_clusters():
            for cluster in graph.graphcluster_set.all():
                graph_json["data"][cluster.url] = {}
        else:
            for dataset in graph.graphdataset_set.all():
                graph_json["data"][dataset.url] = []
    numeric_min = None
    numeric_max = None
    numeric2_min = None
    numeric2_max = None
    horiz_min = None
    horiz_max = None
    for gd in graph.get_data(pval=pval):
        if graph.use_numeric_axes():
            if graph.use_secondary_numeric_axis and gd.dataset.use_secondary_numeric_axis:
                (numeric2_min, numeric2_max)=update_maxmin(gd.value, 
                            numeric2_min, numeric2_max)
            else:
                (numeric_min, numeric_max)=update_maxmin(gd.value, 
                            numeric_min, numeric_max)
        if not graph.use_clusters():
            (horiz_min, horiz_max) = update_maxmin(gd.horiz_value(),
                            horiz_min, horiz_max)
        if verbose:
            if graph.use_clusters():
                if gd.dataset.use_secondary_numeric_axis:
                    data_label = graph.secondary_numeric_axis_label
                else:
                    data_label = graph.numeric_axis_label
                data_label = parametise_label(graph.widget(), view, data_label)
                graph_json["data"].append({
                        parametise_label(graph.widget(), view, graph.cluster_label): parametise_label(graph.widget(), view, get_graph_subset_displayname(gd.cluster,pval)),
                        parametise_label(graph.widget(), view, graph.dataset_label): parametise_label(graph.widget(), view, get_graph_subset_displayname(gd.dataset,pval)),
                        data_label: gd.value
                        })
            else:
                graph_json["data"].append({
                        parametise_label(graph.widget(), view, graph.horiz_axis_label): gd.horiz_json_value(),
                        parametise_label(graph.widget(), view, graph.dataset_label): parametise_label(graph.widget(), view, get_graph_subset_displayname(gd.dataset,pval)),
                        data_label: gd.value
                        })
        else:
            if graph.use_clusters():
                graph_json["data"][gd.cluster.url][gd.dataset.url] = gd.value
            else:
                graph_json["data"][gd.dataset.url].append([
                                    gd.horiz_json_value(),
                                    gd.value
                                ])
    if graph.use_numeric_axes():
        graph_json["%s_scale" % graph.numeric_axis_name()] = {
                "min": numeric_min,
                "max": numeric_max
        }
        if graph.use_secondary_numeric_axis:
            graph_json["%s_2_scale" % graph.numeric_axis_name()] = {
                    "min": numeric2_min,
                    "max": numeric2_max
            }
    if not graph.use_clusters():
        graph_json["horizontal_axis_scale"] = {
                "min": graph.jsonise_horiz_value(horiz_min),
                "max": graph.jsonise_horiz_value(horiz_max)
        }
    overrides = get_graph_overrides(graph.graphcluster_set, GraphClusterData, "cluster", pval)
    if overrides:
        graph_json["cluster_name_overrides"] = overrides
    overrides = get_graph_overrides(graph.graphdataset_set, GraphDatasetData, "dataset", pval)
    if overrides:
        graph_json["dataset_name_overrides"] = overrides
    return graph_json
Пример #15
0
 def csv(self, view=None):
     """Return a CSV escaped heading for this column"""
     return csv_escape(parametise_label(self.rds.widget, view,
                                        self.heading))
Пример #16
0
 def __getstate__(self, view=None):
     return {
         "label": self.url,
         "name": parametise_label(self.widget(), view, self.label),
         "hyperlink": parametise_label(self.widget(), view, self.hyperlink),
     }
Пример #17
0
 def __getstate__(self, view=None):
     data = { "heading": parametise_label(self.rds.widget, view, self.heading) }
     if self.description:
         data["description"] = parametise_label(self.rds.widget, view, self.description)
     return data
Пример #18
0
 def __getstate__(self, view=None):
     return {
         "label": self.url,
         "name": parametise_label(self.widget, view, self.name),
         "columns": [ c.__getstate__(view) for c in self.rawdatasetcolumn_set.all() ],
     }
Пример #19
0
def api_get_single_graph_data(graph, view, pval=None, verbose=False):
    pval = resolve_pval(graph.widget().parametisation, view=view, pval=pval)
    graph_json = {"data": {}}
    if verbose:
        graph_json["data"] = []
    else:
        if graph.use_clusters():
            for cluster in graph.clusters(pval):
                graph_json["data"][cluster.url] = {}
        else:
            for dataset in graph.datasets.all():
                graph_json["data"][dataset.url] = []
    numeric_min = None
    numeric_max = None
    numeric2_min = None
    numeric2_max = None
    horiz_min = None
    horiz_max = None
    for gd in graph.get_data(pval=pval):
        if graph.use_numeric_axes():
            if graph.use_secondary_numeric_axis and gd.dataset.use_secondary_numeric_axis:
                (numeric2_min,
                 numeric2_max) = update_graph_maxmin(gd, numeric2_min,
                                                     numeric2_max)
            else:
                (numeric_min,
                 numeric_max) = update_graph_maxmin(gd, numeric_min,
                                                    numeric_max)
        if not graph.use_clusters():
            (horiz_min, horiz_max) = update_maxmin(gd.horiz_value(), horiz_min,
                                                   horiz_max)
        if verbose:
            if graph.use_numeric_axes():
                if gd.dataset.use_secondary_numeric_axis:
                    data_label = graph.secondary_numeric_axis_label
                else:
                    data_label = graph.numeric_axis_label
                data_label = parametise_label(graph.widget(), view, data_label)
            else:
                data_label = "value"
            graph_datum = {
                parametise_label(graph.widget(), view, graph.dataset_label):
                parametise_label(
                    graph.widget(), view,
                    get_graph_subset_displayname(gd.dataset, pval)),
                data_label:
                gd.value
            }
            if graph.use_clusters():
                graph_datum[parametise_label(
                    graph.widget(), view,
                    graph.cluster_label)] = parametise_label(
                        graph.widget(), view,
                        gd.get_cluster().label)
            else:
                graph_datum[parametise_label(
                    graph.widget(), view,
                    graph.horiz_axis_label)] = gd.horiz_json_value()
            if gd.dataset.use_error_bars:
                graph_datum[data_label + "_min"] = gd.err_valmin
                graph_datum[data_label + "_max"] = gd.err_valmax
            graph_json["data"].append(graph_datum)
        else:
            if gd.dataset.use_error_bars:
                json_val = {
                    "value": gd.value,
                    "min": gd.err_valmin,
                    "max": gd.err_valmax,
                }
            else:
                json_val = gd.value
            if graph.use_clusters():
                graph_json["data"][gd.get_cluster().url][
                    gd.dataset.url] = json_val
            else:
                if gd.dataset.use_error_bars:
                    json_val["horizontal_value"] = gd.horiz_json_value()
                else:
                    json_val = (gd.horiz_json_value(), json_val)
                graph_json["data"][gd.dataset.url].append(json_val)
    if graph.use_numeric_axes():
        numeric_min, numeric_max = apply_vertical_axis_buffer(
            graph, numeric_min, numeric_max)
        graph_json["%s_scale" % graph.numeric_axis_name()] = {
            "min": numeric_min,
            "max": numeric_max
        }
        if graph.use_secondary_numeric_axis:
            numeric2_min, numeric2_max = apply_vertical_axis_buffer(
                graph, numeric2_min, numeric2_max)
            graph_json["%s_2_scale" % graph.numeric_axis_name()] = {
                "min": numeric2_min,
                "max": numeric2_max
            }
    if not graph.use_clusters():
        graph_json["horizontal_axis_scale"] = {
            "min": graph.jsonise_horiz_value(horiz_min),
            "max": graph.jsonise_horiz_value(horiz_max)
        }
    if graph.use_clusters():
        if graph.is_histogram():
            clusters_attrib = "clusters"
        else:
            clusters_attrib = "pies"
        graph_json[clusters_attrib] = [
            c.__getstate__(view=view) for c in graph.clusters(pval)
        ]
    overrides = get_graph_overrides(graph.datasets, GraphDatasetData,
                                    "dataset", pval)
    datasets = {}
    for ds in graph.datasets.all():
        datasets[ds.url] = ds.__getstate__(view=view)
        del datasets[ds.url]["dynamic_name_display"]
        if ds.url in overrides:
            datasets[ds.url]["name"] = overrides[ds.url]
    if graph.is_histogram():
        datasets_attrib = "datasets"
    else:
        datasets_attrib = "sectors"
    graph_json[datasets_attrib] = datasets
    if overrides:
        graph_json["dataset_name_overrides"] = overrides
    return graph_json