示例#1
0
def retrieve_transactions():
    sql = """
        SELECT *
         FROM  Collector_log
         WHERE event = 'buy'
         ORDER BY session_id, content_id
    """
    cursor = DataHelper.get_query_cursor(sql)
    data = DataHelper.dictfetchall(cursor)

    return data
def retrieve_transactions():
    sql = """
        SELECT *
         FROM  Collector_log
         WHERE event = 'buy'
         ORDER BY session_id, content_id
    """
    cursor = DataHelper.get_query_cursor(sql)
    data = DataHelper.dictfetchall(cursor)

    return data
示例#3
0
def chart(request, take=10):
    sql = """SELECT content_id,
                mov.title,
                count(*) as sold
            FROM    collector_log log
            JOIN    moviegeeks_movie mov
            ON      log.content_id = mov.movie_id
            WHERE 	event like 'buy'
            GROUP BY content_id, mov.title
            ORDER BY sold desc
            LIMIT {}
            """.format(take)

    c = DataHelper.get_query_cursor(sql)
    data = DataHelper.dictfetchall(c)

    return JsonResponse(data, safe=False)
示例#4
0
def chart(request, take=10):
    sql = """SELECT content_id,
                mov.title,
                count(*) as sold
            FROM    collector_log log
            JOIN    moviegeeks_movie mov
            ON      log.content_id = mov.movie_id
            WHERE 	event like 'buy'
            GROUP BY content_id, mov.title
            ORDER BY sold desc
            LIMIT {}
            """.format(take)

    c = DataHelper.get_query_cursor(sql)
    data = DataHelper.dictfetchall(c)

    return JsonResponse(data, safe=False)
def save_rules(rules):
    conn = DataHelper.connect_to_db()

    for rule in rules:
        sql = """INSERT INTO seeded_recs (created, source, target, support, confidence, type)
             VALUES ('{}', '{}', '{}', {}, {}, 'associate')"""
        print(sql.format(rule[0], rule[1], rule[2], rule[3], rule[4]))
        conn.cursor().execute(sql.format(rule[0], rule[1], rule[2], rule[3], rule[4]))
    conn.commit()
    conn.close()
def save_ratings(ratings, userid, type, conn=DataHelper.connect_to_db()):

    print("saving ratings")
    i = 0

    for content_id, rating in ratings.items():

        sql = """
        UPDATE analytics_rating
        SET rating = {},rating_timestamp = '{}', type='{}'
        WHERE user_id = {} and movie_id = {}
        """.format(rating, datetime.datetime.now(), type, userid, content_id)
        # print (sql)
        conn.cursor().execute(sql)

        i += 1

        if i == 100:
            print('.', end="")
            i = 0