約1,000,000人のユーザーがいるとしましょう。特定のユーザーがどの位置にいて、どのユーザーが彼の周りにいるのかを知りたいです。ユーザーはいつでも新しい成果を得ることができます。彼が自分の最新の更新を見ることができれば、それは素晴らしいことです。
正直なところ、これを行うことを考えるすべての方法は、時間やメモリの面で恐ろしく高価になります。アイデア?これまでの私の最も近い考えは、ユーザーをオフラインで注文してパーセンタイルバケットを作成することですが、それではユーザーに正確な位置を示すことはできません。
それがあなたのdjangoの人々を助けるならいくつかのコード:
class Alias(models.Model) :
awards = models.ManyToManyField('Award', through='Achiever')
@property
def points(self) :
p = cache.get('alias_points_' + str(self.id))
if p is not None : return p
points = 0
for a in self.achiever_set.all() :
points += a.award.points * a.count
cache.set('alias_points_' + str(self.id), points, 60 * 60) # 1 hour
return points
class Award(MyBaseModel):
owner_points = models.IntegerField(help_text="A non-normalized point value. Very subjective but try to be consistent. Should be proporional. 2x points = 2x effort (or skill)")
true_points = models.FloatField(help_text="The true value of this award. Recalculated with a cron job. Based on number of people who won it", editable=False, null=True)
@property
def points(self) :
if self.true_points :
# blend true_points into real points over 30 days
age = datetime.now() - self.created
blend_days = 30
if age > timedelta(days=blend_days) :
age = timedelta(days=blend_days)
num_days = 1.0 * age.days / blend_days
r = self.true_points * num_days + self.owner_points * (1 - num_days)
return int(r * 10) / 10.0
else :
return self.owner_points
class Achiever(MyBaseModel):
award = models.ForeignKey(Award)
alias = models.ForeignKey(Alias)
count = models.IntegerField(default=1)