Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] getHistoricalTags not working on client #1463

Open
LordNetro opened this issue Oct 29, 2024 · 1 comment
Open

[BUG] getHistoricalTags not working on client #1463

LordNetro opened this issue Oct 29, 2024 · 1 comment
Labels

Comments

@LordNetro
Copy link

Describe the bug
The $getHistoricalTags system function on the Scripts tab is not working properly.

To Reproduce
Steps to reproduce the behavior:

  1. Go to 'Scripts'
  2. Click on 'Any client script or create a new one'
  3. Click on 'System Functions'
  4. Click on 'getHistoricalTags'
  5. Test Script
  6. It won't work

Expected behavior
The expected behavior is the same as the $getTag, get the historical tag data on client script

I'm trying to load custom data on a chart to preview a few tags that were registered each hour once to display 24 registers on the chart (full day).
I have this script, but it seems that the $getHistoricalTags is not working on client, but $getTag works.

//const util = require('util');
// Obtener el tiempo actual en milisegundos
let tiempoActual = Date.now();
let day = new Date().getDay();
console.log(`El consumo total en el intervalo registrado es: ${tiempoActual}`);
let num = $getTag('t_9ab544e6-9b844ef9' /* FUXA - consumo_hora */);
console.log(num);
// Definir el tiempo de hace dos dias 172800000 hace un dia 86400000
let haceUnDia = tiempoActual - 86400000;

// Usar el intervalo desde hace una hora hasta el tiempo actual
let valores = $getHistoricalTags(['t_9ab544e6-9b844ef9' /* FUXA - consumo_hora */], haceUnDia, tiempoActual);
//console.log(util.inspect(valores, {showHidden: false, depth: null, colors: false}))
//console.log(valores['t_9ab544e6-9b844ef9' /* FUXA - consumo_hora */]);
let valoresY = valores['t_9ab544e6-9b844ef9' /* FUXA - consumo_hora */].map(item => item.y);
//console.log(util.inspect(valoresY, {showHidden: false, depth: null, colors: false}))

var lines = [];
var line = {};
const count = 24;
var y = [];
var x = [];
for (var i = 0; i < count; i++) {
    //const randomNumber = Math.sin(i + parseInt(toAdd));// + Math.floor(Math.random() * 21);
    y.push(valoresY[i]);
    x.push(i);
  /*try{
    let valor = valoresY[i];
    if(valor){
      console.log(`${i} : ${valor}`);
      y.push(30);
    }else{
      console.log("ERROR PUSHING Y null"); 
      console.log(`${i} : ${0}`);
      y.push(0);
    }
  }catch{
   console.log("ERROR PUSHING Y"); 
    y.push(0);
  }
  x.push(i); */

}
line['y'] = y;
line['x'] = x;
lines.push(line);
$invokeObject('chart_1', 'setCustomValues', lines);

Screenshots
On the following screenshot you can see that I'm getting undefined. But when I try the function on server script works perfectly.
image

Environment

  • FUXA version: v1.2.0-1818
  • Node.js version: v18.20.3
  • npm version: 10.8.3
  • Platform/OS: Windows 11 Pro
  • Browser: Chrome
@henjoe
Copy link

henjoe commented Nov 1, 2024

Hi you have to put "await" before you use the $getHistorical

// Usar el intervalo desde hace una hora hasta el tiempo actual
let valores = await $getHistoricalTags(['t_9ab544e6-9b844ef9' /* FUXA - consumo_hora */], haceUnDia, tiempoActual);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants