Select specific data from CSV file based on today's current date

Hi guys,

I have a csv file that contains data (say column for month, column from day and data ...) as follows please Have a look to the Image below

I want the app to display the data that are related to the current date only vertically as shown in the attached Image (today's date)

I am a beginner and I assume my enquiry will be easy from experts ones

Your help will be greatly appreciated

Do you have control over how the CSV file is created?

Your format is awkward for purposes of filtering, sorting, and expansion to new years and new people.

Consider this format for the CSV:
2023-06-04, David, 10
2023-06-04, Nicole,17
2023-06-04, Lucy,21
2023-06-05, David, 11
2023-06-05, Nicole,19
...

With this format, new years and new people are just extra rows.
Sorting the date column (column 1) alphabetically gives yo the data in time order.

Can you change the format?

1 Like

Thank you for getting back to me
Yes I have full control over the csv file (I built it in excel and saved it in a csv format)
I am open to change the date format it's not a problem

I am seeking help on selecting a specfic cell from the file based on specfic date (ideally reading the date from current date using the clock item)

I am currently reading some help/ideas

So in points:

  1. how to use if/then function to check the current date and finding it in the csv list/index
  2. Selecting specific data that's linked to that date and feeding them into setting lables text

Any Help using MIT inventor (I guess I will need the following items: clock, file (upload the csv), lables)

Thank you again

Here is a sample similar project...

Learning resources:

1 Like

Thank you for the reply
However it's too much for me to figure out

My request is much simpler I guess

I could manage to read the data from CSV file already
Please see the images below





5

csv_display_date.aia (5.0 KB)
jun_test.csv (425 Bytes)

What I want now is to display only the data/item that are in the current date (i.e. when the item in d column matches the current day)

So I don't want to display the entire csv data , only one row that belongs to the current date (say today 6th June) when the list item in index 2 matches today date/day

I believe that I will need to use:

  • if/then function
  • and the clock/now (call clock/DayOfMonth/instant?clock.now) to match the item in the column d

Any help/suggestion?

Thanks

This is a more general version of the app, which turns out simpler.

csv_display_date_ABG.aia (3.8 KB)

I used a List Picker populated from the days in column 1 of your table.
I left it to the user to know what day they wanted.

I used all the columns past column 1 with that header row to populate a ListView with all player scores for the selected day. I used the Main/detail ListView format to pair the names and scores.

Add extra columns for extra players. The column count and player count is not hardwired.

1 Like

@ABG wow... Amazing

That's great and very inspiring
Thank you so much

I really appreciate your efforts and the time you took to generate such comprehensive perfect piece of work

However, :thinking::smirk:

I embarrassingly still want it to be based on the current day/date automatically
And to show the data of the current day as soon as the app initiate the screen without the needless additional step to pick up specific day by the user

Would it be possible by any chance please?

Thank you

Kindest Regards

What if the days cross a month boundary?

Do you mean just start with the last row of the table?

By the way, how would you refresh the data every day for all those users?

Time to switch to an online downloaded table like a Google Sheet.

1 Like

With JavaScript.

borrar_tabla22.aia (3.2 KB)

Summary
<!DOCTYPE html><html><head>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=0">
  <style>
    table {
      border-collapse: collapse;
    }
    table, th, td{
      border: 1px solid black;
	  padding: 8px;
    }
  </style>
</head>
<body>
<table id="dataTable"></table>

  <script>
datos =  window.AppInventor.getWebViewString().split("|"); // Entrada de datos.
day = datos[0];
month = datos[1];
csvData = datos[2];

function updateTable(day) {
  const dataTable = document.getElementById("dataTable");
  // Limpiar tabla
  while (dataTable.rows.length > 0) {
    dataTable.deleteRow(1);
  }

  if (day) {
    const rows = csvData.trim().split("\n");
    const headerRow = rows[0].split(",");
    const selectedRow = rows[parseInt(day)];

    if (selectedRow) {
      const cells = selectedRow.split(",");

	  // Crear la primera fila con las celdas unidas
      const firstRow = dataTable.insertRow();
      const cell = firstRow.insertCell();
      cell.textContent = month + " " + day;
      cell.colSpan = cells.length;
	  day =  parseInt(day) - 1;
		  
      for (let i = 1; i < cells.length; i++) {
        const name = headerRow[i];
        const note = cells[i];

        const row = dataTable.insertRow();
        const cell1 = row.insertCell();
        const cell2 = row.insertCell();
        cell1.textContent = name;
        cell2.textContent = note;
      }
    }
  }
}

  window.addEventListener("load", function() {
  updateTable(day);
});
</script>
</body>
</html>
1 Like

@ABG thank you
Do you mean just start with the last row of the table?
I want to call and the display the the data in the row where the day in the table matches the current day of the current date

when I open the app it will go and check the column d (the day number) and compare it against the current today's date and then display it, crystal clear

By the way, how would you refresh the data every day for all those users?
the data is always fixed not changeable
i just want to display part of it based of the date that's all

Thanks

@Juan_Antonio

Wow .... amazing
You already nailed it :clap: :clap: :clap: :clap: :clap: :clap:

I have tested it and it works perfectly
Thank you so much

The only issue for me is that I will need to learn JavaSript in case I wanted to modify the app
And I don't think I can learn it over the night long journey for me :slightly_frowning_face:

I have noticed that you used IF function and Clock.now
both are available in MIT app components

Is there any easier way to implement the same idea using simple blocks in MIT App Inventor rather than solving with JS coding?

Thank you so much



csv_display_date_ABG.aia (4.3 KB)

This is like the opposite of that Mick Jagger song You Can't Always Get What You Want.

It's what you want, but I am not convinced it's what you need.

2 Likes

:clap: :clap: :clap: :clap: :clap: :clap:

@ABG
You have already given me the solution
Highly appreciated

Tested and works perfectly

Trust me that's exactly what I needed :smiley: :smiley: :smiley:

I can clearly see that you preferred LISTVIEW and LISTPICKER which is fine and doing the job

Whenever you got free time if possible no pressure no rush the topic is resolved already
But it will look much simpler if you do me a massive favour by using simple LABLES to feed it with data

Thanks you so much guys
You are doing fantastic job in here

I have no idea what you mean by this.

1 Like

Alright let me explain it
going back to me reply above I post the following Image

I used labels which refers to data for each person (David , Lucy, ....)
I aimed to SET those labels and add text that's found in the CSV table
you thankfully replaced that with listview
Using the listpicker method which is fine but I think it will look nicer and simpler if we return to labels
no need to use listview and listpicker way I guess

Never mind
All good
I will try to do it myself

Thank you so much

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.