Created
October 3, 2016 10:49
-
-
Save SiarheiFedartsou/d37d027f8414357bec3b5bb16be8953f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
PIQGolfGameStatistics* statistics = [[PIQGolfGameStatistics alloc] initWithHoles:[self holes] isMale:player.gender == GAGenderMen]; | |
@weakify(self); | |
NSArray<PIQGolfGameMotion*>* motions = [self.gameInfo.holes.allValues bk_reduce:[NSMutableArray array] | |
withBlock:^id(NSMutableArray<PIQGolfGameMotion*>* motionsAccumulator, MTPGameHole* hole) { | |
NSArray<PIQGolfGameMotion*>* holeMotions = [hole.shotsWithoutTeePositionShot bk_map:^id(MTPHoleShot* shot) { | |
@strongify(self); | |
return [self gameMotionFromShot:shot]; | |
}]; | |
[motionsAccumulator addObjectsFromArray:holeMotions]; | |
return motionsAccumulator; | |
}]; | |
[statistics recalculateWithMotions:motions]; | |
NSMutableDictionary<NSNumber*, NSNumber*>* putts = [[NSMutableDictionary alloc] init]; | |
for (PIQGolfGameMotion* motion in motions) { | |
if (motion.type == PIQGolfGameMotionTypePutt) { | |
putts[@(motion.holeNumber)] = @([putts[@(motion.holeNumber)] integerValue] + 1); | |
} | |
} | |
float average = [putts.allValues bk_reduceFloat:0 withBlock:^CGFloat(CGFloat result, NSNumber* puttCount) { | |
return result + [puttCount floatValue]; | |
}] / self.gameInfo.course.holesCount; | |
NSLog(@"%f %f", average, [statistics averagePuttsPerHoleWithHoleVisitType:PIQGolfHoleVisitAllHoles]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment