-
Notifications
You must be signed in to change notification settings - Fork 4
/
beesleep
executable file
·54 lines (42 loc) · 1.04 KB
/
beesleep
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
#!/usr/bin/env ruby
def convert(time)
hour, minute = time.split(':', 2)
hour = Integer(hour)
minute = Integer(minute)
def func(x)
2**(1-x)
end
# assume previous day for hours >= 20
if hour >= 20
return ['1', '*%02d%02d' % [hour, minute]]
end
# times before 1 am get a score of 1
if hour == 0
return ['1', '%02d%02d' % [hour, minute]]
end
input = hour + minute / 60.0
score = func(input)
["%.3f" % score, "%02d%02d" % [hour, minute]]
end
def convert_print(line)
parts = line.split
if parts.length < 2
raise 'Expected format: DAYOFMONTH HOUR:MINUTE'
end
daynum, time, source_comment = parts
score, comment = convert(time)
comment = comment + ' ' + source_comment if source_comment
puts daynum + ' ' + score + ' "' + comment + '"'
end
if ARGV.empty?
STDERR.puts "format: DAYOFMONTH HOUR:MINUTE [COMMENT]"
while true
resp = $stdin.readline.chomp
break if resp.empty?
convert_print(resp)
end
else
ARGV.each_with_index do |time, i|
convert_print("##{i + 1} " + time)
end
end