Browse files

Small style cleanups.

  • Loading branch information...
1 parent ff10488 commit d42b91f0c4dfb2bc9f4c71019d9dd4586677cb15 @malcolmt committed Sep 28, 2010
Showing with 14 additions and 10 deletions.
  1. +1 −1 minerva/forms.py
  2. +11 −8 minerva/questions.py
  3. +1 −0 minerva/signal_handlers.py
  4. +1 −1 minerva/views.py
View
2 minerva/forms.py
@@ -1,7 +1,7 @@
from django import forms
from general import form_helpers
-from minerva.models import Profile, Language
+from minerva.models import Language
class QuestionForm(forms.Form):
meta = forms.CharField(widget=forms.HiddenInput)
View
19 minerva/questions.py
@@ -3,8 +3,6 @@
from django.conf import settings
from django.core.cache import cache
-from django.db.models import Min
-
from minerva.models import Word
from minerva.models import SessionProgress
@@ -21,13 +19,14 @@ def get_available_words(query, language_id, level, last_question):
pks = word_keys(language_id, level)
current_words = set(available_words.values_list("word", flat=True))
# Collisions should be infrequent, so we should be able to get surplus
- sampled_words = set(Word.objects.filter(pk__in=random.sample(pks, num_required + 10)))
+ sampled_words = set(Word.objects.filter(
+ pk__in=random.sample(pks, num_required + 10)))
# remove duplicate words from our candidates
selected = sampled_words - current_words
for i in selected:
new_word = dict(query)
new_word["word"] = i
- new_entry = SessionProgress.objects.create(**new_word)
+ SessionProgress(**new_word).save()
available_words = SessionProgress.objects.filter(**query)
if last_question:
last_word = Word.objects.get(id=last_question)
@@ -56,15 +55,17 @@ def process_answer(query_base, data):
progress_on_correct_answer = SessionProgress.objects.get(**query)
if int(correct_answer) != int(data['answer']):
# data['answer'] is the selected answer
- # Relax the weights because we got them wrong, we want to be more likely to select it next time
+ # Relax the weights because we got them wrong, we want to be more
+ # likely to select it next time.
query['word'] = data['answer']
progress_on_incorrect_select = SessionProgress.objects.get(**query)
decrement_weight(progress_on_correct_answer)
decrement_weight(progress_on_incorrect_select)
else:
progress_on_correct_answer.correct += 1
if progress_on_correct_answer.correct > 5:
- # we have seen this word enough times and answered correctly remove it from the fold
+ # We have seen this word enough times and answered correctly.
+ # Remove it from the fold.
progress_on_correct_answer.delete()
else:
progress_on_correct_answer.weight += 10 + (10 * random.random())
@@ -78,12 +79,14 @@ def create_question_complex(query_base, language_id, level, last_question,
last_question)
#query['language'] = language_id
next_word = available_words[0]
- possible_answers = random.sample(available_words[1:], num_choices - 1) + [next_word]
+ possible_answers = (random.sample(available_words[1:], num_choices - 1)
+ + [next_word])
random.shuffle(possible_answers)
question_attribute, answer_attribute = random.choice(QUESTION_SCENARIOS)
question_data = (
[next_word.word.pk, getattr(next_word.word, question_attribute)],
- [(word.word.pk, getattr(word.word, answer_attribute)) for word in possible_answers]
+ [(word.word.pk, getattr(word.word, answer_attribute))
+ for word in possible_answers]
)
return question_data
#next_word = .aggregate(Min('weight'))
View
1 minerva/signal_handlers.py
@@ -4,6 +4,7 @@ def create_user_profile(sender, **kwargs):
"""
Create an empty Profile whenever a new User is created.
"""
+ # pylint: disable-msg=W0613
from minerva import models
try:
ContentType.objects.get_by_natural_key("minerva", "profile")
View
2 minerva/views.py
@@ -41,7 +41,7 @@ def validate_answer(request, query_base):
def question(request):
context = {}
- query= {}
+ query = {}
if request.user.is_authenticated():
query['student'] = request.user
language_id = Profile.objects.get(user=request.user).language_pref_id

0 comments on commit d42b91f

Please sign in to comment.