-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.rb
80 lines (61 loc) · 1.14 KB
/
main.rb
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
require 'sinatra'
require 'mongoid'
require 'json'
Mongoid.load!("mongoid.yml")
set :protection, :origin_whitelist => ['chrome-extension://hgmloofddffdnphfgcellkdfbfbjeloo']
post '/' do
splitArray = request.body.string.split(',')
session = Session.create(
dateRecorded: DateTime.now
)
limit = splitArray.length - 3
splitArray.each_index do |index|
if index > limit
break
end
if isStartOfSet(index)
session.measurements.create(
X: splitArray.at(index),
Y: splitArray.at(index + 1),
Z: splitArray.at(index + 2)
)
else
next
end
end
session.to_json
end
get '/' do
returnArray = Array.new
Session.each do |session|
returnArray.push(session)
end
return returnArray.to_json
end
get '/deleteSession' do
Session.delete_all
end
def isStartOfSet(val)
if val == 0
return true
end
i = 3
until i > val
if i == val
return true
end
i = i + 3
end
end
class Session
include Mongoid::Document
field :dateRecorded, type: DateTime
embeds_many :measurements
end
class Measurement
include Mongoid::Document
field :X, type: Float
field :Y, type: Float
field :Z, type: Float
embedded_in :session
end