a9f16bca4a
- Move to Models folder - Improve code and nullability notation - Rename class with typo in name
66 lines
1.5 KiB
Objective-C
66 lines
1.5 KiB
Objective-C
//
|
|
// EQNMath.m
|
|
// Earthquake Network
|
|
//
|
|
// Created by Luca Beretta on 14/09/18.
|
|
// Copyright © 2018 Luca Beretta. All rights reserved.
|
|
//
|
|
|
|
#import "EQNMath.h"
|
|
#import "Costanti.h"
|
|
#include <math.h>
|
|
|
|
|
|
@implementation EQNMath
|
|
|
|
#pragma mark - Public
|
|
|
|
+ (float)powSum:(CMAccelerometerData *)accelerometerData {
|
|
|
|
return sqrt(pow(accelerometerData.acceleration.x, 2.0)+pow(accelerometerData.acceleration.y, 2.0)+pow(accelerometerData.acceleration.z, 2.0));
|
|
}
|
|
|
|
+ (NSNumber *)meanOf:(NSArray *)array
|
|
{
|
|
double runningTotal = 0.0;
|
|
for (NSNumber *number in array)
|
|
{
|
|
runningTotal += [number doubleValue];
|
|
}
|
|
|
|
return [NSNumber numberWithDouble:(runningTotal / [array count])];
|
|
}
|
|
|
|
+ (NSNumber *)standardDeviationOf:(NSArray *)array
|
|
{
|
|
if (![array count]) {
|
|
return nil;
|
|
}
|
|
double mean = [[self meanOf:array] doubleValue];
|
|
double sumOfSquaredDifferences = 0.0;
|
|
for (NSNumber *number in array)
|
|
{
|
|
double valueOfNumber = [number doubleValue];
|
|
double difference = valueOfNumber - mean;
|
|
sumOfSquaredDifferences += difference * difference;
|
|
}
|
|
|
|
return [NSNumber numberWithDouble:sqrt(sumOfSquaredDifferences / [array count])];
|
|
}
|
|
|
|
+ (NSDictionary *)rLimiti:(NSArray *)array
|
|
{
|
|
float xmax = -MAXFLOAT;
|
|
float xmin = MAXFLOAT;
|
|
|
|
for (NSNumber *num in array) {
|
|
float x = num.floatValue;
|
|
if (x < xmin) xmin = x;
|
|
if (x > xmax) xmax = x;
|
|
}
|
|
|
|
return @{rMax : @(xmax), rMin : @(xmin)};
|
|
}
|
|
|
|
@end
|