aboutsummaryrefslogtreecommitdiff
path: root/app/models.py
diff options
context:
space:
mode:
authorrubenwardy <rw@rubenwardy.com>2018-07-04 01:05:32 +0100
committerrubenwardy <rw@rubenwardy.com>2018-07-04 01:08:34 +0100
commit7813c766acb44a328e2a79bc95d8b949b0c1c205 (patch)
tree364bf58c6789e002cd93b723ba28a2f39ebbd1dc /app/models.py
parent9fc9826d3012b2551e1f36baf2ad4ad78be2cd14 (diff)
downloadcheatdb-7813c766acb44a328e2a79bc95d8b949b0c1c205.tar.xz
Add package scores and split homepage into new and popular
Diffstat (limited to 'app/models.py')
-rw-r--r--app/models.py24
1 files changed, 22 insertions, 2 deletions
diff --git a/app/models.py b/app/models.py
index b5b4836..338b4f0 100644
--- a/app/models.py
+++ b/app/models.py
@@ -339,6 +339,8 @@ class Package(db.Model):
approved = db.Column(db.Boolean, nullable=False, default=False)
soft_deleted = db.Column(db.Boolean, nullable=False, default=False)
+ score = db.Column(db.Float, nullable=False, default=0)
+
review_thread_id = db.Column(db.Integer, db.ForeignKey("thread.id"), nullable=True, default=None)
review_thread = db.relationship("Thread", foreign_keys=[review_thread_id])
@@ -385,7 +387,8 @@ class Package(db.Model):
"shortDesc": self.shortDesc,
"type": self.type.toName(),
"release": self.getDownloadRelease().id if self.getDownloadRelease() is not None else None,
- "thumbnail": (base_url + tnurl) if tnurl is not None else None
+ "thumbnail": (base_url + tnurl) if tnurl is not None else None,
+ "score": round(self.score * 10) / 10
}
def getAsDictionary(self, base_url):
@@ -412,7 +415,9 @@ class Package(db.Model):
"screenshots": [base_url + ss.url for ss in self.screenshots],
"url": base_url + self.getDownloadURL(),
- "release": self.getDownloadRelease().id if self.getDownloadRelease() is not None else None
+ "release": self.getDownloadRelease().id if self.getDownloadRelease() is not None else None,
+
+ "score": round(self.score * 10) / 10
}
def getThumbnailURL(self):
@@ -498,6 +503,21 @@ class Package(db.Model):
else:
raise Exception("Permission {} is not related to packages".format(perm.name))
+ def recalcScore(self):
+ import datetime
+
+ self.score = 0
+
+ if self.forums is None:
+ return
+
+ topic = ForumTopic.query.get(self.forums)
+ if topic:
+ days = (datetime.datetime.now() - topic.created_at).days
+ months = days / 30
+ years = days / 365
+ self.score = topic.views / years + 80*min(6, months)
+
class MetaPackage(db.Model):
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String(100), unique=True, nullable=False)