Writing to CSV, new set of rows each day, is it possible?

I have this recording function that updates every 5 sec and records data as such:

void SaveToFile ()

{ //table.clearRows();
   //newRow.setInt("MACH ID", table.getRowCount() - 1);
   for (int i=1; i<=10; i++)
 {TableRow newRow = table.addRow();
  newRow.setString("MACH ID", Mach_Name[i]);
  newRow.setString("CUMM UPTIME", HuUpTime[i]);
  newRow.setInt("UPTIME %", round (Pr[i]));
  newRow.setInt("CYCLES", Cycles[i]);
  newRow.setString("LAST TIME", TimeStampArr[i]);
  newRow.setString("DATE", DateStamp);

//println("ROW COUNT= " + table.getRowCount()); 

  Filename = "/data/"+"Infinity_Report_"+"Perpetual_V_09" + ".csv"; //DateStamp
  saveTable(table, Filename);
  //println("Settings Saved");

This is monitoring the uptime of a machine. Every day I would generate a new file but now my needs have changed.
I would like to write in the same file this data and move to a new set of rows after midnight.
If I keep “ClearRows” it deletes the previous days…
I want to keep them.

Is it possible to start clearing and re-writing only from this row to this row? ( I would increment that with each date change)/


I’m sorry I don’t understand.

  • Not a new file every day – so, one file. ok
  • don’t delete previous days, keep them. ok
  • a new “set of rows” after midnight. ?

I don’t understand what “set of rows” is. Normally, if you use addRow, you add a row. There is only one file, and you don’t delete previous rows, you keep them, so this seems like what you want:

1    this is row one
2    this is row two
99   this is row ninety-nine

But that is the simplest thing to do, and it seems like you want something else. Could you explain a bit more what you want?

Jeremy , thanks for your help.
I know my explanations are all over…

I dont want o make new files, just one and the file would have a new entry each day.
Stuff would appear like this on the CSV:

31 0 0 8_29_2021
200 0 0 8_29_2021
700 0 0 8_29_2021
POD1 0 0 8_29_2021
POD2 0 0 8_29_2021
BHX1 0 0 8_29_2021
BHX2 0 0 8_29_2021
EDG1 0 0 8_29_2021
EDG2 0 0 8_29_2021
10 0 0 8_29_2021
31 0 0 8_30_2021
200 0 0 8_30_2021
700 0 0 8_30_2021
POD1 0 0 8_30_2021
POD2 0 0 8_30_2021
BHX1 0 0 8_30_2021
BHX2 0 0 8_30_2021
EDG1 0 0 8_30_2021
EDG2 0 0 8_30_2021
10 0 0 8_30_2021

Each day would create a new set of rows in the same file over and over …
Hope I clarified a bit…


Okay, got it. You are updating every five seconds – do you save your file to disk every 5 seconds, or once per day?

If every five seconds, do you want it like this:

  • today.log ← updates every five seconds
  • history.log ← adds a copy of today.log once per day

or do you want it like this:

  • history.log ← last 10 rows change every five seconds, and at midnight, 10 new rows appear and start changing

I decided to record once a day at 6 pm so I went:

 cur_hrs = hour();
if (HourPrev !=cur_hrs ) //  && Counting)
  {HourPrev =cur_hrs;
  if (HourPrev == 18 )
   println ("Recorded at " + cur_hrs);
    SaveToFile ();

I wonder if thats gonna work reliably and dont do only one entry per day…
Thanks a lot,

Suggestions welcome.

1 Like

It depends on how reliable you need the logging to be, and how the log will be used. Most logs write to disk more often than once a day – but maybe that is all you want or need? I don’t know your requirements for the Table in your problem, or the “Infinity_Report” on disk, so I don’t know what to suggest.