~sircmpwn/hnstats

3e1a40450c319c3d147cacd8f83acaf0902e6fd3 — Drew DeVault 6 years ago d1f7266
Add cleaned status to pages
3 files changed, 13 insertions(+), 1 deletions(-)

M clean.py
M templates/article.html
M update.py
M clean.py => clean.py +3 -1
@@ 17,14 17,16 @@ for article in articles:
        continue
    samples = (ArticleSample.query
        .filter(ArticleSample.article_id == article.id)
        .filter(ArticleSample.rank > 30)
        .filter(ArticleSample.sample_time < cutoff))
    print("Deleting {} samples for article {}".format(
        samples.count(), article.id))
    samples.delete()
    article.cleaned = True

# Delete all samples >90 days
cutoff = datetime.utcnow() - timedelta(days=90)
records = ArticleSample.query\
    .filter(ArticleSample.sample_time < cutoff)\
    .delete()

db.commit()

M templates/article.html => templates/article.html +6 -0
@@ 84,6 84,12 @@
<noscript>
  <p>We would render some graphs here, but you have JavaScript disabled.</p>
</noscript>
{% if article.cleaned %}
<div class="alert alert-warning">
  Due to this article's age, some samples have been cleaned from the database.
  Any samples from when the article was not on the front page are missing.
</div>
{% endif %}
<div class="row charts">
  <div class="col-md-6">
    <h4>Rank over time</h4>

M update.py => update.py +4 -0
@@ 90,6 90,10 @@ class Article(db.Base):
    comments = sa.Column(sa.Integer,
            nullable=False)

    cleaned = sa.Column(sa.Boolean,
            nullable=False,
            default=False)

class ArticleSample(db.Base):
    __tablename__ = "article_samples"
    id = sa.Column(sa.Integer,