Commit cc2ad68a38a3d45676ed92a20ded5a3ad54b782e
Exists in
master
Merge branch 'master' of git.ucsd.edu:110swag/flashy-backend
Showing 3 changed files Side-by-side Diff
flashcards/models.py
View file @
cc2ad68
... | ... | @@ -17,8 +17,6 @@ |
17 | 17 | from fields import MaskField |
18 | 18 | from cached_property import cached_property |
19 | 19 | |
20 | - | |
21 | - | |
22 | 20 | # Hack to fix AbstractUser before subclassing it |
23 | 21 | |
24 | 22 | AbstractUser._meta.get_field('email')._unique = True |
... | ... | @@ -473,4 +471,11 @@ |
473 | 471 | |
474 | 472 | def __unicode__(self): |
475 | 473 | return '%s whitelisted for %s' % (str(self.email), str(self.section)) |
474 | + | |
475 | +class JulianDay(Func): | |
476 | + function = 'julianday' | |
477 | + | |
478 | + def __init__(self, expression, **extra): | |
479 | + output = extra.pop('output_field', DateTimeField()) | |
480 | + super(JulianDay, self).__init__(expression, output_field=output, **extra) |
flashcards/views.py
View file @
cc2ad68
1 | 1 | import django |
2 | 2 | from django.contrib import auth |
3 | -from django.db import IntegrityError | |
4 | 3 | from django.shortcuts import get_object_or_404 |
5 | 4 | from django.utils.log import getLogger |
6 | 5 | from flashcards.api import StandardResultsSetPagination, IsEnrolledInAssociatedSection, IsFlashcardReviewer, \ |
7 | 6 | |
... | ... | @@ -20,10 +19,13 @@ |
20 | 19 | from django.core.mail import send_mail |
21 | 20 | from django.contrib.auth import authenticate |
22 | 21 | from django.contrib.auth.tokens import default_token_generator |
22 | +from django.db.models import Count, Max, F, Value, When, Case, DateTimeField, FloatField | |
23 | 23 | from rest_framework.status import HTTP_204_NO_CONTENT, HTTP_201_CREATED, HTTP_200_OK |
24 | 24 | from rest_framework.response import Response |
25 | 25 | from rest_framework.exceptions import AuthenticationFailed, NotAuthenticated, ValidationError, PermissionDenied |
26 | 26 | from simple_email_confirmation import EmailAddress |
27 | +from math import e | |
28 | +from django.utils.timezone import now | |
27 | 29 | |
28 | 30 | |
29 | 31 | def log_event(request, event=''): |
30 | 32 | |
... | ... | @@ -401,17 +403,19 @@ |
401 | 403 | if not user_flashcard_filter.exists(): |
402 | 404 | raise ValidationError("No matching flashcard found in your decks") |
403 | 405 | |
404 | - user_flashcard = user_flashcard_filter.order_by('?').first() | |
405 | - """ | |
406 | - user_flashcard_pks = user_flashcard_filter.values('pk') | |
407 | - quiz_filter = UserFlashcardQuiz.filter( | |
408 | - user_flashcard__in=user_flashcard_pks | |
409 | - ).annotate( | |
410 | - revise_count=Count('user_flashcard') | |
411 | - ).annotate( | |
406 | + quiz_filter = user_flashcard_filter.prefetch_related('userflashcardquiz_set').annotate( | |
407 | + revise_count=Count('pk'), | |
408 | + days_since=Case( | |
409 | + When(userflashcardquiz__when=None, then=Value(now(), output_field=DateTimeField())-F('pulled')), | |
410 | + default=Value(now(), output_field=DateTimeField())-Max('userflashcardquiz__when'), | |
411 | + output_field=FloatField() | |
412 | + ), | |
413 | + retention_score=Case( | |
414 | + default=Value(e, output_field=FloatField()) ** (F('days_since')*(-0.1/(F('revise_count')+1))), | |
415 | + output_field=FloatField()) | |
416 | + ).order_by('retention_score') | |
412 | 417 | |
413 | - ) | |
414 | - """ | |
418 | + user_flashcard = quiz_filter.first() | |
415 | 419 | mask = user_flashcard.get_mask().get_random_blank() |
416 | 420 | user_flashcard_quiz = UserFlashcardQuiz(user_flashcard=user_flashcard, |
417 | 421 | blanked_word=user_flashcard.flashcard.text[slice(*mask)]) |
flashy/settings.py
View file @
cc2ad68
... | ... | @@ -16,6 +16,7 @@ |
16 | 16 | 'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.LimitOffsetPagination', |
17 | 17 | 'PAGE_SIZE': 20 |
18 | 18 | } |
19 | + | |
19 | 20 | INSTALLED_APPS = [ |
20 | 21 | 'simple_email_confirmation', |
21 | 22 | 'flashcards', |
... | ... | @@ -92,7 +93,6 @@ |
92 | 93 | } |
93 | 94 | |
94 | 95 | LANGUAGE_CODE = 'en-us' |
95 | -TIME_ZONE = 'America/Los_Angeles' | |
96 | 96 | USE_I18N = True |
97 | 97 | USE_L10N = True |
98 | 98 | USE_TZ = True |