Turning Ranked Numbers Into Word Tags

Hello there!

I am currently developing a finance app and I'm trying to implement a function which ranks the categories that the user spent their salary on. Here's how it going to work:

  1. The app calculates the budget and actual amount of the user’s expenses for each category, it will make a list of the budget and actual amounts for each category.
  2. The app will then find the differences between the actual amount and budget amount for each category.
  3. The app will then rank the list from the smallest to the largest differences in budget and actual for each category.
  4. The app will then take that ordered list of categories and insert it into a temporary database.
  5. The app will then turn the differences in each category that it represents (Home Expenses, Utilities, Food, etc).
  6. The app will then display the text from the database into the notifier that will pop up.

I've so far done coding all the procedures up until procedure/step/number 5 where the app will turn the sorted differences into their supposed categories. I have attempted this by using dictionaries but it gave me an error message. I've searched for solutions and played around with the blocks to try to find a solution for way too many hours. Below are my blocks and project download, if you see something wrong with my blocks, please reply to this post ASAP. However, if anyone has a different way of doing this in a more efficient way, please feel free to send out your method of how you would achieve this.

PS: in the project, the blocks in the screenshot can be found in the near top right hand corner of the blocks

Thx :)!


The_Finance_Budgeter_checkpoint3.aia (6.0 MB)

1 Like

You have made several mistakes in your blocks:

  • You open Screen1 instead of closing your current screen
  • Your blocks image looks like a box of combs, because you did not work from lists and use parameterized procedures, which would have reduced your number of blocks by 90%.
  • The month is a data value like 202112 (December 2021), not a name that needs to be hard coded in blocks.
  • to init a global variable with textbox.text values is useless, since the init happens at screen startup, before the .text values have been typed in. Better to init global variables with the textbox components in a list or dictionary, matched against their categories ('home', etc.) so you can loop through them later.

More errors:
You have an Windows executable file in your Media folder, masquerading as an mp3 file, like a Trojan. Run a good virus checker on your PC and delete that useless evil file.
happymusic

You kept your head down and grinded away in error for to long before coming up for air to ask for advice.

Here is a table (list of lists) structure for your data, that will let you do your data collection:

  • month (yyyymm format, like 202112)
  • category name ('home')
  • budgeted money amount (999)
  • actual money amount (000)

Here is the Lists FAQ, which has several sorting solutions:

3 Likes

What do you mean by that? Could you please elaborate? Thx for the thorough evaluation tho! @ABG

1 Like

To do this do I use dictionary blocks or list blocks? Or is there something else I'm not understanding here? @ABG

1 Like

How would the app know that I want to open Screen1 if I close the monthly screen? I can't do them both at the same time. :confused: @ABG

1 Like

Please read the chapter 21 on procedures in the free online book
http://www.appinventor.org/book2
from

Read the chapter all the way to the end.

1 Like

See

from

1 Like

If you are doing accounting, with the same kind of data you would have loaded into a spreadsheet, use tables. This is for consistently shaped data,

If your data is lumpy or ragged, with missing or extra or deeply nested pieces that won't fit evenly into rows and columns, you need dictionaries.

Here is a sample project for you to read:

also

1 Like

Ah that clears it up now thx

Thx! Will look into your suggestions.

Um to make the database, do I use a csv sheet or the blocks as shown in the document? Or can I use either? @ABG

Never mind the question above I already done one in MIT App Inventor. Does this look about right so far? @ABG

unfortunately not, as @ABG already explained earlier

you first should do some more tutorials to learn the basics...

additionally it does not make much sense to copy blocks like you did for each of the categories.... and this is only one month... now the same monster block for the other months? you are repeating over and over again...

DRY - Don't repeat yourself

Taifun

1 Like

Oh... now I'm confused about this table. So am I supposed to do this in a csv document? I am not so sure on how I'm supposed to complete the table correctly. I'm trying to understand the document that @ABG shared with me. I've honestly never attempted something like this on App Inventor before. @Taifun

Also, when I complete this table/database, am I able to turn the values back into their specific categories? Or is this supposed to replace the TinyDB that I've implemented into my code? Pls explain. @ABG @Taifun

Thx for the tip!

Here are a couple of more samples to read, to get a feel for how to work with lists and TinyDB tags and values ...

I'm not sure on how my csv sheet is supposed to look like. What is the format or do I just add commas? What are those symbols highlighted in black? I think I can work it out if I understand how csv sheets work in App Inventor since I can understand majority of the blocks in this post and your documents so far. Pls explain how I can create one properly. Thanks!

The CRLF in black is Notepad++'s way of telling its users there are two otherwise invisible characters (carriage return and Line Feed) at the end of each line, typical of a text file on the Windows platform.

How is your CSV file supposed to look like?

A CSV file is typically used to transport a table across machines as a text file.
If you want to transport your monthly budget and spending data by category,
your CSV file would contain 4 columns, as I described at Turning Ranked Numbers Into Word Tags - #2 by ABG

Comma Separated Values (CSV) files have the data items in each line separated by commas (,). Don't ask for trouble by putting commas inside your data items without protecting them with quotes ("Bond, James Bond"), otherwise your column count will be off when you try to read that row.

CSV files, while good for data transport and long term storage, are inconvenient for updating and accessing individual data items. TinyDB would be easier during the current month, if you built tags containing enough information to home in on just the value you want to retrieve and update, like

tag : value
202112/snacks/BUDGETTED : 20.00
202112/snacks/ACTUAL : 25.00
202112/travel/BUDGETTED : 50.00
202112.travel/ACTUAL : 20

(Bottom line, I stayed home and snacked this month.)

Every day as I spend money, I would retrieve the ACTUAL for that item and update it in TinyDB.
At end of month, I would take a TinyDB Taglist, and build a CSV file for export or an in-memory table if I want to do list manipulation (filtering, sorting, summarizing.)

1 Like

Ohhhhhh, everything makes sense now! Thanks a lot! I don't need the CRLF right since I don't use notepad++ or do I need it? If it is required, how am I supposed to find that symbol? Thanks again for the detailed explanation!

Do I need quotes as well for the date and amount of money since they are numbers?

there seem to be colons and slashes in each of the rows, do I need that or do I just use commas since it is a csv sheet?