Permalink
Browse files

undo erroneous README change; update some utility code to the current…

… csc-utils
  • Loading branch information...
1 parent a1905e9 commit da1dd9f199873d9526cb238ea56fc1ce26ca03dd @rspeer rspeer committed Oct 20, 2011
Showing with 18 additions and 8 deletions.
  1. +3 −2 conceptnet/corpus/models.py
  2. +1 −1 conceptnet/models.py
  3. +14 −5 maint/update_scores.py
@@ -31,13 +31,14 @@ def get_rating(self, user):
"""
return getattr(Vote.objects.get_for_user(self, user), 'vote', None)
- def set_rating(self, user, val, activity):
+ def set_rating(self, user, val, activity=None):
"""
Set a user's Vote on a certain object. If the user has previously voted
on that object, it removes the old vote.
"""
Vote.objects.record_vote(self, user, val)
- Event.record_event(self, user, activity)
+ if activity is not None:
+ Event.record_event(self, user, activity)
#self.update_score()
def update_score(self):
@@ -5,7 +5,7 @@
from events.models import Event, Activity
from voting.models import Vote, SCORES
from django.contrib.contenttypes import generic
-from csc_utils import cached
+from csc_utils.cache import cached
from datetime import datetime
from urllib import quote as urlquote
import re
@@ -1,9 +1,18 @@
from csc_utils.batch import queryset_foreach
from conceptnet.models import Sentence, Assertion, RawAssertion
-queryset_foreach(Assertion.objects.all(), lambda x: x.update_score(),
-batch_size=100)
-queryset_foreach(RawAssertion.objects.all(), lambda x: x.update_score(),
-batch_size=100)
-# queryset_foreach(Sentence.objects.exclude(language__id='en'), lambda x: x.update_score(), batch_size=100)
+
+def update_scores():
+ queryset_foreach(Assertion, lambda x: x.update_score(),
+ batch_size=100)
+ queryset_foreach(RawAssertion, lambda x: x.update_score(),
+ batch_size=100)
+ # queryset_foreach(Sentence.objects.exclude(language__id='en'), lambda x: x.update_score(), batch_size=100)
+
+def fix_raw_assertion_vote(raw):
+ for vote in raw.votes.all():
+ raw.assertion.set_rating(vote.user, vote.vote)
+
+def update_votes():
+ queryset_foreach(RawAssertion, lambda x: fix_raw_assertion_vote(x), batch_size=100)

0 comments on commit da1dd9f

Please sign in to comment.