約1,000,000人のユーザーがいるとします。特定のユーザーがどのようなポジションにいるのか、どのユーザーが自分の周りにいるのかを知りたい。ユーザーはいつでも新しい成果を得ることができ、彼の立場の更新を見ることができればすばらしいことになります。Django:リーダーボードの作成方法
正直言って、私がこれをやっていると思うあらゆる方法は、時間やメモリの面倒な高価になるでしょう。アイデア?私の最近の考えは、ユーザーをオフラインにしてパーセンタイルバケットを作成することですが、ユーザーに彼の正確な位置を示すことはできません。それはあなたが人々を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)
誰かがこれをもっと明確にするために編集してください、私は就寝します。 –
私は、ユーザーに彼らの上に人をぶつけて見せることによって目標を与えようとしていましたが、到達できないほど遠くはありませんでした。 –
ディストリビューションの底に向かってのジッタは非常に大きいので、1ポイント上がったり下がったりしても、1Mから数千の場所を得ることができます。スコア分布がどのように見えるかを測定する必要があります。 –