def get_users_cache(user_list):
    user_list = ', '.join([f"({i})" for i in user_list])
    res = db_instance.fetch_rows(
        f"SELECT * FROM computed_cache WHERE uuid in ({user_list}) AND deleted_at IS NULL"
    )
    res = [parse(UserCache.fields, row) for row in res] if res else []
    return res
Esempio n. 2
0
def get_groups():
    res = db_instance.fetch_rows(
        "SELECT * FROM groups WHERE deleted_at IS NULL")
    if res:
        res = [parse(Group.fields, row) for row in res]
        return res
    else:
        return []
def get_group_average(user_list):
    user_list = ', '.join([f"({i})" for i in user_list])
    query = f"""
    SELECT 
    AVG(avg_accuracy) AS avg_accuracy, 
    AVG(exercises_attempted) AS avg_exercises_attempted, 
    AVG(problems_attempted) AS avg_problems_attempted
    FROM computed_cache WHERE uuid in ({user_list}) AND deleted_at IS NULL
    """
    res = db_instance.fetch_row(query)
    res = parse(GroupComputedStats.fields, res) if res else None
    return res
def filter_users_by_clusters(user_list, cluster_list):
    user_list = ', '.join([f"({i})" for i in user_list])
    cluster_list = ', '.join([f"({i})" for i in cluster_list])
    query = f"""
    SELECT
        *
    FROM
    computed_cache 
    LEFT JOIN
    algorithm_cache
    ON
    computed_cache.uuid = algorithm_cache.uuid
    WHERE 
    computed_cache.uuid IN ({user_list})
    AND
    algorithm_cache.cluster IN ({cluster_list}) 
    AND 
    computed_cache.deleted_at IS NULL
    """
    res = db_instance.fetch_rows(query)
    res = [parse(UserCache.fields, row) for row in res] if res else []
    return res
Esempio n. 5
0
def get_user(id):
    res = db_instance.fetch_row(
        "SELECT * FROM users WHERE id = %s AND deleted_at IS NULL", (id, ))
    res = parse(User.fields, res)
    return res
Esempio n. 6
0
def get_users(user_list):
    user_list = ', '.join([f"({i})" for i in user_list])
    query = f"SELECT * FROM users WHERE id in ({user_list}) AND deleted_at IS NULL"
    res = db_instance.fetch_rows(query)
    res = [parse(User.fields, row) for row in res]
    return res
Esempio n. 7
0
def get_all_users():
    query = "SELECT * FROM users WHERE deleted_at IS NULL"
    res = db_instance.fetch_rows(query)
    res = [parse(User.fields, row) for row in res]
    return res
def get_contents():
    res = db_instance.fetch_rows(
        f"SELECT * FROM contents WHERE deleted_at IS NULL")
    res = [parse(Content.fields, row) for row in res]
    return res
Esempio n. 9
0
def get_clusters():
    res = db_instance.fetch_rows(
        f"SELECT * FROM clusters WHERE deleted_at IS NULL")
    res = [parse(Cluster.fields, row) for row in res]
    return res
def get_user_cache(id):
    res = db_instance.fetch_row(
        "SELECT * FROM computed_cache WHERE uuid = %s AND deleted_at IS NULL",
        (id, ))
    res = parse(UserCache.fields, res) if res else None
    return res
def get_users_cache():
    res = db_instance.fetch_rows(
        "SELECT * FROM computed_cache WHERE deleted_at IS NULL")
    res = [parse(UserCache.fields, row) for row in res] if res else []
    return res
Esempio n. 12
0
def get_logs_by_user(user_list):
    user_list = ', '.join([f"({i})" for i in user_list])
    res = db_instance.fetch_rows(f"SELECT * FROM logs WHERE uuid IN ({user_list}) AND deleted_at IS NULL")
    res = [parse(Log.fields, row) for row in res]
    return res