/Como calcular la moda | App Inventor 2

Como calcular la moda | App Inventor 2

Video: Como calcular la moda | App Inventor 2


hello, we are developing this app that it calls Trends Calculator this app calculates the trend, the half and the median in the past video i explain how to do the design of this app and what are the names of each element i recommend you to see the video to avoid confusions at the momment of the programming this time we'll do the part of the trend it will calculate the trends. if there are 1, 2 3, or whatever amount of trends this algorithm works in other programming languages it will serve at the same ok go to app inventor ok on blocks part and we'll start the promamming with the add button this button will add the new data of the text box to a list in which we will review the data and we will calculate the trend, the half and the median but in this case we will only do the part of the trend so we initialize a variable that we are going to call numbers and on list we put we use an element to create an empty list when we do this on the on the numbers list we will agregate elements so we use this block, add item to the list we will agregate this to the numbers list the item will be what the text box has but we are going to replace the elements this block replace some elements of the text for other thing in this case will be the text will be ,what the numbers text box has in the .

text atribute that is what user wrote to avoid another problems we will eliminate the spaces in the case that the user insert a space because we can't calculate the spaces so to the segment that will eliminate we duplicate this before the segment that we are going to eliminate will be the spaces if it find an space it will delete it and we only will save thenumber now what we need to do is to the numbers label we will agregate this new element and we will agregate all the list for this we are going to put a set set text of the numbers list and we will do a process which will delete the parethesis ( ) and the commas ' , ' it will replace the coma for script i'll explain a little bit how a list stores tha data a list stores the data in this form: the name for exmaple: mario coma , Valentin coma, 5, coma, hello it stores the data in this form so it will delete the parenthesis and we will change the commas for scripts with each space, so it will look like this so we will do a process to do that this process will return a result and it will replace text we are going to use this element but we will replace what the numbers list have so we put a get so it will replace the commas for scripts it will be like this (space) script (space) ok and we need another of this to replace the parenthesis we delete this int this case we are going to delete the parenthesis ahh in a second thought we will leave the parenthesis like that sometimes in diferents versions of app inventor it agregate some quotation marks to each data so we will delete it and we will leave the data with the parenthesis ok here we replace for nothing and we put it inside of this so this will replace the string of the numbers variable it will delete it and and it will put the list with all the data but this will serve us only for this case of the list but when it return the trend, it will return it as the same form like you in the previous video so it will work with various elements it will generate what the user send so we agregate this variable which we will call elements and we change this for the elements variable now in this part we call the process here we canc hange the name to the process i'll put it clean list and here is the variable that we are going to send it to delete the aparenthesis in an easy mode we use this block list to csv row list and we send it the elements this block convert all the data for exmaple 4 3 2 so it will generate this list we are going to change the commas for scripts and we´ll delete the quotation marks so it will do the same with any list and that's easier ok and now we will clean the text box where the user writes the number, to insert another number so we put this and we put an empty text so those are the things that almost we are going to use also we need todo the clean button when button click it will get the numbers list in we put it what i have on the thext that is number list and here we put number list also we need to clean the list which we have the data we will delete it and it will restart and to the trend label we have to put the normal script so with this we have the clean button we change it here and we copy this for the other elements half and median so with this we have the process that will clean all the data i'll show you how it works ok an i'll test it 2 and add and like you se now is on the numbers list i'll agregate another, 5 add and like you see it convert the coma for a script 6, add and it writes like that and if we click on the clean button it clean the data and it restart the textbox and the list ok lets do the the part of the number list this is part is a little complicated is the part where we calculate the trend the trend is the most difficult to calculate instead the half and the median so for this we need another process we are going to do all bu process to avoid confusions in the programming this will calls, trend calculus and here when the add button click will call to this and it will generate the calculus it will be according you insert numbers so here we are going to start the trend part and for this we need some variables beacause it will calculate any amount of trends it could calculate multiple trends so first we create all the variable that we need we initialize 5 variables we put it in 0 and to create more variables we put in here until it becomes to 5 each variable will save some data, and some will be in list form and the others will be in values but first we are going to rename the variables int this case this will calls, number it will be the number of the list that we will select another one will be will be the number list that we have already seen it won't count this list again i will call it list of numbers another one that will be the maximum number that it repeat in the list for exmaple if there is five numbers 2 but when it calculates again and it find ten numbers 8 we need to know which is the most repeated number so this is prev max repeated that is the previous most repeated number and another that will be the actual numer max repeated and to the last one, we calculate the trend of the list it will generate the trends that it found it so for this we put his element here it creates an empty list and for both this is cero and for the last one is also a list ok, now with a for, will calculate each inserted numbers on the number list for this in control we put this for cycle this variable will be the count this will start in 1 and it will stop until the amount of the inserted numbers of the numbers list so we go to list and we put lenght of list that it returns the totala mount of elements of the ist in this case is of the numbers list that is global numbers here is where we save the insterted numbers ok now we will save the selected number in the number variable so we put a select to the list we will select the element that is on the count the list will be the number list and the index will be the count if it select the first element, it will be 1 and it will increase the position until it becomes to the total amount of elements and this we need to restart each time when it find another number we have to initialize in cero and now we are going to do another for cycle wich will analyze the number that we select and it will count, how many equal numbers are in the numbers list for example the first element is 2 it will agregate to numbers and it will compare with the other numbers and it will count the amount of repeated numbers 2 so we put the for ok this is gonna be very similar it also will review all the number list here i'll change some variables, because it could generate an error in one cycle and it could stop the last cycle, because the first count has finished ok in this cycle, will ignore the numers that it has alredy rewied if it review the number 2, the next time it won't count again the numer 2 so for this we put an item the list, it's gonna be the already viewed numbers and the item it's gonna be the number so if it has reviewed a number, it won't count this number again in the elements counting we put an if and inside this if, we put an equal logic and here, on list we put this block this block send a true if the selected number is already on the list and the opposite case it sends an false so here we are going to send the number wich it will select on this for for example, here is on the number variable and if it's already on the numbers list, that number won't review again so in case taht this returns a false it means that this number has never been reviewed and it could count it so in this case it will enter to this if and in the if we are going to compare if the number that we are reviewing, i equals to this number it means that it is again in the list so we need another if in this case we need an equal logic in the same form, but in this case we put a select in the same form that we are comparing if this number is equals to thuis other number that is the number taht we are reviewing we duplicate this so each time that we find a number the maximum repeated number will increase the counter so for this we put a set it's gonna be, the maximum repeated will increase in one, remember that we initiliaze in 0 when it find a number in math, we put a sum we duplicate this the max repeated + 1 this will repeat 1 time for each number and it will increase the maximum now we hace to compare if this number it's greater than the number of the list for example if we review the number 2, and there's for numbers 2 and now we revies the number 7, and there's 8 repeated numbers so it is greater, it means that the previous number has been deleted there's a most repeated number so for this we need an if which we will calculate this control and here we use a math of higher remember that we put a previous max repeated so in case that max repeated is higher that prev max repeated it means that the new number that we are checking is the most repeated so we put prev max repeated so in this case the previos max repeated will be here will be the previous it's gonna be equals to max repeated (the actual) so now it will save the actual value of repeated numbers so it will replace the previous max repeated for the actual most repeated and now we need to save the most repeated number in the trend list so for this we will do almost the same set the trend list so in the case that it find one, it will create a list it doesn't matter if the list has already numbers, it will restatr and will initialize in cero and we wil add only one element that will be the number that we are checking in this form, if before it found the amount of each number it will delete the inferior numbers and it will keep only the most repeated number in case that max repeated and previous repeated be equals it means that it's a multiple trend there's 2 or more so for this we put an else if and we will do the same calculus we duplicate this in case that this is equals we will add an item to the trend list for exmaple if here we found 8 numbers 4, but then it found 8 numbers of other number so it will agrgate it to the list we put this add items to list so it will add to the list the number that we found to the trend list so with this if it found some repeated numbers with same amount, it will add to the list ok now we will continue ok now we have to write in the trend label all the numbers that we found ok so on label, we only put this set text, remember that we have already done a process that eliminates the parethesis, and comas so we will use the same process but this time for the list we will use the same element list to csv row and we send it trend that contains all the elements ok now lets test the app ok now i'll agregate some numbers here the trend is 2 now is 2 and 3, those are the most repeated i put another 2 and now the trend is 2 ok now add a 6 and again i the 2 now i'll put a 3 and now there's a multiple trend 2 and 3 another 6 and now the 2, 3 and 6 are the trend and if i add a 3 the 3 will be the trend now and like you see it works ok so this is the algorythm to calculate the trend, also a multiple trend ok in other video we will see the half, and in other video the median don't forget to watch the first video of the design of the app ok see you next time bye.

READ  EtherBlade.net V2 assembler block conceptual model demonstration.