Skip to content

Static records writer

AreaRecord

Bases: StaticRecord

Source code in june/records/static_records_writer.py
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
class AreaRecord(StaticRecord):
    """ """
    def __init__(self):
        super().__init__(
            table_name="areas",
            int_names=["id", "super_area_id"],
            float_names=["latitude", "longitude", "socioeconomic_index"],
            str_names=["name"],
            expectedrows=10_000,
        )

    def get_data(self, world):
        """

        Args:
            world: 

        """
        (
            area_id,
            super_area_id,
            latitude,
            longitude,
            socioeconomic_index,
            area_name,
        ) = ([], [], [], [], [], [])
        if world.areas is not None:
            for area in world.areas:
                area_id.append(area.id)
                super_area_id.append(area.super_area.id)
                latitude.append(area.coordinates[0])
                longitude.append(area.coordinates[1])
                socioeconomic_index.append(area.socioeconomic_index)
                area_name.append(area.name)
        int_data = [area_id, super_area_id]
        float_data = [latitude, longitude, socioeconomic_index]
        str_data = [area_name]
        return int_data, float_data, str_data

get_data(world)

Parameters:

Name Type Description Default
world
required
Source code in june/records/static_records_writer.py
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
def get_data(self, world):
    """

    Args:
        world: 

    """
    (
        area_id,
        super_area_id,
        latitude,
        longitude,
        socioeconomic_index,
        area_name,
    ) = ([], [], [], [], [], [])
    if world.areas is not None:
        for area in world.areas:
            area_id.append(area.id)
            super_area_id.append(area.super_area.id)
            latitude.append(area.coordinates[0])
            longitude.append(area.coordinates[1])
            socioeconomic_index.append(area.socioeconomic_index)
            area_name.append(area.name)
    int_data = [area_id, super_area_id]
    float_data = [latitude, longitude, socioeconomic_index]
    str_data = [area_name]
    return int_data, float_data, str_data

LocationRecord

Bases: StaticRecord

Source code in june/records/static_records_writer.py
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
class LocationRecord(StaticRecord):
    """ """
    def __init__(self):
        super().__init__(
            table_name="locations",
            int_names=["id", "group_id", "area_id"],
            float_names=["latitude", "longitude"],
            str_names=["spec"],
            expectedrows=1_000_000,
        )

    def get_data(self, world):
        """

        Args:
            world: 

        """
        (ids, latitude, longitude, group_spec, group_id, area_id) = (
            [],
            [],
            [],
            [],
            [],
            [],
        )
        counter = 0
        for attribute, value in world.__dict__.items():
            if isinstance(value, Supergroup) and attribute not in (
                "cities",
                "cemeteries",
                "stations",
            ):
                for group in getattr(world, attribute):
                    if group.external:
                        continue
                    ids.append(counter)
                    group_spec.append(group.spec)
                    group_id.append(group.id)
                    area_id.append(group.area.id)
                    latitude.append(group.coordinates[0])
                    longitude.append(group.coordinates[1])
                    counter += 1
        int_data = [ids, group_id, area_id]
        float_data = [latitude, longitude]
        str_data = [group_spec]
        return int_data, float_data, str_data

get_data(world)

Parameters:

Name Type Description Default
world
required
Source code in june/records/static_records_writer.py
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
def get_data(self, world):
    """

    Args:
        world: 

    """
    (ids, latitude, longitude, group_spec, group_id, area_id) = (
        [],
        [],
        [],
        [],
        [],
        [],
    )
    counter = 0
    for attribute, value in world.__dict__.items():
        if isinstance(value, Supergroup) and attribute not in (
            "cities",
            "cemeteries",
            "stations",
        ):
            for group in getattr(world, attribute):
                if group.external:
                    continue
                ids.append(counter)
                group_spec.append(group.spec)
                group_id.append(group.id)
                area_id.append(group.area.id)
                latitude.append(group.coordinates[0])
                longitude.append(group.coordinates[1])
                counter += 1
    int_data = [ids, group_id, area_id]
    float_data = [latitude, longitude]
    str_data = [group_spec]
    return int_data, float_data, str_data

PeopleRecord

Bases: StaticRecord

Source code in june/records/static_records_writer.py
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
class PeopleRecord(StaticRecord):
    """ """
    def __init__(self):
        super().__init__(
            table_name="population",
            int_names=["id", "age", "primary_activity_id", "residence_id", "area_id"],
            float_names=[],
            str_names=["sex", "ethnicity", "primary_activity_type", "residence_type"],
            expectedrows=1_000_000,
        )

        self.extra_float_data = {}
        self.extra_int_data = {}
        self.extra_str_data = {}

    def get_data(self, world):
        """

        Args:
            world: 

        """
        (
            ids,
            age,
            primary_activity_type,
            primary_activity_id,
            residence_type,
            residence_id,
            area_id,
            sex,
            ethnicity,
        ) = ([], [], [], [], [], [], [], [], [])
        for person in world.people:
            ids.append(person.id)
            age.append(person.age)
            primary_activity_type.append(
                person.primary_activity.group.spec
                if person.primary_activity is not None
                else "None"
            )
            primary_activity_id.append(
                person.primary_activity.group.id
                if person.primary_activity is not None
                else 0
            )
            residence_type.append(
                person.residence.group.spec if person.residence is not None else "None"
            )
            residence_id.append(
                person.residence.group.id if person.residence is not None else 0
            )
            area_id.append(person.area.id if person.area is not None else 0)
            sex.append(person.sex)
            ethnicity.append(
                person.ethnicity if person.ethnicity is not None else "None"
            )
        int_data = [ids, age, primary_activity_id, residence_id, area_id]
        float_data = []
        str_data = []
        str_data = [sex, ethnicity, primary_activity_type, residence_type]
        return int_data, float_data, str_data

get_data(world)

Parameters:

Name Type Description Default
world
required
Source code in june/records/static_records_writer.py
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
def get_data(self, world):
    """

    Args:
        world: 

    """
    (
        ids,
        age,
        primary_activity_type,
        primary_activity_id,
        residence_type,
        residence_id,
        area_id,
        sex,
        ethnicity,
    ) = ([], [], [], [], [], [], [], [], [])
    for person in world.people:
        ids.append(person.id)
        age.append(person.age)
        primary_activity_type.append(
            person.primary_activity.group.spec
            if person.primary_activity is not None
            else "None"
        )
        primary_activity_id.append(
            person.primary_activity.group.id
            if person.primary_activity is not None
            else 0
        )
        residence_type.append(
            person.residence.group.spec if person.residence is not None else "None"
        )
        residence_id.append(
            person.residence.group.id if person.residence is not None else 0
        )
        area_id.append(person.area.id if person.area is not None else 0)
        sex.append(person.sex)
        ethnicity.append(
            person.ethnicity if person.ethnicity is not None else "None"
        )
    int_data = [ids, age, primary_activity_id, residence_id, area_id]
    float_data = []
    str_data = []
    str_data = [sex, ethnicity, primary_activity_type, residence_type]
    return int_data, float_data, str_data

RegionRecord

Bases: StaticRecord

Source code in june/records/static_records_writer.py
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
class RegionRecord(StaticRecord):
    """ """
    def __init__(self):
        super().__init__(
            table_name="regions",
            int_names=["id"],
            float_names=[],
            str_names=["name"],
            expectedrows=50,
        )

    def get_data(self, world):
        """

        Args:
            world: 

        """
        region_id, region_name = [], []
        if world.regions is not None:
            for region in world.regions:
                region_id.append(region.id)
                region_name.append(region.name)
        int_data = [region_id]
        float_data = []
        str_data = [region_name]
        return int_data, float_data, str_data

get_data(world)

Parameters:

Name Type Description Default
world
required
Source code in june/records/static_records_writer.py
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
def get_data(self, world):
    """

    Args:
        world: 

    """
    region_id, region_name = [], []
    if world.regions is not None:
        for region in world.regions:
            region_id.append(region.id)
            region_name.append(region.name)
    int_data = [region_id]
    float_data = []
    str_data = [region_name]
    return int_data, float_data, str_data

StaticRecord

Source code in june/records/static_records_writer.py
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
class StaticRecord:
    """ """
    def __init__(self, table_name, int_names, float_names, str_names, expectedrows):
        self.table_name = table_name
        self.int_names = int_names
        self.float_names = float_names
        self.str_names = str_names
        self.expectedrows = expectedrows
        self.extra_int_data = {}
        self.extra_float_data = {}
        self.extra_str_data = {}

    def _create_table(self, file, int_names, float_names, str_names, expectedrows):
        """

        Args:
            file: 
            int_names: 
            float_names: 
            str_names: 
            expectedrows: 

        """
        table_description = _get_description_for_event(
            int_names=int_names,
            float_names=float_names,
            str_names=str_names,
            timestamp=False,
        )
        self.table = file.create_table(
            file.root, self.table_name, table_description, expectedrows=expectedrows
        )

    def _record(self, hdf5_file, int_data, float_data, str_data):
        """

        Args:
            hdf5_file: 
            int_data: 
            float_data: 
            str_data: 

        """
        data = np.rec.fromarrays(
            [np.array(data, dtype=np.uint32) for data in int_data]
            + [np.array(data, dtype=np.float32) for data in float_data]
            + [np.array(data, dtype="S20") for data in str_data]
        )
        table = getattr(hdf5_file.root, self.table_name)
        table.append(data)
        table.flush()

    def get_data(self, world):
        """

        Args:
            world: 

        """
        pass

    def record(self, hdf5_file, world):
        """

        Args:
            hdf5_file: 
            world: 

        """
        int_data, float_data, str_data = self.get_data(world=world)
        if self.extra_int_data is not None:
            self.int_names += list(self.extra_int_data.keys())
            for value in self.extra_int_data.values():
                int_data += [value]
        if self.extra_float_data is not None:
            self.float_names += list(self.extra_float_data.keys())
            for value in self.extra_float_data.values():
                float_data += [value]
        if self.extra_str_data is not None:
            self.str_names += list(self.extra_str_data.keys())
            for value in self.extra_str_data.values():
                str_data += [value]
        self._create_table(
            hdf5_file,
            self.int_names,
            self.float_names,
            self.str_names,
            self.expectedrows,
        )
        self._record(
            hdf5_file=hdf5_file,
            int_data=int_data,
            float_data=float_data,
            str_data=str_data,
        )

get_data(world)

Parameters:

Name Type Description Default
world
required
Source code in june/records/static_records_writer.py
59
60
61
62
63
64
65
66
def get_data(self, world):
    """

    Args:
        world: 

    """
    pass

record(hdf5_file, world)

Parameters:

Name Type Description Default
hdf5_file
required
world
required
Source code in june/records/static_records_writer.py
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
def record(self, hdf5_file, world):
    """

    Args:
        hdf5_file: 
        world: 

    """
    int_data, float_data, str_data = self.get_data(world=world)
    if self.extra_int_data is not None:
        self.int_names += list(self.extra_int_data.keys())
        for value in self.extra_int_data.values():
            int_data += [value]
    if self.extra_float_data is not None:
        self.float_names += list(self.extra_float_data.keys())
        for value in self.extra_float_data.values():
            float_data += [value]
    if self.extra_str_data is not None:
        self.str_names += list(self.extra_str_data.keys())
        for value in self.extra_str_data.values():
            str_data += [value]
    self._create_table(
        hdf5_file,
        self.int_names,
        self.float_names,
        self.str_names,
        self.expectedrows,
    )
    self._record(
        hdf5_file=hdf5_file,
        int_data=int_data,
        float_data=float_data,
        str_data=str_data,
    )

SuperAreaRecord

Bases: StaticRecord

Source code in june/records/static_records_writer.py
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
class SuperAreaRecord(StaticRecord):
    """ """
    def __init__(self):
        super().__init__(
            table_name="super_areas",
            int_names=["id", "region_id"],
            float_names=["latitude", "longitude"],
            str_names=["name"],
            expectedrows=5_000,
        )

    def get_data(self, world):
        """

        Args:
            world: 

        """
        super_area_id, region_id, latitude, longitude, super_area_name = (
            [],
            [],
            [],
            [],
            [],
        )
        if world.super_areas is not None:
            for super_area in world.super_areas:
                super_area_id.append(super_area.id)
                region_id.append(super_area.region.id)
                latitude.append(super_area.coordinates[0])
                longitude.append(super_area.coordinates[1])
                super_area_name.append(super_area.name)
        int_data = [super_area_id, region_id]
        float_data = [latitude, longitude]
        str_data = [super_area_name]
        return int_data, float_data, str_data

get_data(world)

Parameters:

Name Type Description Default
world
required
Source code in june/records/static_records_writer.py
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
def get_data(self, world):
    """

    Args:
        world: 

    """
    super_area_id, region_id, latitude, longitude, super_area_name = (
        [],
        [],
        [],
        [],
        [],
    )
    if world.super_areas is not None:
        for super_area in world.super_areas:
            super_area_id.append(super_area.id)
            region_id.append(super_area.region.id)
            latitude.append(super_area.coordinates[0])
            longitude.append(super_area.coordinates[1])
            super_area_name.append(super_area.name)
    int_data = [super_area_id, region_id]
    float_data = [latitude, longitude]
    str_data = [super_area_name]
    return int_data, float_data, str_data