title: Firebase query retrieve data from several children and do math
body: <p>I am trying to do a query to my firebase to calculate an average of some entries.</p>
  
  <p>I feel like i did't completely understand this, and feel like I am fumbling in the dark.</p>
  
  <p>My code to try to retrieve the data is like this:</p>
  
  <pre><code>Calendar mcurrentTime = Calendar.getInstance();
          int day = mcurrentTime.get(Calendar.DAY_OF_MONTH);
          int month = mcurrentTime.get(Calendar.MONTH)+1;
          int year = mcurrentTime.get(Calendar.YEAR);
          String dateString = year + checkDigit(month) + checkDigit(day);
          Long date = Long.valueOf(dateString);
          Long alongweekago = date - 6;
          String aweekago = alongweekago.toString();
          String userId = FirebaseAuth.getInstance().getCurrentUser().getUid();
          mDatabase = FirebaseDatabase.getInstance().getReference().child(userId);
  
          Query lastSevenDays = mDatabase.orderByKey().endAt(aweekago).limitToLast(7);
  
          lastSevenDays.addChildEventListener(new ChildEventListener() {
              @Override
              public void onChildAdded(DataSnapshot dataSnapshot, String s) {
                  final String lastsevendates = dataSnapshot.getValue().toString();
                  Log.w(TAG, lastsevendates);
              }
  
              @Override
              public void onChildChanged(DataSnapshot dataSnapshot, String s) {
  
              }
  
              @Override
              public void onChildRemoved(DataSnapshot dataSnapshot) {
  
              }
  
              @Override
              public void onChildMoved(DataSnapshot dataSnapshot, String s) {
  
              }
  
              @Override
              public void onCancelled(DatabaseError databaseError) {
  
              }
          });
  </code></pre>
  
  <p>my datastructure is like this:</p>
  
  <p><a href="https://i.stack.imgur.com/7icMX.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/7icMX.png" alt="enter image description here"></a></p>
  
  <p>What I want to do is retrieve the "efficiency" key from the last 7 dates, and calculate an average on them. I am just not sure about the best way to do this. Can anyone help me in the right direction?</p>
  
  <p>Regards
  Rune</p>