예제 #1
0
파일: db.py 프로젝트: always19/clutch
def delete_dev_modes_for_user_and_app(user_id, app_id):
    SQL = """
    DELETE
    FROM dashboard_developmentmode D
    WHERE D.user_id = %s AND D.app_id = %s
    """
    db.execute(SQL, [user_id, app_id])
예제 #2
0
def delete_dev_modes_for_user_and_app(user_id, app_id):
    SQL = """
    DELETE
    FROM dashboard_developmentmode D
    WHERE D.user_id = %s AND D.app_id = %s
    """
    db.execute(SQL, [user_id, app_id])
예제 #3
0
파일: db.py 프로젝트: always19/clutch
def create_or_update_dev_mode(app_id, user_id, url, toolbar):
    UPDATE_SQL = """
    UPDATE dashboard_developmentmode
    SET url = %s, toolbar = %s, date_updated = %s
    WHERE app_id = %s AND user_id = %s
    """

    INSERT_SQL = """
    INSERT INTO dashboard_developmentmode
        (app_id, user_id, url, toolbar, date_updated, date_created)
    VALUES (%s, %s, %s, %s, %s, %s)
    """

    now = utils.get_now()
    try:
        db.execute(INSERT_SQL, [app_id, user_id, url, toolbar, now, now])
    except psycopg2.IntegrityError:
        db.execute(UPDATE_SQL, [url, toolbar, now, app_id, user_id])
예제 #4
0
def create_or_update_dev_mode(app_id, user_id, url, toolbar):
    UPDATE_SQL = """
    UPDATE dashboard_developmentmode
    SET url = %s, toolbar = %s, date_updated = %s
    WHERE app_id = %s AND user_id = %s
    """

    INSERT_SQL = """
    INSERT INTO dashboard_developmentmode
        (app_id, user_id, url, toolbar, date_updated, date_created)
    VALUES (%s, %s, %s, %s, %s, %s)
    """

    now = utils.get_now()
    try:
        db.execute(INSERT_SQL, [app_id, user_id, url, toolbar, now, now])
    except psycopg2.IntegrityError:
        db.execute(UPDATE_SQL, [url, toolbar, now, app_id, user_id])
예제 #5
0
파일: db.py 프로젝트: JohnHerry/clutch
    def _coro0(log):
        try:
            db.execute(
                LOG_INSERT_SQL,
                [
                    log["ts"],
                    log["action"],
                    simplejson.dumps(log["data"]),
                    udid,
                    api_version,
                    app_version,
                    bundle_version,
                    app_key,
                    log["uuid"],
                    platform,
                ],
            )
        except psycopg2.IntegrityError:
            return

        # Don't care about disappearing in aggregate yet
        if log["action"] == "viewDidDisappear":
            return

        slug = log["data"]["slug"]

        ts = datetime.datetime.utcfromtimestamp(log["ts"]).replace(tzinfo=pytz.utc)
        hour = ts.replace(minute=0, second=0, microsecond=0)
        day = hour.replace(hour=0)
        month = day.replace(day=1)
        year = month.replace(month=1)

        try:
            db.execute(UNIQUE_ALLTIME_INSERT_SQL, [app_id, udid, platform])
            new = True
        except psycopg2.IntegrityError:
            new = False

        pt = zip(("hour", "day", "month", "year"), (hour, day, month, year))
        for period, timestamp in pt:
            pool.spawn_link_exception(_coro1, period, timestamp, slug, new)
            pool.spawn_link_exception(_coro2, period, timestamp, slug)
            pool.spawn_link_exception(_coro3, period, timestamp, slug)
예제 #6
0
    def _coro0(log):
        try:
            db.execute(LOG_INSERT_SQL, [
                log['ts'],
                log['action'],
                simplejson.dumps(log['data']),
                udid,
                api_version,
                app_version,
                bundle_version,
                app_key,
                log['uuid'],
                platform,
            ])
        except psycopg2.IntegrityError:
            return

        # Don't care about disappearing in aggregate yet
        if log['action'] == 'viewDidDisappear':
            return

        slug = log['data']['slug']

        ts = datetime.datetime.utcfromtimestamp(
            log['ts']).replace(tzinfo=pytz.utc)
        hour = ts.replace(minute=0, second=0, microsecond=0)
        day = hour.replace(hour=0)
        month = day.replace(day=1)
        year = month.replace(month=1)

        try:
            db.execute(UNIQUE_ALLTIME_INSERT_SQL, [app_id, udid, platform])
            new = True
        except psycopg2.IntegrityError:
            new = False

        pt = zip(('hour', 'day', 'month', 'year'), (hour, day, month, year))
        for period, timestamp in pt:
            pool.spawn_link_exception(_coro1, period, timestamp, slug, new)
            pool.spawn_link_exception(_coro2, period, timestamp, slug)
            pool.spawn_link_exception(_coro3, period, timestamp, slug)
예제 #7
0
파일: db.py 프로젝트: always19/clutch
    def insert_ab_log(log):
        try:
            data = log['data']
        except KeyError:
            # TODO: Log error somewhere?
            return

        try:
            db.execute(LOG_INSERT_SQL, [
                log['ts'],
                data['action'],
                simplejson.dumps(log['data']),
                udid,
                api_version,
                app_version,
                bundle_version,
                app_key,
                log['uuid'],
                platform,
            ])
        except psycopg2.IntegrityError:
            return

        ts = datetime.datetime.utcfromtimestamp(log['ts']).replace(
            tzinfo=pytz.utc)
        month = ts.replace(day=1, hour=0, minute=0, second=0, microsecond=0)

        try:
            db.execute(UNIQUE_INSERT_SQL,
                [str(uuid.uuid1()), app_id, udid, month, now])
        except psycopg2.IntegrityError:
            pass

        # Don't care about disappearing in aggregate yet
        if data['action'] == 'failure':
            return

        experiment = get_experiment(app_id, data['name'])
        if experiment is None:
            if 'has_data' not in data:
                return
            db.execute(EXP_INSERT_SQL, [
                app_id,
                'Experiment for ' + data['name'],
                data['name'],
                data['has_data'],
                0,
                True,
                now,
            ])
            experiment = get_experiment(app_id, data['name'])

        if 'num_choices' in data:
            if data['num_choices'] != experiment['num_choices']:
                # First update the experiment object
                db.execute(EXP_UPDATE_SQL,
                    [data['num_choices'], experiment['id']])

                # Now create any un-created variation objects
                for i in xrange(data['num_choices']):
                    try:
                        name = 'Test ' + ('ABCDEFGHIJKLMNOPQRSTUVWXYZ'[i])
                        db.execute(VARIATION_INSERT_SQL, [
                            experiment['id'],
                            0.5 / data['num_choices'],
                            i + 1,
                            name,
                            '{\n}' if experiment['has_data'] else '',
                            now,
                        ])
                    except psycopg2.IntegrityError:
                        pass

            # If it's one of the 'num-choices' actions, we've done that
            # already so we can continue on.
            if data['action'] == 'num-choices':
                return

        if data['action'] == 'test':
            try:
                dt = datetime.datetime.utcfromtimestamp(log['ts']).replace(
                    tzinfo=pytz.utc)
                db.execute(TRIAL_INSERT_SQL, [
                    str(uuid.uuid1()),
                    udid,
                    app_id,
                    experiment['id'],
                    now,
                    dt,
                    None,
                    data['choice'],
                    False,
                ])
            except psycopg2.IntegrityError:
                # What is the expected behavior here?  If a trial is
                # already started for this user, then do we discard the old
                # one, or do we start a new one with a new timestamp and
                # choice?  Do we update the started timestamp on the
                # current one?  Not sure.  For now we just continue and do
                # nothing.
                pass

            return

        if data['action'] == 'goal':
            dt = datetime.datetime.utcfromtimestamp(log['ts']).replace(
                tzinfo=pytz.utc)
            db.execute(TRIAL_UPDATE_SQL, [
                dt,
                True,
                udid,
                experiment['id'],
            ])
예제 #8
0
파일: db.py 프로젝트: always19/clutch
 def _coro3(period, timestamp, slug):
     args = [app_id, platform, timestamp, slug]
     try:
         db.execute(VIEW_SLUG_INSERT_SQL % (period,), args)
     except psycopg2.IntegrityError:
         db.execute(VIEW_SLUG_UPDATE_SQL % (period,), args)
예제 #9
0
파일: db.py 프로젝트: always19/clutch
 def _coro1(period, timestamp, slug, new):
     try:
         db.execute(UNIQUE_INSERT_SQL % (period,),
             [app_id, udid, platform, new, timestamp])
     except psycopg2.IntegrityError:
         pass
예제 #10
0
파일: db.py 프로젝트: always19/clutch
def create_app_version(app_id, app_version):
    SQL = """
    INSERT INTO dashboard_version (app_id, version) VALUES (%s, %s)
    """
    db.execute(SQL, [app_id, app_version])
예제 #11
0
    def insert_ab_log(log):
        try:
            data = log['data']
        except KeyError:
            # TODO: Log error somewhere?
            return

        try:
            db.execute(LOG_INSERT_SQL, [
                log['ts'],
                data['action'],
                simplejson.dumps(log['data']),
                udid,
                api_version,
                app_version,
                bundle_version,
                app_key,
                log['uuid'],
                platform,
            ])
        except psycopg2.IntegrityError:
            return

        ts = datetime.datetime.utcfromtimestamp(
            log['ts']).replace(tzinfo=pytz.utc)
        month = ts.replace(day=1, hour=0, minute=0, second=0, microsecond=0)

        try:
            db.execute(UNIQUE_INSERT_SQL,
                       [str(uuid.uuid1()), app_id, udid, month, now])
        except psycopg2.IntegrityError:
            pass

        # Don't care about disappearing in aggregate yet
        if data['action'] == 'failure':
            return

        experiment = get_experiment(app_id, data['name'])
        if experiment is None:
            if 'has_data' not in data:
                return
            db.execute(EXP_INSERT_SQL, [
                app_id,
                'Experiment for ' + data['name'],
                data['name'],
                data['has_data'],
                0,
                True,
                now,
            ])
            experiment = get_experiment(app_id, data['name'])

        if 'num_choices' in data:
            if data['num_choices'] != experiment['num_choices']:
                # First update the experiment object
                db.execute(EXP_UPDATE_SQL,
                           [data['num_choices'], experiment['id']])

                # Now create any un-created variation objects
                for i in xrange(data['num_choices']):
                    try:
                        name = 'Test ' + ('ABCDEFGHIJKLMNOPQRSTUVWXYZ'[i], )
                        db.execute(VARIATION_INSERT_SQL, [
                            experiment['id'],
                            0.5 / data['num_choices'],
                            i + 1,
                            name,
                            '{\n}' if experiment['has_data'] else '',
                            now,
                        ])
                    except psycopg2.IntegrityError:
                        pass

            # If it's one of the 'num-choices' actions, we've done that
            # already so we can continue on.
            if data['action'] == 'num-choices':
                return

        if data['action'] == 'test':
            try:
                dt = datetime.datetime.utcfromtimestamp(
                    log['ts']).replace(tzinfo=pytz.utc)
                db.execute(TRIAL_INSERT_SQL, [
                    str(uuid.uuid1()),
                    udid,
                    app_id,
                    experiment['id'],
                    now,
                    dt,
                    None,
                    data['choice'],
                    False,
                ])
            except psycopg2.IntegrityError:
                # What is the expected behavior here?  If a trial is
                # already started for this user, then do we discard the old
                # one, or do we start a new one with a new timestamp and
                # choice?  Do we update the started timestamp on the
                # current one?  Not sure.  For now we just continue and do
                # nothing.
                pass

            return

        if data['action'] == 'goal':
            dt = datetime.datetime.utcfromtimestamp(
                log['ts']).replace(tzinfo=pytz.utc)
            db.execute(TRIAL_UPDATE_SQL, [
                dt,
                True,
                udid,
                experiment['id'],
            ])
예제 #12
0
 def _coro3(period, timestamp, slug):
     args = [app_id, platform, timestamp, slug]
     try:
         db.execute(VIEW_SLUG_INSERT_SQL % (period, ), args)
     except psycopg2.IntegrityError:
         db.execute(VIEW_SLUG_UPDATE_SQL % (period, ), args)
예제 #13
0
 def _coro1(period, timestamp, slug, new):
     try:
         db.execute(UNIQUE_INSERT_SQL % (period, ),
                    [app_id, udid, platform, new, timestamp])
     except psycopg2.IntegrityError:
         pass
예제 #14
0
def create_app_version(app_id, app_version):
    SQL = """
    INSERT INTO dashboard_version (app_id, version) VALUES (%s, %s)
    """
    db.execute(SQL, [app_id, app_version])