def statistics(self): statistics = s11n.from_json(self._model.statistics) statistics['race_percents'] = dict( (RACE(int(key)), value) for key, value in statistics['race_percents'].items()) statistics['person_race_percents'] = dict( (RACE(int(key)), value) for key, value in statistics['person_race_percents'].items()) statistics['race_cities'] = dict( (RACE(int(key)), value) for key, value in statistics['race_cities'].items()) statistics['terrain_percents'] = dict( (MAP_STATISTICS(int(key)), value) for key, value in statistics['terrain_percents'].items()) return statistics
def __init__(self, data): self._data = data if not self._data: self._data.update( {race.value: 1.0 / len(RACE.records) for race in RACE.records}) self._races = { RACE(int(race_id)): percents for race_id, percents in self._data.iteritems() }
def deserialize(cls, data): obj = cls() obj.person_id = data['person_id'] obj.person_name = data['person_name'] obj.person_race = RACE(data['person_race']) obj.person_type = PERSON_TYPE(data['person_type']) obj.person_gender = GENDER(data['person_gender']) obj.place_id = data['place_id'] if 'old_place_name_forms' in data: obj.old_place_name_forms = utg_words.Word.deserialize(data['old_place_name_forms']) else: obj.old_place_name_forms = names.generator().get_fast_name('название утрачено') return obj
def deserialize(cls, data): return cls(races={ RACE(int(race_id)): percents for race_id, percents in data.items() })
def handle(self, *args, **options): region = options['region'] if not region: region = map_settings.GEN_REGION_OUTPUT % map_info_storage.version output = options['output'] if not output: output = '/tmp/the-tale-map.png' with open(region) as region_file: data = json.loads(region_file.read()) terrain = data['terrain'] buildings = data['buildings'].values() places = data['places'].values() roads = data['roads'].values() width = data['width'] height = data['height'] roads_map = get_roads_map(width, height, roads, {place['id']: place for place in places}) image = PIL.Image.new( 'RGBA', (width * map_settings.CELL_SIZE, height * map_settings.CELL_SIZE)) texture = PIL.Image.open(map_settings.TEXTURE_PATH) for y, row in enumerate(terrain): for x, cell in enumerate(row): terrain_type = TERRAIN(cell) draw_sprite(image, texture, terrain_type.name, x, y) if roads_map[y][x]: draw_sprite(image, texture, terrain_type.name, x, y, base=True) road_sprite = get_road_sprite_info(roads_map, x, y) draw_sprite(image, texture, road_sprite['name'], x, y, rotate=road_sprite['rotate']) for place_info in places: size = place_info['size'] race = RACE(place_info['race']) if size < 3: verbose_size = 'small' elif size < 6: verbose_size = 'medium' elif size < 9: verbose_size = 'large' else: verbose_size = 'capital' sprite_name = ('city_%s_%s' % (race.name.lower(), verbose_size)).upper() draw_sprite(image, texture, sprite_name, place_info['pos']['x'], place_info['pos']['y']) for building_info in buildings: x, y = building_info['pos']['x'], building_info['pos']['y'] draw_sprite(image, texture, TERRAIN(terrain[y][x]).name, x, y, base=True) sprite_name = 'BUILDING_%s' % BUILDING_TYPE( building_info['type']).name draw_sprite(image, texture, sprite_name, x, y) image.crop(OUTPUT_RECTANGLE).resize(REAL_SIZE, PIL.Image.ANTIALIAS).save(output)