$query = Ad::
select(array('ads.*', DB::raw('COUNT(DISTINCT clicks.id) as clicks_count'), DB::raw('COUNT(DISTINCT shows.id) as shows_count'), DB::raw('(COUNT(DISTINCT clicks.id) * COUNT(DISTINCT shows.id))/100 as CTR')))
->leftJoin('clicks', function($join) use($date){
$join->on('ads.id', '=', 'clicks.ad_id')->where(DB::raw('DATE(clicks.created_at)'), '=', $date);
})
->leftJoin('shows', function($join) use($date){
$join->on('ads.id', '=', 'shows.ad_id')->where(DB::raw('DATE(shows.created_at)'), '=', $date);
})
->groupBy('ads.id')->with('devices', 'platforms');
-(void) start{
double __block firstY, mediumY, lastY=0;
int __block i=0;
[self addObserver:self forKeyPath:@"count" options:NSKeyValueObservingOptionNew context:nil];
self.motionManager = [[CMMotionManager alloc]init];
self.motionManager.deviceMotionUpdateInterval = 0.1;
[self.motionManager startDeviceMotionUpdatesToQueue:[[NSOperationQueue alloc]init] withHandler:^(CMDeviceMotion *motion, NSError *error) {
CMAcceleration acceleration = motion.userAcceleration;
[self changeFilter:[LowpassFilter class]];
[filter addAcceleration:&acceleration];
if([UIDevice currentDevice].orientation!=1){
[self.messageText performSelectorOnMainThread:@selector(setText:) withObject:@"Держите телефон вертикально!" waitUntilDone:NO];
} else {
[self.messageText performSelectorOnMainThread:@selector(setText:) withObject:@"" waitUntilDone:NO];
double y = filter.y>0.5?filter.y:0;
if (i < 3){
if(i%3==0){
firstY = y;
}
if(i%3==1){
mediumY = y;
}
if(i%3==2){
lastY = y;
}
}else{
firstY = mediumY;
mediumY = lastY;
lastY = y;
}
if(mediumY>firstY){
if(mediumY>lastY){
self.count++;
AudioServicesPlayAlertSound(kSystemSoundID_Vibrate);
}
}
i++;
}
}];
self.trained = YES;
}
user.php?viewer_id=1&auth_key=178368163&action=profile
$.api=function(m,o,c){o.method=m;o.viewer_id=api.viewer_id;o.auth_key=api.auth_key;$.post('api.php',o,c);}