Пример #1
0
def init():

    # create the database
    db.configure_mappers()
    db.create_all()

    # create the super user
    u = User(name=settings.SUPER_USER,
             email=settings.SUPER_USER_EMAIL,
             password=settings.SUPER_USER_PASSWORD,
             admin=True,
             super_user=True)

    # optionally add super user apikey
    if getattr(settings, 'SUPER_USER_APIKEY', None):
        u.apikey = settings.SUPER_USER_APIKEY
    db_session.add(u)

    # load sql extensions + functions
    for sql in load_sql():
        db_session.execute(sql)

    # load built-in sous-chefs
    for sc in load_sous_chefs():
        sc = sous_chef_schema.validate(sc)
        s = SousChef(**sc)
        db_session.add(s)

    # commit
    db_session.commit()
Пример #2
0
def gen_content_metric_timeseries(org,
                                  content_items,
                                  metrics,
                                  n_content_item_timeseries_metrics=1000):
    for _ in xrange(n_content_item_timeseries_metrics):
        _metrics = {}
        for m in metrics:
            if 'timeseries' in m.content_levels:
                _metrics[m.name] = random_int(1, 1000)

        cmd_kwargs = {
            'org_id': org.id,
            'content_item_id': choice(content_items).id,
            'datetime': dates.floor(random_date(1, 7), unit='hour', value=1),
            'metrics': obj_to_json(_metrics)
        }
        # upsert command
        cmd = """SELECT upsert_content_metric_timeseries(
                    {org_id},
                    {content_item_id},
                    '{datetime}',
                    '{metrics}');
               """.format(**cmd_kwargs)
        db_session.execute(cmd)
    db_session.commit()