本文整理汇总了Python中main.models.ExerciseLog.full_clean方法的典型用法代码示例。如果您正苦于以下问题:Python ExerciseLog.full_clean方法的具体用法?Python ExerciseLog.full_clean怎么用?Python ExerciseLog.full_clean使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类main.models.ExerciseLog
的用法示例。
在下文中一共展示了ExerciseLog.full_clean方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: handle
# 需要导入模块: from main.models import ExerciseLog [as 别名]
# 或者: from main.models.ExerciseLog import full_clean [as 别名]
def handle(self, *args, **options):
if settings.CENTRAL_SERVER:
raise CommandError("Don't run this on the central server!! Data not linked to any zone on the central server is BAD.")
facility = Facility(name="Wilson Elementary")
facility.save()
group1 = FacilityGroup(facility=facility, name="Class 4E")
group1.full_clean()
group1.save()
group2 = FacilityGroup(facility=facility, name="Class 5B")
group2.full_clean()
group2.save()
facilityusers = []
for i in range(0,10):
newuser1 = FacilityUser(facility=facility, username=usernames[i], first_name=firstnames[i], last_name=lastnames[i], group=group1)
if settings.DEBUG:
newuser1.set_password(hashed_password = hashed_blah)#"blah")
else:
newuser1.set_password("blah")
newuser1.full_clean()
newuser1.save()
facilityusers.append(newuser1)
newuser2 = FacilityUser(facility=facility, username=usernames[i+10], first_name=firstnames[i+10], last_name=lastnames[i+10], group=group2)
if settings.DEBUG:
newuser2.set_password(hashed_password = hashed_blah)#"blah")
else:
newuser2.set_password("blah")
newuser2.full_clean()
newuser2.save()
facilityusers.append(newuser2)
for topic in topics:
exercises = get_topic_exercises(topic_id=topic)
exercises_a = [random.random() for i in range(len(exercises))]
exercises_b = [float(i) / len(exercises) for i in range(len(exercises))]
for i, user in enumerate(facilityusers):
for j, exercise in enumerate(exercises):
sig = sigmoid(proficiency[i], exercises_a[j], exercises_b[j])
if random.random() < 0.05 * (1-sig) and j > 2:
break
if random.random() < 0.15:
continue
attempts = random.random() * 40 + 10
streak_progress = max(10, min(100, 10 * random.random() + 10 * attempts * sig))
print int(attempts), int(streak_progress), user.first_name, exercise["name"]
log = ExerciseLog(user=user, exercise_id=exercise["name"], attempts=attempts, streak_progress=streak_progress)
log.full_clean()
log.save()
示例2: handle
# 需要导入模块: from main.models import ExerciseLog [as 别名]
# 或者: from main.models.ExerciseLog import full_clean [as 别名]
def handle(self, *args, **options):
facility = Facility(name="Wilson Elementary")
facility.save()
group1 = FacilityGroup(facility=facility, name="Class 4E")
group1.full_clean()
group1.save()
group2 = FacilityGroup(facility=facility, name="Class 5B")
group2.full_clean()
group2.save()
facilityusers = []
for i in range(0,10):
newuser1 = FacilityUser(facility=facility, username=usernames[i], first_name=firstnames[i], last_name=lastnames[i], group=group1)
newuser1.set_password("blah")
newuser1.full_clean()
newuser1.save()
facilityusers.append(newuser1)
newuser2 = FacilityUser(facility=facility, username=usernames[i+10], first_name=firstnames[i+10], last_name=lastnames[i+10], group=group2)
newuser2.set_password("blah")
newuser2.full_clean()
newuser2.save()
facilityusers.append(newuser2)
for topic in topics:
exercises = json.load(open("./static/data/topicdata/" + topic + ".json","r"))
exercises = sorted(exercises, key = lambda k: (k["h_position"], k["v_position"]))
exercises_a = [random.random() for i in range(len(exercises))]
exercises_b = [float(i) / len(exercises) for i in range(len(exercises))]
for i, user in enumerate(facilityusers):
for j, exercise in enumerate(exercises):
sig = sigmoid(proficiency[i], exercises_a[j], exercises_b[j])
if random.random() < 0.05 * (1-sig) and j > 2:
break
if random.random() < 0.15:
continue
attempts = random.random() * 40 + 10
streak_progress = max(10, min(100, 10 * random.random() + 10 * attempts * sig))
print int(attempts), int(streak_progress), user.first_name, exercise["name"]
log = ExerciseLog(user=user, exercise_id=exercise["name"], attempts=attempts, streak_progress=streak_progress)
log.full_clean()
log.save()
示例3: generate_fake_exercise_logs
# 需要导入模块: from main.models import ExerciseLog [as 别名]
# 或者: from main.models.ExerciseLog import full_clean [as 别名]
#.........这里部分代码省略.........
(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),
completion_timestamp=date_completed,
completion_counter=datediff(date_completed, start_date, units="seconds"),
)
elog.full_clean()
elog.save() # TODO(bcipolli): bulk saving of logs
# For now, make all attempts on an exercise into a single UserLog.
seconds_per_attempt = 10 * (1 + user_settings["speed_of_learning"] * random.random())
time_to_navigate = 15 * (0.5 + random.random()) #between 7.5s and 22.5s
time_to_logout = 5 * (0.5 + random.random()) # between 2.5 and 7.5s
ulog = UserLog(
user=facility_user,
activity_type=1,
start_datetime = date_completed - datetime.timedelta(seconds=int(attempts * seconds_per_attempt + time_to_navigate)),
end_datetime = date_completed + datetime.timedelta(seconds=time_to_logout),
last_active_datetime = date_completed,
)
ulog.full_clean()
ulog.save()
user_logs.append(ulog)
exercise_logs.append(elog)
return (exercise_logs, user_logs)