2016년 12월 13일 화요일

MIT App Inventor 2 Count the duplicates in a list


I have to, maybe a easy question, if possible reading how many items in the list , are equal ?

--
If what you need is the list filtered with no duplicates, may be a faster way to do it would be to save each item of the list as a tag in TinyDB and then reload the list with all the tags saved. Since the duplicates will be overwritten, you will have no duplicates.
I just thought of that, and I just woke up ;-) so maybe there's a better way. Any ideas?

-- 
Now if you need to know exactly how many duplicates you have for each one, you can check first, if the tag already exists, add 1 to the number saved in that tag, if not, just create the tag.

--
Many thanks for the quick response, the need is the number of duplicates have the list, you can see my picture (List Home). I honestly do not understand how you suggest to do . Can you please post a image within a example ?

-- 
I filtered with no duplicates with ( For each ) procedure  ....
-- 
Do you know how to use TinyDB? 

Delete all the tags in TinyDB
Use a for each to run the whole list.
Ask if the current item in the for each exists as a tag
If it doesn't exist, create it (Tag = element in the list and value = 1)
If it exists, that means is a duplicate and was created before, so the value must be increased in 1. 

After the for each ends, you can show each tag and its values when the value is > 1. That will give you only the duplicates and how many times is that item in the list.
Of course you can do it with a procedure, but I think using this TinyDB methid it will be faster, especially if the list is big.

-- 
Here are two examples of how to REMOVE duplicates from a list  https://groups.google.com/forum/#!msg/mitappinventortest/j1GukExhQ1k/vnnRTzDDctAJ;context-place=category-topic/mitappinventortest/l8EMUJz_jHk      Perhaps you can modify one of them to count as it removes duplicates.  I think this will modify the original list so you would have to retain a copy of the original list...there is a block to do that.

Try it.   You do not have to use a TinyDB to count the duplicates.

Merry Christmas, Wesołych Świąt,  Feliz Navidad, God Jul, Joyeux Noel, Καλά Χριστούγεννα, Happy Christmas, Veseloho Rizdva, Prettige Kerstdagen, Frohe Weihnachten!, 성탄 축하 , Buon Natale,  聖誕快樂 ,  圣诞快乐,  Sretan Božić, C рождеством!,  عيد ميلاد مجيد

-- 
One of the examples is exactly my procedure to remove duplicates, using two different Lists (List BEFORE ) and (List AFTER) .
After that i use the ( List AFTER ) to populate a ( List Picker ) .
I need to use e (ListPicker Selection) to know how many items , inside to the (List Before) ,  are present with the same value / name .
I do not know how to count how many time , in the procedure ( For Each ) it read the same value/ name  .

-- 
length of list block tell you how many items are in a list, so, if you have a copy of the before and after lists (List BEFORE and List AFTER ... whatever you name them), use the block length on each and subtract one from another = numbers of duplicates perhaps?     

To count in a procedure Ivo,  normally you would and a variable called counter and increment it by one each time you loop.    perhaps try that if you do not want to compare the 'length of two lists"

Just try some things.  Any luck?

-- 


Updating Button status on different phones with same app


I have been wondering, is it possible to update a button's status in the same app on different phones? Can we use tinyWebDB for it ? if so then how it can be used?

-- 
I believe your app would need to "poll" the tinyWebdb on a regular basis, then a routine to respond to the change, in which case you could use a variety of methods to set the value you require (spreadsheet/csv)

There are "push" features about but this is not a mainstream feature yet with AI2.

-- 
try the FirebaseDB component, which offers a DataChanged event

-- 
I would do it using firebaseDB but I read on web somewhere that FirebaseDB can't be used for long run. And as I want to customize this app

Are there any sort of tutorial which could help me with this. 
I tried with the TinywebDB but it doesn't work as I'm able to get the data stored but retrieving it is difficult. Data seems to be lost somewhere. 

-- 
the Make Quiz Take Quiz tutorial uses TinyWebDB http://www.appinventor.org/book2
If I were you, I would use the FirebaseDB...
all other databases require constantly polling

you also can take a look into PubNub, which offers at least long polling https://puravidaapps.com/pubnub.php
I'll surely look into those tutorial and give a try with the firebase too. 

I still have doubt's with the TinyWebDB, as I'm storing the data it stores the data with extra backslashes"//" so while I retrieve the data through the get value tag the data is not visible on my label. 

-- 
It would really help if you provided a screenshot of your relevant blocks, so we can see what you are trying to do, and where the problem may be.

-- 
I'm sorry I tried to add the image in last post but the server was down. Below are blocks, in which I'm trying to update the label image using TinyWebDB
-- 

as I'm storing the data it stores the data with extra backslashes"//" so while I retrieve the data through the get value tag the data is not visible on my label. 
the TinyWebDB.GetValue block must be outside of the TinyWebDB.GotValue event (for example in another Button.Click event), else you create an endless loop
do again the mentioned tutorial to learn how to work with TInyWebDB

please store the valueFromWebDB additionally in a label and use Do it to display its value, then take another screenshot including Do it result, so we can see the value...
see also tip 4 here 

Top 5 Tips: How to learn App Inventor


-- 
I tried changing the my blocks by adding one more button to get the values and it worked but unfortunately I didn't understand how does the "Do It" option works when I tried it gives me error like this "The variable $valueFromWebDB is not bound in the current context" .


Also could you suggest a way to use only one button to store and retrieve the web data??

One more thing I downloaded google app engine to create my custom webDB, but its not a launcher its a cloud. I'm finidng it difficult to create it, 
If you have a new tutorial based on the google cloud engine please let me know.

-- 
See this link for how to capture values after they have evaporated ...


-- 
Thank you Abraham, I'll surely look into it.

--
I have been wondering, is it possible to update a button's status in the same app on different phones? Can we use tinyWebDB for it ? if so then how it can be used?

-- 
I believe your app would need to "poll" the tinyWebdb on a regular basis, then a routine to respond to the change, in which case you could use a variety of methods to set the value you require (spreadsheet/csv)

There are "push" features about but this is not a mainstream feature yet with AI2.

-- 
try the FirebaseDB component, which offers a DataChanged event

-- 
I would do it using firebaseDB but I read on web somewhere that FirebaseDB can't be used for long run. And as I want to customize this app

Are there any sort of tutorial which could help me with this. 
I tried with the TinywebDB but it doesn't work as I'm able to get the data stored but retrieving it is difficult. Data seems to be lost somewhere. 

-- 
the Make Quiz Take Quiz tutorial uses TinyWebDB http://www.appinventor.org/book2
If I were you, I would use the FirebaseDB...
all other databases require constantly polling

you also can take a look into PubNub, which offers at least long polling https://puravidaapps.com/pubnub.php
I'll surely look into those tutorial and give a try with the firebase too. 

I still have doubt's with the TinyWebDB, as I'm storing the data it stores the data with extra backslashes"//" so while I retrieve the data through the get value tag the data is not visible on my label. 

-- 
It would really help if you provided a screenshot of your relevant blocks, so we can see what you are trying to do, and where the problem may be.

-- 

Tinywebdb on local server (app inventor 2 and tinywebdb)


I am using app inventor 2 now for 2 months and i can work with lists and the tinydb.
But with the Tinywebdb i cant get it working.

I have installed pyton, i have installed google app engine launger and i have a working tinywebdb on http://127.0.0.1:8080
I can put tings in the data base enad i can read from data base.

But i like to use the local database in a local app.

Local app inventor server http://127.0.0.1:8888
customtinywebdb27  runing on local server http://127.0.0.1:8080

I keep it simple and  only ask wen click on button get tag test

in the servsice url is now: http://appinvtinywebdb.appspot.com
I have tried http://127.0.0.1:8080 but also not working.

What must i use in service url to get it work (if possibble)

-- 
127.0.0.1 is another name for localhost... and the database is on your computer, but not on your device, correct? So I would try the ip address of your computer instead, which usually is something like 192.168.0.x...

-- 
I know that 127.0.0.1 is a other name for local host.
But i use that because i try it wit a simulator on the same machine.

So at one Computer i have App inventor 2 (offline version) at port 8888, i have the pyton webserver at port 8000 and the tinywebdb database at 8080

So i have to use 127.0.0.1 or local host.

but in the url "http://appinvtinywebdb.appspot.com" is"appinvtinywebdb" only a subdomein from 
"appspot.com" so there is no reference to a speciale database.

I hope its no clear what i want and what i mean because DUTCH is my mother language.

-- 
But for your phone (assuming your app runs on your phone) you cannot use 127.0.0.1 because your PC is not localhost for your phone.
Try what Taifun suggested to you. (Dutch is my mother language too, but I think your English should be good enough).

-- 
I can try it but a run the emulator on my pc.
So if its not working on my pc then i'm doing somthing wrong.

If i use the standard http://appinvtinywebdb.appspot.com then its working fine.
But i want that my users only can use the app/data when the are in MY network.

I know that when its working on my local emulator that i must change it to my pc ipadres
or local domain name when using it on a phone or tablet.

But i wil try.
I wil post my findings here.

-- 
I have tried http://192.168.1.xx (ip of my pc.
I have tried http://locathost:8080
i have tried http://127.0.0.1:8080

but i still get the message:
commenucation with the webserver time out.


--
what about trying http://192.168.0.105:8080
assuming, that 192.168.0.105 is the ip address of your computer...

PS: read here https://en.wikipedia.org/wiki/Localhost why localhost will not work to access your computer from somewhere else

In computer networking, localhost is a hostname that means this computer

-- 


How to control the vertical spacing between lines in ListView


Is there a way to control the vertical spacing between lines in ListView?

-- 
You can set the textsize, but not the vertical spacing.

-- 
You can add extra n line feeds to the elements.

-- 
I want to decrease the space between lines but I guess this is not possible. Is there a way to send recommendations to the AI2 development team?

-- 

Another Error 2601 fusion table issue


Mango Drive is a Technovation Challenge group. We are using fusion tables to store data. After reading these forums and trying a lot of code, we seem to have found an approach that works for reading rows of the tables (attached). However, every so often we get the following: 


Error 2601: Fusion tables returned an error. The query was: SELECT activity,user,when,start,end,description FROM <TABLE_ID>. The response was: Read error: ssl=0x6265db90: I/O error during system call, Connection reset by peer.

Any ideas what that might be? It's intermittent and occurs even though the data in the fusion tables have not changed. Thanks.

-- 
yes, I agree, unfortunately this error message does not help very much
probably a temporary issue on the server site?

as far as I can see, you also did not use any reserved words, see also https://developers.google.com/fusiontables/docs/v2/sql-reference#reserved

what happens, if you use the Query block to define the sql statement like this
SELECT activity,user,when,start,end,description FROM <TABLE_ID>
and then use the SendQuery block to send the statement to the table instead?

does a simple SELECT * FROM >tableid> work?

-- 
Yes, we have tried all the variations you suggest — including downloading a packaged .APK file to the tablet — and the result is the same: intermittently there are read errors (as described), other I/O errors, or (lately) the return is blank. It's not inspiring great confidence. Any help on resolving this (or perhaps responding to it under program control) would be appreciated.

-- 
try my simple test project here https://puravidaapps.com/fusionservice.php
and let us know, if it works for you

-- 

Button Images and Changing Buttons


Ok, this one seems to be a tough one for me.

I have 16 buttons, each with a specific image that have a white background. When a button is pressed, upon validation of the action, I turn the button green. If the action is invalid, I turn the button red. After 3 seconds, the default image returns.

I have everything working perfectly...except for one thing. I am unable to dynamically change the button name so that I can change the button image. As it stands, every button I press, changes Button1. How can I make my procedure call that does all the work use the button information that was pressed to select the button image change process?

If I didn't explain this well, please let me know.

--
You can't change the components names dynamically. Looks like you are taking a wrong approach to something that it's possible to do in MIT AI2.
Anyway you question is not clear. Please elaborate and post a screenshot of your blocks, so we can see what is wrong with your project.

-- 
Thanks, Italo, for the feedback. I redesigned my approach, and now a a similar, but different problem.

Basically,I have programmed Button5mph to call GetGPS, write data, play a sound, and set the flag variable SetGPSSucess to 1 for success or 0 for fail. When the call is transferred back to the button, I then change the button image from white to green for success or to red for fail. It works perfectly until I attempt to change the button back to white after a 3 second timer call. Then only sounds are made, no image changes.

Attached is the Blocks download.
blocks.png 표시 중
--
Move the blocks that sets the button back to white INSIDE the Clock Timer event. Also, right after those blocks, set the clock to disabled.

-- 
I had tried that earlier, and it did work. However, I have 16 buttons and would therefore need to create 16 timers, one for each button to change back to white. Which, ultimately, puts me back to my original problem, needing to pick a button name dynamically and then set the image to white.

-- 
instead of using a global variable SetGPSSuccess you might want to take a look into procedures with result http://appinventor.mit.edu/explore/ai2/support/blocks/procedures.html#return
see also chapter 21 here http://www.appinventor.org/book2
the result  in your case could be true or false

--
You don't need 16 timers. It can be done with just one clock.

If you need to allow the user to keep pressing buttons while there's a red button, then you can record the instant when an individual button turned red, save that instant in a list that has 16 items (one for each button).
Save the instant in the correct index, so if the 3rd button turns red, save the instant it turned in the item 3 of the list.
For this solution, you need to have the clock timer enabled all the time.
Inside the clock timer event, check each item of the list and if you find one that is not 0, that means that button is red right now. Compare the value (instant recorded) with the instant now and if it's greater than 3 seconds, turn that button white and change that item value to 0.

It sounds a little complicated, but it's actually easier that it looks.

-- 
The user does not need to keep pressing buttons while the procedure is active. Specifically, the user will press a button, capture the GPS and write it to the sdcard. Upon success, turn the button green for 3 seconds, If there is a failure, turn the button red for 3 seconds and then return to white. Once the procedure is complete, the user can press another button and repeat the process.

Even if I don't use the timer function, the 3rd image change for the button (from green or red back to white) fails the procedure. I am not seeing how a list will help me change the button for the 3rd time.

I does work when I use the timer and set the 3rd image change under the time. So, a separate timer for each button is the only way I see to change a static button. If I could say something like:

"Set <ButtonName> Join.Get SetMPH + Get "white.png".image" I would have it made.

I hope this explains it better.

--
In that case is even easier, but somehow you have to prevent the user from pressing another button while there's a red one, then.

See this example:

-- 
With your suggestion, I was actually able to locate and program a universal button, like the "set Button.---", except in this case, it actually controls the button image. I am including the blocks.
blocks.png 표시 중
-- 
Great! I can give you a couple of suggestion if you want:

1. Since the [SET ButtonClock TimerEnabled TO TRUE] block is repeated exactly in each Button.Click event, may be you can include it at the beggining of the procedure GetGPS, just to save some blocks space, unless there's another reason that I don't see to have it repeated in each click event.

2. You can create a list of your buttons and optimize your enabling and disabling procedures like in this image:
--
Actually, you can use just one procedure for setting the buttons enabled or disabled:
--
Love the ideas, Italo.

I've tried implementing them, but I keep getting a single error. It doesn't stop the program, just throws the error.

runtime error setting was expecting a button component but got a string instead

Not even sure what the error is or where it is. Any ideas?

--
It would really help if you provided a screenshot of your relevant blocks, so we can see what you are trying to do, and where the problem may be.

--
Yes, like Taifun said, post the blocks you are having problem with.
I think you might be using strings instead of the actual button block (the one you find at the bottom in that button blocks drawer) when creating the list of buttons.

--
Thank you, Gentlemen. I was actually able to locate the error and correct it. Turns out I was trying to initialize a global variable for a button...which, apparently, cannot be done with a button.

-- 


How to change Font family in app inventor 2


hello i want to change font family in label. i want to use iskolepotha,ttf font to label. how i use this font in appinventor sorry for my bad english.

-- 
unfortunately you can't change the font family in AppInventor
you could do it using a webviewer, see also https://puravidaapps.com/snippets.php#2htmlread
--