如何检索每天整月入门的firebase数据,并找出每天的最高值?

时间:2017-03-17 12:35:52

标签: ios iphone firebase firebase-realtime-database

`在这里我试图获得一个月中每天最高的疼痛水平并将其保存在一个数组中并将其绘制成图表。我设法获得疼痛程度,但它仅检索输入日期。我需要检查一个月的1到31日期...如果它是一个非受试者的日子意味着..应该返回0到阵列.....任何帮助将不胜感激..?

我的代码`

   func DataFromFirebase()
   {
     var u_id = FIRAuth.auth()?.currentUser!.uid
     print(u_id)

      databaseRef = FIRDatabase.database().reference().child("medical_details")
      databaseRef.queryOrderedByChild("user_id").queryEqualToValue(u_id).observeEventType(.Value, withBlock: { (snapshot) in
        for the item in snapshot.children
           {

            let c_date = item.value!!["created_date"] as! String


            let Key = item.key
            //reference to the selected key
            let usersRef = self.databaseRef.childByAppendingPath(Key!!)
            //reference to the medicine node inside the key
            let Ref = usersRef.childByAppendingPath("parts_list")

            Ref.observeEventType(.Value , withBlock: { (snapshot) in
                for the item in snapshot.children
                {
                    let date = item.value!!["date"] as! String

                    if (c_date == date)
                    {
                    let dosage = item.value!!["pain_level"] as! String
                     print(dosage)
                    }
                }
            })

           }
    })
}

这里是我的Firebase数据库结构

"-KfBHEzFkEpfy0g2sU4S" : {
  "created_date" : "14/2/2017",
  "created_time" : "15:36",
  "medicine" : {
    "-KfBHEzYDrMII9o2OECQ" : {
      "dosage" : "2mg",
      "frequency" : "8",
      "interval" : "10",
      "number_of_tablets" : "2",
      "reminder" : "",
      "tablet" : "Dilaudid"
    }
  },
  "parts_list" : {
    "-KfBHEzbFQEBEjFk5uLN" : {
      "comments" : "cgsg",
      "date" : "14/2/2017",
      "pain_level" : "3",
      "part_name" : "Leg",
      "time" : "15:36"
    },
    "-KfBHEzeY45XKs-u8S9H" : {
      "comments" : "vhdh",
      "date" : "14/2/2017",
      "pain_level" : "8",
      "part_name" : "Mouth",
      "time" : "15:36"
    }
  },
  "remedies" : "Heating Pad",
  "user_id" : "xqgiYomblxcFbSnO0Q9T5fFOKWL2"
},

需要根据一个月的所有日子来检索疼痛等级。?

0 个答案:

没有答案