HistoryObject.m
1.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
//
// HistoryObject.m
// LifeLog
//
// Created by nvtu on 8/5/17.
// Copyright © 2017 PhongNV. All rights reserved.
//
#import "HistoryObject.h"
#import "Utilities.h"
@implementation HistoryObject
-(id) initWithData : (NSDictionary *) dict {
if([dict objectForKey:@"steps"] != nil) {
self.step = [dict[@"steps"] intValue];
}
if([dict objectForKey:@"step_diff"] != nil) {
self.step_diff = [dict[@"step_diff"] intValue];
}
if([dict objectForKey:@"target"] != nil) {
self.target = [dict[@"target"] intValue];
}
if([dict objectForKey:@"step_remain"] != nil) {
self.missing = [dict[@"step_remain"] intValue];
}
if([dict objectForKey:@"complete_percent"] != nil) {
self.percent = [dict[@"complete_percent"] floatValue];
}
if([dict objectForKey:@"distance"] != nil) {
if([dict[@"distance"] isKindOfClass:[NSString class]]) {
NSString *distance = dict[@"distance"];
self.distance = [distance floatValue];
}
else {
self.distance = [dict[@"distance"] floatValue];
}
}
if([dict objectForKey:@"kcal"] != nil) {
self.calories = [dict[@"kcal"] floatValue];
}
if([dict objectForKey:@"time"] != nil) {
self.time = [dict[@"time"] intValue];
}
if([dict objectForKey:@"date"] != nil) {
NSString *dateString = dict[@"date"];
self.date = [Utilities dateFromString:dateString withFormat:@"yyyy-MM-dd"];
}
else {
self.date = [NSDate date];
}
if([dict objectForKey:@"data_chart"] != nil) {
self.dataGraph = [[NSMutableArray alloc] init];
NSDictionary * graph = [dict objectForKey:@"data_chart"];
if([graph count] == 24) {
for(int i = 0; i < 24; i++) {
[self.dataGraph addObject:[graph objectForKey:[NSString stringWithFormat:@"%d", i]]];
}
}
}
return self;
}
@end