Created
October 22, 2014 07:46
-
-
Save OdNairy/1c745c782df9a9428574 to your computer and use it in GitHub Desktop.
This file contains 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
- (NSArray *)timelineRecordsFromEvents:(NSArray *)events { | |
WOTimelineRecord *lastRecord = [self.items lastObject]; | |
WOTimeLineSessionGroup *lastSessionGroup = (lastRecord.type == WOTimelineRecordTypeGroupedAuthEvents) ? lastRecord.item : nil; | |
NSMutableArray *newRecords = [NSMutableArray new]; | |
NSMutableArray *sessionEvents = [NSMutableArray new]; | |
for (int i = 0; i < [events count]; i++) { | |
WOTimeLineEvent *event = events[i]; | |
if (event.type == WOEventTypeSession) { | |
[sessionEvents addObject:event]; | |
WOTimeLineSessionGroupType groupType = WOTimeLineSessionGroupTypeSingle; | |
//grouping auth events | |
for (int j = i + 1; j < [events count]; j++) { | |
event = events[j]; | |
if (event.type == WOEventTypeSession) { | |
WOTimelineAuthEvent *prevEvent = [sessionEvents lastObject]; | |
[sessionEvents addObject:event]; | |
BOOL shouldGroupAsSingle = [self shouldGroupAsSingeWihtAuthEvent1:prevEvent authEvent2:(WOTimelineAuthEvent *)event]; | |
if (!shouldGroupAsSingle && groupType == WOTimeLineSessionGroupTypeSingle) { | |
groupType = WOTimeLineSessionGroupTypeMulti; | |
} | |
if (j + 1 == [events count]) { | |
i = j + 1; | |
if (lastSessionGroup) { | |
[lastSessionGroup addEvents:sessionEvents]; | |
} else { | |
[newRecords addObject:[WOTimelineRecord authEventRecordWithEvents:sessionEvents groupType:groupType]]; | |
} | |
break; | |
} | |
} | |
else { | |
if (!lastSessionGroup) { | |
[newRecords addObject:[WOTimelineRecord authEventRecordWithEvents:sessionEvents groupType:groupType]]; | |
} | |
else { | |
[lastSessionGroup addEvents:sessionEvents]; | |
lastSessionGroup = nil; | |
} | |
[sessionEvents removeAllObjects]; | |
i = j; | |
break; | |
} | |
} | |
} | |
if (i + 1 >= [events count] ) { | |
break; | |
} | |
WOTimelineRecord *record = [WOTimelineRecord new]; | |
record.item = event; | |
record.type = WOTimelineRecordTypeEvent; | |
[newRecords addObject:record]; | |
} | |
return newRecords; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment