Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save SiarheiFedartsou/d37d027f8414357bec3b5bb16be8953f to your computer and use it in GitHub Desktop.
Save SiarheiFedartsou/d37d027f8414357bec3b5bb16be8953f to your computer and use it in GitHub Desktop.
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