本文整理汇总了Python中main.models.VideoLog.counter方法的典型用法代码示例。如果您正苦于以下问题:Python VideoLog.counter方法的具体用法?Python VideoLog.counter怎么用?Python VideoLog.counter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类main.models.VideoLog
的用法示例。
在下文中一共展示了VideoLog.counter方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: generate_fake_video_logs
# 需要导入模块: from main.models import VideoLog [as 别名]
# 或者: from main.models.VideoLog import counter [as 别名]
#.........这里部分代码省略.........
# and watching videos without finishing.
# Get (or create) user type
try:
user_settings = json.loads(facility_user.notes)
except:
user_settings = sample_user_settings()
facility_user.notes = json.dumps(user_settings)
facility_user.save()
date_diff_started = datetime.timedelta(seconds=datediff(date_diff, units="seconds") * user_settings["time_in_program"]) # when this user started in the program, relative to NOW
for topic in topics:
videos = get_topic_videos(topic_id=topic)
exercises = get_topic_exercises(topic_id=topic)
exercise_ids = [ex["id"] if "id" in ex else ex['name'] for ex in exercises]
exercise_logs = ExerciseLog.objects.filter(user=facility_user, id__in=exercise_ids)
# Probability of watching a video, irrespective of the context
p_video_outer = probability_of("video", user_settings=user_settings)
logging.debug("# videos: %d; p(videos)=%4.3f, user settings: %s\n" % (len(videos), p_video_outer, json.dumps(user_settings)))
for video in videos:
p_completed = probability_of("completed", user_settings=user_settings)
# If we're just doing random videos, fine.
# If these videos relate to exercises, then suppress non-exercise-related videos
# for this user.
p_video = p_video_outer # start with the context-free value
did_exercise = False
if exercise_logs.count() > 0:
# 5x less likely to watch a video if you haven't done the exercise,
if "related_exercise" not in video:
p_video /= 5 # suppress
# 5x more likely to watch a video if they've done the exercise
# 2x more likely to have finished it.
else:
exercise_log = ExerciseLog.objects.filter(user=facility_user, id=video["related_exercise"]["id"])
did_exercise = exercise_log.count() != 0
if did_exercise:
p_video *= 5
p_completed *= 2
# Do the sampling
if p_video < random.random():
continue
# didn't watch it
elif p_completed > random.random():
pct_completed = 100.
else: # Slower students will use videos more. Effort also important.
pct_completed = 100. * min(1., sqrt(random.random() * sqrt(user_settings["effort_level"] * user_settings["time_in_program"] / sqrt(user_settings["speed_of_learning"]))))
# Compute quantities based on sample
total_seconds_watched = int(video["duration"] * pct_completed / 100.)
points = int(750 * pct_completed / 100.)
# Choose a rate of videos, based on their effort level.
# Compute the latest possible start time.
# Then sample a start time between their start time
# and the latest possible start_time
if did_exercise:
# More jitter if you learn fast, less jitter if you try harder (more diligent)
date_jitter = datetime.timedelta(days=max(0, random.gauss(1, user_settings["speed_of_learning"] / user_settings["effort_level"])))
date_completed = exercise_log[0].completion_timestamp - date_jitter
else:
rate_of_videos = 0.66 * user_settings["effort_level"] + 0.33 * user_settings["speed_of_learning"] # exercises per day
time_for_watching = total_seconds_watched
time_delta_completed = datetime.timedelta(seconds=random.randint(int(time_for_watching), int(datediff(date_diff_started, units="seconds"))))
date_completed = datetime.datetime.now() - time_delta_completed
try:
vlog = VideoLog.objects.get(user=facility_user, youtube_id=video["youtube_id"])
except VideoLog.DoesNotExist:
logging.info("Creating video log: %-12s: %-45s (%4.1f%% watched, %d points)%s" % (
facility_user.first_name,
video["title"],
pct_completed,
points,
" COMPLETE on %s!" % date_completed if pct_completed == 100 else "",
))
vlog = VideoLog(
user=facility_user,
youtube_id=video["youtube_id"],
total_seconds_watched=total_seconds_watched,
points=points,
complete=(pct_completed == 100.),
completion_timestamp=date_completed,
completion_counter=datediff(date_completed, start_date, units="seconds"),
)
vlog.full_clean()
# TODO(bcipolli): bulk saving of logs
vlog.counter = own_device.increment_and_get_counter()
vlog.sign(own_device) # have to sign after setting the counter
vlog.save(imported=True) # avoid userlog issues
video_logs.append(vlog)
return video_logs