Exemplo n.º 1
0
def add_listener(the_circus):

    users = the_circus.create_population(
        name="user", size=5, ids_gen=gen.SequencialGenerator(prefix="user_"))

    users.create_attribute(name="FIRST_NAME",
                           init_gen=gen.FakerGenerator(method="first_name",
                                                       seed=next(
                                                           the_circus.seeder)))
    users.create_attribute(name="LAST_NAME",
                           init_gen=gen.FakerGenerator(method="last_name",
                                                       seed=next(
                                                           the_circus.seeder)))
Exemplo n.º 2
0
def create_products(circus, params):
    """
    :param circus:
    :param params:
    :return:
    """

    for product_name, description in params["products"].items():
        product = circus.create_population(
            name=product_name,
            ids_gen=random_generators.SequencialGenerator(
                prefix=description["prefix"]),
            size=description["product_types_num"])

        product.create_attribute(name="product_description",
                                 init_gen=random_generators.FakerGenerator(
                                     method="text", seed=next(circus.seeder)))

    sims = circus.actors["sim"]

    sims.create_attribute("type",
                          init_gen=snd_constants.gen("SIM_TYPES",
                                                     next(circus.seeder)))

    sims.create_attribute("ean",
                          init_gen=random_generators.FakerGenerator(
                              method="ean", seed=next(circus.seeder)))

    handsets = circus.actors["handset"]

    handsets.create_attribute("tac_id",
                              init_gen=random_generators.FakerGenerator(
                                  method="ean", seed=next(circus.seeder)))

    handsets.create_attribute("category",
                              init_gen=snd_constants.gen(
                                  "HANDSET_CATEGORY", next(circus.seeder)))

    handsets.create_attribute("internet_technology",
                              init_gen=snd_constants.gen(
                                  "SIM_CAP", next(circus.seeder)))

    handsets.create_attribute("brand",
                              init_gen=snd_constants.gen(
                                  "HANDSET_BRANDS", next(circus.seeder)))

    handsets.create_attribute("ean",
                              init_gen=random_generators.FakerGenerator(
                                  method="ean", seed=next(circus.seeder)))
Exemplo n.º 3
0
def create_customer_population(the_circus):
    """
    Creates a customer population and attach it to the circus
    """
    customer = the_circus.create_population(
        name="customer", size=2500,
        ids_gen=gen.SequencialGenerator(prefix="CUS_"))

    customer.create_attribute(
        name="FIRST_NAME",
        init_gen=gen.FakerGenerator(method="first_name",
                                    seed=next(the_circus.seeder)))
    customer.create_attribute(
        name="LAST_NAME",
        init_gen=gen.FakerGenerator(method="last_name",
                                    seed=next(the_circus.seeder)))

    customer.create_relationship(name="my_items")
Exemplo n.º 4
0
def add_products_populations(the_circus, size=100):
    """
    Creates a products population and attach it to the circus
    """
    products = the_circus.create_population(
        name="products",
        size=size,
        ids_gen=gen.SequencialGenerator(prefix="PID_"))

    product_name_gen = gen.FakerGenerator(method="sentence",
                                          nb_words=2,
                                          seed=next(the_circus.seeder))
    products.create_attribute(name="ProductName", init_gen=product_name_gen)

    score_gen = gen.FakerGenerator(method="random_int",
                                   min=0,
                                   max=1000,
                                   seed=next(the_circus.seeder))
    products.create_attribute(name="ProductScore", init_gen=score_gen)

    products.create_relationship(name="my_products")
    """
    Write products to product_score.txt
    
    Example product_score.txt:
    ============================
    2939     600     
    2123     300     
    ============================
    """
    products_copy = products.to_dataframe().copy()
    products_copy['PID'] = products_copy.index
    products_copy['PID'] = products_copy['PID'].apply(
        lambda x: seq2int(x, 'PID_'))
    products_copy.sort_values(by=['PID'], inplace=True)
    products_copy.to_csv('results/product_score.txt',
                         sep='\t',
                         index=False,
                         quoting=2,
                         columns=['PID', 'ProductScore'])
    print('Written to results/product_score.txt')
    del products_copy

    return products
Exemplo n.º 5
0
def create_pos_population(the_circus):
    """
    Creates a point of sale population and attach it to the circus
    """
    pos = the_circus.create_population(
        name="point_of_sale", size=1000,
        ids_gen=gen.SequencialGenerator(prefix="POS_"))

    name_gen = gen.FakerGenerator(method="name", seed=next(the_circus.seeder))
    pos.create_attribute("NAME", init_gen=name_gen)

    city_gen = gen.FakerGenerator(method="city", seed=next(the_circus.seeder))
    pos.create_attribute("CITY", init_gen=city_gen)

    company_gen = gen.FakerGenerator(method="company",
                                     seed=next(the_circus.seeder))
    pos.create_attribute("COMPANY", init_gen=company_gen)

    pos.create_relationship(name="items")
Exemplo n.º 6
0
def add_user_population(the_circus, size=100):
    """
    Creates a user population and attach it to the circus
    """
    customer = the_circus.create_population(
        name="users",
        size=size,
        ids_gen=gen.SequencialGenerator(prefix="UID_"))

    customer.create_attribute(name="FIRST_NAME",
                              init_gen=gen.FakerGenerator(
                                  method="first_name",
                                  seed=next(the_circus.seeder)))
    customer.create_attribute(name="LAST_NAME",
                              init_gen=gen.FakerGenerator(
                                  method="last_name",
                                  seed=next(the_circus.seeder)))

    customer.create_relationship(name="my_items")

    return customer
Exemplo n.º 7
0
def add_song_populations(the_circus):

    songs = the_circus.create_population(
        name="song", size=0, ids_gen=gen.SequencialGenerator(prefix="SONG_"))

    # since the size of the population is 0, we can create attribute without
    # providing any initialization
    songs.create_attribute(name="artist_name")
    songs.create_attribute(name="song_genre")
    songs.create_attribute(name="title")
    songs.create_attribute(name="duration_seconds")
    songs.create_attribute(name="recording_year")

    song_id_gen = gen.SequencialGenerator(prefix="S_")

    # generate artist names from a list of randomly generated ones, so we have
    # some redundancy in the generated dataset
    artist_name_gen = gen.NumpyRandomGenerator(
        method="choice",
        a=gen.FakerGenerator(method="name",
                             seed=next(the_circus.seeder)).generate(size=200),
        seed=next(the_circus.seeder))

    title_gen = gen.FakerGenerator(method="sentence",
                                   seed=next(the_circus.seeder),
                                   nb_words=4,
                                   variable_nb_words=True)

    # generates recording years within a desired date range
    year_gen = gen.FakerGenerator(
            method="date_time_between_dates",
            seed=next(the_circus.seeder),
            datetime_start=pd.Timestamp("1910-10-20"),
            datetime_end=pd.Timestamp("2016-12-02")) \
        .map(f=lambda d: d.year)

    duration_gen = gen.ParetoGenerator(xmin=60,
                                       seed=next(the_circus.seeder),
                                       force_int=True,
                                       a=1.2)

    repo = the_circus.populations["music_repository"]
    repo_genre_rel = repo.get_attribute("genre_name")
    for genre_id, genre_name in repo_genre_rel.get_values().items():

        # an operation capable of creating songs of that genre
        init_attribute = ops.Chain(
            artist_name_gen.ops.generate(named_as="artist_name"),
            title_gen.ops.generate(named_as="title"),
            year_gen.ops.generate(named_as="recording_year"),
            duration_gen.ops.generate(named_as="duration_seconds"),
            gen.ConstantGenerator(value=genre_name).ops.generate(
                named_as="song_genre"))

        # dataframe of emtpy songs: just with one SONG_ID column for now
        song_ids = song_id_gen.generate(size=1000)
        emtpy_songs = story.Story.init_story_data(
            member_id_field_name="SONG_ID", active_ids=song_ids)

        # we can already adds the generated songs to the music repo relationship
        repo.get_relationship("songs").add_grouped_relations(
            from_ids=[genre_id], grouped_ids=[song_ids])

        # here we generate all desired columns in the dataframe
        initialized_songs, _ = init_attribute(emtpy_songs)
        initialized_songs.drop(["SONG_ID"], axis=1, inplace=True)

        # this works because the columns of init_attribute match exactly the
        # ones of the attributes of the populations
        songs.update(initialized_songs)

    # makes sure year and duration are handled as integer
    songs.get_attribute("recording_year").transform_inplace(int)
    songs.get_attribute("duration_seconds").transform_inplace(int)