-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.rb
69 lines (56 loc) · 1.17 KB
/
app.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
# loudfoundry.rb
require 'sinatra'
get '/' do
max = File.read('max').to_f
min = File.read('min').to_f
prev = File.read('prev').to_f
current = File.read('current').to_f
if prev > current
puts 'getting quieter...'
else
puts 'getting louder...'
end
how_loud_tho(relative_loudness(current, min, max))
end
put '/loudness' do
puts "Params: #{params[:loudness]}"
loudness = params[:loudness]
record_loudness(loudness)
end
private
def relative_loudness(current, min, max)
difference = max - min
current_difference = current - min
current_difference / difference
end
def record_loudness(loud)
p = File.open('prev', 'w')
p.write(File.read('current'))
p.close
c = File.open('current', 'w')
c.write(loud)
c.close
if loud > File.read('max') || File.read('max') == ''
m = File.open('max', 'w')
m.write(loud)
m.close
end
if loud < File.read('min') || File.read('min') == ''
m = File.open('min', 'w')
m.write(loud)
m.close
end
end
def how_loud_tho(r)
if r > 0.8
'hella loud'
elsif r > 0.5
'wicked loud'
elsif r == 0.5
'average loud'
elsif r > 0.2
'kinda quiet'
else
'so quiet wow'
end
end