Skip to content

Commit

Permalink
fixed reviews math
Browse files Browse the repository at this point in the history
  • Loading branch information
skucheria committed Sep 10, 2019
1 parent 47cf803 commit 9979647
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 3 deletions.
1 change: 0 additions & 1 deletion Helpers/Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ extension UIViewController{
user.fcmToken = item.value["fcmToken"] as? String
user.numReviews = item.value["numReviews"] as? Float
user.reviews = item.value["reviews"] as? [String]

}
}
}
Expand Down
Binary file not shown.
7 changes: 5 additions & 2 deletions LearnLab/ViewControllers/NewReviewVC.swift
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,6 @@ class NewReviewVC: UIViewController, UITextViewDelegate {


@objc func review(){
print("Leaving review with rating: ", stars.rating)
//for grouped reviews
let ref = Database.database().reference().child("grouped-reviews").child(currentTutor!)
let revRef = ref.childByAutoId()
Expand All @@ -165,9 +164,13 @@ class NewReviewVC: UIViewController, UITextViewDelegate {
else{
// do the math here
let starRate : Float = Float(stars.rating)
var newRating : Float = (oldRating * numReview) + starRate
numReview += 1
var newRating : Float = (oldRating + numReview) + starRate
newRating = newRating / numReview
print("Old overall rating: ", oldRating)
print("Total num of reviews now ", numReview)
print("New rating ", starRate)
print("Overall new rating ", newRating)
userRef.child(curr!.id!).updateChildValues(["rating" : newRating, "numReviews" : numReview])
}
var oldReviews = [String]()
Expand Down

0 comments on commit 9979647

Please sign in to comment.