当前位置: 首页>>代码示例>>Python>>正文


Python DataMap.shard_model方法代码示例

本文整理汇总了Python中ichnaea.models.content.DataMap.shard_model方法的典型用法代码示例。如果您正苦于以下问题:Python DataMap.shard_model方法的具体用法?Python DataMap.shard_model怎么用?Python DataMap.shard_model使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ichnaea.models.content.DataMap的用法示例。


在下文中一共展示了DataMap.shard_model方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_files

# 需要导入模块: from ichnaea.models.content import DataMap [as 别名]
# 或者: from ichnaea.models.content.DataMap import shard_model [as 别名]
    def test_files(self, db_rw, session):
        today = util.utcnow().date()
        rows = [
            dict(time=today, lat=12.345, lon=12.345),
            dict(time=today, lat=0, lon=12.345),
            dict(time=today, lat=-10.000, lon=-11.000),
        ]
        for row in rows:
            lat, lon = DataMap.scale(row['lat'], row['lon'])
            data = DataMap.shard_model(lat, lon)(
                grid=(lat, lon), created=row['time'], modified=row['time'])
            session.add(data)
        session.flush()

        lines = []
        rows = 0
        db_url = str(db_rw.engine.url)
        with util.selfdestruct_tempdir() as temp_dir:
            quaddir = os.path.join(temp_dir, 'quadtrees')
            os.mkdir(quaddir)
            shapes = os.path.join(temp_dir, 'shapes')
            tiles = os.path.join(temp_dir, 'tiles')

            for shard_id, shard in DataMap.shards().items():
                filename = 'map_%s.csv.gz' % shard_id
                filepath = os.path.join(temp_dir, filename)
                result = export_file(
                    db_url, filepath, shard.__tablename__,
                    _session=session)

                if not result:
                    assert not os.path.isfile(filepath)
                    continue

                rows += result
                with util.gzip_open(filepath, 'r') as fd:
                    written = fd.read()
                lines.extend([line.split(',') for line in written.split()])

                encode_file(filename, temp_dir, quaddir, DATAMAPS_DIR)

                quadfolder = os.path.join(quaddir, 'map_' + shard_id)
                assert os.path.isdir(quadfolder)
                self._check_quadtree(quadfolder)

            merge_files(quaddir, shapes, DATAMAPS_DIR)
            self._check_quadtree(shapes)

            render_tiles(shapes, tiles, 1, 2, DATAMAPS_DIR, PNGQUANT)
            assert (sorted(os.listdir(tiles)) == ['0', '1', '2'])
            assert (sorted(os.listdir(os.path.join(tiles, '0', '0'))) ==
                    ['0.png', '[email protected]'])

        assert rows == 36
        assert len(lines) == 36
        assert (set([round(float(l[0]), 2) for l in lines]) ==
                set([-10.0, 0.0, 12.35]))
        assert (set([round(float(l[1]), 2) for l in lines]) ==
                set([-11.0, 12.35]))
开发者ID:amjadm61,项目名称:ichnaea,代码行数:61,代码来源:test_datamap.py

示例2: test_grid_bytes

# 需要导入模块: from ichnaea.models.content import DataMap [as 别名]
# 或者: from ichnaea.models.content.DataMap import shard_model [as 别名]
 def test_grid_bytes(self):
     lat = 12000
     lon = 34000
     grid = encode_datamap_grid(lat, lon)
     model = DataMap.shard_model(lat, lon)
     self.session.add(model(grid=grid))
     self.session.flush()
     result = self.session.query(model).first()
     self.assertEqual(result.grid, (lat, lon))
开发者ID:cemoulto,项目名称:ichnaea,代码行数:11,代码来源:test_content.py

示例3: test_fields

# 需要导入模块: from ichnaea.models.content import DataMap [as 别名]
# 或者: from ichnaea.models.content.DataMap import shard_model [as 别名]
 def test_fields(self):
     today = util.utcnow().date()
     lat = 12345
     lon = -23456
     model = DataMap.shard_model(lat, lon)
     self.session.add(model(grid=(lat, lon), created=today, modified=today))
     self.session.flush()
     result = self.session.query(model).first()
     self.assertEqual(result.grid, (lat, lon))
     self.assertEqual(result.created, today)
     self.assertEqual(result.modified, today)
开发者ID:cemoulto,项目名称:ichnaea,代码行数:13,代码来源:test_content.py

示例4: test_files

# 需要导入模块: from ichnaea.models.content import DataMap [as 别名]
# 或者: from ichnaea.models.content.DataMap import shard_model [as 别名]
    def test_files(self):
        today = util.utcnow().date()
        rows = [
            dict(time=today, lat=12.345, lon=12.345),
            dict(time=today, lat=0, lon=12.345),
            dict(time=today, lat=-10.000, lon=-11.000),
        ]
        for row in rows:
            lat, lon = DataMap.scale(row["lat"], row["lon"])
            data = DataMap.shard_model(lat, lon)(grid=(lat, lon), created=row["time"], modified=row["time"])
            self.session.add(data)
        self.session.flush()

        lines = []
        rows = 0
        with util.selfdestruct_tempdir() as temp_dir:
            quaddir = os.path.join(temp_dir, "quadtrees")
            os.mkdir(quaddir)
            shapes = os.path.join(temp_dir, "shapes")
            tiles = os.path.join(temp_dir, "tiles")

            for shard_id, shard in DATAMAP_SHARDS.items():
                filename = "map_%s.csv.gz" % shard_id
                filepath = os.path.join(temp_dir, filename)
                result = export_file(None, filepath, shard.__tablename__, _db_rw=_make_db(), _session=self.session)

                if not result:
                    self.assertFalse(os.path.isfile(filepath))
                    continue

                rows += result
                with util.gzip_open(filepath, "r") as fd:
                    written = fd.read()
                lines.extend([line.split(",") for line in written.split()])

                encode_file(filename, temp_dir, quaddir, DATAMAPS_DIR)

                quadfolder = os.path.join(quaddir, "map_" + shard_id)
                self.assertTrue(os.path.isdir(quadfolder))
                self._check_quadtree(quadfolder)

            merge_files(quaddir, shapes, DATAMAPS_DIR)
            self._check_quadtree(shapes)

            render_tiles(shapes, tiles, 1, 2, DATAMAPS_DIR, PNGQUANT)
            self.assertEqual(sorted(os.listdir(tiles)), ["0", "1", "2"])
            self.assertEqual(sorted(os.listdir(os.path.join(tiles, "0", "0"))), ["0.png", "[email protected]"])

        self.assertEqual(rows, 36)
        self.assertEqual(len(lines), 36)
        self.assertEqual(set([round(float(l[0]), 2) for l in lines]), set([-10.0, 0.0, 12.35]))
        self.assertEqual(set([round(float(l[1]), 2) for l in lines]), set([-11.0, 12.35]))
开发者ID:voolitels,项目名称:ichnaea,代码行数:54,代码来源:test_datamap.py

示例5: test_grid_list

# 需要导入模块: from ichnaea.models.content import DataMap [as 别名]
# 或者: from ichnaea.models.content.DataMap import shard_model [as 别名]
 def test_grid_list(self):
     lat = 1000
     lon = -2000
     self.session.add(DataMap.shard_model(lat, lon)(grid=[lat, lon]))
     with self.assertRaises(Exception):
         self.session.flush()
开发者ID:cemoulto,项目名称:ichnaea,代码行数:8,代码来源:test_content.py

示例6: test_grid_length

# 需要导入模块: from ichnaea.models.content import DataMap [as 别名]
# 或者: from ichnaea.models.content.DataMap import shard_model [as 别名]
 def test_grid_length(self):
     self.session.add(DataMap.shard_model(0, 9)(grid=b'\x00' * 9))
     with self.assertRaises(Exception):
         self.session.flush()
开发者ID:cemoulto,项目名称:ichnaea,代码行数:6,代码来源:test_content.py

示例7: test_grid_none

# 需要导入模块: from ichnaea.models.content import DataMap [as 别名]
# 或者: from ichnaea.models.content.DataMap import shard_model [as 别名]
 def test_grid_none(self):
     self.session.add(DataMap.shard_model(0, 0)(grid=None))
     with self.assertRaises(Exception):
         self.session.flush()
开发者ID:cemoulto,项目名称:ichnaea,代码行数:6,代码来源:test_content.py

示例8: test_grid_length

# 需要导入模块: from ichnaea.models.content import DataMap [as 别名]
# 或者: from ichnaea.models.content.DataMap import shard_model [as 别名]
 def test_grid_length(self, session):
     session.add(DataMap.shard_model(0, 9)(grid=b'\x00' * 9))
     with pytest.raises(Exception):
         session.flush()
开发者ID:crankycoder,项目名称:ichnaea,代码行数:6,代码来源:test_content.py

示例9: test_grid_none

# 需要导入模块: from ichnaea.models.content import DataMap [as 别名]
# 或者: from ichnaea.models.content.DataMap import shard_model [as 别名]
 def test_grid_none(self, session):
     with warnings.catch_warnings():
         warnings.simplefilter('ignore', SAWarning)
         session.add(DataMap.shard_model(0, 0)(grid=None))
         with pytest.raises(Exception):
             session.flush()
开发者ID:crankycoder,项目名称:ichnaea,代码行数:8,代码来源:test_content.py

示例10: _add

# 需要导入模块: from ichnaea.models.content import DataMap [as 别名]
# 或者: from ichnaea.models.content.DataMap import shard_model [as 别名]
 def _add(self, entries):
     for lat, lon, time in entries:
         lat, lon = DataMap.scale(lat, lon)
         self.session.add(DataMap.shard_model(lat, lon)(
             grid=(lat, lon), created=time, modified=time))
     self.session.flush()
开发者ID:cemoulto,项目名称:ichnaea,代码行数:8,代码来源:test_datamap.py

示例11: _one

# 需要导入模块: from ichnaea.models.content import DataMap [as 别名]
# 或者: from ichnaea.models.content.DataMap import shard_model [as 别名]
 def _one(self, lat, lon, time):
     lat, lon = DataMap.scale(lat, lon)
     return DataMap.shard_model(lat, lon)(
         grid=(lat, lon), created=time, modified=time)
开发者ID:crankycoder,项目名称:ichnaea,代码行数:6,代码来源:test_datamap.py

示例12: test_grid_none

# 需要导入模块: from ichnaea.models.content import DataMap [as 别名]
# 或者: from ichnaea.models.content.DataMap import shard_model [as 别名]
 def test_grid_none(self, session):
     session.add(DataMap.shard_model(0, 0)(grid=None))
     with pytest.raises(Exception):
         session.flush()
开发者ID:amjadm61,项目名称:ichnaea,代码行数:6,代码来源:test_content.py


注:本文中的ichnaea.models.content.DataMap.shard_model方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。