summaryrefslogtreecommitdiff
path: root/application.rb
blob: abe4112454bf5b54e30674a0d82ba0128e3aa978 (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
27
28
29
30
31
require 'json'
require_relative './nanoparticles.rb'

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

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

get '/enm-workshop' do
  File.read(File.join('public', 'presentation', 'enm-workshop.html'))
end

get '/predict/?' do
  data = JSON.parse(File.read("./data.json"))
  query_features = JSON.parse(File.read("./query-features.json"))
  @example = data[data.keys.sample]["physchem"].select{|f,v| query_features.include? f}
  #@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