Esempio n. 1
0
def _user_count(db, username=None):
    params = query._params()
    if username:
        params.users = utils.pg_escape(username.decode("utf-8")).split(",")

    if not params.users:
        return

    res = query._count(db, params, ['dynpoi_class.level'], ['dynpoi_class.level'])
    ret = {1:0, 2:0, 3:0}
    for (l, c) in res:
        ret[l] = c

    return ret
Esempio n. 2
0
def _user_count(db, username=None):
    params = query._params()
    if username:
        params.users = utils.pg_escape(username.decode("utf-8")).split(",")

    if not params.users:
        return

    res = query._count(db, params, ['class.level'], ['class.level'])
    ret = {1:0, 2:0, 3:0}
    for (l, c) in res:
        ret[l] = c

    return ret
Esempio n. 3
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)
Esempio n. 4
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)
Esempio n. 5
0
def _users(db):
    params = query._params()
    return query._count(db, params, ["marker_elem.username"])
Esempio n. 6
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)
Esempio n. 7
0
def _users(db):
    params = query._params()
    return query._count(db, params, ["marker_elem.username"])
Esempio n. 8
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)