From 962b7e8d59b935b3adeeab0a094f0ffd08c5a0c4 Mon Sep 17 00:00:00 2001 From: joshua stein Date: Mon, 25 Aug 2014 18:11:53 -0500 Subject: [PATCH] add per-tag story hotness modifiers --- app/models/story.rb | 7 ++++++- db/migrate/20140825225915_add_tag_hotness_mod.rb | 5 +++++ db/schema.rb | 3 ++- 3 files changed, 13 insertions(+), 2 deletions(-) create mode 100644 db/migrate/20140825225915_add_tag_hotness_mod.rb diff --git a/app/models/story.rb b/app/models/story.rb index 3fed063..df0f207 100644 --- a/app/models/story.rb +++ b/app/models/story.rb @@ -128,8 +128,13 @@ class Story < ActiveRecord::Base end def calculated_hotness + base = 10 + self.tags.select{|t| t.hotness_mod != 0 }.each do |t| + base -= t.hotness_mod + end + # don't immediately kill stories at 0 by bumping up score by one - order = Math.log([ (score + 1).abs + comments_count, 1 ].max, 10) + order = Math.log([ (score + 1).abs + comments_count, 1 ].max, base) if score > 0 sign = 1 elsif score < 0 diff --git a/db/migrate/20140825225915_add_tag_hotness_mod.rb b/db/migrate/20140825225915_add_tag_hotness_mod.rb new file mode 100644 index 0000000..7f4a51d --- /dev/null +++ b/db/migrate/20140825225915_add_tag_hotness_mod.rb @@ -0,0 +1,5 @@ +class AddTagHotnessMod < ActiveRecord::Migration + def change + add_column :tags, :hotness_mod, :integer, :default => 0 + end +end diff --git a/db/schema.rb b/db/schema.rb index 37ddb2c..54bccea 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20140804005415) do +ActiveRecord::Schema.define(version: 20140825225915) do create_table "comments", force: true do |t| t.datetime "created_at", null: false @@ -134,6 +134,7 @@ ActiveRecord::Schema.define(version: 20140804005415) do t.boolean "privileged", default: false t.boolean "is_media", default: false t.boolean "inactive", default: false + t.integer "hotness_mod", default: 0 end add_index "tags", ["tag"], name: "tag", unique: true, using: :btree