当前位置: 首页>>代码示例>>Python>>正文


Python UserLog.get_activity_int方法代码示例

本文整理汇总了Python中main.models.UserLog.get_activity_int方法的典型用法代码示例。如果您正苦于以下问题:Python UserLog.get_activity_int方法的具体用法?Python UserLog.get_activity_int怎么用?Python UserLog.get_activity_int使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在main.models.UserLog的用法示例。


在下文中一共展示了UserLog.get_activity_int方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: generate_fake_coachreport_logs

# 需要导入模块: from main.models import UserLog [as 别名]
# 或者: from main.models.UserLog import get_activity_int [as 别名]
def generate_fake_coachreport_logs(password="hellothere"):
    t,_ = FacilityUser.objects.get_or_create(
        facility=Facility.objects.all()[0],
        username=random.choice(firstnames)
    )
    t.set_password(password)

    # TODO: create flags later
    num_logs = 20
    logs = []
    for _ in xrange(num_logs):
        date_logged_in = datetime.datetime.now() - datetime.timedelta(days=random.randint(1,10))
        date_viewed_coachreport = date_logged_in + datetime.timedelta(minutes=random.randint(0, 30))
        date_logged_out = date_viewed_coachreport + datetime.timedelta(minutes=random.randint(0, 30))
        login_log = UserLog.objects.create(
            user=t,
            activity_type=UserLog.get_activity_int("login"),
            start_datetime=date_logged_in,
            last_active_datetime=date_viewed_coachreport,
            end_datetime=date_logged_out,
        )
        logging.info("created login log for teacher %s" % t.username)
        coachreport_log = UserLog.objects.create(
            user=t,
            activity_type=UserLog.get_activity_int("coachreport"),
            start_datetime=date_viewed_coachreport,
            last_active_datetime=date_viewed_coachreport,
            end_datetime=date_viewed_coachreport,
        )
        logs.append((login_log, coachreport_log))
        logging.info("created coachreport log for teacher %s" % t.username)
    return logs
开发者ID:EconometricsBySimulation,项目名称:ka-lite,代码行数:34,代码来源:generaterealdata.py

示例2: _get_user_usage_data

# 需要导入模块: from main.models import UserLog [as 别名]
# 或者: from main.models.UserLog import get_activity_int [as 别名]
def _get_user_usage_data(users, period_start=None, period_end=None):
    """
    Returns facility user data, within the given date range.
    """

    # compute period start and end
    # Now compute stats, based on queried data
    len_all_exercises = len(topicdata.NODE_CACHE['Exercise'])
    user_data = OrderedDict()
    group_data = OrderedDict()


    # Make queries efficiently
    exercise_logs = ExerciseLog.objects.filter(user__in=users, complete=True)
    video_logs = VideoLog.objects.filter(user__in=users)
    login_logs = UserLogSummary.objects.filter(user__in=users)

    # filter results
    if period_start:
        exercise_logs = exercise_logs.filter(completion_timestamp__gte=period_start)
        video_logs = video_logs.filter(completion_timestamp__gte=period_start)
        login_logs = login_logs.filter(start_datetime__gte=period_start)
    if period_end:
        exercise_logs = exercise_logs.filter(completion_timestamp__lte=period_end)
        video_logs = video_logs.filter(completion_timestamp__lte=period_end)
        login_logs = login_logs.filter(end_datetime__lte=period_end)

    # Force results in a single query
    exercise_logs = list(exercise_logs.values("exercise_id", "user__pk"))
    video_logs = list(video_logs.values("youtube_id", "user__pk"))
    login_logs = list(login_logs.values("activity_type", "total_seconds", "user__pk"))

    for user in users:
        user_data[user.pk] = OrderedDict()
        user_data[user.pk]["first_name"] = user.first_name
        user_data[user.pk]["last_name"] = user.last_name
        user_data[user.pk]["username"] = user.username
        user_data[user.pk]["group"] = user.group


        user_data[user.pk]["total_report_views"] = 0#report_stats["count__sum"] or 0
        user_data[user.pk]["total_logins"] =0# login_stats["count__sum"] or 0
        user_data[user.pk]["total_hours"] = 0#login_stats["total_seconds__sum"] or 0)/3600.

        user_data[user.pk]["total_exercises"] = 0
        user_data[user.pk]["pct_mastery"] = 0.
        user_data[user.pk]["exercises_mastered"] = []

        user_data[user.pk]["total_videos"] = 0
        user_data[user.pk]["videos_watched"] = []
    

    for elog in exercise_logs:
        user_data[elog["user__pk"]]["total_exercises"] += 1
        user_data[elog["user__pk"]]["pct_mastery"] += 1. / len_all_exercises
        user_data[elog["user__pk"]]["exercises_mastered"].append(elog["exercise_id"])

    for vlog in video_logs:
        user_data[vlog["user__pk"]]["total_videos"] += 1
        user_data[vlog["user__pk"]]["videos_watched"].append(vlog["youtube_id"])

    for llog in login_logs:
        if llog["activity_type"] == UserLog.get_activity_int("coachreport"):
            user_data[llog["user__pk"]]["total_report_views"] += 1
        elif llog["activity_type"] == UserLog.get_activity_int("login"):
            user_data[llog["user__pk"]]["total_hours"] += (llog["total_seconds"]) / 3600.
            user_data[llog["user__pk"]]["total_logins"] += 1

    # Add group data.  Allow a fake group "Ungrouped"
    for user in users:
        group_pk = getattr(user.group, "pk", None)
        group_name = getattr(user.group, "name", "Ungrouped")
        if not group_pk in group_data:
            group_data[group_pk] = {
                "name": group_name,
                "total_logins": 0,
                "total_hours": 0,
                "total_users": 0,
                "total_videos": 0,
                "total_exercises": 0,
                "pct_mastery": 0,
            }
        group_data[group_pk]["total_users"] += 1
        group_data[group_pk]["total_logins"] += user_data[user.pk]["total_logins"]
        group_data[group_pk]["total_hours"] += user_data[user.pk]["total_hours"]
        group_data[group_pk]["total_videos"] += user_data[user.pk]["total_videos"]
        group_data[group_pk]["total_exercises"] += user_data[user.pk]["total_exercises"]

        total_mastery_so_far = (group_data[group_pk]["pct_mastery"] * (group_data[group_pk]["total_users"] - 1) + user_data[user.pk]["pct_mastery"])
        group_data[group_pk]["pct_mastery"] =  total_mastery_so_far / group_data[group_pk]["total_users"]

    return (user_data, group_data)
开发者ID:Eleonore9,项目名称:ka-lite,代码行数:94,代码来源:views.py

示例3: facility_usage

# 需要导入模块: from main.models import UserLog [as 别名]
# 或者: from main.models.UserLog import get_activity_int [as 别名]
def facility_usage(request, facility_id, org_id=None, zone_id=None):

    # Basic data
    org = get_object_or_None(Organization, pk=org_id) if org_id else None
    zone = get_object_or_None(Zone, pk=zone_id) if zone_id else None
    facility = get_object_or_404(Facility, pk=facility_id)
    groups = FacilityGroup.objects.filter(facility=facility).order_by("name")
    users = FacilityUser.objects.filter(facility=facility).order_by("last_name")

    # Accumulating data
    len_all_exercises = len(topicdata.NODE_CACHE['Exercise'])

    group_data = collections.OrderedDict()
    user_data = collections.OrderedDict()
    for user in users:
        exercise_logs = ExerciseLog.objects.filter(user=user)
        exercise_stats = {"count": exercise_logs.count(), "total_mastery": exercise_logs.aggregate(Sum("complete"))["complete__sum"]}
        video_stats = {"count": VideoLog.objects.filter(user=user).count()}
        login_stats = UserLogSummary.objects \
            .filter(user=user, activity_type=UserLog.get_activity_int("login")) \
            .aggregate(Sum("count"), Sum("total_seconds"))

        user_data[user.pk] = {
            "first_name": user.first_name,
            "last_name": user.last_name,
            "name": user.get_name(),
            "group": user.group,
            "total_logins": login_stats["count__sum"] or 0,
            "total_hours": (login_stats["total_seconds__sum"] or 0)/3600.,
            "total_videos": video_stats["count"],
            "total_exercises": exercise_stats["count"],
            "pct_mastery": (exercise_stats["total_mastery"] or 0)/float(len_all_exercises),
        }

        group = user.group
        if group:
            if not group.pk in group_data:
                group_data[group.pk] = {
                    "name": group.name,
                    "total_logins": 0,
                    "total_hours": 0,
                    "total_users": 0,
                    "total_videos": 0,
                    "total_exercises": 0,
                    "pct_mastery": 0,
                }
            group_data[group.pk]["total_users"] += 1
            group_data[group.pk]["total_logins"] += user_data[user.pk]["total_logins"]
            group_data[group.pk]["total_hours"] += user_data[user.pk]["total_hours"]
            group_data[group.pk]["total_videos"] += user_data[user.pk]["total_videos"]
            group_data[group.pk]["total_exercises"] += user_data[user.pk]["total_exercises"]

            total_mastery_so_far = (group_data[group.pk]["pct_mastery"] * (group_data[group.pk]["total_users"] - 1) + user_data[user.pk]["pct_mastery"])
            group_data[group.pk]["pct_mastery"] =  total_mastery_so_far / group_data[group.pk]["total_users"]

    return {
        "org": org,
        "zone": zone,
        "facility": facility,
        "groups": group_data,
        "users": user_data,
    }
开发者ID:NiallEgan,项目名称:ka-lite,代码行数:64,代码来源:views.py


注:本文中的main.models.UserLog.get_activity_int方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。