Пример #1
0
import logging
import pandas as pd
from tabulate import tabulate

from core import container, operations
from core.random_generators import SequencialGenerator, FakerGenerator, NumpyRandomGenerator, ConstantDependentGenerator, ConstantGenerator
import core.util_functions as util_functions

util_functions.setup_logging()

example_circus = container.Container(name="example",
                                     master_seed=12345,
                                     start=pd.Timestamp("1 Jan 2017 00:00"),
                                     step_duration=pd.Timedelta("1h"))

id_gen = SequencialGenerator(prefix="PERSON_")
age_gen = NumpyRandomGenerator(method="normal",
                               loc=3,
                               scale=5,
                               seed=next(example_circus.seeder))
name_gen = FakerGenerator(method="name", seed=next(example_circus.seeder))

person = example_circus.create_population(name="person",
                                          size=1000,
                                          ids_gen=id_gen)
person.create_attribute("NAME", init_gen=name_gen)
person.create_attribute("AGE", init_gen=age_gen)

hello_world = example_circus.create_story(
    name="hello_world",
    initiating_population=example_circus.populations["person"],
Пример #2
0
    return cells, cities, timer_config


if __name__ == "__main__":
    # This is meant to be executed only once, to create the data on disk.

    # Note: using generators and persisting the result could make sense
    # if such generation is costly or for facilitating reproduceability,
    # though a more common use cas might be to build such Populations  and
    # relationship from empirical exploration of a dataset.

    # Note2: only the "static" properties of an environment are saved here,
    # whereas the "dynamic parts" (e.g. stories) are stored "in code", i.e.
    # in the withXYZ() class above that then need to be mixed in a Circus.

    setup_logging()

    cells, cities, timer_config = build_uganda_populations()

    db.remove_namespace("uganda")
    db.save_population(population=cells,
                       namespace="uganda",
                       population_id="cells")
    db.save_population(population=cities,
                       namespace="uganda",
                       population_id="cities")

    db.save_timer_gen(timer_gen=timer_config,
                      namespace="uganda",
                      timer_gen_id="cell_repair_timer_profile")