Fixing exporting and clearing my TinyDB data

Today I got the error :slight_smile:

Schermata 2022-09-08 alle 09.11.12

There are several tags with data on my phone; day readings of three months.
For example this is one Namespace (one day reading data) with two tags (two reading sessions data):
Schermata 2022-09-08 alle 10.29.31

Today, with the "...list to table..." block I got my file, but it contains only data of the selected day in my table. That's why yesterday the file was empty.

I should get all the existing tags when clicking "Export Database". How?

I also added the Namespace settings and it seems it makes no difference. Should I keep it or is it enough just "get tags" like above?
Anyway, this or previous combination is perfect for exporting the day data by clicking "Export Day Data" button.
For this option I added a second File component "File2". Is it ok?
And I added also the data title; the date of the exported day (I would need it also when exporting the whole database).

So this is how it appears in Excel:
Schermata 2022-09-08 alle 11.13.22

This is in Word:
Schermata 2022-09-08 alle 11.14.22

This is in Mail Preview:
Schermata 2022-09-08 alle 11.13.47

...instead, it should look like this:

Schermata 2022-09-08 alle 11.23.58

I would have preferred the date pattern as I set it in my blocks, but Excel automatically sets it short.

So all of this has to be fixed, how?
Nadi_11.aia (791.8 KB)

You have made the beginner blunder of over-formatting the internal storage of your data to match how you want it to appear externally in the phone display.

Internal data formats like lists and Instants preserve data values independently of other data values that you might want to mix with them at display times.

The price for the early blunder is to try to recover independent data from each cell of your stored data, usually by splitting each cell at \n, cell by cell.

The data I archived is not real, it was just for testing, so I don't care about recovering the data.
I would like to understand how to fix the blocks so that from now on the data storage can be exported.
So how can I get all tags?

If you want csv format exports, you can't have embedded \n in any cell.
You might try replacing them with '|', cell by cell, before export.

Decide on a date range for you export, using 2 date pickers.
Convert the 2 Instants (from, to) to milliseconds, and loop for each milliseconds from milliseconds1 to milliseconds2 by (number of milliseconds in a day).
In each loop, convert the current milliseconds back to an Instant and format it as a NameSpace value (YYYYMMDD).
Append the exported csv for that TinyDB NameSpace to your out file, day by day.

The "\n" separator in the cell is ok. The wrong display not separating items into columns was just a problem with my Excel.
I opened the file in Google Sheets and it's perfect.

However I think it is useful to save a second file by replacing the column separators from "," to ";" (this works fine) so users can open the file in Excel as well.

But the Sharing sends two separate emails.
How can I send two files in the same email?

I tried to understand it but I can't.
Can you show the blocks, please?

Sorry, I have not used email or the sharing component yet.

My email FAQ:

Can you do the first step, adding a From Date and To Date Date picker to your export request button in the Designer?

Is this what you asked?

I set it on invisible, ...I hope your solution does not involve entering dates by the user.
Nadi_12.aia (792.5 KB)

Do you want to include multiple dates' worth of reading in individual export files?

By clicking on the "Export Database" button I have to send all the data (all the tags) in a single file, and each day of readings must have the date as a title (as I did for the export of the day's data by clicking "Export Day Data", as above).

I didn't find the answer in Abraham's link.
Can anyone tell me how to send two files in the same mail?

My question and blocks are above:

The sharing component is not able to do it
Use one of the other email solutions mentioned in @ABG s contribution... for example my mail extension is able to do it

Send email.
Subject and To address are mandatory. For To , Cc and Bcc you can add several addresses, use a comma as delimiter. Also you can add several attachments, use a comma as delimiter. You can't send attachments from the assets of the app.

Taifun

The way to approach this depends on how you are using NameSpaces to separate records by day.

Go back and reread your code to see how you are using NameSpaces, and tell us how they are used.

Oh, thanks Taifun, ...I forgot to mention that I don't use extensions :slight_smile:
However thanks for the information that the sharing component is not able to do it. So I will find some other solution.

Namespace is set to "call Clock: Now" in the format "yyyyMMdd" and each time I save a tag it is associated with that day's Namespace. And I have to set the Namespace every time I recall the tags of the day.

So if there is no way to retrieve the name of the Namespace, every time I save I could append this tag to the File, as you mentioned? ...but what is the best way to do it in my case?

...but I'm also thinking ...I can't append to File, because the user may have deleted a tag from the table, but it will remain in the File. So another solution is needed.

I just would like to recall all tags, then I will think how to write the day date.

Since the NameSpace values are just dates YYYYMMDD, the Clock component has blocks that can be used to jump forward and backwards in time to generate YYYYMMDD values for all dates in whatever date range you want.

That's why i suggested a From and To Date Picker as one alternative for requesting a range of dates.

Alternatively, you could make a List Picker with options

  • Last Week
  • Last Month
  • Forever

to generate sequences of dates stretching over recent history.

This is a matter of personal taste, and I would not impose such a choice on you.

The File need not be persistent. Since the persistent data is already in the TinyDB NameSpaces, it is cleaner to generate the File contents fresh at each export time, with just the requested range of dates' data.

Things to study:

  • Control blocks for iteration
  • Clock blocks for millisecond conversion
  • Clock blocks for date conversion and addition.

Could I set date pickers FromDate: January 2022 ToDate: Clock-Now so that automatically when "Export Database" is clicked all the Namespaces (till Now) are called without making the user choose? ...could you show me the blocks?

P.S. These blocks can be dragged directly into your Blocks Editor workspace.

See A way to group projects by theme - #10 by ABG
for a demo.

Because your Blocks Workspace is so bloated I had to work in a separate Screen.
It should be no problem for you to correct component names to match what you have.

Great, it works, ...thanks
The "NameSpaces" variable is necessary? ...I don't see it used in blocks.

01

Before moving on to data cleaning, I have a question:
In August I reinstalled companion and the data was deleted, but only for August, the data from other months remained on TinyDB.
How does it work?

Right, I missed that.
Glad to see you're reading the code.
It's left over from when I was torn between two different ways of iterating over the different NameSpaces:

  • generating all of them first in a list, then looping over the list, or
  • using one of the loop forms (Do While) involving incrementing a value in a range
    I ended up choosing the second approach, and forgot I had left a remnant of the first approach.
    You can remove that using the blue button and the keyboard delete key. Beware of things popping out of their sockets when you do that.

The storage for the Companion is a garbage can shared across all the apps that have been tested on the Companion. No one cleans it out.

I thought I had developed a little app to browse all the different File scopes available to an app, but I can't find it.

The reinstall residue remains a mystery to me.

Well,
I assembled these blocks to clear Day Data and they work.
...for me it is always a nice surprise when something works :slight_smile:

Are they ok? ...or is there any block to improve?

I also assembled the blocks to clear All Data from TinyDB, are they okay?
...is it enough to use just "ClearAll" block?
(other blocks under "ClearAll" are for reloading the table)

How can I test them before clicking the "Clear Data" button?
...once the data is deleted there will be nothing to test :slight_smile:

Also,
is a new notifier required for each notification?