def read(self): fn = os.path.join(self._config.parent.parent.basedir, self.__filename) with open(fn, 'r') as f: data = geojson.loads(f.read(), object_hook=geojson.GeoJSON.to_instance) for f in data.features: obj = Result(id=f.properties['ID'], level_id=self._config.parent.id) if self._geometry == 'area': obj.area_wkt = asShape(f.geometry).wkt yield obj
def __read_row(self, header, row): obj = Result(level_id=self._config.parent.id) record = self._process_record(dict(zip(header, row))) for k, v in record.items(): if v == '': v = None if k in ('id', 'parent_id', 'name') and v: v = v.decode('utf-8') if not k.startswith('vote_count_') and hasattr(obj, k): setattr(obj, k, v) yield obj for k, v in record.items(): if k.startswith('vote_count_'): vobj = ResultVote(result_id=obj.id, participant_id=int( k.replace('vote_count_', '')), vote_count=int(v)) yield vobj