def items(db, lang): return {"items": query_meta._items(db, lang)}
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, user, lang): if request.query_string: redirect("./#" + request.query_string) tags = query_meta._tags(db) categories = query_meta._items(db, langs=lang) item_levels = {'1': set(), '2': set(), '3': set()} for categ in categories: for item in categ['items']: del (item['number']) for index, classs in enumerate(item['class']): item['class'][index] = { 'class': classs['class'], 'title': classs['title'], } for level in item['levels']: item_levels[str(level['level'])].add(item['item']) item_levels['1,2'] = item_levels['1'] | item_levels['2'] item_levels['1,2,3'] = item_levels['1,2'] | item_levels['3'] item_levels = {k: list(v) for k, v in item_levels.items()} sql = """ SELECT timestamp FROM updates_last ORDER BY timestamp LIMIT 1 OFFSET (SELECT COUNT(*)/2 FROM updates_last) ; """ db.execute(sql) timestamp = db.fetchone() timestamp = str(timestamp[0]) if timestamp and timestamp[0] else None if user != None: if user: user_error_count = _user_count(db, user) else: # user == False user = '******' user_error_count = {1: 0, 2: 0, 3: 0} else: user_error_count = None return dict(categories=categories, tags=tags, item_levels=item_levels, main_project=utils.main_project, timestamp=timestamp, languages_name=utils.languages_name, website=utils.website, remote_url_read=utils.remote_url_read, user=user, user_error_count=user_error_count, main_website=utils.main_website)
def index(db, user, lang): if request.query_string: redirect("./#" + request.query_string) tags = query_meta._tags(db) categories = query_meta._items(db, langs=lang) item_tags = defaultdict(set) item_levels = {'1': set(), '2': set(), '3': set()} for categ in categories: for item in categ['items']: for level in item['levels']: item_levels[str(level['level'])].add(item['item']) if item['tags']: for tag in item['tags']: item_tags[tag].add(item['item']) item_levels['1,2'] = item_levels['1'] | item_levels['2'] item_levels['1,2,3'] = item_levels['1,2'] | item_levels['3'] urls = [] # TRANSLATORS: link to help in appropriate language if user: urls.append(("byuser", _("Issues by user"), "../byuser/")) urls.append(("relation_analyser", _("Relation analyser"), "http://analyser.openstreetmap.fr/")) # TRANSLATORS: link to source code urls.append(("statistics", _("Statistics"), "../control/update_matrix")) helps = [] helps.append((_("Contact"), "../contact")) helps.append( (_("Help on wiki"), _("http://wiki.openstreetmap.org/wiki/Osmose"))) helps.append((_("Copyright"), "../copyright")) helps.append((_("Sources"), "https://github.com/osm-fr?q=osmose")) helps.append((_("Translation"), "../translation")) sql = """ SELECT EXTRACT(EPOCH FROM ((now())-timestamp)) AS age FROM updates_last ORDER BY timestamp LIMIT 1 OFFSET (SELECT COUNT(*)/2 FROM updates_last) ; """ db.execute(sql) delay = db.fetchone() if delay and delay[0]: delay = delay[0] / 60 / 60 / 24 else: delay = 0 if user != None: if user: user_error_count = _user_count(db, user) else: # user == False user = '******' user_error_count = {1: 0, 2: 0, 3: 0} else: user_error_count = None return template('map/index', categories=categories, item_tags=item_tags, tags=tags, item_levels=item_levels, main_project=utils.main_project, urls=urls, helps=helps, delay=delay, languages_name=utils.languages_name, translate=translator(lang), website=utils.website, remote_url_read=utils.remote_url_read, request=request, user=user, user_error_count=user_error_count)
m = get_symb(symbole) head = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n" head += "<svg xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" width=\"" + str( l) + "\" height=\"" + str(h) + "\">\n" tail = "</svg>" return head + c + "\n<g transform='" + g + "' style='fill:#000000;'>\n" + m + "</g>\n" + tail ################################################################################ if __name__ == "__main__": conn = utils.get_dbconn() db = conn.cursor() all_items = [] for g in query_meta._items(db): all_items += g["items"] #all_items = [{"item":9999, "marker_flag":"=-", "marker_color":"#ff0000"}] # Test marker_folder = os.path.join("..", "web", "static", "images", "markers") subprocess.getstatusoutput("rm %s" % os.path.join(marker_folder, "*.png")) css = "/* sprite-loader-enable */\n" for i in all_items: print(i) for m in "LB": file_svg = os.path.join( marker_folder, "marker-%s-%d.svg" % (m.lower(), i["item"])) file_png = os.path.join( marker_folder, "marker-%s-%d.png" % (m.lower(), i["item"])) open(file_svg, "w").write(get_marker(m, i["flag"], i["color"])) #subprocess.getstatusoutput("rsvg %s %s"%(file_svg, file_png))
def items(db, langs, item, classs): return {"categories": (query_meta._items(db, item = item, classs = classs, langs = langs))}
def items(db, langs): return {"categories": _map_items(query_meta._items(db, langs = langs))}