2014년 12월 7일 일요일

Filtering Lists from TinyDB


Thank you for all your help so far with understanding AI2.

I am trying to search a tinyDB database stores names/dob/email/phone numbers of friends.  I want to return all records where the the gender is female.  I am trying to use that to understand how lists work.
So far with my example, I have based it on steve's tutorial here TinyDB - a persistent data solution.  How do I get all the records back to the label called selection? I have just put something together based on what I think is right and just annotated on the second image to show where the gender will be stored.  Thanks for your help in advance



--
MJ... in all cases, the gender will be in the same field index... at least they should be.  So if you know that index, search JUST that index... going through all fields doesn't make sense...

Also... you should be saving each record int he TinyDB as a list with a named tag.  Each tag should have a list as it's value, which is the same list as all other records... that's what the database structure for each record is.  So, save a record with MJ as the tag, and the list of the structure as the value.  Then, bring back each record and search the field in the list that corresponds to gender.

--
Thanks Enis.  I have modified according to your suggestion - please see blocks below it just gives me the else message when i run it saying no females in database any ideas please?



--
Please post screenshots of how you're making the two lists... GlobalPeopleList and GenderList...

--
Here's a link to a doc showing how to filter lists of lists ...

Build Your Own DB - Part 1

--
Here is all the code so far




--
Thank you ABG.  I had a look at this tutorial but it seemed very complex to me because I am not using rows or columns.  I stored the data using tags I am not a this advance level yet.  All I want to do is return the records that the user has saved as females.
From your code, I would assume my best bet is to create an empty global list, search for the index that corresponds with the tag for gender ask it to return the ones = females using a compare block and for each item block? and append to the global list add item to list? Will this be possible? Or what's your suggestion please?

--
You're storing names to the Global NamesList.  That's just names... no genders... so your search would always come up empty.

So, once you get the name, you have to get the entire record from the TinyDB, and store it to a LIST... then your list.gender field needs to be checked.  Then you go on to the next record.  Instead of testing each item in the record by extracting the list value again from the TinyDB, extract it once, check the values, then go on to the next TinyDB record, store it to the list, check the list...

--
Thanks for being patient.  I have modified my list and created a variable called Genderlist which then holds the entire contents of TinyDB in a newly created list.  
It doesn't work still but I think my issue is how do I get it to get the list.gender field then go to the next record.  I have tried to do that via the compare text with select list item list and index 3 but I don't know how to tell it to check the third item in every record in the DB.


--
refer to: search results for Filtering Lists from TinyDB

--

댓글 없음:

댓글 쓰기