custom_sort 0.4.03 → 0.4.04

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d0c16cb0f36675e44f51915fbe66ae39256481edb407a1d366e3b3ca735942ed
4
- data.tar.gz: 8414db0f014acccd5d7e5b736728ffdda788b9fc7d4625dece0acfe916d8845a
3
+ metadata.gz: 9b1388dee282745a5a3b3dd0057b3cd353438c04960628d51bb7d815551776be
4
+ data.tar.gz: 3e827f529101221c05d5155484b5e439a5c7bc38cea7756ffbd3683821340515
5
5
  SHA512:
6
- metadata.gz: fef53e1038cae0510db6fedf7f8a911aba496a0e21abee47fdf45b40b30ef57751335faaa96bceb7617065d8c89fee23eb3a6e255fc25b600d471e91e205b33e
7
- data.tar.gz: 6ade261b33d3c754c6518912075377a230710c0ec56b58aeadb9f3d01648df09e08de3b2f562a018d49e0b0950037373b352715bf2d1998d8ccb539a24fe9695
6
+ metadata.gz: 3c599fda9a65f20b1e2d2117c2a0502f77beea22eb31baf2d45a006af5a53c4bbf1fcf11274af9b8553b0fa92976f8a97133fefda0756dbe64ee736f29b161d0
7
+ data.tar.gz: 2c96f8f718ce75756e441305cd69ba0db57abe5e93aab38af9ba9bdee9b90928502f9bfe209e7c687fbeca6504b872b100d4b2d22ee998d516e15269e4951cc2
@@ -14,7 +14,11 @@ module CustomSort
14
14
  class Error < StandardError; end
15
15
  # Your code goes here...
16
16
 
17
- FIELDS = [:blended,:blended_recent,:quality,:interesting,:learned,:votes,:nofeedback,:nojoin] # [:second, :minute, :hour, :day, :week, :month, :quarter, :year, :day_of_week, :hour_of_day, :minute_of_hour, :day_of_month, :day_of_year, :month_of_year]
17
+ # currently, :labeled requires a vote_scope/label as well, the other queries ignore vote_scope
18
+ FIELDS = [:labeled,:blended,:blended_recent,:quality,:interesting,:learned,:votes,:nofeedback,:nojoin] # [:second, :minute, :hour, :day, :week, :month, :quarter, :year, :day_of_week, :hour_of_day, :minute_of_hour, :day_of_month, :day_of_year, :month_of_year]
19
+
20
+ LABELS = [:quality,:interesting,:fun,:funny,:learnedfrom,:spam,:ad,:clickbait,:english]
21
+
18
22
  METHODS = FIELDS.map { |v| :"customsort_by_#{v}" } + [:customsort_by_field]
19
23
  LAMBDA_VALUES = [-0.02445,-0.0489,-0.0990, nil]
20
24
 
@@ -2,13 +2,16 @@ require "i18n"
2
2
 
3
3
  module CustomSort
4
4
  class MagicNew
5
- attr_accessor :query_name, :recency_key, :options
5
+ attr_accessor :query_name, :recency_key, :label, :options
6
6
 
7
7
  def initialize(query_name:, **options)
8
8
  @query_name = query_name
9
9
  @options = options
10
10
 
11
11
  @recency_key = options[:recency_key] ? options[:recency_key].to_i : 2
12
+ @label = options[:label] ? options[:label] : nil
13
+ @label = @label.nil? ? CustomSort::LABELS[0].to_s : @label
14
+
12
15
  end
13
16
 
14
17
  def self.validate_period(period, permit)
@@ -46,7 +49,8 @@ module CustomSort
46
49
  relation,
47
50
  column: field,
48
51
  query_name: magic.query_name,
49
- recency_key: magic.recency_key
52
+ recency_key: magic.recency_key,
53
+ label: magic.label
50
54
  ).generate
51
55
 
52
56
  relation
@@ -1,10 +1,10 @@
1
1
  module CustomSort
2
2
  class RelationBuilder
3
- attr_reader :query_name, :column, :recency_key #, :period
3
+ attr_reader :query_name, :column, :recency_key, :label #, :period
4
4
  #, :period, :day_start, :week_start, :n_seconds
5
5
 
6
6
  #def initialize(relation, column:, period:, time_zone:, time_range:, week_start:, day_start:, n_seconds:)
7
- def initialize(relation, column:, query_name:, recency_key:)
7
+ def initialize(relation, column:, query_name:, recency_key:, label: nil)
8
8
  @relation = relation
9
9
  @column = resolve_column(relation, column) unless column.nil?
10
10
  @query_name = query_name
@@ -14,6 +14,8 @@ module CustomSort
14
14
  @recency = true
15
15
  @lambda_key = recency_key #2
16
16
 
17
+ @label = label #label.nil? ? CustomSort::LABELS[0].to_s : label
18
+
17
19
  #if relation.default_timezone == :local
18
20
  # raise CustomSort::Error, "ActiveRecord::Base.default_timezone must be :utc to use Groupdate"
19
21
  #end
@@ -77,6 +79,10 @@ module CustomSort
77
79
  end
78
80
  "(#{cols.join(" + ")})"
79
81
  end
82
+ def labeled_col
83
+ "(cached_weighted_#{@label}_average * cached_weighted_#{@label}_total)"
84
+ end
85
+
80
86
  def blended_where vote_filter_col
81
87
  cols = []
82
88
  CustomSort.blended_columns.each do |col|
@@ -87,20 +93,21 @@ module CustomSort
87
93
  ["#{vote_filter_col} = ? AND #{cols.join(" AND ")}",@class_name]
88
94
  end
89
95
 
96
+ def labeled_where vote_filter_col
97
+ ["#{vote_filter_col} = ?",@class_name]
98
+ end
99
+
100
+
101
+
102
+
90
103
  def data_table
91
104
  CustomSort.data_table
92
105
  end
93
106
 
94
107
  def sort_col
95
108
  case query_name
96
- when "quality"
97
- quality_col
98
- when "interesting"
99
- interesting_col
100
- when "learned"
101
- learned_col
102
- when "blended"
103
- blended_col
109
+ when "quality", "interesting","learned","blended","labeled"
110
+ send(query_name+"_col")
104
111
  when "blended_recent"
105
112
  "(#{time_decay}*#{blended_col})"
106
113
  when "nofeedback","nojoin"
@@ -132,6 +139,8 @@ module CustomSort
132
139
  case query_name
133
140
  when "blended", "blended_recent"
134
141
  query = blended_where vote_filter_col
142
+ when "weighted"
143
+ query = weighted_where vote_filter_col
135
144
  when "interesting"
136
145
  query = ["#{vote_filter_col} = ? AND #{interesting_col} > ?",@class_name, interesting_min]
137
146
  when "learned"
@@ -1,3 +1,3 @@
1
1
  module CustomSort
2
- VERSION = "0.4.03"
3
- end
2
+ VERSION = "0.4.04"
3
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: custom_sort
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.03
4
+ version: 0.4.04
5
5
  platform: ruby
6
6
  authors:
7
7
  - Scott Merritt