lundi 16 décembre 2019

Logging from Websocket and removing Data from Table

  1. Im logging some Data from a Websocket in an Object and Im displaying that object in a HTML-Table.
  2. Because the Websocket never stops sending Data, my Table will get a huge amount of logs, and im trying to prevent that.
  3. My Problem is, I want to delete the first 50 Elements that were logged as soon as I reach 100 logged elements. (If 100 logs are made --> Delete the first 0-49 --> so there is space for new logs).

This is what I have got so far:

function websocketPush(item) {
    const t_item = {}
    for (let key in properties) {
        t_item[key] = resolve(properties[key], item);
    }
    t_item["id"] = id;
    id++;
    table.addData([t_item], true);
    if(id >= limit){
        limit + 50;
        table.deleteRow()
    }
}

I made a global variable named "limit" which is set to 100. "id" is also a global variable which counts how many logs are made. Now if "id" is more than 100(more than the limit), I want to delete the first 0-49 elements. And as soon as "id" reaches 100 again I want to delete the first 50 elements again.

I somehow must increase the limit variable with each time "id" reaches 100 Elements, and I somehow must delete the FIRST 50 Elements as soon as it reaches the "limit".

Any Help is greatly appreciated, I hope you understod what im trying to do.

Aucun commentaire:

Enregistrer un commentaire