trailguide 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 50116eb2206e240c060371109c4a16e87d5b7ec5fe39bfad66b824583f99e33f
4
- data.tar.gz: 5432c696f6dc9258fd9b9abf9b79322caf70eb9ac0f0efac7e177a08fd5b4f38
3
+ metadata.gz: e499f17a07bf44c93e4ef7e4312a7d9c41e92081d178789dbac73fc2fc78fa51
4
+ data.tar.gz: 2d7bab3cd7cf33fed1b05745833f637b3242984607e4fcab447ebb9167f9254f
5
5
  SHA512:
6
- metadata.gz: b8c465669f1c0b7f7686f55f4c33dc6c0c560bd00c69563ac181cc4bb9110a6ca22c528bf7a1b8e8bd0fe4c22b437a58a151aa57b5639774ed4df5e0453826ff
7
- data.tar.gz: 24a51c4c675a18790b5a4676998f628d473ec70b134745b7a0a0192a39b499cb9ccb245309215e16d87910cf673f890056f1c25d1c52969de7937b631d60289f
6
+ metadata.gz: 7f53ad801154678194c1c4d19aef32c949eea5d230daf3c6c744eae566c7c3ddb671259e28544d778f3fabe582e4729a12762615894ddf95a1b4095318632740
7
+ data.tar.gz: 3e5ffe742e6e512fb2467b02361504ffc561801abf00d70bd5d1dbff667bd0790afa47209849d8b3c18aa12a10d2a3459069f46b007bc21fd85d8a1e980aca98
@@ -0,0 +1,2 @@
1
+ //= link_directory ../../javascripts/trail_guide/admin .js
2
+ //= link_directory ../../stylesheets/trail_guide/admin .css
@@ -0,0 +1,15 @@
1
+ // This is a manifest file that'll be compiled into application.js, which will include all the files
2
+ // listed below.
3
+ //
4
+ // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5
+ // or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
6
+ //
7
+ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
+ // compiled file. JavaScript code in this file should be added after the last require_* statement.
9
+ //
10
+ // Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
11
+ // about supported directives.
12
+ //
13
+ //= require rails-ujs
14
+ //= require activestorage
15
+ //= require_tree .
@@ -0,0 +1,15 @@
1
+ /*
2
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
3
+ * listed below.
4
+ *
5
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
+ * or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
7
+ *
8
+ * You're free to add application-wide styles to this file and they'll appear at the bottom of the
9
+ * compiled file so the styles you add here take precedence over styles defined in any other CSS/SCSS
10
+ * files in this directory. Styles in this file should be added after the last require_* statement.
11
+ * It is generally better to create a new file per style scope.
12
+ *
13
+ *= require_tree .
14
+ *= require_self
15
+ */
@@ -0,0 +1,7 @@
1
+ module TrailGuide
2
+ module Admin
3
+ class ApplicationController < ActionController::Base
4
+ protect_from_forgery with: :exception
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,8 @@
1
+ module TrailGuide
2
+ module Admin
3
+ class ExperimentsController < ApplicationController
4
+ def index
5
+ end
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,43 @@
1
+ module TrailGuide
2
+ class ApplicationController < ::ApplicationController
3
+ before_action do
4
+ render json: { error: "Experiment does not exist" }, status: 404 and return unless experiment.present?
5
+ end
6
+
7
+ def choose
8
+ variant = trailguide.choose!(experiment.experiment_name, metadata: metadata)
9
+ render json: {
10
+ experiment: experiment.experiment_name,
11
+ variant: variant.name,
12
+ metadata: variant.metadata.merge(metadata)
13
+ }
14
+ rescue => e
15
+ render json: { error: e.message }, status: 500
16
+ end
17
+
18
+ def convert
19
+ trailguide.convert!(experiment.experiment_name, checkpoint, metadata: metadata)
20
+ render json: {
21
+ experiment: experiment.experiment_name,
22
+ checkpoint: checkpoint,
23
+ metadata: metadata
24
+ }
25
+ rescue => e
26
+ render json: { error: e.message }, status: 500
27
+ end
28
+
29
+ private
30
+
31
+ def experiment
32
+ @experiment ||= TrailGuide.catalog.find(params[:experiment_name])
33
+ end
34
+
35
+ def checkpoint
36
+ @checkpoint ||= params[:checkpoint]
37
+ end
38
+
39
+ def metadata
40
+ @metadata ||= params[:metadata].try(:permit!) || {}
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,16 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>TrailGuide Admin</title>
5
+ <%= csrf_meta_tags %>
6
+ <%= csp_meta_tag %>
7
+
8
+ <%= stylesheet_link_tag "trail_guide/admin/application", media: "all" %>
9
+ <%= javascript_include_tag "trail_guide/admin/application" %>
10
+ </head>
11
+ <body>
12
+
13
+ <%= yield %>
14
+
15
+ </body>
16
+ </html>
@@ -0,0 +1 @@
1
+ <h1>Experiments</h1>
@@ -0,0 +1,3 @@
1
+ TrailGuide::Admin::Engine.routes.draw do
2
+ resources :experiments, only: [:index]
3
+ end
data/config/routes.rb CHANGED
@@ -1,2 +1,10 @@
1
1
  TrailGuide::Engine.routes.draw do
2
+ get '/:experiment_name' => 'application#choose',
3
+ defaults: { format: :json }
4
+ match '/:experiment_name' => 'application#convert',
5
+ defaults: { format: :json },
6
+ via: [:put, :post]
7
+ match '/:experiment_name/:checkpoint' => 'application#convert',
8
+ defaults: { format: :json },
9
+ via: [:put, :post]
2
10
  end
@@ -0,0 +1,13 @@
1
+ module TrailGuide
2
+ module Admin
3
+ class Engine < ::Rails::Engine
4
+ isolate_namespace TrailGuide::Admin
5
+
6
+ config.generators do |g|
7
+ g.test_framework = :rspec
8
+ end
9
+ end
10
+ end
11
+ end
12
+
13
+ load TrailGuide::Admin::Engine.root.join("config/admin/routes.rb")
@@ -0,0 +1,6 @@
1
+ require "trail_guide/admin/engine"
2
+
3
+ module TrailGuide
4
+ module Admin
5
+ end
6
+ end
@@ -228,12 +228,22 @@ module TrailGuide
228
228
  end
229
229
 
230
230
  def as_json(opts={})
231
- # TODO fill in the rest of the values i've added
232
- {
233
- experiment_name: experiment_name,
234
- algorithm: algorithm,
235
- variants: variants.as_json
236
- }
231
+ { experiment_name => {
232
+ configuration: {
233
+ metric: metric,
234
+ algorithm: algorithm.name,
235
+ variants: variants.as_json,
236
+ goals: goals.as_json,
237
+ resettable: resettable?,
238
+ allow_multiple_conversions: allow_multiple_conversions?,
239
+ allow_multiple_goals: allow_multiple_goals?
240
+ },
241
+ statistics: {
242
+ # TODO expand on this for variants/goals
243
+ participants: variants.sum(&:participants),
244
+ converted: variants.sum(&:converted)
245
+ }
246
+ } }
237
247
  end
238
248
 
239
249
  def storage_key
@@ -2,7 +2,7 @@ module TrailGuide
2
2
  module Version
3
3
  MAJOR = 0
4
4
  MINOR = 1
5
- PATCH = 2
5
+ PATCH = 3
6
6
  VERSION = "#{MAJOR}.#{MINOR}.#{PATCH}"
7
7
 
8
8
  class << self
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: trailguide
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mark Rebec
@@ -103,6 +103,15 @@ extra_rdoc_files: []
103
103
  files:
104
104
  - MIT-LICENSE
105
105
  - README.md
106
+ - app/assets/config/trail_guide/admin_manifest.js
107
+ - app/assets/javascripts/trail_guide/admin/application.js
108
+ - app/assets/stylesheets/trail_guide/admin/application.css
109
+ - app/controllers/trail_guide/admin/application_controller.rb
110
+ - app/controllers/trail_guide/admin/experiments_controller.rb
111
+ - app/controllers/trail_guide/application_controller.rb
112
+ - app/views/layouts/trail_guide/admin/application.html.erb
113
+ - app/views/trail_guide/admin/experiments/index.html.erb
114
+ - config/admin/routes.rb
106
115
  - config/routes.rb
107
116
  - lib/trail_guide/adapters.rb
108
117
  - lib/trail_guide/adapters/participants.rb
@@ -112,6 +121,8 @@ files:
112
121
  - lib/trail_guide/adapters/participants/redis.rb
113
122
  - lib/trail_guide/adapters/participants/session.rb
114
123
  - lib/trail_guide/adapters/participants/unity.rb
124
+ - lib/trail_guide/admin.rb
125
+ - lib/trail_guide/admin/engine.rb
115
126
  - lib/trail_guide/algorithms.rb
116
127
  - lib/trail_guide/algorithms/bandit.rb
117
128
  - lib/trail_guide/algorithms/distributed.rb