fino-solid 1.10.0 → 1.11.0

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: d001f6bb38d131992464c9cdeab1e5927fd5a16623759459c7020b1c35d6664a
4
- data.tar.gz: 339ab6d35c8dc40ecd553f835f536eb74a6978375ed29943cf5c8905c9c812e2
3
+ metadata.gz: 316e2cce3c27678cdf847e621410ec7d91b02c4da86dde2450bca861b8d50159
4
+ data.tar.gz: 359289766581dc9f4a3e02500379f659985a16d06ed07b3c1e69a61a03f1b3d3
5
5
  SHA512:
6
- metadata.gz: 6f81641ee84473e0fb6262bfa41d6beefd0e2051eb8caf6fc15364198385324f162f395a959d6658791dd70b9dbc28de46259a561a7c08b7df90f7d04f7c0f54
7
- data.tar.gz: 53eef4644ef38aaa358cf40d9f2cbf5ed587800a5acb0e47b94cf09b8f51371d5cb5a34678385f691a524d2beda08ed5814e029ebbf0180cf63a6055299585c8
6
+ metadata.gz: 4cd553efffc63fc306a528419ccad8c186677eb7febce0c344ed03c1f23a3d91a262ec8825ab13958c50e48a5253cc1b63d81c874a2c3a485f0df61bf683451a
7
+ data.tar.gz: cf00571edcb858d874a3ed4f8b83c894c42cf7782f64341a899b3ac9b6dcb0ac9f74d794af677bdd4cfce007ccc6c64190eeabef4d3db1b36438a2caa268445d
data/README.md CHANGED
@@ -238,7 +238,7 @@ Fino.value(:model, at: :openai, for: "user_2") #=> "gpt-5"
238
238
 
239
239
  #### Experiment analysis
240
240
 
241
- Some Fino adapters support A/B testing analysis, e.g built-in Redis adapter
241
+ Fino adapters might support A/B testing analysis, both built-in `solid` and `redis` adapters do
242
242
 
243
243
  When you run an A/B test for a setting, fino automatically calculates variant based on a stable identifier you pass as
244
244
  a `for` option
@@ -416,6 +416,14 @@ end
416
416
  end
417
417
  ```
418
418
 
419
+ ## Development
420
+
421
+ To create and mugrate dummy app db to test solid adapter, do
422
+
423
+ ```bash
424
+ cd spec/dummy && bin/rails db:create db:migrate
425
+ ```
426
+
419
427
  ## Releasing
420
428
 
421
429
  `rake release`
@@ -62,6 +62,36 @@ module Fino
62
62
  end
63
63
  end
64
64
 
65
+ def record_ab_testing_conversion(setting_definition, variant, scope, time)
66
+ Fino::Solid::Conversion.insert(
67
+ {
68
+ setting_key: setting_definition.key,
69
+ variant_id: variant.id,
70
+ scope: scope.to_s,
71
+ converted_at: time
72
+ },
73
+ unique_by: :idx_fino_conversions_unique
74
+ )
75
+ end
76
+
77
+ def read_ab_testing_conversions(setting_definition, variants)
78
+ rows =
79
+ Fino::Solid::Conversion
80
+ .where(setting_key: setting_definition.key, variant_id: variants.map(&:id))
81
+ .pluck(:variant_id, :scope, :converted_at)
82
+
83
+ grouped = rows.group_by(&:first)
84
+
85
+ variants.each_with_object({}) do |variant, memo|
86
+ entries = grouped.fetch(variant.id, [])
87
+ memo[variant] = entries.map { |_vid, scope, converted_at| [scope, (converted_at.to_f * 1000).to_i] }
88
+ end
89
+ end
90
+
91
+ def clear_ab_testing_conversions(setting_key)
92
+ Fino::Solid::Conversion.where(setting_key: setting_key).delete_all
93
+ end
94
+
65
95
  def fetch_raw_variants_from(raw_adapter_data)
66
96
  raw_adapter_data.each_with_object([]) do |(key, value), memo|
67
97
  next unless key.start_with?("#{VARIANT_PREFIX}/")
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Fino
4
+ module Solid
5
+ class Conversion < Record
6
+ self.table_name = "fino_ab_testing_conversions"
7
+ end
8
+ end
9
+ end
@@ -1,8 +1,9 @@
1
1
  Description:
2
- Installs Fino::Solid adapter by creating necessary database migration.
2
+ Installs Fino::Solid adapter by creating necessary database migrations.
3
3
 
4
4
  Example:
5
5
  bin/rails generate fino:solid:install
6
6
 
7
7
  This will create:
8
8
  db/migrate/[timestamp]_create_fino_settings.rb
9
+ db/migrate/[timestamp]_create_fino_ab_testing_conversions.rb
@@ -11,8 +11,10 @@ module Fino
11
11
 
12
12
  source_root File.expand_path("templates", __dir__)
13
13
 
14
- def copy_migration
14
+ def copy_migrations
15
15
  migration_template "create_fino_settings.rb.tt", File.join(db_migrate_path, "create_fino_settings.rb")
16
+ migration_template "create_fino_ab_testing_conversions.rb.tt",
17
+ File.join(db_migrate_path, "create_fino_ab_testing_conversions.rb")
16
18
  end
17
19
 
18
20
  private
@@ -0,0 +1,17 @@
1
+ class CreateFinoAbTestingConversions < ActiveRecord::Migration[<%= ActiveRecord::Migration.current_version %>]
2
+ def change
3
+ create_table :fino_ab_testing_conversions do |t|
4
+ t.string :setting_key, null: false
5
+ t.string :variant_id, null: false
6
+ t.string :scope, null: false
7
+ t.datetime :converted_at, null: false
8
+
9
+ t.timestamps
10
+ end
11
+
12
+ add_index :fino_ab_testing_conversions, %i[setting_key variant_id scope],
13
+ unique: true, name: :idx_fino_conversions_unique
14
+ add_index :fino_ab_testing_conversions, %i[setting_key variant_id],
15
+ name: :idx_fino_conversions_lookup
16
+ end
17
+ end
data/lib/fino/solid.rb CHANGED
@@ -16,6 +16,7 @@ end
16
16
 
17
17
  require "fino/solid/record"
18
18
  require "fino/solid/setting"
19
+ require "fino/solid/conversion"
19
20
  require "fino/solid/adapter"
20
21
  require "fino/solid/railtie" if defined?(Rails::Railtie)
21
22
 
data/lib/fino/version.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Fino
4
- VERSION = "1.10.0"
4
+ VERSION = "1.11.0"
5
5
  REQUIRED_RUBY_VERSION = ">= 3.2.0"
6
6
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fino-solid
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.10.0
4
+ version: 1.11.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Egor Iskrenkov
@@ -29,14 +29,14 @@ dependencies:
29
29
  requirements:
30
30
  - - "~>"
31
31
  - !ruby/object:Gem::Version
32
- version: 1.10.0
32
+ version: 1.11.0
33
33
  type: :runtime
34
34
  prerelease: false
35
35
  version_requirements: !ruby/object:Gem::Requirement
36
36
  requirements:
37
37
  - - "~>"
38
38
  - !ruby/object:Gem::Version
39
- version: 1.10.0
39
+ version: 1.11.0
40
40
  - !ruby/object:Gem::Dependency
41
41
  name: mysql2
42
42
  requirement: !ruby/object:Gem::Requirement
@@ -91,8 +91,10 @@ files:
91
91
  - lib/fino/solid.rb
92
92
  - lib/fino/solid/README.md
93
93
  - lib/fino/solid/adapter.rb
94
+ - lib/fino/solid/conversion.rb
94
95
  - lib/fino/solid/generators/install/USAGE
95
96
  - lib/fino/solid/generators/install/install_generator.rb
97
+ - lib/fino/solid/generators/install/templates/create_fino_ab_testing_conversions.rb.tt
96
98
  - lib/fino/solid/generators/install/templates/create_fino_settings.rb.tt
97
99
  - lib/fino/solid/railtie.rb
98
100
  - lib/fino/solid/record.rb
@@ -119,7 +121,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
119
121
  - !ruby/object:Gem::Version
120
122
  version: '0'
121
123
  requirements: []
122
- rubygems_version: 3.6.9
124
+ rubygems_version: 4.0.3
123
125
  specification_version: 4
124
126
  summary: ActiveRecord adapter for Fino settings engine
125
127
  test_files: []