forked from Tank/braga
weather
This commit is contained in:
parent
f79564fd9f
commit
e60505de77
BIN
database/16
BIN
database/16
Binary file not shown.
BIN
database/cellar
BIN
database/cellar
Binary file not shown.
@ -7,6 +7,8 @@ local _M = {}
|
||||
|
||||
_M.cellar = {}
|
||||
|
||||
_M.weather = {}
|
||||
|
||||
_M.room = {}
|
||||
|
||||
if not db.cellar then
|
||||
@ -14,6 +16,11 @@ if not db.cellar then
|
||||
db:save()
|
||||
end
|
||||
|
||||
if not db.weather then
|
||||
db.weather = {{temp=0, date = os.date('%Y-%m-%d %H:%M:%S'), warm=0, warm_status='is-success',temp_status='is-success'}}
|
||||
db:save()
|
||||
end
|
||||
|
||||
if not db.room then
|
||||
db.room = {{temp=0, date = os.date('%Y-%m-%d %H:%M:%S'), warm=0, warm_status='is-danger',temp_status='is-warning'}}
|
||||
db:save()
|
||||
@ -35,6 +42,22 @@ function _M.cellar.data(start,ends)
|
||||
return res
|
||||
end
|
||||
|
||||
function _M.weather.now()
|
||||
return db.weather[#db.weather]
|
||||
end
|
||||
|
||||
function _M.weather.data(start,ends)
|
||||
if not start then start = date(start) else start = date():addhours(-24) end
|
||||
if not ends then ends = date(ends) else ends = date() end
|
||||
local res = {}
|
||||
for key,val in pairs(db.weather) do
|
||||
if date(val.date) >= start and date(val.date) <= ends then
|
||||
table.insert(res,val)
|
||||
end
|
||||
end
|
||||
return res
|
||||
end
|
||||
|
||||
function _M.room.now()
|
||||
return db.room[#db.room]
|
||||
end
|
||||
|
||||
BIN
database/weather
Normal file
BIN
database/weather
Normal file
Binary file not shown.
@ -5,8 +5,9 @@ local tanks = require('database.tanks')
|
||||
local function resp(start,ends)
|
||||
local view = template.new("archive.html", "layout.html")
|
||||
view.title = "Мои архивные чаны"
|
||||
view.cellar = {temp=12, warm=45, warm_status='is-danger',temp_status='is-warning'}
|
||||
view.room = {temp=18, warm=45,warm_status='is-success',temp_status='is-warning'}
|
||||
view.cellar = sensors.cellar.now()
|
||||
view.room = sensors.room.now()
|
||||
view.weather = sensors.weather.now()
|
||||
view.tanks = tanks.archive()
|
||||
view:render()
|
||||
end
|
||||
|
||||
@ -10,6 +10,7 @@ local function resp(start,ends)
|
||||
view.data = sensors.cellar.data(start,ends)
|
||||
view.cellar = sensors.cellar.now()
|
||||
view.room = sensors.room.now()
|
||||
view.weather = sensors.weather.now()
|
||||
view:render()
|
||||
end
|
||||
|
||||
|
||||
@ -11,6 +11,7 @@ local function resp(start,ends)
|
||||
view.cellar = sensors.cellar.now()
|
||||
view.room = sensors.room.now()
|
||||
view.tanks = tanks.active(start,ends)
|
||||
view.weather = sensors.weather.now()
|
||||
view:render()
|
||||
end
|
||||
|
||||
|
||||
@ -10,6 +10,7 @@ local function resp(start,ends)
|
||||
view.data = sensors.room.data(start,ends)
|
||||
view.cellar = sensors.cellar.now()
|
||||
view.room = sensors.room.now()
|
||||
view.weather = sensors.weather.now()
|
||||
view:render()
|
||||
end
|
||||
|
||||
|
||||
30
front/weather.lua
Normal file
30
front/weather.lua
Normal file
@ -0,0 +1,30 @@
|
||||
local template = require "resty.template"
|
||||
local handle = require('framework.handle')
|
||||
local sensors = require('database.sensors')
|
||||
|
||||
local function resp(start,ends)
|
||||
local view = template.new("climate.html", "layout.html")
|
||||
view.start = start
|
||||
view.ends = ends
|
||||
view.title = "Погода на улице"
|
||||
view.data = sensors.weather.data(start,ends)
|
||||
view.cellar = sensors.cellar.now()
|
||||
view.room = sensors.room.now()
|
||||
view.weather = sensors.weather.now()
|
||||
view:render()
|
||||
end
|
||||
|
||||
local request = {
|
||||
POST = function()
|
||||
ngx.req.read_body()
|
||||
local args, err = ngx.req.get_post_args()
|
||||
resp(string.match(args['datetimes'], "([%d-%s:]+)%s>%s([%d-%s:]+)"))
|
||||
end,
|
||||
GET = function()
|
||||
local ends = os.date('%Y-%m-%d %H:%M:%S',os.time()+14400)
|
||||
local start = os.date('%Y-%m-%d %H:%M:%S',os.time()-86400)
|
||||
resp(start,ends)
|
||||
end
|
||||
}
|
||||
|
||||
ngx.say(handle(request))
|
||||
@ -58,13 +58,25 @@
|
||||
<a href="/room"><span class="tag {{room.temp_status}} is-large"><i class="fa fa-thermometer-three-quarters fa-fw" aria-hidden="true"></i>{{room.temp}}</span></a>
|
||||
<a href="/room"><span class="tag {{room.warm_status}} is-large"><i class="fa fa-tint fa-fw" aria-hidden="true"></i>{{room.warm}}</span></a>
|
||||
</li>
|
||||
</ul>
|
||||
<p class="menu-label">
|
||||
Подвал
|
||||
</p>
|
||||
<li>
|
||||
<a href="/cellar"><span class="tag {{cellar.temp_status}} is-large"><i class="fa fa-thermometer-three-quarters fa-fw" aria-hidden="true"></i>{{cellar.temp}}</span></a>
|
||||
<a href="/cellar"><span class="tag {{cellar.warm_status}} is-large"><i class="fa fa-tint fa-fw" aria-hidden="true"></i>{{cellar.warm}}</span></a>
|
||||
</li>
|
||||
<ul class="menu-list">
|
||||
<li>
|
||||
<a href="/cellar"><span class="tag {{cellar.temp_status}} is-large"><i class="fa fa-thermometer-three-quarters fa-fw" aria-hidden="true"></i>{{cellar.temp}}</span></a>
|
||||
<a href="/cellar"><span class="tag {{cellar.warm_status}} is-large"><i class="fa fa-tint fa-fw" aria-hidden="true"></i>{{cellar.warm}}</span></a>
|
||||
</li>
|
||||
</ul>
|
||||
<p class="menu-label">
|
||||
Улица
|
||||
</p>
|
||||
<ul class="menu-list">
|
||||
<li>
|
||||
<a href="/weather"><span class="tag {{weather.temp_status}} is-large"><i class="fa fa-thermometer-three-quarters fa-fw" aria-hidden="true"></i>{{weather.temp}}</span></a>
|
||||
<a href="/weather"><span class="tag {{weather.warm_status}} is-large"><i class="fa fa-tint fa-fw" aria-hidden="true"></i>{{weather.warm}}</span></a>
|
||||
</li>
|
||||
</ul>
|
||||
</nav>
|
||||
</aside>
|
||||
<main class="column main">
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user