Filling list with for loop from firebase

41 views
Skip to first unread message

Geetha Venugopal

unread,
Dec 18, 2019, 11:00:13 PM12/18/19
to MIT App Inventor Forum
Hi :)

I was trying to fill in a list of studentGrade via for loop. For each iteration, I designed 3 getValue methods to retrieve value from firebase and add them all, and added the aggregated value into next index of the list. But the initial result was a list all filled with 0, then when I called the method again, a list all filled with what the value in final index should be. I found that for loop identifies the name of the student correctly, and that each getValue method correctly retrieves intended score to be added next. I was struggling with this for last few days but couldn't find way to solve it. The problematic code is in Rankings page, SortAZ. Please help :)

Thanks.

internalAssessment.aia
blocks (1).png
blocks (2).png
20191219_092710.jpg
20191219_092739.jpg

TimAI2

unread,
Dec 19, 2019, 4:15:21 AM12/19/19
to MIT App Inventor Forum
If you are using Firebase GetValue block, the you must use the Firebase GotValue event block to act on the data returned

ABG

unread,
Dec 19, 2019, 6:39:31 PM12/19/19
to MIT App Inventor Forum
I cached your input stream of (tag,value) pairs into a list:

Do It Result: (
(/StudentList (Namgi Cha Seojin Kim Seoyoung Lee Vikram Noronha))
 (/StudentList (Seoyoung Lee Vikram Noronha Seojin Kim Namgi Cha)) 
(StudentVikram Noronha/AggregateOS 10.8)
 (ScoringOpeningSpeech/Weight 0.3)
 (Student((/StudentList (Namgi Cha Seojin Kim Seoyoung Lee Vikram Noronha)))/AggregateRes *empty-string*)
 (ScoringResolution/Weight 0.4)
 (StudentVikram Noronha/AggregatePP 9.6)
 (ScoringPositionPaper/Weight 0.3)
 (StudentSeoyoung Lee/AggregateOS 9.2)
 (ScoringOpeningSpeech/Weight 0.3)
 (Student((/StudentList (Namgi Cha Seojin Kim Seoyoung Lee Vikram Noronha)))/AggregateRes *empty-string*)
 (ScoringResolution/Weight 0.4)
 (StudentSeoyoung Lee/AggregatePP 18)
 (ScoringPositionPaper/Weight 0.3)
 (StudentSeojin Kim/AggregateOS 3.6)
 (ScoringOpeningSpeech/Weight 0.3)
 (Student((/StudentList (Namgi Cha Seojin Kim Seoyoung Lee Vikram Noronha)))/AggregateRes *empty-string*)
 (ScoringResolution/Weight 0.4)
 (StudentSeojin Kim/AggregatePP 6.4)
 (ScoringPositionPaper/Weight 0.3)
 (StudentNamgi Cha/AggregateOS 33.2)
 (ScoringOpeningSpeech/Weight 0.3)
 (Student((/StudentList (Namgi Cha Seojin Kim Seoyoung Lee Vikram Noronha)))/AggregateRes *empty-string*)
 (ScoringResolution/Weight 0.4)
 (StudentNamgi Cha/AggregatePP 24)
 (ScoringPositionPaper/Weight 0.3)
)
---

The red pairs look suspicious.

I suggest you do your filtering and statistics from the cache I collected in
the Firebase.GotValue event.

Are these tag/value pairs enough to do your math?

ABG




when FirebaseDB1.GotValue.png
InternalAssessment.png
internalAssessmentABG.aia
sortAZ.png

ABG

unread,
Dec 19, 2019, 9:10:56 PM12/19/19
to MIT App Inventor Forum
Looking further at your code, I see a timing problem.

You have at least three phases to your data collection from Firebase.
Each phase must complete before you can start the next phase.

  1. Empty out global lists
    1. student names
    2. name & score pairs
  2. request student name list
  3. student name list arrives
    1. sort student name list as needed
    2. for each student name, request their score
  4. student name & score arrives
    1. add pair to name & score lookup table
    2. if length of list(name & score lookup table) >= length of list(student name table) then
      1. scores table is complete, so show it

ABG


Reply all
Reply to author
Forward
0 new messages