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

**URL:** https://discourse.processing.org/t/writing-to-csv-new-set-of-rows-each-day-is-it-possible/32018
**Category:** Coding Questions
**Created:** [August 31, 2021, 3:10am UTC](https://discourse.processing.org/t/writing-to-csv-new-set-of-rows-each-day-is-it-possible/32018 "2021-08-31T03:10:11Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![laptophead](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/laptophead/32/2701_2.png) [@laptophead](https://discourse.processing.org/u/laptophead)
#### Post date: [August 31, 2021, 3:10am UTC](https://discourse.processing.org/t/writing-to-csv-new-set-of-rows-each-day-is-it-possible/32018/1 "2021-08-31T03:10:11Z")

</div>

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

```auto
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)/

Thanks  
Mitch

---

<div class="post-metadata">

### Author: ![jeremydouglass](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jeremydouglass/32/20_2.png) [@jeremydouglass](https://discourse.processing.org/u/jeremydouglass)
#### Post date: [August 31, 2021, 2:57pm UTC](https://discourse.processing.org/t/writing-to-csv-new-set-of-rows-each-day-is-it-possible/32018/2 "2021-08-31T14:57:19Z")

</div>

> [@laptophead](#):
>
> 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.

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?

---

<div class="post-metadata">

### Author: ![laptophead](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/laptophead/32/2701_2.png) [@laptophead](https://discourse.processing.org/u/laptophead)
#### Post date: [August 31, 2021, 4:18pm UTC](https://discourse.processing.org/t/writing-to-csv-new-set-of-rows-each-day-is-it-possible/32018/3 "2021-08-31T16:18:16Z")

</div>

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

So:  
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:

| MACH ID | CUMM UPTIME | UPTIME % | CYCLES | LAST TIME | DATE |
| --- | --- | --- | --- | --- | --- |
| 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…

Thanks  
mitch

---

<div class="post-metadata">

### Author: ![jeremydouglass](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jeremydouglass/32/20_2.png) [@jeremydouglass](https://discourse.processing.org/u/jeremydouglass)
#### Post date: [August 31, 2021, 4:30pm UTC](https://discourse.processing.org/t/writing-to-csv-new-set-of-rows-each-day-is-it-possible/32018/4 "2021-08-31T16:30:07Z")

</div>

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

---

<div class="post-metadata">

### Author: ![laptophead](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/laptophead/32/2701_2.png) [@laptophead](https://discourse.processing.org/u/laptophead)
#### Post date: [September 1, 2021, 4:29pm UTC](https://discourse.processing.org/t/writing-to-csv-new-set-of-rows-each-day-is-it-possible/32018/5 "2021-09-01T16:29:27Z")

</div>

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

```auto

 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.

---

<div class="post-metadata">

### Author: ![jeremydouglass](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jeremydouglass/32/20_2.png) [@jeremydouglass](https://discourse.processing.org/u/jeremydouglass)
#### Post date: [September 1, 2021, 8:35pm UTC](https://discourse.processing.org/t/writing-to-csv-new-set-of-rows-each-day-is-it-possible/32018/6 "2021-09-01T20:35:02Z")

</div>

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.
