forked from e621ng/e621ng
[Cleanup] Remove a few unused files
This commit is contained in:
parent
348827de5d
commit
de0311a268
@ -1,60 +0,0 @@
|
||||
require "set"
|
||||
|
||||
class PostVoteSimilarity
|
||||
THRESHOLD = 0.05
|
||||
|
||||
class Element
|
||||
attr_reader :user_id, :score
|
||||
|
||||
def initialize(user_id, score)
|
||||
@user_id = user_id
|
||||
@score = score
|
||||
end
|
||||
|
||||
def <=>(rhs)
|
||||
score <=> rhs.score
|
||||
end
|
||||
end
|
||||
|
||||
attr_reader :user_id
|
||||
|
||||
def initialize(user_id)
|
||||
@user_id = user_id
|
||||
end
|
||||
|
||||
# returns user ids with strong positive correlation
|
||||
def calculate_positive(limit = 10)
|
||||
posts0 = PostVote.positive_post_ids(user_id)
|
||||
set = []
|
||||
|
||||
PostVote.positive_user_ids.each do |uid|
|
||||
posts1 = PostVote.positive_post_ids(uid)
|
||||
score = calculate_with_jaccard(posts0, posts1)
|
||||
if score >= THRESHOLD
|
||||
set << Element.new(uid, score)
|
||||
end
|
||||
end
|
||||
|
||||
set.sort.reverse.first(limit)
|
||||
end
|
||||
|
||||
def calculate_with_jaccard(posts0, posts1)
|
||||
a = (posts0 & posts1).size
|
||||
div = posts0.size + posts1.size - a
|
||||
if div == 0
|
||||
0
|
||||
else
|
||||
a / div.to_f
|
||||
end
|
||||
end
|
||||
|
||||
def calculate_with_cosine(posts0, posts1)
|
||||
a = (posts0 & posts1).size
|
||||
div = Math.sqrt(posts0.size * posts1.size)
|
||||
if div == 0
|
||||
0
|
||||
else
|
||||
a / div
|
||||
end
|
||||
end
|
||||
end
|
@ -1,22 +0,0 @@
|
||||
#!/usr/bin/env ruby
|
||||
|
||||
require 'mail'
|
||||
|
||||
class UploadErrorChecker
|
||||
def check!
|
||||
uploads = Upload.where("status like 'error%' and status not like 'error: Upload::Error - Post with MD5%' and status not like 'error: ActiveRecord::RecordInvalid - Validation failed: Md5 duplicate%' and created_at >= ?", 1.hour.ago)
|
||||
if uploads.size > 5
|
||||
mail = Mail.new do
|
||||
from Danbooru.config.contact_email
|
||||
to Danbooru.config.contact_email
|
||||
CurrentUser.as_system do
|
||||
subject "[#{Danbooru.config.app_name}] Upload error count at #{uploads.size}"
|
||||
end
|
||||
body uploads.map {|x| x.status}.join("\n")
|
||||
end
|
||||
mail.delivery_method :sendmail
|
||||
mail.deliver
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -11,18 +11,6 @@ class PostVote < ApplicationRecord
|
||||
|
||||
scope :for_user, ->(uid) {where("user_id = ?", uid)}
|
||||
|
||||
def self.positive_user_ids
|
||||
select_values_sql("select user_id from post_votes where score > 0 group by user_id having count(*) > 100")
|
||||
end
|
||||
|
||||
def self.negative_post_ids(user_id)
|
||||
select_values_sql("select post_id from post_votes where score < 0 and user_id = ?", user_id)
|
||||
end
|
||||
|
||||
def self.positive_post_ids(user_id)
|
||||
select_values_sql("select post_id from post_votes where score > 0 and user_id = ?", user_id)
|
||||
end
|
||||
|
||||
def initialize_attributes
|
||||
self.user_id ||= CurrentUser.user.id
|
||||
self.user_ip_addr ||= CurrentUser.ip_addr
|
||||
|
@ -1,18 +0,0 @@
|
||||
require 'test_helper'
|
||||
|
||||
class CountsControllerTest < ActionDispatch::IntegrationTest
|
||||
context "The counts commentary controller" do
|
||||
context "posts action" do
|
||||
should "render" do
|
||||
get posts_counts_path
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
should "render an error during a timeout" do
|
||||
Post.stubs(:fast_count).raises(Post::TimeoutError.new)
|
||||
get posts_counts_path
|
||||
assert_response :error
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
@ -1,55 +0,0 @@
|
||||
require "test_helper"
|
||||
|
||||
module Moderator
|
||||
class TagBatchChangeTest < ActiveSupport::TestCase
|
||||
def setup
|
||||
super
|
||||
end
|
||||
|
||||
context "a tag batch change" do
|
||||
setup do
|
||||
@user = FactoryBot.create(:moderator_user)
|
||||
CurrentUser.user = @user
|
||||
CurrentUser.ip_addr = "127.0.0.1"
|
||||
@post = FactoryBot.create(:post, :tag_string => "aaa")
|
||||
end
|
||||
|
||||
teardown do
|
||||
CurrentUser.user = nil
|
||||
CurrentUser.ip_addr = nil
|
||||
end
|
||||
|
||||
context "#estimate_update_count" do
|
||||
setup do
|
||||
@change = TagBatchChange.new("aaa", "bbb", @user.id, "127.0.0.1")
|
||||
end
|
||||
|
||||
should "find the correct count" do
|
||||
assert_equal(1, @change.estimate_update_count)
|
||||
end
|
||||
end
|
||||
|
||||
should "execute" do
|
||||
tag_batch_change = TagBatchChange.new("aaa", "bbb", @user.id, "127.0.0.1")
|
||||
tag_batch_change.perform
|
||||
@post.reload
|
||||
assert_equal("bbb", @post.tag_string)
|
||||
end
|
||||
|
||||
should "move blacklists" do
|
||||
@user.update(blacklisted_tags: "123 456\n789\n")
|
||||
tag_batch_change = TagBatchChange.new("456", "xxx", @user.id, "127.0.0.1")
|
||||
tag_batch_change.perform
|
||||
@user.reload
|
||||
assert_equal("123 xxx\n789", @user.blacklisted_tags)
|
||||
end
|
||||
|
||||
should "raise an error if there is no predicate" do
|
||||
tag_batch_change = TagBatchChange.new("", "bbb", @user.id, "127.0.0.1")
|
||||
assert_raises(TagBatchChange::Error) do
|
||||
tag_batch_change.perform
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
@ -1,88 +0,0 @@
|
||||
require 'test_helper'
|
||||
|
||||
class PostViewCountServiceTest < ActiveSupport::TestCase
|
||||
def setup
|
||||
super
|
||||
|
||||
CurrentUser.user = FactoryBot.create(:user)
|
||||
CurrentUser.ip_addr = "127.0.0.1"
|
||||
|
||||
PostViewCountService.stubs(:enabled?).returns(true)
|
||||
@post = FactoryBot.create(:post)
|
||||
end
|
||||
|
||||
def teardown
|
||||
super
|
||||
CurrentUser.user = nil
|
||||
CurrentUser.ip_addr = nil
|
||||
end
|
||||
|
||||
subject { PostViewCountService.new }
|
||||
|
||||
context "#popular_posts" do
|
||||
setup do
|
||||
subject.stubs(:fetch_rank).returns([[@post.id, 1]])
|
||||
end
|
||||
|
||||
should "return the posts" do
|
||||
posts = subject.popular_posts
|
||||
assert_equal(@post.id, posts[0].id)
|
||||
end
|
||||
end
|
||||
|
||||
context "#fetch_rank" do
|
||||
context "success" do
|
||||
setup do
|
||||
@date = "2000-01-01"
|
||||
@body = "[[1,1.0],[2,2.0]]"
|
||||
stub_request(:get, "localhost:1234/post_views/rank").with(query: {"date" => @date}).to_return(body: @body)
|
||||
end
|
||||
|
||||
should "return a list" do
|
||||
json = subject.fetch_rank(@date)
|
||||
assert(json.is_a?(Array))
|
||||
assert_equal(1, json[0][0])
|
||||
assert_equal(2, json[1][0])
|
||||
end
|
||||
end
|
||||
|
||||
context "failure" do
|
||||
setup do
|
||||
@date = "2000-01-01"
|
||||
stub_request(:get, "localhost:1234/post_views/rank").with(query: {"date" => @date}).to_return(body: "", status: 400)
|
||||
end
|
||||
|
||||
should "return nil" do
|
||||
json = subject.fetch_rank(@date)
|
||||
assert_nil(json)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "#fetch_count" do
|
||||
context "success" do
|
||||
setup do
|
||||
@body = "[[1,5],[2,20]]"
|
||||
stub_request(:get, "localhost:1234/post_views/#{@post.id}").to_return(body: @body)
|
||||
end
|
||||
|
||||
should "return a list" do
|
||||
json = subject.fetch_count(@post.id)
|
||||
assert(json.is_a?(Array))
|
||||
assert_equal(1, json[0][0])
|
||||
assert_equal(2, json[1][0])
|
||||
end
|
||||
end
|
||||
|
||||
context "failure" do
|
||||
setup do
|
||||
stub_request(:get, "localhost:1234/post_views/#{@post.id}").to_return(body: "", status: 400)
|
||||
end
|
||||
|
||||
should "return nil" do
|
||||
json = subject.fetch_count(@post.id)
|
||||
assert_nil(json)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue
Block a user