示例#1
0
 def setUp(self):
     # create resources
     self.polygon = [[[-63.154907226557498, -4.8118385341739005],
                      [-64.143676757807498, -4.8118385341739005],
                      [-64.132690429682498, -6.2879986723276584],
                      [-62.814331054682498, -6.3535159310087908]]]
     self.inv_polygon = [[[y, x] for x, y in self.polygon[0]]]
     self.r = Report(start=date(year=2011, month=2, day=1),
                     end=date(year=2011, month=3, day=1),
                     finished=True)
     self.r.put()
     self.cell = Cell(x=0,
                      y=0,
                      z=2,
                      report=self.r,
                      ndfi_high=1.0,
                      ndfi_low=0.0)
     self.cell.put()
     self.area = Area(geo=json.dumps(self.inv_polygon),
                      added_by=None,
                      type=1,
                      cell=self.cell)
     self.area.put()
     self.area.create_fusion_tables()
     self.ndfi = NDFI(self.r.comparation_range(), self.r.range())
     self.stats = Stats()
class PolygonApi(unittest.TestCase, GoogleAuthMixin):
    def setUp(self):
        app.config['TESTING'] = True
        self.app = app.test_client()
        self.login('*****@*****.**', 'testuser')
        for x in Area.all():
            x.delete()
        for x in Cell.all():
            x.delete()
        r = Report(start=date.today(), finished=False)
        r.put()
        self.r = r
        self.cell = Cell(x=0, y=0, z=2, report=self.r, ndfi_high=1.0, ndfi_low=0.0)
        self.cell.put()
        self.area = Area(geo='[]', added_by=users.get_current_user(), type=1, cell=self.cell)
        self.area.put()

    def test_list(self):
        rv = self.app.get('/api/v0/report/' + str(self.r.key()) + '/cell/2_0_0/polygon')
        js = json.loads(rv.data)
        self.assertEquals(1, len(js))

    def test_create_non_existing_cell(self):
        rv = self.app.post('/api/v0/report/' + str(self.r.key()) + '/cell/2_1_0/polygon',
            data='{"paths": "test", "type": 1}'
        )
        self.assertEquals(2, Area.all().count())
        self.assertEquals(4, Cell.all().count())
        # check parents exists
        cell = Cell.all().filter('report =', self.r).filter('x =', 1).filter('y =', 0).filter('z =', 2).fetch(1)[0]
        self.assertEquals('test', cell.get_parent().last_change_by.nickname())
        self.assertEquals('test', cell.get_parent().get_parent().last_change_by.nickname())
        self.assertNotEquals(0, cell.get_parent().last_change_on)
        

    def test_create(self):
        rv = self.app.post('/api/v0/report/' + str(self.r.key()) + '/cell/2_0_0/polygon',
            data='{"paths": "[]", "type": 1}'
        )
        self.assertEquals(2, Area.all().count())
        rv = self.app.get('/api/v0/report/' + str(self.r.key()) + '/cell/2_0_0/polygon')
        js = json.loads(rv.data)
        self.assertEquals(2, len(js))

    def test_update(self):
        rv = self.app.put('/api/v0/report/' + str(self.r.key()) + '/cell/2_0_0/polygon/' + str(self.area.key()),
            data='{"paths": "[[1, 2, 3]]", "type": 100}'
        )
        self.assertEquals(1, Area.all().count())
        a = Area.get(self.area.key())
        self.assertEquals(100, a.type)
        self.assertEquals("\"[[1, 2, 3]]\"", a.geo)
        js = json.loads(rv.data)
        self.assertEquals(100, js['type'])
        self.assertEquals("[[1, 2, 3]]", js['paths'])

    def test_delete(self):
        rv = self.app.delete('/api/v0/report/' + str(self.r.key()) + '/cell/2_0_0/polygon/' + str(self.area.key()))

        self.assertEquals(0, Area.all().count())
 def create(self, report_id, cell_pos):
     r = Report.get(Key(report_id))
     z, x, y = Cell.cell_id(cell_pos)
     cell = Cell.get_or_create(r, x, y, z)
     data = json.loads(request.data)
     a = Area(geo=json.dumps(data["paths"]), type=data["type"], added_by=users.get_current_user(), cell=cell)
     a.save()
     cell.last_change_by = users.get_current_user()
     cell.put()
     return Response(a.as_json(), mimetype="application/json")
 def test_update(self):
     rv = self.app.put('/api/v0/report/' + str(self.r.key()) + '/cell/2_0_0/polygon/' + str(self.area.key()),
         data='{"paths": "[[1, 2, 3]]", "type": 100}'
     )
     self.assertEquals(1, Area.all().count())
     a = Area.get(self.area.key())
     self.assertEquals(100, a.type)
     self.assertEquals("\"[[1, 2, 3]]\"", a.geo)
     js = json.loads(rv.data)
     self.assertEquals(100, js['type'])
     self.assertEquals("[[1, 2, 3]]", js['paths'])
示例#5
0
 def test_update(self):
     rv = self.app.put('/api/v0/report/' + str(self.r.key()) +
                       '/cell/2_0_0/polygon/' + str(self.area.key()),
                       data='{"paths": "[[1, 2, 3]]", "type": 100}')
     self.assertEquals(1, Area.all().count())
     a = Area.get(self.area.key())
     self.assertEquals(100, a.type)
     self.assertEquals("\"[[1, 2, 3]]\"", a.geo)
     js = json.loads(rv.data)
     self.assertEquals(100, js['type'])
     self.assertEquals("[[1, 2, 3]]", js['paths'])
 def create(self, report_id, cell_pos):
     r = Report.get(Key(report_id))
     z, x, y = Cell.cell_id(cell_pos)
     cell = Cell.get_or_create(r, x, y, z)
     data = json.loads(request.data)
     a = Area(geo=json.dumps(data['paths']),
              type=data['type'],
              added_by=users.get_current_user(),
              cell=cell)
     a.save()
     cell.last_change_by = users.get_current_user()
     cell.put()
     return Response(a.as_json(), mimetype='application/json')
 def setUp(self):
     app.config['TESTING'] = True
     self.app = app.test_client()
     self.login('*****@*****.**', 'testuser')
     for x in Area.all():
         x.delete()
     for x in Cell.all():
         x.delete()
     r = Report(start=date.today(), finished=False)
     r.put()
     self.r = r
     self.cell = Cell(x=0, y=0, z=2, report=self.r, ndfi_high=1.0, ndfi_low=0.0)
     self.cell.put()
     self.area = Area(geo='[]', added_by=users.get_current_user(), type=1, cell=self.cell)
     self.area.put()
 def delete(self, report_id, cell_pos, id):
     a = Area.get(Key(id))
     if a:
         a.delete();
         a = Response("deleted", mimetype='text/plain')
         a.status_code = 204;
         return a
     abort(404)
 def test_create(self):
     rv = self.app.post('/api/v0/report/' + str(self.r.key()) + '/cell/2_0_0/polygon',
         data='{"paths": "[]", "type": 1}'
     )
     self.assertEquals(2, Area.all().count())
     rv = self.app.get('/api/v0/report/' + str(self.r.key()) + '/cell/2_0_0/polygon')
     js = json.loads(rv.data)
     self.assertEquals(2, len(js))
 def delete(self, report_id, cell_pos, id):
     a = Area.get(Key(id))
     if a:
         a.delete()
         a = Response("deleted", mimetype='text/plain')
         a.status_code = 204
         return a
     abort(404)
示例#11
0
 def setUp(self):
     app.config['TESTING'] = True
     self.app = app.test_client()
     r = Report(start=date.today(), finished=False)
     r.put()
     self.r = r
     self.cell = Cell(x=0,
                      y=0,
                      z=2,
                      report=self.r,
                      ndfi_high=1.0,
                      ndfi_low=0.0)
     self.cell.put()
     self.area = Area(
         geo='[[[-61.5,-12],[-61.5,-11],[-60.5,-11],[-60.5,-12]]]',
         added_by=users.get_current_user(),
         type=1,
         cell=self.cell)
示例#12
0
 def setUp(self):
     app.config['TESTING'] = True
     self.app = app.test_client()
     r = Report(start=date.today(), finished=False)
     r.put()
     self.r = r
     self.cell = Cell(x=0, y=0, z=2, report=self.r, ndfi_high=1.0, ndfi_low=0.0)
     self.cell.put()
     self.area = Area(geo='[[[-61.5,-12],[-61.5,-11],[-60.5,-11],[-60.5,-12]]]', added_by=users.get_current_user(), type=1, cell=self.cell)
示例#13
0
 def test_create(self):
     rv = self.app.post('/api/v0/report/' + str(self.r.key()) +
                        '/cell/2_0_0/polygon',
                        data='{"paths": "[]", "type": 1}')
     self.assertEquals(2, Area.all().count())
     rv = self.app.get('/api/v0/report/' + str(self.r.key()) +
                       '/cell/2_0_0/polygon')
     js = json.loads(rv.data)
     self.assertEquals(2, len(js))
    def update(self, report_id, cell_pos, id):
        data = json.loads(request.data)
        a = Area.get(Key(id))

        a.geo = json.dumps(data['paths'])
        a.type = data['type']

        a.added_by = users.get_current_user()
        a.save();
        return Response(a.as_json(), mimetype='application/json')
    def update(self, report_id, cell_pos, id):
        data = json.loads(request.data)
        a = Area.get(Key(id))

        a.geo = json.dumps(data['paths'])
        a.type = data['type']

        a.added_by = users.get_current_user()
        a.save()
        return Response(a.as_json(), mimetype='application/json')
示例#16
0
 def test_create_non_existing_cell(self):
     rv = self.app.post('/api/v0/report/' + str(self.r.key()) + '/cell/2_1_0/polygon',
         data='{"paths": "test", "type": 1}'
     )
     self.assertEquals(2, Area.all().count())
     self.assertEquals(4, Cell.all().count())
     # check parents exists
     cell = Cell.all().filter('report =', self.r).filter('x =', 1).filter('y =', 0).filter('z =', 2).fetch(1)[0]
     self.assertEquals('test', cell.get_parent().last_change_by.nickname())
     self.assertEquals('test', cell.get_parent().get_parent().last_change_by.nickname())
     self.assertNotEquals(0, cell.get_parent().last_change_on)
示例#17
0
 def setUp(self):
     app.config['TESTING'] = True
     self.app = app.test_client()
     self.login('*****@*****.**', 'testuser')
     for x in Area.all():
         x.delete()
     for x in Cell.all():
         x.delete()
     r = Report(start=date.today(), finished=False)
     r.put()
     self.r = r
     self.cell = Cell(x=0,
                      y=0,
                      z=2,
                      report=self.r,
                      ndfi_high=1.0,
                      ndfi_low=0.0)
     self.cell.put()
     self.area = Area(geo='[]',
                      added_by=users.get_current_user(),
                      type=1,
                      cell=self.cell)
     self.area.put()
示例#18
0
 def test_create_non_existing_cell(self):
     rv = self.app.post('/api/v0/report/' + str(self.r.key()) +
                        '/cell/2_1_0/polygon',
                        data='{"paths": "test", "type": 1}')
     self.assertEquals(2, Area.all().count())
     self.assertEquals(4, Cell.all().count())
     # check parents exists
     cell = Cell.all().filter('report =', self.r).filter('x =', 1).filter(
         'y =', 0).filter('z =', 2).fetch(1)[0]
     self.assertEquals('test', cell.get_parent().last_change_by.nickname())
     self.assertEquals(
         'test',
         cell.get_parent().get_parent().last_change_by.nickname())
     self.assertNotEquals(0, cell.get_parent().last_change_on)
 def setUp(self):
     # create resources
     self.polygon = [[[-63.154907226557498, -4.8118385341739005], [-64.143676757807498, -4.8118385341739005], [-64.132690429682498, -6.2879986723276584], [-62.814331054682498, -6.3535159310087908]]]
     self.inv_polygon = [[[y, x] for x, y in self.polygon[0]]]
     self.r = Report(start=date(year=2011, month=2, day=1),
                     end=date(year=2011, month=3, day=1),
                     finished=True)
     self.r.put()
     self.cell = Cell(x=0, y=0, z=2, report=self.r, ndfi_high=1.0, ndfi_low=0.0)
     self.cell.put()
     self.area = Area(geo=json.dumps(self.inv_polygon), added_by=None, type=1, cell=self.cell)
     self.area.put()
     self.area.create_fusion_tables()
     self.ndfi = NDFI(self.r.comparation_range(), self.r.range())
     self.stats = Stats()
示例#20
0
    def test_delete(self):
        rv = self.app.delete('/api/v0/report/' + str(self.r.key()) + '/cell/2_0_0/polygon/' + str(self.area.key()))

        self.assertEquals(0, Area.all().count())
示例#21
0
    def test_delete(self):
        rv = self.app.delete('/api/v0/report/' + str(self.r.key()) +
                             '/cell/2_0_0/polygon/' + str(self.area.key()))

        self.assertEquals(0, Area.all().count())
示例#22
0
class FTTest(unittest.TestCase):
    def setUp(self):
        app.config['TESTING'] = True
        self.app = app.test_client()
        r = Report(start=date.today(), finished=False)
        r.put()
        self.r = r
        self.cell = Cell(x=0,
                         y=0,
                         z=2,
                         report=self.r,
                         ndfi_high=1.0,
                         ndfi_low=0.0)
        self.cell.put()
        self.area = Area(
            geo='[[[-61.5,-12],[-61.5,-11],[-60.5,-11],[-60.5,-12]]]',
            added_by=users.get_current_user(),
            type=1,
            cell=self.cell)
        #self.area.put()

    def test_save_on_ft(self):
        self.area.put()
        self.area.create_fusion_tables()
        self.assertNotEquals(None, self.area.fusion_tables_id)
        self.area.type = 2
        self.area.save()
        self.area.update_fusion_tables()
        self.area.delete()
        self.area.delete_fusion_tables()
 def get(self, report_id, cell_pos, id):
     a = Area.get(Key(id))
     if not a:
         abort(404)
     return Response(a.as_json(), mimetype='application/json')
示例#24
0
class PolygonApi(unittest.TestCase, GoogleAuthMixin):
    def setUp(self):
        app.config['TESTING'] = True
        self.app = app.test_client()
        self.login('*****@*****.**', 'testuser')
        for x in Area.all():
            x.delete()
        for x in Cell.all():
            x.delete()
        r = Report(start=date.today(), finished=False)
        r.put()
        self.r = r
        self.cell = Cell(x=0,
                         y=0,
                         z=2,
                         report=self.r,
                         ndfi_high=1.0,
                         ndfi_low=0.0)
        self.cell.put()
        self.area = Area(geo='[]',
                         added_by=users.get_current_user(),
                         type=1,
                         cell=self.cell)
        self.area.put()

    def test_list(self):
        rv = self.app.get('/api/v0/report/' + str(self.r.key()) +
                          '/cell/2_0_0/polygon')
        js = json.loads(rv.data)
        self.assertEquals(1, len(js))

    def test_create_non_existing_cell(self):
        rv = self.app.post('/api/v0/report/' + str(self.r.key()) +
                           '/cell/2_1_0/polygon',
                           data='{"paths": "test", "type": 1}')
        self.assertEquals(2, Area.all().count())
        self.assertEquals(4, Cell.all().count())
        # check parents exists
        cell = Cell.all().filter('report =', self.r).filter('x =', 1).filter(
            'y =', 0).filter('z =', 2).fetch(1)[0]
        self.assertEquals('test', cell.get_parent().last_change_by.nickname())
        self.assertEquals(
            'test',
            cell.get_parent().get_parent().last_change_by.nickname())
        self.assertNotEquals(0, cell.get_parent().last_change_on)

    def test_create(self):
        rv = self.app.post('/api/v0/report/' + str(self.r.key()) +
                           '/cell/2_0_0/polygon',
                           data='{"paths": "[]", "type": 1}')
        self.assertEquals(2, Area.all().count())
        rv = self.app.get('/api/v0/report/' + str(self.r.key()) +
                          '/cell/2_0_0/polygon')
        js = json.loads(rv.data)
        self.assertEquals(2, len(js))

    def test_update(self):
        rv = self.app.put('/api/v0/report/' + str(self.r.key()) +
                          '/cell/2_0_0/polygon/' + str(self.area.key()),
                          data='{"paths": "[[1, 2, 3]]", "type": 100}')
        self.assertEquals(1, Area.all().count())
        a = Area.get(self.area.key())
        self.assertEquals(100, a.type)
        self.assertEquals("\"[[1, 2, 3]]\"", a.geo)
        js = json.loads(rv.data)
        self.assertEquals(100, js['type'])
        self.assertEquals("[[1, 2, 3]]", js['paths'])

    def test_delete(self):
        rv = self.app.delete('/api/v0/report/' + str(self.r.key()) +
                             '/cell/2_0_0/polygon/' + str(self.area.key()))

        self.assertEquals(0, Area.all().count())
class StatsTest(unittest.TestCase):
    """ test for reporting api 
    """

    def setUp(self):
        # create resources
        self.polygon = [[[-63.154907226557498, -4.8118385341739005], [-64.143676757807498, -4.8118385341739005], [-64.132690429682498, -6.2879986723276584], [-62.814331054682498, -6.3535159310087908]]]
        self.inv_polygon = [[[y, x] for x, y in self.polygon[0]]]
        self.r = Report(start=date(year=2011, month=2, day=1),
                        end=date(year=2011, month=3, day=1),
                        finished=True)
        self.r.put()
        self.cell = Cell(x=0, y=0, z=2, report=self.r, ndfi_high=1.0, ndfi_low=0.0)
        self.cell.put()
        self.area = Area(geo=json.dumps(self.inv_polygon), added_by=None, type=1, cell=self.cell)
        self.area.put()
        self.area.create_fusion_tables()
        self.ndfi = NDFI(self.r.comparation_range(), self.r.range())
        self.stats = Stats()

    def test_stats(self):
        """
        """
        # freeze map with on area
        report_id = self.r.key().id()
        data = self.ndfi.freeze_map(self.r.base_map(), 
                             int(settings.FT_TABLE_ID),
                             self.r.key().id())
        self.assertTrue('data' in data)
        self.assertTrue('id' in data['data'])
        self.assertTrue(len(data['data']['id']) > 0)
    
        asset_id = data['data']['id']
        print "report id: ", asset_id

        # get stats for this area
        st = self.stats.get_stats_for_polygon(report_id, asset_id, self.polygon)
        
        self.assertTrue(st is not None)
        polygon_stats = st[0]
        print polygon_stats
        self.assertTrue(float(polygon_stats['def']) > 0.0)
        self.assertAlmostEquals(0.0, float(polygon_stats['deg']))
        def_area = float(polygon_stats['def'])
        print "deforested area: ", def_area

        # get stats for this area
        # move the polygon a little bit
        p = [[[x, y + 1.0] for x, y in self.polygon[0]]]
        st = self.stats.get_stats_for_polygon(report_id, asset_id, p)
        self.assertTrue(st is not None)
        print st[0]
        polygon_stats = st['data']['properties']['classHistogram']['values']['null']['values']
        self.assertTrue(float(polygon_stats['def']) > 0.0)
        self.assertTrue(float(polygon_stats['def']) < def_area)
        print "new deforested area: ", float(polygon_stats['def'])

        # search in area whiout deforesation
        p = [[[x+4.0, y] for x, y in self.polygon[0]]]
        st = self.stats.get_stats_for_polygon(report_id, asset_id, p)
        self.assertTrue(st is not None)
        polygon_stats = st[0]
        self.assertAlmostEquals(0.0, float(polygon_stats['def']))
        self.assertAlmostEquals(0.0, float(polygon_stats['deg']))
 def get(self, report_id, cell_pos, id):
     a = Area.get(Key(id))
     if not a:
         abort(404)
     return Response(a.as_json(), mimetype='application/json')
示例#27
0
class StatsTest(unittest.TestCase):
    """ test for reporting api 
    """
    def setUp(self):
        # create resources
        self.polygon = [[[-63.154907226557498, -4.8118385341739005],
                         [-64.143676757807498, -4.8118385341739005],
                         [-64.132690429682498, -6.2879986723276584],
                         [-62.814331054682498, -6.3535159310087908]]]
        self.inv_polygon = [[[y, x] for x, y in self.polygon[0]]]
        self.r = Report(start=date(year=2011, month=2, day=1),
                        end=date(year=2011, month=3, day=1),
                        finished=True)
        self.r.put()
        self.cell = Cell(x=0,
                         y=0,
                         z=2,
                         report=self.r,
                         ndfi_high=1.0,
                         ndfi_low=0.0)
        self.cell.put()
        self.area = Area(geo=json.dumps(self.inv_polygon),
                         added_by=None,
                         type=1,
                         cell=self.cell)
        self.area.put()
        self.area.create_fusion_tables()
        self.ndfi = NDFI(self.r.comparation_range(), self.r.range())
        self.stats = Stats()

    def test_stats(self):
        """
        """
        # freeze map with on area
        report_id = self.r.key().id()
        data = self.ndfi.freeze_map(self.r.base_map(),
                                    int(settings.FT_TABLE_ID),
                                    self.r.key().id())
        self.assertTrue('data' in data)
        self.assertTrue('id' in data['data'])
        self.assertTrue(len(data['data']['id']) > 0)

        asset_id = data['data']['id']
        print "report id: ", asset_id

        # get stats for this area
        st = self.stats.get_stats_for_polygon(report_id, asset_id,
                                              self.polygon)

        self.assertTrue(st is not None)
        polygon_stats = st[0]
        print polygon_stats
        self.assertTrue(float(polygon_stats['def']) > 0.0)
        self.assertAlmostEquals(0.0, float(polygon_stats['deg']))
        def_area = float(polygon_stats['def'])
        print "deforested area: ", def_area

        # get stats for this area
        # move the polygon a little bit
        p = [[[x, y + 1.0] for x, y in self.polygon[0]]]
        st = self.stats.get_stats_for_polygon(report_id, asset_id, p)
        self.assertTrue(st is not None)
        print st[0]
        polygon_stats = st['data']['properties']['classHistogram']['values'][
            'null']['values']
        self.assertTrue(float(polygon_stats['def']) > 0.0)
        self.assertTrue(float(polygon_stats['def']) < def_area)
        print "new deforested area: ", float(polygon_stats['def'])

        # search in area whiout deforesation
        p = [[[x + 4.0, y] for x, y in self.polygon[0]]]
        st = self.stats.get_stats_for_polygon(report_id, asset_id, p)
        self.assertTrue(st is not None)
        polygon_stats = st[0]
        self.assertAlmostEquals(0.0, float(polygon_stats['def']))
        self.assertAlmostEquals(0.0, float(polygon_stats['deg']))
示例#28
0
class FTTest(unittest.TestCase):

    def setUp(self):
        app.config['TESTING'] = True
        self.app = app.test_client()
        r = Report(start=date.today(), finished=False)
        r.put()
        self.r = r
        self.cell = Cell(x=0, y=0, z=2, report=self.r, ndfi_high=1.0, ndfi_low=0.0)
        self.cell.put()
        self.area = Area(geo='[[[-61.5,-12],[-61.5,-11],[-60.5,-11],[-60.5,-12]]]', added_by=users.get_current_user(), type=1, cell=self.cell)
        #self.area.put()

    def test_save_on_ft(self):
        self.area.put()
        self.area.create_fusion_tables()
        self.assertNotEquals(None, self.area.fusion_tables_id)
        self.area.type = 2
        self.area.save()
        self.area.update_fusion_tables()
        self.area.delete()
        self.area.delete_fusion_tables()