Generating reports

Материал из WebHMI Wiki
Перейти к: навигация, поиск
Эта страница — перевод страницы Формирование отчетов. Перевод выполнен на 100%.

Generating reports at regular time intervals (dayly, weekly, etc.)

Другие языки:
English • ‎русский

To optimize the performance of the device, it is advisable to register the data for the reports 'in the stream'. In WebHMI, for this, there is an event mechanism that, after triggering, actually gives ready reports.

Required variables, scripts and events
  • A script that calculates the day, month, week, quarter, etc. from the system time to the internal register 'day of the week', 'hour', 'second'
  • the script for calculating the difference 'current reading - the previous', and storing the result in the register 'counter' (the script also works by changing the register 'minute')
  • register-flag for generating an event, momentary, sufficient to write the current counted counter and timestamp
  • A script that clears the flag when there is an event (that is, data is already recorded) '
  • recording event

For demonstration, you can use an example in which at each second the 'virtual' counter is incremented by 2. Other scripts realize a minute-by-minute recording of the difference in its readings into a report. To add other parameters, you may similarly add them to the appropriate scripts and events.

The script that generates the minutes:

function main (userId)
  -- get minute number
  local min = os.date("%M",os.time());
  -- store in internal register 
  WriteReg("minute", min); -- minute
end

The script working on changing the register 'minute':


function main (userId)
 
  local current = GetReg("FlowMeter"); -- current readings
  local prevMin = GetReg("pMinTotal"); -- previous readings 
  local cnt = current - prevMin; -- calc. difference
 
  WriteReg("MinuteFlow", cnt); -- the counter to the int. register. it is used in an event
  WriteReg("pMinTotal", current); -- remember current value for next cycle  

   -- rise event flag
  WriteReg("EventFlag", 1); 
  end


A script that removes the flag and, correspondingly, the event after recording:


function main (userId)
  -- check if event running
  local event_state = (GetReg("ES1") == 1); -- event #1 is on (ES1@Internal register)
  -- and resetting flag
  if event_state then 
      WriteReg("EventFlag", 0); -- minute report event flag 
  end 
end

Event settings for the report:
Rep example2.png
Rep example3.png


The resulting report will be like this:
Rep example.png
При поминутной регистрации данные результаты получаться, если время скана будет меньше чем секунда. Тогда "виртуальный" электросчетчик не пропустит своих секунд. Correct results for per-minute logging will be obtained if the scan time is less than a second. Then the 'virtual' electricity meter will not miss its seconds.