-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.rb
116 lines (89 loc) · 1.74 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
require 'rubygems'
require 'sinatra'
require 'dm-core'
require 'dm-migrations'
DataMapper.setup(:default, ENV['DATABASE_URL'] || 'sqlite3:db.sqlite3')
class Post #データベースを操作するクラス
include DataMapper::Resource
def migrate
DataMapper.auto_migrate!
end
property :id, Serial
property :number, Integer
property :create_at, DateTime
property :per_minute, Integer
property :per_hour, Integer
auto_upgrade!
end
class PerMath
include DataMapper::Resource
def init
@min = Time.now
$per_minute = 0
$per_hour = 0
end
def per_update
Post.all.map{ |r|
if @min.year == r.create_at.year &&
@min.month == r.create_at.month &&
@min.day == r.create_at.day &&
@min.hour == r.create_at.hour &&
@min.min == r.create_at.min then
$per_minute += 1
end
}
end
def hour_update
Post.all.map{ |r|
if @min.year == r.create_at.year &&
@min.month == r.create_at.month &&
@min.day == r.create_at.day &&
@min.hour == r.create_at.hour then
$per_hour += 1
end
}
end
def getPer_minute
hoge = Post.all.size
if hoge != 0 then
"#{Post.all[Post.all.size - 1].per_minute}"
else
"0"
end
end
def getPer_hour
hoge = Post.all.size
if hoge != 0 then
"#{Post.all[Post.all.size - 1].per_hour}"
else
"0"
end
end
def jsGen
end
end
$hoge = PerMath.new()
get '/' do
erb :index
end
post '/' do
$hoge.init
$hoge.per_update
$hoge.hour_update
post = Post.create(
:number => 0,
:create_at => Time.now,
:per_minute => $per_minute.to_i,
:per_hour => $per_hour.to_i
)
end
get '/reload' do
redirect '/'
end
get '/reset' do
Post.auto_migrate!
redirect '/'
end
get '/map' do
Post.all.map{ |r| "#{r.id}, #{r.number},日時#{r.create_at.year}<br/>"}
end