local max_prec = prec_historico_grid('Hidro', 96) or 0
local prev24h = maximo_eta('Eta10km',24)
if max_prec == nil then
max_prec = 0
end
if prev24h == nil then
prev24h = 0
end
local chuvaTotal = max_prec + prev24h
print(chuvaTotal)

local duracao = 24
local Tc = 0.87 * comprio^3 /(cotmax - cotsec)^0.385

local FatorN = 0
if chuvaTotal < 36 then
 FatorN = 84
elseif chuvaTotal < 53 then
 FatorN = 68
else
  FatorN = 93
end


local H0 = (5080/FatorN) - 50.8
if chuvaTotal < H0 then
  local HU = 0
else
  local HU = ((chuvaTotal - H0)^(2))/(chuvaTotal + 4 * H0)
end

local Tp = 0.5 * duracao + 0.6 * Tc
local tr = 1.67 * Tp
local Qp = (0.27 * k * HU *areakm2)/Tp

if Qp == nil or chuvaTotal < 500 then
return 0
elseif chuvaTotal < 700 then
return 1
elseif chuvaTotal < 1000 then
return 2
elseif chuvaTotal < 1500 then
return 3
else
return 4
end