From e60505de77f3be26d05caf82c3a91eaf7333d4a8 Mon Sep 17 00:00:00 2001 From: root Date: Sun, 8 Mar 2026 21:18:45 +0000 Subject: [PATCH] weather --- database/16 | Bin 47 -> 47 bytes database/cellar | Bin 84 -> 84 bytes database/sensors.lua | 23 +++++++++++++++++++++++ database/weather | Bin 0 -> 85 bytes front/archive.lua | 5 +++-- front/cellar.lua | 1 + front/index.lua | 1 + front/room.lua | 1 + front/weather.lua | 30 ++++++++++++++++++++++++++++++ templates/layout.html | 20 ++++++++++++++++---- 10 files changed, 75 insertions(+), 6 deletions(-) create mode 100644 database/weather create mode 100644 front/weather.lua diff --git a/database/16 b/database/16 index c04f60f66c959d7bff08211256e0e5d5acfeee37..9ef2b536843b0f14aa24d32c187c295e9f3441a9 100644 GIT binary patch literal 47 hcmbQ#w4@|8w}4?uN@7XsDkB3UGhG7= 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 diff --git a/database/weather b/database/weather new file mode 100644 index 0000000000000000000000000000000000000000..7b91adeced83c19def0a44da5d168efc675f271b GIT binary patch literal 85 zcmbQ(y1FDaw;;Z_B(bElcvWVxZgFXHa%yq$l9a@f)Xhc)MrOJO#<~U;3Py%jhNf1A UCQCr-8J3hM7UeRm29cP00gewKlK=n! literal 0 HcmV?d00001 diff --git a/front/archive.lua b/front/archive.lua index b4322fb..6225d38 100644 --- a/front/archive.lua +++ b/front/archive.lua @@ -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 diff --git a/front/cellar.lua b/front/cellar.lua index 6d75757..2e79a0a 100644 --- a/front/cellar.lua +++ b/front/cellar.lua @@ -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 diff --git a/front/index.lua b/front/index.lua index 6b002d5..39189cd 100644 --- a/front/index.lua +++ b/front/index.lua @@ -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 diff --git a/front/room.lua b/front/room.lua index 39199fb..4b6a5f4 100644 --- a/front/room.lua +++ b/front/room.lua @@ -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 diff --git a/front/weather.lua b/front/weather.lua new file mode 100644 index 0000000..c4955bb --- /dev/null +++ b/front/weather.lua @@ -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)) diff --git a/templates/layout.html b/templates/layout.html index 144a7ae..be7f221 100644 --- a/templates/layout.html +++ b/templates/layout.html @@ -58,13 +58,25 @@ {{room.temp}} {{room.warm}} + -
  • - {{cellar.temp}} - {{cellar.warm}} -
  • + + +