Beispiel #1
0
def errors(db, lang):
    params = query._params(max_limit=10000)
    results = query._gets(db, params)
    translate = utils.translator(lang)

    out = []
    for res in results:
        i = {
            'lat': float(res["lat"]),
            'lon': float(res["lon"]),
            'id': res["id"],
            'item': str(res["item"]),
        }
        if params.full:
            i.update({
                'lat': float(res["lat"]),
                'lon': float(res["lon"]),
                'id': res["id"],
                'item': str(res["item"]),
                'source': res["source"],
                'classs': res["class"],
                'elems': res["elems"],
                'subclass': res["subclass"],
                'subtitle': translate.select(res["subtitle"]),
                'title': translate.select(res["title"]),
                'level': res["level"],
                'update': str(res["timestamp"]),
                'username': res["username"] or None,
            })
        out.append(i)

    return {'issues': out}
Beispiel #2
0
def user(db, lang, username=None, format=None):
    params = query._params()
    if username:
        params.users = utils.pg_escape(username.decode("utf-8")).split(",")
    params.limit = 500
    params.full = True
    username = "******".join(params.users)

    if not params.users:
        return template('byuser/index', translate=utils.translator(lang))

    errors = query._gets(db, params)
    count = len(errors)
    if request.path.startswith("/api") or format == "json":
        out = OrderedDict()
        for res in errors:
            res["timestamp"] = str(res["timestamp"])
            res["lat"] = float(res["lat"])
            res["lon"] = float(res["lon"])
        out["issues"] = map(dict, errors)
        return out

    elif format == 'rss':
        response.content_type = "application/rss+xml"
        return template('byuser/byuser.rss', username=username, users=params.users, count=count, errors=errors, translate=utils.translator(lang), website=utils.website)

    else:
        return template('byuser/byuser', username=username, users=params.users, count=count, errors=errors, translate=utils.translator(lang), website=utils.website, main_website=utils.main_website, remote_url_read=utils.remote_url_read, html_escape=html_escape)
Beispiel #3
0
def _errors(db, lang, params):
    results = query._gets(db, params)
    out = OrderedDict()

    if not params.full:
        out["description"] = ["lat", "lon", "error_id", "item"]
    else:
        out["description"] = ["lat", "lon", "error_id", "item", "source", "class", "elems", "subclass", "subtitle", "title", "level", "update", "username"]
    out["errors"] = []

    translate = utils.translator(lang)

    for res in results:
        lat       = res["lat"]
        lon       = res["lon"]
        error_id  = res["id"]
        item      = res["item"] or 0

        if not params.full:
            out["errors"].append([str(lat), str(lon), str(error_id), str(item)])
        else:
            source    = res["source"]
            classs    = res["class"]
            elems     = res["elems"]
            subclass  = res["subclass"]
            subtitle  = translate.select(res["subtitle"])
            title     = translate.select(res["title"])
            level     = res["level"]
            update    = res["timestamp"]
            username  = res["username"] or ""
            out["errors"].append([str(lat), str(lon), str(error_id), str(item), str(source), str(classs), str(elems), str(subclass), subtitle, title, str(level), str(update), username])

    return out
Beispiel #4
0
def _errors(db, lang, params):
    results = query._gets(db, params)
    out = OrderedDict()

    if not params.full:
        out["description"] = ["lat", "lon", "error_id", "item"]
    else:
        out["description"] = ["lat", "lon", "error_id", "item", "source", "class", "elems", "subclass", "subtitle", "title", "level", "update", "username"]
    out["errors"] = []

    translate = utils.translator(lang)

    for res in results:
        lat       = res["lat"]
        lon       = res["lon"]
        error_id  = res["id"]
        item      = res["item"] or 0

        if not params.full:
            out["errors"].append([str(lat), str(lon), str(error_id), str(item)])
        else:
            source    = res["source"]
            classs    = res["class"]
            elems     = res["elems"]
            subclass  = res["subclass"]
            subtitle  = translate.select(res["subtitle"])
            title     = translate.select(res["title"])
            level     = res["level"]
            update    = res["timestamp"]
            username  = res["username"] or ""
            out["errors"].append([str(lat), str(lon), str(error_id), str(item), str(source), str(classs), str(elems), str(subclass), subtitle, title, str(level), str(update), username])

    return out
Beispiel #5
0
def user(db, lang, username=None, format=None):
    params = query._params()
    if username:
        params.users = utils.pg_escape(username.decode("utf-8")).split(",")
    params.limit = 500
    params.full = True
    username = "******".join(params.users)

    if not params.users:
        return template('byuser/index')

    errors = query._gets(db, params)
    count = len(errors)
    if request.path.startswith("/api") or format == "json":
        out = OrderedDict()
        out["description"] = ["id", "item", "lat", "lon", "source", "class", "elems", "subclass", "subtitle", "comment", "title", "level", "timestamp", "menu", "username", "date"]
        for res in errors:
            res["timestamp"] = str(res["timestamp"])
            res["date"] = str(res["date"])
        out["byusers"] = errors
        return out

    elif format == 'rss':
        response.content_type = "application/rss+xml"
        return template('byuser/byuser.rss', username=username, users=params.users, count=count, errors=errors, translate=utils.translator(lang), website=utils.website)

    else:
        return template('byuser/byuser', username=username, users=params.users, count=count, errors=errors, translate=utils.translator(lang), website=utils.website, main_website=utils.main_website, remote_url_read=utils.remote_url_read, html_escape=html_escape)
Beispiel #6
0
def _errors_mvt(db, params, z, min_x, min_y, max_x, max_y, limit):
    params.limit = limit
    results = query._gets(db, params) if z >= 6 else None

    if not results or len(results) == 0:
        global MVT_EMPTY
        if not MVT_EMPTY:
            MVT_EMPTY = mapbox_vector_tile.encode([])
        return MVT_EMPTY
    else:
        limit_feature = []
        if len(results) == limit and z < 18:
            limit_feature = [{
                "name": "limit",
                "features": [{
                    "geometry": Point((min_x + max_x) / 2, (min_y + max_y) / 2)
                }]
            }]

        issues_features = []
        for res in sorted(results, key=lambda res: -res["lat"]):
            issues_features.append({
                "geometry": Point(res["lon"], res["lat"]),
                "properties": {
                    "issue_id": res["id"],
                    "item": res["item"] or 0}
            })

        return mapbox_vector_tile.encode([{
            "name": "issues",
            "features": issues_features
        }] + limit_feature, quantize_bounds=(min_x, min_y, max_x, max_y))
Beispiel #7
0
def errors(db, lang):
    params = query._params(max_limit=10000)
    results = query._gets(db, params)
    translate = utils.translator(lang)

    out = []
    for res in results:
        i = {
            'lat': float(res["lat"]),
            'lon': float(res["lon"]),
            'id': res["id"],
            'item': str(res["item"]),
        }
        if params.full:
            i.update({
                'lat': float(res["lat"]),
                'lon': float(res["lon"]),
                'id': res["id"],
                'item': str(res["item"]),
                'source': res["source"],
                'classs': res["class"],
                'elems': res["elems"],
                'subclass': res["subclass"],
                'subtitle': translate.select(res["subtitle"]),
                'title': translate.select(res["title"]),
                'level': res["level"],
                'update': str(res["timestamp"]),
                'username': res["username"] or None,
            })
        out.append(i)

    return {'issues': out}
Beispiel #8
0
def _errors_geo(db, params):
    results = query._gets(db, params)

    features = []

    for res in results:
        properties = {"error_id": res["id"], "item": res["item"] or 0}
        features.append({"type": "Feature", "geometry": {"type": "Point", "coordinates": [float(res["lon"]), float(res["lat"])]}, "properties": properties})

    return {"type": "FeatureCollection", "features": features}
Beispiel #9
0
def _errors_geo(db, params):
    results = query._gets(db, params)

    features = []

    for res in results:
        properties = {"error_id": res["id"], "item": res["item"] or 0}
        features.append({"type": "Feature", "geometry": {"type": "Point", "coordinates": [float(res["lon"]), float(res["lat"])]}, "properties": properties})

    return {"type": "FeatureCollection", "features": features}
Beispiel #10
0
def user(db, lang, username=None, format=None):
    params = query._params()
    if username:
        params.users = utils.pg_escape(username.decode("utf-8")).split(",")
    params.limit = 500
    params.full = True
    username = "******".join(params.users)

    if not params.users:
        return template('byuser/index')

    errors = query._gets(db, params)
    count = len(errors)
    if request.path.startswith("/api") or format == "json":
        out = OrderedDict()
        out["description"] = [
            "id", "item", "lat", "lon", "source", "class", "elems", "subclass",
            "subtitle", "comment", "title", "level", "timestamp", "menu",
            "username", "date"
        ]
        for res in errors:
            res["timestamp"] = str(res["timestamp"])
            res["date"] = str(res["date"])
        out["byusers"] = errors
        return out

    elif format == 'rss':
        response.content_type = "application/rss+xml"
        return template('byuser/byuser.rss',
                        username=username,
                        users=params.users,
                        count=count,
                        errors=errors,
                        translate=utils.translator(lang),
                        website=utils.website)

    else:
        return template('byuser/byuser',
                        username=username,
                        users=params.users,
                        count=count,
                        errors=errors,
                        translate=utils.translator(lang),
                        website=utils.website,
                        main_website=utils.main_website,
                        remote_url_read=utils.remote_url_read,
                        html_escape=html_escape)
Beispiel #11
0
def issues_mvt(db, z, x, y, format):
    lon1, lat2 = tiles.tile2lonlat(x, y, z)
    lon2, lat1 = tiles.tile2lonlat(x + 1, y + 1, z)
    dlon = (lon2 - lon1) / 256
    dlat = (lat2 - lat1) / 256

    params = query._params(max_limit=50 if z > 18 else 10000)
    params.tilex = x
    params.tiley = y
    params.zoom = z
    params.lat = None
    params.lon = None
    params.full = False

    if params.zoom > 18:
        return
    if (not params.users) and (not params.source) and (params.zoom < 6):
        return

    results = query._gets(db, params) if z >= 6 else None

    if format == 'mvt':
        tile = _errors_mvt(db, results, z, lon1, lat1, lon2, lat2,
                           params.limit)
        if tile:
            response.content_type = 'application/vnd.mapbox-vector-tile'
            return tile
        else:
            return HTTPError(404)
    elif format in ('geojson', 'json'):  # Fall back to GeoJSON
        tile = _errors_geojson(db, results, z, lon1, lat1, lon2, lat2,
                               params.limit)
        if tile:
            response.content_type = 'application/vnd.geo+json'
            return tile
        else:
            return []
    else:
        return HTTPError(404)
Beispiel #12
0
def issues_mvt(db, z, x, y, format):
    lon1,lat2 = tiles.tile2lonlat(x,y,z)
    lon2,lat1 = tiles.tile2lonlat(x+1,y+1,z)
    dlon = (lon2 - lon1) / 256
    dlat = (lat2 - lat1) / 256

    params = query._params(max_limit=50 if z > 18 else 10000)
    params.tilex = x
    params.tiley = y
    params.zoom = z
    params.lat = None
    params.lon = None
    params.full = False

    if params.zoom > 18:
        return
    if (not params.users) and (not params.source) and (params.zoom < 6):
        return

    results = query._gets(db, params) if z >= 6 else None

    if format == 'mvt':
        tile = _errors_mvt(db, results, z, lon1, lat1, lon2, lat2, params.limit)
        if tile:
            response.content_type = 'application/vnd.mapbox-vector-tile'
            return tile
        else:
            return HTTPError(404)
    elif format in ('geojson', 'json'):  # Fall back to GeoJSON
        tile = _errors_geojson(db, results, z, lon1, lat1, lon2, lat2, params.limit)
        if tile:
            response.content_type = 'application/vnd.geo+json'
            return tile
        else:
            return []
    else:
        return HTTPError(404)
Beispiel #13
0
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 = query._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)::hstore AS menu",
            "min(class.title::text)::hstore 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 = []
        for res in errors:
            if res["elems"]:
                elems = res["elems"].split("_")
                for e in elems:
                    m = re.match(r"([a-z]+)([0-9]+)", e)
                    if m:
                        cur_type = m.group(1)
                        objects.append(cur_type[0] + m.group(2))

        response.status = 302
        response.set_header('Location', 'http://localhost:8111/load_object?objects=%s' % ','.join(objects))
        return
    elif format == 'csv':
        output = StringIO.StringIO()
        writer = csv.writer(output)
        h = ['id', 'source', 'item', 'class', 'subclass', 'level', 'title', 'subtitle', 'country', 'analyser', 'timestamp', 'username', 'lat', 'lon', 'elems']
        writer.writerow(h)
        for res in errors:
            writer.writerow(map(lambda a: 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, translate=utils.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)
Beispiel #14
0
def index(db, lang, format=None):
    if request.path.endswith("false-positive"):
        title = _("False positives")
        gen = "false-positive"
    elif request.path.endswith("done"):
        title = _("Fixed issues")
        gen = "done"
    else:
        title = _("Informations")
        gen = "error"

    if not format in ('rss', 'gpx', 'josm'):
        format = None

    countries = query_meta._countries(db, lang) if format == None else None
    items = query_meta._items(db, lang)

    params = query._params()
    params.status = {"error":"open", "false-positive": "false", "done":"done"}[gen]
    params.limit = None

    if format == None and params.item:
        errors_groups = query._count(db, params, [
            "dynpoi_class.item",
            "dynpoi_class.source",
            "dynpoi_class.class",
            "source.country",
            "source.analyser"],
            ["dynpoi_item"], [
            "first(dynpoi_item.menu) AS menu",
            "first(dynpoi_class.title) AS title"],
            orderBy = True)

        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 == 'josm':
        objects = []
        for res in errors:
            if res["elems"]:
                elems = res["elems"].split("_")
                for e in elems:
                    m = re.match(r"([a-z]+)([0-9]+)", e)
                    if m:
                        cur_type = m.group(1)
                        objects.append(cur_type[0] + m.group(2))

        response.status = 302
        response.set_header('Location', 'http://localhost:8111/load_object?objects=%s' % ','.join(objects))
        return
    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, translate=utils.translator(lang), gen=gen, opt_date=opt_date, title=title, website=utils.website)
Beispiel #15
0
def index(db, lang, format=None):
    if request.path.endswith("false-positive"):
        title = _("False positives")
        gen = "false-positive"
    elif request.path.endswith("done"):
        title = _("Fixed issues")
        gen = "done"
    else:
        title = _("Informations")
        gen = "error"

    if not format in ('rss', 'gpx', 'josm'):
        format = None

    countries = query_meta._countries(db, lang) if format == None else None
    items = query_meta._items(db, lang)

    params = query._params()
    params.status = {
        "error": "open",
        "false-positive": "false",
        "done": "done"
    }[gen]
    params.limit = None

    if format == None and params.item:
        errors_groups = query._count(
            db,
            params, [
                "dynpoi_class.item", "dynpoi_class.source",
                "dynpoi_class.class", "source.country", "source.analyser"
            ], ["dynpoi_item"], [
                "min(dynpoi_item.menu::text)::hstore AS menu",
                "min(dynpoi_class.title::text)::hstore AS title"
            ],
            orderBy=True)

        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 == 'josm':
        objects = []
        for res in errors:
            if res["elems"]:
                elems = res["elems"].split("_")
                for e in elems:
                    m = re.match(r"([a-z]+)([0-9]+)", e)
                    if m:
                        cur_type = m.group(1)
                        objects.append(cur_type[0] + m.group(2))

        response.status = 302
        response.set_header(
            'Location',
            'http://localhost:8111/load_object?objects=%s' % ','.join(objects))
        return
    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,
                    translate=utils.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)
Beispiel #16
0
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 = query._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)::hstore AS menu",
            "min(class.title::text)::hstore AS title"],
            orderBy = True)

        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 = []
        for res in errors:
            if res["elems"]:
                elems = res["elems"].split("_")
                for e in elems:
                    m = re.match(r"([a-z]+)([0-9]+)", e)
                    if m:
                        cur_type = m.group(1)
                        objects.append(cur_type[0] + m.group(2))

        response.status = 302
        response.set_header('Location', 'http://localhost:8111/load_object?objects=%s' % ','.join(objects))
        return
    elif format == 'csv':
        output = StringIO.StringIO()
        writer = csv.writer(output)
        h = ['id', 'source', 'item', 'class', 'subclass', 'level', 'title', 'subtitle', 'country', 'analyser', 'timestamp', 'username', 'lat', 'lon', 'elems']
        writer.writerow(h)
        for res in errors:
            writer.writerow(map(lambda a: 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, translate=utils.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)