This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

calculation with table
#1
Hi @all,

I working on a script to calculate the solar energy through the windows based on Solcast API. Therefore I defining the window parameters as tables and want to calculate the energy forecast for each window and write them to a new table (fe) for the window index. 

Unfortutately this writing to the table is not working, logs attached.

Can you please help me what I'm doing wrong?

Many thanks for your help!

Best Regards
Steffen

Code:
require('json')
https = require 'ssl.https'


appid = 'xxx'
lat = '52'
lon ='10'
azi = '170'
hours = '48'
format = 'json'


url = 'https://api.solcast.com.au/world_radiation/forecasts?latitude=%s&longitude=%s&hours=%s&format=%s&api_key=%s'
url = string.format(url, lat, lon, hours, format, appid)

res, code, headers, status = ssl.https.request(url)
log (code, status, headers)
data = json.pdecode(res)

--Fault messages:
if not data then
  alert('Error converting data')
  return
end

if not res then
  alert('Error collecting data')
  return
end

data = data.forecasts


gwert=0.5
ff={} --Tabelle Fensterfläche
fw={} -- Tabelle Fenster Winkel
fn={} -- Tabelle Fenster Neigung, Senkrecht = 90
fe={} --Fensterenergemenge aus f_energiesum

--Galerie
ff[2]=1.6 -- Glasfläche Fenster
fw[2]=8 -- Azimuth Fenster zu Süden = 0° ; Westen = + 90°
fn[2]=33 -- Neigung Senkrecht = 90

--Leben
ff[3]=2.1 -- Glasfläche Fenster
fw[3]=8 -- Azimuth Fenster zu Süden = 0° ; Westen = + 90°
fn[3]=90 -- Neigung Senkrecht = 90
ff[4]=7.45 -- Glasfläche Fenster
fw[4]=8 -- Azimuth Fenster zu Süden = 0° ; Westen = + 90°
fn[4]=90 -- Neigung Senkrecht = 90
ff[5]=2.63 -- Glasfläche Fenster
fw[5]=-82 -- Azimuth Fenster zu Süden = 0° ; Westen = + 90°
fn[5]=90 -- Neigung Senkrecht = 90

now = os.date('*t')
hour = now.hour
i=1 --Index halbe Stunde aus Solcast json
f=2 --Fensterindex Tabelle
f_energiesum = 0
rest_hour = 24 - hour

for f=2,5,1 do --EDIT Anpassung Fensteranzahl
    while i<3 do
    dni = data[i].dni
    ghi = data[i].ghi --global horizontal
    dhi = data[i].dhi --diffus horizontal
    bh = ghi - dhi --direkt horrizontal
    zenith = data[i].zenith
    sunh = 90 - zenith -- Sonnenhöhe
    azimuth = data[i].azimuth

    w_einstrahl = math.asin(math.sin(math.rad(sunh)) * math.cos(math.rad(fn[f])) + math.cos(math.rad(sunh))*math.cos(math.rad(fw[f]-azimuth))*math.sin(math.rad(fn[f])))
    dir_einstrahl = math.sin(w_einstrahl)/math.sin(math.rad(sunh))*bh --Direktstrahlung auf eine geneigte Oberfläche
    if sunh == 0 then dir_einstrahl = 0 end -- Abfangen Division durch 0

    dif_einstrahl = (1 + math.cos(math.rad(fn[f])))/2*dhi --diffuse Horizontalstrahlung
    f_energie = (dir_einstrahl + dif_einstrahl)*ff[f]*gwert
    
    f_energiesum = f_energiesum + f_energie
    fe[f] = f_energiesum
--    log(i,f, ghi, dhi, bh, sunh, azimuth, w_einstrahl, dir_einstrahl, dif_einstrahl, f_energie, f_energiesum, ff[f], fw[f], fe[f])

    i=i+1
    end
   
grp.write('49/'..f..'/8', f_energiesum)
log(f,fw,ff,fn,fe)
    

end


Code:
Solcast_Radiation 22.08.2022 08:27:09
* arg: 1
  * number: 2
* arg: 2
  * table:
   [2]
    * number: 8
   [3]
    * number: 8
   [4]
    * number: 8
   [5]
    * number: -82
* arg: 3
  * table:
   [2]
    * number: 1.6
   [3]
    * number: 2.1
   [4]
    * number: 7.45
   [5]
    * number: 2.63
* arg: 4
  * table:
   [2]
    * number: 33
   [3]
    * number: 90
   [4]
    * number: 90
   [5]
    * number: 90
* arg: 5
  * table:
   [2]
    * number: 280.824289622413
Solcast_Radiation 22.08.2022 08:27:09
* arg: 1
  * number: 3
* arg: 2
  * table:
   [2]
    * number: 8
   [3]
    * number: 8
   [4]
    * number: 8
   [5]
    * number: -82
* arg: 3
  * table:
   [2]
    * number: 1.6
   [3]
    * number: 2.1
   [4]
    * number: 7.45
   [5]
    * number: 2.63
* arg: 4
  * table:
   [2]
    * number: 33
   [3]
    * number: 90
   [4]
    * number: 90
   [5]
    * number: 90
* arg: 5
  * table:
   [2]
    * number: 280.824289622413
Solcast_Radiation 22.08.2022 08:27:09
* arg: 1
  * number: 4
* arg: 2
  * table:
   [2]
    * number: 8
   [3]
    * number: 8
   [4]
    * number: 8
   [5]
    * number: -82
* arg: 3
  * table:
   [2]
    * number: 1.6
   [3]
    * number: 2.1
   [4]
    * number: 7.45
   [5]
    * number: 2.63
* arg: 4
  * table:
   [2]
    * number: 33
   [3]
    * number: 90
   [4]
    * number: 90
   [5]
    * number: 90
* arg: 5
  * table:
   [2]
    * number: 280.824289622413
Solcast_Radiation 22.08.2022 08:27:09
* arg: 1
  * number: 5
* arg: 2
  * table:
   [2]
    * number: 8
   [3]
    * number: 8
   [4]
    * number: 8
   [5]
    * number: -82
* arg: 3
  * table:
   [2]
    * number: 1.6
   [3]
    * number: 2.1
   [4]
    * number: 7.45
   [5]
    * number: 2.63
* arg: 4
  * table:
   [2]
    * number: 33
   [3]
    * number: 90
   [4]
    * number: 90
   [5]
    * number: 90
* arg: 5
  * table:
   [2]
    * number: 280.824289622413
Reply


Messages In This Thread
calculation with table - by pioneersteffen - 22.08.2022, 06:32
RE: calculation with table - by admin - 23.08.2022, 06:59

Forum Jump: