本文整理汇总了Python中kalite.main.models.UserLog.save方法的典型用法代码示例。如果您正苦于以下问题:Python UserLog.save方法的具体用法?Python UserLog.save怎么用?Python UserLog.save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类kalite.main.models.UserLog
的用法示例。
在下文中一共展示了UserLog.save方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: generate_fake_exercise_logs
# 需要导入模块: from kalite.main.models import UserLog [as 别名]
# 或者: from kalite.main.models.UserLog import save [as 别名]
def generate_fake_exercise_logs(
facility_user=None, topics=topics, start_date=datetime.datetime.now() - datetime.timedelta(days=30 * 6)
):
"""Add exercise logs for the given topics, for each of the given users.
If no users are given, they are created.
If no topics exist, they are taken from the list at the top of this file.
By default, users start learning randomly between 6 months ago and now.
"""
date_diff = datetime.datetime.now() - start_date
exercise_logs = []
user_logs = []
# It's not a user: probably a list.
# Recursive case
if not hasattr(facility_user, "username"):
# It's NONE :-/ generate the users first!
if not facility_user:
(facility_user, _, _) = generate_fake_facility_users()
for topic in topics:
for user in facility_user:
(elogs, ulogs) = generate_fake_exercise_logs(facility_user=user, topics=[topic], start_date=start_date)
exercise_logs.append(elogs)
user_logs.append(ulogs)
# Actually generate!
else:
# 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:
# Get all exercises related to the topic
exercises = get_topic_exercises(topic_id=topic)
# Problem:
# Not realistic for students to have lots of unfinished exercises.
# If they start them, they tend to get stuck, right?
#
# So, need to make it more probable that they will finish an exercise,
# and less probable that they start one.
#
# What we need is P(streak|started), not P(streak)
# Probability of doing any particular exercise
p_exercise = probability_of(qty="exercise", user_settings=user_settings)
logging.info(
"# exercises: %d; p(exercise)=%4.3f, user settings: %s\n"
% (len(exercises), p_exercise, json.dumps(user_settings))
)
# of exercises is related to
for j, exercise in enumerate(exercises):
if random.random() > p_exercise:
continue
# Probability of completing this exercise, and .. proportion of attempts
p_attempts = probability_of(qty="attempts", user_settings=user_settings)
attempts = int(random.random() * p_attempts * 30 + 10) # always enough to have completed
elog, created = ExerciseLog.objects.get_or_create(user=facility_user, exercise_id=exercise["id"])
alogs = []
for i in range(0, attempts):
alog = AttemptLog.objects.create(
user=facility_user, exercise_id=exercise["id"], timestamp=start_date + date_diff * i / attempts
)
alogs.append(alog)
if random.random() < user_settings["speed_of_learning"]:
alog.correct = True
alog.points = 10
alog.save()
elog.attempts = attempts
elog.latest_activity_timestamp = start_date + date_diff
elog.streak_progress = sum([log.correct for log in alogs][-10:]) * 10
elog.points = sum([log.points for log in alogs][-10:])
elog.save()
exercise_logs.append(elog)
ulog = UserLog(
user=facility_user,
activity_type=1,
start_datetime=start_date,
end_datetime=start_date + date_diff,
last_active_datetime=start_date + date_diff,
)
#.........这里部分代码省略.........
示例2: generate_fake_exercise_logs
# 需要导入模块: from kalite.main.models import UserLog [as 别名]
# 或者: from kalite.main.models.UserLog import save [as 别名]
def generate_fake_exercise_logs(facility_user=None, topics=topics, start_date=datetime.datetime.now() - datetime.timedelta(days=30 * 6)):
"""Add exercise logs for the given topics, for each of the given users.
If no users are given, they are created.
If no topics exist, they are taken from the list at the top of this file.
By default, users start learning randomly between 6 months ago and now.
"""
date_diff = datetime.datetime.now() - start_date
exercise_logs = []
user_logs = []
# It's not a user: probably a list.
# Recursive case
if not hasattr(facility_user, "username"):
# It's NONE :-/ generate the users first!
if not facility_user:
(facility_user, _, _) = generate_fake_facility_users()
for topic in topics:
for user in facility_user:
(elogs, ulogs) = generate_fake_exercise_logs(facility_user=user, topics=[topic], start_date=start_date)
exercise_logs.append(elogs)
user_logs.append(ulogs)
# Actually generate!
else:
# 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:
# Get all exercises related to the topic
exercises = get_topic_exercises(topic_id=topic)
# Problem:
# Not realistic for students to have lots of unfinished exercises.
# If they start them, they tend to get stuck, right?
#
# So, need to make it more probable that they will finish an exercise,
# and less probable that they start one.
#
# What we need is P(streak|started), not P(streak)
# Probability of doing any particular exercise
p_exercise = probability_of(qty="exercise", user_settings=user_settings)
logging.debug("# exercises: %d; p(exercise)=%4.3f, user settings: %s\n" % (len(exercises), p_exercise, json.dumps(user_settings)))
# of exercises is related to
for j, exercise in enumerate(exercises):
if random.random() > p_exercise:
continue
# Probability of completing this exercise, and .. proportion of attempts
p_completed = probability_of(qty="completed", user_settings=user_settings)
p_attempts = probability_of(qty="attempts", user_settings=user_settings)
attempts = int(random.random() * p_attempts * 30 + 10) # always enough to have completed
completed = (random.random() < p_completed)
if completed:
streak_progress = 100
else:
streak_progress = max(0, min(90, random.gauss(100 * user_settings["speed_of_learning"], 20)))
streak_progress = int(floor(streak_progress / 10.)) * 10
points = streak_progress / 10 * 12 if completed else 0 # only get points when you master.
# Choose a rate of exercises, based on their effort level and speed of learning.
# Compute the latest possible start time.
# Then sample a start time between their start time
# and the latest possible start_time
rate_of_exercises = 0.66 * user_settings["effort_level"] + 0.33 * user_settings["speed_of_learning"] # exercises per day
time_for_attempts = min(datetime.timedelta(days=rate_of_exercises * attempts), date_diff_started) # protect with min
time_delta_completed = datetime.timedelta(seconds=random.randint(int(datediff(time_for_attempts, units="seconds")), int(datediff(date_diff_started, units="seconds"))))
date_completed = datetime.datetime.now() - time_delta_completed
# Always create new
logging.info("Creating exercise log: %-12s: %-25s (%d points, %d attempts, %d%% streak on %s)" % (
facility_user.first_name,
exercise["name"],
points,
attempts,
streak_progress,
date_completed,
))
try:
elog = ExerciseLog.objects.get(user=facility_user, exercise_id=exercise["name"])
except ExerciseLog.DoesNotExist:
elog = ExerciseLog(
user=facility_user,
exercise_id=exercise["name"],
attempts=int(attempts),
streak_progress=streak_progress,
points=int(points),
complete=completed,
completion_timestamp=date_completed,
#.........这里部分代码省略.........