Esempio n. 1
0
def stats(table, zone=None, format="csv"):

    reports = request.args.get('reports', None)
    if not reports:
        abort(400)
    try:
        reports = map(int, reports.split(','))
    except ValueError:
        logging.error("bad format for report id")
        abort(400)

    this_report = ReportType.factory(format)
    this_report.init(zone)
    this_report.write_header()

    logging.info("table id is %s ", table)
    logging.info("and we see %s ", FustionTablesNames.all().filter('table_id =', table).fetch(1))
    logging.info("and zone %s ", zone)
    logging.info("and format %s ", format)

    reports = [Report.get_by_id(x) for x in reports]
    for r in reports:
        if not r:
            logging.error("report not found")
            abort(404)

        stats = this_report.get_stats(r, table)

        for s in stats:
            this_report.write_row(r, s, table)

    this_report.write_footer()
    return this_report.response("report_%s" % table)
Esempio n. 2
0
def stats(table, zone=None, format="csv"):

    reports = request.args.get('reports', None)
    if not reports:
        abort(400)
    try:
        reports = map(int, reports.split(','))
    except ValueError:
        logging.error("bad format for report id")
        abort(400)

    this_report = ReportType.factory(format)
    this_report.init(zone)
    this_report.write_header()

    logging.info("table id is %s ", table)
    logging.info("and we see %s ",
                 FustionTablesNames.all().filter('table_id =', table).fetch(1))
    logging.info("and zone %s ", zone)
    logging.info("and format %s ", format)

    reports = [Report.get_by_id(x) for x in reports]
    for r in reports:
        if not r:
            logging.error("report not found")
            abort(404)

        stats = this_report.get_stats(r, table)

        for s in stats:
            this_report.write_row(r, s, table)

    this_report.write_footer()
    return this_report.response("report_%s" % table)
Esempio n. 3
0
 def report_get(self, request):
     item = Report.get_by_id(request.id)
     current_user = users.get_current_user()
     if item and item.author == current_user.author:
         return item.to_message()
     else:
         raise endpoints.NotFoundException('Report %s not found.' %
                                           (request.id,))
Esempio n. 4
0
def polygon_stats(format=None):
    reports = request.args.get('reports', None)
    if not reports:
        abort(400)
    try:
        reports = map(int, reports.split(','))
    except ValueError:
        logging.error("bad format for report id")
        abort(400)

    try:
        reports = [Report.get_by_id(x) for x in reports]
    except ValueError:
        logging.error("can't find some report")
        abort(404)

    #TODO: test if polygon is ccw
    # exchange lat, lon -> lon, lat
    polygon = json.loads(request.args.get('polygon', None))
    polygon.append(polygon[0])
    logging.info(polygon)
    logging.info(path_to_kml([polygon]))
    if not polygon:
        abort(404)
    ee = Stats()
    normalized_poly = [(coord[1], coord[0]) for coord in polygon]
    stats = ee.get_stats_for_polygon([(str(r.key().id()), r.assetid)
                                      for r in reports], [normalized_poly])

    this_report = ReportType.factory(format)
    this_report.init("custom polygon")
    try:
        this_report.write_header()
        for i, s in enumerate(stats):
            r = reports[i]
            this_report.write_row(r, s, None, path_to_kml([polygon]))

        this_report.write_footer()
        return this_report.response("report_polygon")
    except (KeyError, ValueError, IndexError):
        abort(404)
Esempio n. 5
0
def polygon_stats(format=None):
    reports = request.args.get('reports', None)
    if not reports:
        abort(400)
    try:
        reports = map(int, reports.split(','))
    except ValueError:
        logging.error("bad format for report id")
        abort(400)

    try:
        reports = [Report.get_by_id(x) for x in reports]
    except ValueError:
        logging.error("can't find some report")
        abort(404)

    #TODO: test if polygon is ccw
    # exchange lat, lon -> lon, lat
    polygon = json.loads(request.args.get('polygon', None))
    polygon.append(polygon[0])
    logging.info(polygon)
    logging.info(path_to_kml([polygon]))
    if not polygon:
        abort(404)
    ee = Stats()
    normalized_poly = [(coord[1], coord[0]) for coord in polygon]
    stats = ee.get_stats_for_polygon([(str(r.key().id()), r.assetid) for r in reports], [normalized_poly])

    this_report = ReportType.factory(format)
    this_report.init("custom polygon")
    try:
        this_report.write_header()
        for i,s in enumerate(stats):
            r = reports[i]
            this_report.write_row(r, s, None, path_to_kml([polygon]))

        this_report.write_footer()
        return this_report.response("report_polygon")
    except (KeyError, ValueError, IndexError):
        abort(404)