Extraccion de datos especificos desde TinyDB

Hola comunidad, soy Eugenio, autodidacta y fan de este mundillo.. gracias por tanta ayuda, ya me he leido el 90% de posteos sobre listas y TinyDB, he creado una lista de reproduccion de YT con tropecientos video referent a esto, hice y deshice cuanto codigo encontre, pero no logro comprender como funciona el acceso a los datos de la TinyDB y el uso de las listas para su carga y lectura.
En resumen, mi problema es la carga, manejo y acceso a los datos de la base de datos

App a construir
La app debe reproducir un archivo MP3 especifico cuando se encuentra dentro de un radio a partir del punto seleccionado en el mapa. Cada archivo MP3 (uno distinto al otro) está relacionado a una geoposicion

En la app, el usuario es capaz de cargar, tantos registros como desee, especificando: "nombre de locacion", "latitud", "longitud" desde un TAP en el mapa y un "archivo Mp3 de la memoria"
Variable utilizadas:

El sistema almacena los valores en una tinyDB para luego:

Visualizarlos en una listPicker, para su seleccion (borra o editar)
Eliminar registro seleccionado desde listpicker
Reescribir un registro (editarlo) seleccionado desde la lispicker
Utilizar los valores almacenados para realizar funciones condicionadas como reproducir el archivo MP3 relacionado a la ubicacion cercana a la guardada.

Temas resueltos
Entorno visual
Screens
Menues
Seleccion de posicion con TAP en el mapa
Carga de datos en la base de datos (pero no se cual es la mejor manera)
GeoFence

Problema que me tiene desvelado
Carga de datos en la tinyDB (he cargado los datos de al menos 10 maneras diferentes sin exito) ya que a veces me aparecen separados netre (" "), y otras entre ( ) y otras entre [( ]), o me aparece algo asi:
( [ ] (((song1.mp3, /storage/emulated/0/Tracks/song1.mp3, 40.473635, -2.56354))) , simplemente en una sola linea todos los datos de los registros almacenados, uno a continuacion de otro con un unico ID.-.
Acceso a esa informacion (necesito acceder a cada dato del registro en referencia a un mismo identificador)
No logro relizar esta funcion

Algunos ejemplo de carga de datos fallidos a fines ilustrativos,


Hay mucho bloque para depuracion, que muestran datos para ver que está pasando, Cuando funciona una cosa, no logro acceder a otros datos, y asi..

Fallo especifco (o mejor dicho, ignorancia de mi prte)
si mi tinyDB contiene:
id "monasterio" : (song1.mp3, /storage/emulated/0/Tracks/song1.mp3, 40.473635, -2.56354)
id "Puerto" : (song2.mp3, /storage/emulated/0/Tracks/song2.mp3, 40.5765, -2.98876)

Necesito lograr lo siguiente;
Crear un conjunto de bloques que,. me permitan extraer por ejemplo, el elemento 1 del registro id = "Monasterio", es decir,

lograr mostrar donde yo lo necesite "song1.mp3" y solo eso

o por ejemplo,

Cuando ha llegado a una poscion cercana a una de las almacenadas, mantener el id correspondiente y luego con ese id acceder a la ruta del archivo mp3 correspondiente y asignarselo al reproductor para que corra el play

Si posicion actual esta dentro del radio almacenado en el registro id=",Puerto"entonces {
acceder a la posicion 2 del registro id "puerto" y asignarlo al reproductor
acceder a la posicion 1 del registro id: "Puerto" y mostrarlo en un cuadro de texto "posicion actual"
}

3 Preguntas especificas
Cual es la combinacion de bloques pra guardar la info correctamente en TinyDB, de tal modo que el contenido de la variable "idParada" sea el identificador de los datos referidos a ese dato

Cual es la combnacion de bloques que me permitirian obtener y mostrar en un cuadro de texto, un dato contenido dentro de un registro dentro de la lista de datos de TinyDB (id="Puerto", posicion 3)

Cuando muestre la lista en el listpicker, como almceno el valor correspondiente a idParada al clicar en un elemento del picklister, a fin de acceder a los valores del registro correspondiente a ese id

Mi deseo
Que existiese un bloque de TinyDB con las siguientes caracteristicas:
Leer valor dentro de TinyDB1
-> identificador ( aqui cargar el id del registro)
-> posicion en el registro ( aca cargar el indice de posicion donde esta el dato:

O existe y yo no le he interpretado, o puede ser creado con la combinacion de blques seguro.-

Espero no haber sido muy extenso.. quien pued me aporta algo
Gracias!!

Is the user of the app going to be adding his own locations and music, or is this all going to be pre-packaged in the app?

Hello! Thanks for responding :blush:
The user of the app will be adding their own locations and music.
The app does not come with any pre-packaged content.
The user will save their audio tracks in the "Tracks" folder and then select them to associate with a specific location.
Additionally, the user will define the geolocation by tapping on the map, entering the name of the location, and selecting the corresponding audio track from their file folder.
Finally, the system will create a record with the details of the location and the selected track.

Hi again! :wave:

Please disregard the blocks I previously shared. I need a fresh start with the development because I've made so many attempts that I'm now confused and disorganized in my thoughts.

If anyone can share a link or resources explaining the flow of information when loading and reading from TinyDB using lists, I would greatly appreciate it.

I'm a fan of understanding how things work internally. I always say, "If you know how something works inside, you can apply, use, or repair it easily."

Thank you so much for your help!

You have bitten off more than I can chew.

Moving forward, I've achieved the following:
Goal!!
With the following set of blocks, I can correctly save the information for each ID and display a specific piece of data within each record in the "valueRegisterWhenSave" text box without any issues, by specifying the record index.
Additionally, the information stored in TinyDB is correctly displayed in the "locationList_listViewer".

Information entered by the user:

  • Location: Beach
  • Position: Tap in map: 40.47362, -5.85362
  • Audio track: Uptown_funk.mp3

Record visible in listViewer locationList_listViewer: (Beach [Beach, Uptown_funk.mp3, 40.47362, -5.85362, content://com.android.externalstorage.document/document/primary%3Tracks%2FUptown_funk.mp3, 40.47361629276642, -5.853620256696419])

Value visible in text field "txt_valueRegisterWhenSave", using index 3:

  • 40.47362, -5.85362

Error
However, the following does not work and returns an error.

When I try to display some data from the record in the text field "txt_valueRegisterAfterselect" as I did successfully with "txt_valueRegisterWhenSave", it returns the following error:
Select list item: Attempt to get item number 2 of a list of length 0: ()

Thanks a lot for your help! :blush:

Goal!
In the process of helping someone else with this problem, I finally resolved it. Thanks, ABG, for your interest.

With this set of blocks, you can correctly visualize an indexed value within the record using the ID of the selection.

In the previous set of blocks, I changed this: (getElements)

To this: getTags

This way, upon selection, it basically selects the exact ID as it is stored in the DB.
Once the tag is stored, it is possible to access any position within the associated record and perform necessary actions such as deleting, editing, making decisions, etc.

So, finally, these are the blocks
Save

Select value from register

Honestly, posting here helped me solve my week-long problem in just a few hours.

Thank you for being on the forum and listening. Sometimes we just need to express ourselves to hear our own thoughts, and everything falls into place.

If I encounter any other issues, I might come back here to feel accompanied, which means a lot.

Thanks a lot for your help! :blush:

That's a well documented explanation, the kind we like for the board.

Any chance you could post a version for the English-bound with English blocks?

Hello, community!

Following ABG's suggestion, I've renamed everything with meaningful IDs in English and switched the platform's language accordingly.

In addition, I've completed the functionalities for managing the data in the database. Here are the key features I've implemented:

  • Save records
  • Access specific data from each record
  • Delete records
  • Edit records
  • Delete the entire database with double confirmation

Extensions used:

Thank you so much for creating these extensions! :raised_hands:

Variables used:

You should load these variables as your application requires them. I won't go into detail here since my case is specific. My intention is to share the joy of having successfully managed data in the database as I wanted. If anyone is struggling with this, feel free to use this as a reference.
image

When starting the screen:

  • Request permissions
  • Initialize the map (this is for my app; you can remove this part if using the blocks for a different purpose)
  • Initialize the file type to select
  • Display the number of saved locations (number of records in the database)
  • Load the ListViewer with the tags stored in the DB
  • Disable the "Clear Register" button (this button only works AfterPicking)
  • If the DB is empty, disable the "Clear DB" button

"SelectFile" button AfterPicking:
Stores two values: one for display (just the clean file name) and another for playing the track later (the full path correctly to play this track).

"SaveRegister" button:

  • In a cascade, verifies that no field is empty or contains only a blank space.
  • Deletes the record before saving. Why is this? This allows the function to handle both saving a new record and editing a record using the same function. How? If the user is editing or saving, it's the same process—saving the file is the same in both cases. If the ID hasn't changed, no problem; it gets saved with that ID. If it has changed, no problem; the previous one is deleted, and it’s saved with the new ID. To ensure the user feels they are performing the intended action (editing or saving new), the "Save" button text changes accordingly.
  • Adds the data entered by the user and other necessary information for my app, then saves it to the DB with its tag.
  • Clears the user's fields.
  • Notifies "Location saved successfully" (I tried to validate with this block to ensure it really saved, but it didn't work).

  • Updates the list of saved locations.
  • Enables the "ClearAllDB" button since there are now records in the DB.

saveRegister

updateRecord

Select Picker: When selecting an item from the list, the selection is stored, which is the ID of the record. Once we have this ID in a variable, we can access the DB and retrieve each piece of data from a specific record as we please. We can even iterate through the DB in search of specific records and extract specific data from each one. (It's like reaching into a bag of thousands of M&Ms and only picking out the blue ones.) I'm thrilled! This is demonstrated by the fact that in this set of blocks, the user fields are populated with the information contained in the record, from positions 1, 2, 5, 6.

Delete Records: Not much to explain here, except that the notifier waits for the decision from Notifier.afterChoosing to delete the record.

Delete Database: Similar to "delete record," it waits for confirmation from Notifier1.afterChoosing, but with a double confirmation cascade.

Notifier.afterChoosing function

I hope this helps everyone out there trying to manage their database data just the way they want! :tada: Remember, as I always say, "You can properly use, repair, modify, or improve anything you know how it works on the inside."

So, dive your hand into this code and pick out the M&M for your app! :stethoscope::sparkles:

And hey, if you find yourself stuck, remember... there's a forum here to express yourself. Sometimes, you don't even need a reply—your own question can give you the answer!

Wishing everyone a great life! :dancer::man_surfing::sunny::beach_umbrella:

1 Like