summaryrefslogtreecommitdiff
path: root/application.rb
blob: 50f027af1d64f607e16998b4e0af1dde5d6b5a2c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
require 'json'
require_relative './nanoparticles.rb'

configure :development do
  $logger = Logger.new(STDOUT)
end

get '/?' do
  redirect to('/predict') 
end

get '/predict/?' do
  @data = JSON.parse(File.read("./data.json"))
  @example = @data[@data.keys.sample]["physchem"]
  #@json_example = JSON.pretty_generate(@example)
  haml :predict
end

post '/predict/?' do
  size = params[:size].to_i
  @input = []
  (1..size).each{|i| @input << [params["input_key_#{i}"], params["input_value_#{i}"].to_f]}
  @params = Hash[*@input.flatten]
  @prediction = predict @params
  haml :prediction
end