Commit 63502bd39ab07505fd1d795d1edf16e2fbe5f1ea
1 parent
9a1fcf1533
Exists in
master
Added fix for using current time in postgres queries
Showing 2 changed files with 19 additions and 6 deletions Side-by-side Diff
flashcards/models.py
View file @
63502bd
... | ... | @@ -474,6 +474,18 @@ |
474 | 474 | return '%s whitelisted for %s' % (str(self.email), str(self.section)) |
475 | 475 | |
476 | 476 | |
477 | +class Now(Func): | |
478 | + template = 'CURRENT_TIMESTAMP' | |
479 | + | |
480 | + def __init__(self, output_field=DateTimeField(), **extra): | |
481 | + self.source_expressions = [] | |
482 | + self.extra = {} | |
483 | + super(Func, self).__init__(output_field=output_field, **extra) | |
484 | + | |
485 | + def copy(self): | |
486 | + return super(Func, self).copy() | |
487 | + | |
488 | + | |
477 | 489 | class JulianDay(Func): |
478 | 490 | function = 'julianday' |
479 | 491 | template = '%(function)s(%(expressions)s)' |
flashcards/views.py
View file @
63502bd
... | ... | @@ -5,7 +5,7 @@ |
5 | 5 | from flashcards.api import StandardResultsSetPagination, IsEnrolledInAssociatedSection, IsFlashcardReviewer, \ |
6 | 6 | IsAuthenticatedAndConfirmed |
7 | 7 | from flashcards.models import Section, User, Flashcard, FlashcardHide, UserFlashcard, UserFlashcardQuiz, \ |
8 | - FlashcardAlreadyPulledException, FlashcardNotInDeckException, interval_days | |
8 | + FlashcardAlreadyPulledException, FlashcardNotInDeckException, Now, interval_days | |
9 | 9 | from flashcards.notifications import notify_new_card |
10 | 10 | from flashcards.serializers import SectionSerializer, UserUpdateSerializer, RegistrationSerializer, UserSerializer, \ |
11 | 11 | PasswordResetSerializer, PasswordResetRequestSerializer, EmailPasswordSerializer, FlashcardSerializer, \ |
12 | 12 | |
13 | 13 | |
... | ... | @@ -404,15 +404,16 @@ |
404 | 404 | raise ValidationError("No matching flashcard found in your decks") |
405 | 405 | |
406 | 406 | quiz_filter = user_flashcard_filter.prefetch_related('userflashcardquiz_set').annotate( |
407 | - revise_count=Count('pk'), | |
407 | + study_count=Count('pk'), | |
408 | 408 | days_since=Case( |
409 | - When(userflashcardquiz__when=None, then=interval_days(Value(now(), output_field=DateTimeField()), F('pulled'))), | |
410 | - default=interval_days(Value(now(), output_field=DateTimeField()), Max('userflashcardquiz__when')), | |
409 | + When(userflashcardquiz__when=None, then=interval_days(Now(), F('pulled'))), | |
410 | + default=interval_days(Now(), Max('userflashcardquiz__when')), | |
411 | 411 | output_field=FloatField() |
412 | 412 | ), |
413 | 413 | retention_score=Case( |
414 | - default=Value(e, output_field=FloatField()) ** (F('days_since')*(-0.1/(F('revise_count')+1))), | |
415 | - output_field=FloatField()) | |
414 | + default=Value(e, output_field=FloatField()) ** (F('days_since')*(-0.1/(F('study_count')+1))), | |
415 | + output_field=FloatField() | |
416 | + ) | |
416 | 417 | ).order_by('retention_score') |
417 | 418 | |
418 | 419 | user_flashcard = quiz_filter.first() |