def tpcreator_spec_from_tpcreator_uispec(tpcreator_uispec): res = { 'full_tags': [d['tag'] for d in tpcreator_uispec if d['tag'] == d['prefix']], 'prefixes': util.uniq_sameorder(d['prefix'] for d in tpcreator_uispec if d['tag'] != d['prefix']), } res['prefixes'].sort(key=lambda p: len(p)) return res
def tags_matching_tpcreator_spec(tpcreator_spec, tags): if not tpcreator_spec: return None if not tags: return None res = [] for full_tag in tpcreator_spec['full_tags']: if full_tag not in tags: return None res.append(full_tag) for prefix in tpcreator_spec['prefixes']: prefix_matched = False for tag in tags: if tag.startswith(prefix): res.append(tag) prefix_matched = True if not prefix_matched: return None res = util.uniq_sameorder(res) res.sort() return res
def parse_tags(s): if s is None: return None if s == '': return [] tags = s.split(',') tags = [t for t in tags if t.strip()] return util.uniq_sameorder(tags)
def select_multi(owner_id, report_id_list): """Returns an ordered dictionary mapping the report ID present on the ``report_id_list`` to a :class:`Report`, in the order of the ``report_id_list``. Non-existing reports are not present in the result.""" report_id_list = util.uniq_sameorder(report_id_list) rows = c.dao.ReportDAO.select_multi(owner_id, report_id_list) row_by_id = {row['report_id']: row for row in rows} res = OrderedDict() for id in report_id_list: if id in row_by_id: res[id] = Report(row_by_id[id]) return res
def _postprocess_tile_config(cls, tile_config): tile_config['series_spec_list'] = util.uniq_sameorder(tile_config['series_spec_list']) if 'tile_options' in tile_config and 'owner_id' in tile_config[ 'tile_options']: del tile_config['tile_options']['owner_id'] if 'tile_options' in tile_config and 'report_id' in tile_config[ 'tile_options']: del tile_config['tile_options']['report_id'] if 'tile_options' in tile_config and 'series_configs' in tile_config[ 'tile_options']: del tile_config['tile_options']['series_configs']
def colno_score(colno): if _label_score(row[colno]) == 0: return 0 vals = [ report_instance.table.rows[i][colno] for i in report_instance.table.value_or_other_idxs ] label_vals = [v for v in vals if _label_score(v) > 0] label_vals_factor = len(label_vals) / len(vals) if label_vals_factor < 0.5: return 0 label_string_keys = [ev.to_string_key() for ev in label_vals] row_occurrences = label_string_keys.count(row[colno].to_string_key()) if row_occurrences != 1: return 0 uniq_vals = util.uniq_sameorder(label_string_keys) if report_instance.table.num_rows > 1 and len(uniq_vals) == 1: return 0 return len(uniq_vals) * label_vals_factor * util.avg( _label_score(ev) for ev in label_vals)
def colno_score(colno): """Compute a score telling how good is the colno as a filtering column""" # if the label score for the sampled row is 0, it can't be a good filtering column if _label_score(row[colno]) == 0: return 0 # all values of the candidate column vals = [report_instance.table.rows[i][colno] for i in report_instance.table.value_or_other_idxs] # if less than half of column values are labels, it's not a good filtering column label_vals = [v for v in vals if _label_score(v) > 0] label_vals_factor = len(label_vals) / len(vals) if label_vals_factor < 0.5: return 0 # strings which are valid labels label_string_keys = [ev.to_string_key() for ev in label_vals] # if the row can't be uniquely identified by the column, it's not a good filtering column row_occurrences = label_string_keys.count(row[colno].to_string_key()) if row_occurrences != 1: return 0 # unique label values uniq_vals = util.uniq_sameorder(label_string_keys) # if there's only one unique label for a report instance with more than one row, # it's not a good filtering column if report_instance.table.num_rows > 1 and len(uniq_vals) == 1: return 0 # the resulting score combines the number of valid and unique labels and an average # score for a label value return len(uniq_vals) * label_vals_factor * util.avg(_label_score(ev) for ev in label_vals)
def _postprocess_tile_options(cls, tile_options): if tile_options.get('tags'): tile_options['tags'] = util.uniq_sameorder(tile_options['tags']) tile_options['tags'].sort()
def _unique_series_specs(ss_list): return util.uniq_sameorder(ss_list, key=lambda ss: dataseries.series_spec_for_default_options(ss))