def _user(db, lang, username): params = Params() if username: params.users = username.split(",") params.limit = 500 params.full = True username = "******".join(params.users) errors = query._gets(db, params) return [params, username, errors]
def markers(db): params = Params() if (not params.users) and (not params.source) and (params.zoom < 7): return params.limit = 200 params.full = False return _errors_geo(db, params)
def index(db, lang, format=None): if "false-positive" in request.path: title = _("False positives") gen = "false-positive" elif "done" in request.path: title = _("Fixed issues") gen = "done" else: title = _("Informations") gen = "error" if not format in ('rss', 'gpx', 'kml', 'josm', 'csv'): format = None countries = query_meta._countries(db, lang) if format == None else None items = query_meta._items(db, lang) params = Params() params.status = { "error": "open", "false-positive": "false", "done": "done" }[gen] params.limit = None params.fixable = None if format == None and params.item: errors_groups = query._count( db, params, [ "dynpoi_class.item", "marker.source", "marker.class", "source.country", "source.analyser", "dynpoi_update_last.timestamp" ], ["dynpoi_item", "class"], [ "min(dynpoi_item.menu::text)::jsonb AS menu", "min(class.title::text)::jsonb AS title" ], ) total = 0 for res in errors_groups: if res["count"] != -1: total += res["count"] else: errors_groups = [] total = 0 params.limit = request.params.get('limit', type=int, default=100) if params.limit > 10000: params.limit = 10000 if (total > 0 and total < 1000) or params.limit: params.full = True errors = query._gets(db, params) if gen in ("false-positive", "done"): opt_date = "date" else: opt_date = "-1" else: opt_date = None errors = None if format == 'rss': response.content_type = 'application/rss+xml' tpl = 'errors/list.rss' elif format == 'gpx': response.content_type = 'application/gpx+xml' tpl = 'errors/list.gpx' elif format == 'kml': response.content_type = 'application/vnd.google-earth.kml+xml' tpl = 'errors/list.kml' elif format == 'josm': objects = set( sum( map( lambda error: list( map( lambda elem: elem['type'].lower() + str(elem[ 'id']), error['elems'] or [])), errors), [])) response.status = 302 response.set_header( 'Location', 'http://localhost:8111/load_object?objects=%s' % ','.join(objects)) return elif format == 'csv': output = io.StringIO() writer = csv.writer(output) h = [ 'uuid', 'source', 'item', 'class', 'level', 'title', 'subtitle', 'country', 'analyser', 'timestamp', 'username', 'lat', 'lon', 'elems' ] writer.writerow(h) for res in errors: usernames = list( map(lambda elem: elem.get("username", ""), res['elems'] or [])) elems = '_'.join( map( lambda elem: { 'N': 'node', 'W': 'way', 'R': 'relation' }[elem['type']] + str(elem['id']), res['elems'] or [])) writer.writerow( list( map( lambda a: usernames if a == 'username' else elems if a == 'elems' else res[a], h))) response.content_type = 'text/csv' return output.getvalue() else: tpl = 'errors/index' return template(tpl, countries=countries, items=items, errors_groups=errors_groups, total=total, errors=errors, query=request.query_string, country=params.country, item=params.item, level=params.level, lang=lang[0], translate=translator(lang), gen=gen, opt_date=opt_date, title=title, website=utils.website, main_website=utils.main_website, remote_url_read=utils.remote_url_read)
def index(db, lang, format): if "false-positive" in request.path: title = _("False positives") gen = "false-positive" elif "done" in request.path: title = _("Fixed issues") gen = "done" else: title = _("Information") gen = "error" params = Params() params.status = { "error": "open", "false-positive": "false", "done": "done" }[gen] params.fixable = None items = query_meta._items_menu(db, lang) for res in items: if params.item == str(res["item"]): title += ' - ' + res['menu']['auto'] params.limit = request.params.get('limit', type=int, default=100) if params.limit > 10000: params.limit = 10000 params.full = True errors = query._gets(db, params) for error in errors: error["subtitle"] = i10n_select_auto(error["subtitle"], lang) error["title"] = i10n_select_auto(error["title"], lang) error["menu"] = i10n_select_auto(error["menu"], lang) if format == 'rss': response.content_type = 'application/rss+xml' tpl = 'errors/list.rss' elif format == 'gpx': response.content_type = 'application/gpx+xml' tpl = 'errors/list.gpx' elif format == 'kml': response.content_type = 'application/vnd.google-earth.kml+xml' tpl = 'errors/list.kml' elif format == 'josm': objects = set( sum( map( lambda error: list( map( lambda elem: elem['type'].lower() + str(elem[ 'id']), error['elems'] or [])), errors), [])) response.status = 302 response.set_header( 'Location', 'http://localhost:8111/load_object?objects=%s' % ','.join(objects)) return elif format == 'csv': output = io.StringIO() writer = csv.writer(output) h = [ 'uuid', 'source', 'item', 'class', 'level', 'title', 'subtitle', 'country', 'analyser', 'timestamp', 'username', 'lat', 'lon', 'elems' ] hh = {'source': 'source_id'} writer.writerow(h) for res in errors: usernames = list( map(lambda elem: elem.get("username", ""), res['elems'] or [])) elems = '_'.join( map( lambda elem: { 'N': 'node', 'W': 'way', 'R': 'relation' }[elem['type']] + str(elem['id']), res['elems'] or [])) writer.writerow( list( map( lambda a: usernames if a == 'username' else elems if a == 'elems' else res[a], map(lambda y: hh.get(y, y), h)))) response.content_type = 'text/csv' return output.getvalue() else: countries = query_meta._countries(db) items = list(map(dict, items)) if params.item: params.limit = None errors_groups = query._count( db, params, [ "markers_counts.item", "markers.source_id", "markers.class", "sources.country", "sources.analyser", "updates_last.timestamp" ], ["items", "class"], [ "min(items.menu::text)::jsonb AS menu", "min(class.title::text)::jsonb AS title" ], ) total = 0 for res in errors_groups: res["title"] = i10n_select_auto(res["title"], lang) res["menu"] = i10n_select_auto(res["menu"], lang) if res["count"] != -1: total += res["count"] else: errors_groups = [] total = 0 if gen in ("false-positive", "done"): opt_date = "date" else: opt_date = None errors_groups = list(map(dict, errors_groups)) for res in errors_groups: res['timestamp'] = str(res['timestamp']) errors = list(map(dict, errors)) for res in errors: res['timestamp'] = str(res['timestamp']) if 'date' in res: res['date'] = str(res['date']) return dict(countries=countries, items=items, errors_groups=errors_groups, total=total, errors=errors, gen=gen, opt_date=opt_date, website=utils.website, main_website=utils.main_website, remote_url_read=utils.remote_url_read) return template(tpl, items=items, errors=errors, query=request.query_string, lang=lang[0], gen=gen, title=title, website=utils.website, main_website=utils.main_website, remote_url_read=utils.remote_url_read)