algomaker 0.1.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: f9bc8e156c569c0ead06b621c468e38a40b334c1625dbd31d3617810baa80486
4
+ data.tar.gz: d016cde0d75d29db2e748308cb87afcc0e1b545ffd4e59a29b49da1868d26fdf
5
+ SHA512:
6
+ metadata.gz: 4d53fe52cf931f111e964df936036b9b363162172072b0159b544f154cc22bd90414cb8cb8e52dda940ce432128a56528089ef7d0abd50c88b13cf7f78c28a21
7
+ data.tar.gz: 04e31b4e385cccca52ea5c523abb31d0ed3550f7c631dfb04d4fee284ddeb9ec7a38e2ae3863326294402d877cd696aba9bed7e801dbe4ce10d24548fc2ceff0
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright TODO: Write your name
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,28 @@
1
+ # Algomaker
2
+ Short description and motivation.
3
+
4
+ ## Usage
5
+ How to use my plugin.
6
+
7
+ ## Installation
8
+ Add this line to your application's Gemfile:
9
+
10
+ ```ruby
11
+ gem "algomaker"
12
+ ```
13
+
14
+ And then execute:
15
+ ```bash
16
+ $ bundle
17
+ ```
18
+
19
+ Or install it yourself as:
20
+ ```bash
21
+ $ gem install algomaker
22
+ ```
23
+
24
+ ## Contributing
25
+ Contribution directions go here.
26
+
27
+ ## License
28
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,15 @@
1
+ require "bundler/setup"
2
+
3
+ APP_RAKEFILE = File.expand_path("test/dummy/Rakefile", __dir__)
4
+ load "rails/tasks/engine.rake"
5
+
6
+ require "bundler/gem_tasks"
7
+ require "rake/testtask"
8
+
9
+ Rake::TestTask.new(:test) do |t|
10
+ t.libs << "test"
11
+ t.libs << "lib"
12
+ t.test_files = FileList["test/**/*_test.rb"]
13
+ end
14
+
15
+ task default: :test
@@ -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,5 @@
1
+ module Algomaker
2
+ class ApplicationController < ActionController::Base
3
+ helper KeystoneUi::Engine.helpers
4
+ end
5
+ end
@@ -0,0 +1,18 @@
1
+ module Algomaker
2
+ class DatasetsController < Algomaker.parent_controller.constantize
3
+ def index
4
+ @sources = Algomaker.sources.all
5
+ end
6
+
7
+ def show
8
+ @source = Algomaker.source(params[:source_key])
9
+ @dataset = @source.dataset(params[:key])
10
+ end
11
+
12
+ def report
13
+ show
14
+ goal = params[:goal] == "optimize" ? :optimize : :predict
15
+ @report = Report.new(dataset: @dataset, outcome: params[:outcome], goal: goal)
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,4 @@
1
+ module Algomaker
2
+ module ApplicationHelper
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module Algomaker
2
+ class ApplicationJob < ActiveJob::Base
3
+ end
4
+ end
@@ -0,0 +1,6 @@
1
+ module Algomaker
2
+ class ApplicationMailer < ActionMailer::Base
3
+ default from: "from@example.com"
4
+ layout "mailer"
5
+ end
6
+ end
@@ -0,0 +1,5 @@
1
+ module Algomaker
2
+ class ApplicationRecord < ActiveRecord::Base
3
+ self.abstract_class = true
4
+ end
5
+ end
@@ -0,0 +1,15 @@
1
+ <%= ui_show_page(title: "Datasets") %>
2
+ <%= ui_page(max_width: :xl) do %>
3
+ <%= ui_page_header(title: "Datasets") %>
4
+ <% if @sources.empty? %>
5
+ <%= ui_paragraph(text: "No dataset sources are registered.") %>
6
+ <% end %>
7
+ <% @sources.each do |source| %>
8
+ <%= ui_section do %>
9
+ <%= ui_heading(text: source.title) %>
10
+ <% source.datasets.call.each do |dataset| %>
11
+ <%= ui_button(label: dataset.title, href: algomaker.dataset_path(source_key: source.key, key: dataset.key), variant: :secondary) %>
12
+ <% end %>
13
+ <% end %>
14
+ <% end %>
15
+ <% end %>
@@ -0,0 +1,41 @@
1
+ <%= ui_show_page(title: @dataset.title) %>
2
+ <%= ui_page(max_width: :md) do %>
3
+ <%= ui_page_header(title: @dataset.title) %>
4
+ <% if @report.row_count.zero? %>
5
+ <%= ui_paragraph(text: "This dataset has no rows yet.") %>
6
+ <% else %>
7
+ <%= ui_section(title: "Outcome") do %>
8
+ <%= ui_value_list(rows: [
9
+ { label: "Type", value: { yes_no: "Yes or no", one_of: "One of several", number: "Number", date: "Date", text: "Text" }.fetch(@report.outcome_type, @report.outcome_type.to_s) },
10
+ { label: "Rows counted", value: @report.row_count.to_s }
11
+ ]) %>
12
+ <% end %>
13
+ <% if @report.outcome_counts %>
14
+ <%= ui_section(title: "Rows for each outcome") do %>
15
+ <%= ui_value_list(rows: @report.outcome_counts.map { |value, count| { label: (value == true ? "Yes" : value == false ? "No" : value.to_s), value: count.to_s } }) %>
16
+ <% end %>
17
+ <% end %>
18
+ <%= ui_section(title: "Inputs") do %>
19
+ <%= ui_paragraph(text: @report.inputs.empty? ? "No inputs." : @report.inputs.map(&:label).join(", ")) %>
20
+ <% end %>
21
+ <%= ui_section(title: "Left out") do %>
22
+ <%= ui_paragraph(text: @report.left_out.empty? ? "No fields are left out." : @report.left_out.map(&:label).join(", ")) %>
23
+ <% end %>
24
+ <% if @report.no_model_reason.present? %>
25
+ <%= ui_paragraph(text: @report.no_model_reason) %>
26
+ <% else %>
27
+ <% @report.models.each do |model| %>
28
+ <%= ui_section do %>
29
+ <%= ui_heading(text: model.name) %>
30
+ <%= ui_paragraph(text: model.reason) %>
31
+ <%= ui_paragraph(text: @report.enough_rows?(model) ? "Enough rows to try training it." : "Needs #{@report.rows_still_needed(model)} more rows.") %>
32
+ <% end %>
33
+ <% end %>
34
+ <% end %>
35
+ <% if @report.distinct_values %>
36
+ <%= ui_section(title: "Distinct values for each input") do %>
37
+ <%= ui_value_list(rows: @report.inputs.map { |input| { label: input.label, value: @report.distinct_values[input.name].to_s } }) %>
38
+ <% end %>
39
+ <% end %>
40
+ <% end %>
41
+ <% end %>
@@ -0,0 +1,8 @@
1
+ <%= ui_form_page(title: @dataset.title) %>
2
+ <%= ui_page(max_width: :md) do %>
3
+ <%= ui_form(action: algomaker.dataset_report_path(source_key: @source.key, key: @dataset.key), method: :get) do %>
4
+ <%= ui_form_field(attribute: "outcome", label: "Outcome", type: :select, required: true, options: @dataset.fields.map { |field| [field.label, field.name] }) %>
5
+ <%= ui_form_field(attribute: "goal", label: "Goal", type: :select, required: true, options: [["Predict", "predict"], ["Optimize", "optimize"]]) %>
6
+ <%= ui_button(label: "Show") %>
7
+ <% end %>
8
+ <% end %>
@@ -0,0 +1,17 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Algomaker</title>
5
+ <%= csrf_meta_tags %>
6
+ <%= csp_meta_tag %>
7
+
8
+ <%= yield :head %>
9
+
10
+ <%= stylesheet_link_tag "algomaker/application", media: "all" %>
11
+ </head>
12
+ <body>
13
+
14
+ <%= yield %>
15
+
16
+ </body>
17
+ </html>
data/config/routes.rb ADDED
@@ -0,0 +1,5 @@
1
+ Algomaker::Engine.routes.draw do
2
+ resources :datasets, only: [ :index ]
3
+ get "sources/:source_key/datasets/:key", to: "datasets#show", as: :dataset
4
+ get "sources/:source_key/datasets/:key/report", to: "datasets#report", as: :dataset_report
5
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Algomaker
4
+ class Dataset < Data.define(:key, :title, :fields, :rows)
5
+ def field(name)
6
+ fields.find { |field| field.name == name.to_sym }
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,5 @@
1
+ module Algomaker
2
+ class Engine < ::Rails::Engine
3
+ isolate_namespace Algomaker
4
+ end
5
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Algomaker
4
+ class Field < Data.define(:name, :label, :type, :position)
5
+ TYPES = %i[yes_no one_of number date text].freeze
6
+
7
+ def initialize(name:, label:, type:, position:)
8
+ raise ArgumentError, "#{name} has a type algomaker does not know: #{type}" unless TYPES.include?(type)
9
+
10
+ super
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Algomaker
4
+ module ModelGuide
5
+ Model = Data.define(:name, :outcome_types, :reason, :rows_per_input)
6
+
7
+ MODELS = [
8
+ Model.new(
9
+ name: "Logistic regression",
10
+ outcome_types: %i[yes_no],
11
+ reason: "It gives the chance of a yes from inputs that each raise or lower it, and shows how much each input counts.",
12
+ rows_per_input: 10
13
+ ),
14
+ Model.new(
15
+ name: "Multinomial logistic regression",
16
+ outcome_types: %i[one_of],
17
+ reason: "It gives the chance of each of several outcomes from inputs that each raise or lower them.",
18
+ rows_per_input: 10
19
+ ),
20
+ Model.new(
21
+ name: "Linear regression",
22
+ outcome_types: %i[number],
23
+ reason: "It predicts an amount as a sum of what each input adds or takes away.",
24
+ rows_per_input: 10
25
+ ),
26
+ Model.new(
27
+ name: "Time-to-event model",
28
+ outcome_types: %i[date],
29
+ reason: "It predicts how long until the outcome's date from the inputs known before it.",
30
+ rows_per_input: 10
31
+ ),
32
+ Model.new(
33
+ name: "Gradient-boosted trees",
34
+ outcome_types: %i[yes_no one_of number],
35
+ reason: "It finds outcomes that depend on several inputs together, at the cost of needing more rows.",
36
+ rows_per_input: 50
37
+ )
38
+ ].freeze
39
+
40
+ def self.for(outcome_type)
41
+ MODELS.select { |model| model.outcome_types.include?(outcome_type) }
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,75 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Algomaker
4
+ class Report
5
+ def initialize(dataset:, outcome:, goal:)
6
+ @dataset = dataset
7
+ @outcome = dataset.field(outcome)
8
+ @goal = goal
9
+ end
10
+
11
+ def outcome_type
12
+ @outcome.type
13
+ end
14
+
15
+ def inputs
16
+ others.select { |field| field.position < @outcome.position }
17
+ end
18
+
19
+ def left_out
20
+ others - inputs
21
+ end
22
+
23
+ def models
24
+ ModelGuide.for(outcome_type)
25
+ end
26
+
27
+ def rows_still_needed(model)
28
+ [ model.rows_per_input * inputs.size - rows_that_limit, 0 ].max
29
+ end
30
+
31
+ def enough_rows?(model)
32
+ rows_still_needed(model).zero?
33
+ end
34
+
35
+ def distinct_values
36
+ return unless @goal == :optimize
37
+
38
+ inputs.to_h { |input| [ input.name, rows.map { |row| row[input.name] }.uniq.size ] }
39
+ end
40
+
41
+ def no_model_reason
42
+ "No type of model is named for a text outcome." if outcome_type == :text
43
+ end
44
+
45
+ def row_count
46
+ rows.size
47
+ end
48
+
49
+ COUNTED_TYPES = %i[yes_no one_of].freeze
50
+
51
+ def outcome_counts
52
+ return unless COUNTED_TYPES.include?(@outcome.type)
53
+
54
+ unseen_answers.merge(rows.map { |row| row[@outcome.name] }.tally)
55
+ end
56
+
57
+ private
58
+
59
+ def unseen_answers
60
+ @outcome.type == :yes_no ? { true => 0, false => 0 } : {}
61
+ end
62
+
63
+ def rows_that_limit
64
+ outcome_counts ? outcome_counts.values.min.to_i : row_count
65
+ end
66
+
67
+ def others
68
+ @dataset.fields - [ @outcome ]
69
+ end
70
+
71
+ def rows
72
+ @rows ||= @dataset.rows.call.reject { |row| row[@outcome.name].nil? }
73
+ end
74
+ end
75
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Algomaker
4
+ class Source < Data.define(:key, :title, :datasets)
5
+ def dataset(key)
6
+ datasets.call.find { |dataset| dataset.key == key.to_sym }
7
+ end
8
+ end
9
+
10
+ class SourceRegistry
11
+ def initialize
12
+ @sources = {}
13
+ end
14
+
15
+ def register(key:, title:, datasets:)
16
+ @sources[key.to_sym] = Source.new(key: key.to_sym, title: title, datasets: datasets)
17
+ end
18
+
19
+ def all
20
+ @sources.values
21
+ end
22
+
23
+ def fetch(key)
24
+ @sources.fetch(key.to_sym)
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,3 @@
1
+ module Algomaker
2
+ VERSION = "0.1.0"
3
+ end
data/lib/algomaker.rb ADDED
@@ -0,0 +1,28 @@
1
+ require "keystone_ui"
2
+ require "algomaker/version"
3
+ require "algomaker/engine"
4
+ require "algomaker/field"
5
+ require "algomaker/dataset"
6
+ require "algomaker/model_guide"
7
+ require "algomaker/report"
8
+ require "algomaker/source_registry"
9
+
10
+ module Algomaker
11
+ mattr_accessor :parent_controller, default: "Algomaker::ApplicationController"
12
+
13
+ def self.sources
14
+ @sources ||= SourceRegistry.new
15
+ end
16
+
17
+ def self.register_source(key:, title:, datasets:)
18
+ sources.register(key: key, title: title, datasets: datasets)
19
+ end
20
+
21
+ def self.source(key)
22
+ sources.fetch(key)
23
+ end
24
+
25
+ def self.reset_sources!
26
+ @sources = SourceRegistry.new
27
+ end
28
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :algomaker do
3
+ # # Task goes here
4
+ # end
metadata ADDED
@@ -0,0 +1,97 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: algomaker
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Tyler Schneider
8
+ bindir: bin
9
+ cert_chain: []
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
+ dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: rails
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - ">="
17
+ - !ruby/object:Gem::Version
18
+ version: '7.1'
19
+ type: :runtime
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - ">="
24
+ - !ruby/object:Gem::Version
25
+ version: '7.1'
26
+ - !ruby/object:Gem::Dependency
27
+ name: keystone_ui
28
+ requirement: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 0.52.0
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: 0.52.0
40
+ description: Algomaker takes datasets a host app registers, and for an outcome the
41
+ owner picks reports whether there are enough rows to train a model and which types
42
+ of model suit it.
43
+ email:
44
+ - tylercschneider@gmail.com
45
+ executables: []
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - MIT-LICENSE
50
+ - README.md
51
+ - Rakefile
52
+ - app/assets/stylesheets/algomaker/application.css
53
+ - app/controllers/algomaker/application_controller.rb
54
+ - app/controllers/algomaker/datasets_controller.rb
55
+ - app/helpers/algomaker/application_helper.rb
56
+ - app/jobs/algomaker/application_job.rb
57
+ - app/mailers/algomaker/application_mailer.rb
58
+ - app/models/algomaker/application_record.rb
59
+ - app/views/algomaker/datasets/index.html.erb
60
+ - app/views/algomaker/datasets/report.html.erb
61
+ - app/views/algomaker/datasets/show.html.erb
62
+ - app/views/layouts/algomaker/application.html.erb
63
+ - config/routes.rb
64
+ - lib/algomaker.rb
65
+ - lib/algomaker/dataset.rb
66
+ - lib/algomaker/engine.rb
67
+ - lib/algomaker/field.rb
68
+ - lib/algomaker/model_guide.rb
69
+ - lib/algomaker/report.rb
70
+ - lib/algomaker/source_registry.rb
71
+ - lib/algomaker/version.rb
72
+ - lib/tasks/algomaker_tasks.rake
73
+ homepage: https://github.com/DYB-Development/algomaker
74
+ licenses:
75
+ - MIT
76
+ metadata:
77
+ homepage_uri: https://github.com/DYB-Development/algomaker
78
+ source_code_uri: https://github.com/DYB-Development/algomaker
79
+ changelog_uri: https://github.com/DYB-Development/algomaker/blob/main/CHANGELOG.md
80
+ rdoc_options: []
81
+ require_paths:
82
+ - lib
83
+ required_ruby_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ version: 3.3.0
88
+ required_rubygems_version: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ requirements: []
94
+ rubygems_version: 4.0.20
95
+ specification_version: 4
96
+ summary: A Rails engine that judges whether a dataset can train a model.
97
+ test_files: []