Add object detection, tracking, mobile notifications, and search to any security camera.
get segments in main
roryclear410370086dd1
diff --git a/clearcam/FileServer.m b/clearcam/FileServer.mindex 93fcf7c..aef69e7 100644--- a/clearcam/FileServer.m+++ b/clearcam/FileServer.m@@ -77,100 +77,94 @@}- (void)fetchAndProcessSegmentsFromCoreDataForDateParam:(NSString *)dateParam context:(NSManagedObjectContext *)context {- // Create a private queue context for fetching- NSManagedObjectContext *backgroundContext = [[NSManagedObjectContext alloc] initWithConcurrencyType:NSPrivateQueueConcurrencyType];- backgroundContext.parentContext = context; // Link it to the main context-- [backgroundContext performBlock:^{- NSError *error = nil;-- // Fetch the DayEntity for the given date- NSFetchRequest *dayFetchRequest = [[NSFetchRequest alloc] initWithEntityName:@"DayEntity"];- dayFetchRequest.predicate = [NSPredicate predicateWithFormat:@"date == %@", dateParam];+ NSError *error = nil;- NSArray *fetchedDays = [backgroundContext executeFetchRequest:dayFetchRequest error:&error];+ // Fetch the DayEntity for the given date+ NSFetchRequest *dayFetchRequest = [[NSFetchRequest alloc] initWithEntityName:@"DayEntity"];+ dayFetchRequest.predicate = [NSPredicate predicateWithFormat:@"date == %@", dateParam];- if (error) {- NSLog(@"Failed to fetch DayEntity: %@", error.localizedDescription);- return;- }+ NSArray *fetchedDays = [context executeFetchRequest:dayFetchRequest error:&error];- if (fetchedDays.count == 0) {- NSLog(@"No DayEntity found for date %@",dateParam);- return;- }-- NSManagedObject *dayEntity = fetchedDays.firstObject;- NSOrderedSet *segments = [dayEntity valueForKey:@"segments"];+ if (error) {+ NSLog(@"Failed to fetch DayEntity: %@", error.localizedDescription);+ return;+ }- // Create a temporary array for the segment dictionaries- NSMutableArray *tempSegmentDicts = [NSMutableArray array];+ if (fetchedDays.count == 0) {+ NSLog(@"No DayEntity found for date %@",dateParam);+ return;+ }- for (NSManagedObject *segment in segments) {- NSString *url = [segment valueForKey:@"url"];- double timeStamp = [[segment valueForKey:@"timeStamp"] doubleValue];- double duration = [[segment valueForKey:@"duration"] doubleValue];+ NSManagedObject *dayEntity = fetchedDays.firstObject;+ NSOrderedSet *segments = [dayEntity valueForKey:@"segments"];- NSMutableArray *frameDicts = [NSMutableArray array];+ // Create a temporary array for the segment dictionaries+ NSMutableArray *tempSegmentDicts = [NSMutableArray array];- // Fetch the ordered frames- NSOrderedSet *frames = [segment valueForKey:@"frames"];+ for (NSManagedObject *segment in segments) {+ NSString *url = [segment valueForKey:@"url"];+ double timeStamp = [[segment valueForKey:@"timeStamp"] doubleValue];+ double duration = [[segment valueForKey:@"duration"] doubleValue];- for (NSManagedObject *frame in frames) {- double frameTimeStamp = [[frame valueForKey:@"frame_timeStamp"] doubleValue];- double aspectRatio = [[frame valueForKey:@"aspect_ratio"] doubleValue];- int res = [[frame valueForKey:@"res"] intValue];+ NSMutableArray *frameDicts = [NSMutableArray array];- NSMutableArray *squareDicts = [NSMutableArray array];+ // Fetch the ordered frames+ NSOrderedSet *frames = [segment valueForKey:@"frames"];- // Fetch the ordered squares within this frame- NSOrderedSet *squares = [frame valueForKey:@"squares"];+ for (NSManagedObject *frame in frames) {+ double frameTimeStamp = [[frame valueForKey:@"frame_timeStamp"] doubleValue];+ double aspectRatio = [[frame valueForKey:@"aspect_ratio"] doubleValue];+ int res = [[frame valueForKey:@"res"] intValue];- for (NSManagedObject *square in squares) {- double originX = [[square valueForKey:@"originX"] doubleValue];- double originY = [[square valueForKey:@"originY"] doubleValue];- double bottomRightX = [[square valueForKey:@"bottomRightX"] doubleValue];- double bottomRightY = [[square valueForKey:@"bottomRightY"] doubleValue];- int classIndex = [[square valueForKey:@"classIndex"] intValue];+ NSMutableArray *squareDicts = [NSMutableArray array];- NSDictionary *squareDict = @{- @"originX": @(originX),- @"originY": @(originY),- @"bottomRightX": @(bottomRightX),- @"bottomRightY": @(bottomRightY),- @"classIndex": @(classIndex)- };+ // Fetch the ordered squares within this frame+ NSOrderedSet *squares = [frame valueForKey:@"squares"];- [squareDicts addObject:squareDict];- }+ for (NSManagedObject *square in squares) {+ double originX = [[square valueForKey:@"originX"] doubleValue];+ double originY = [[square valueForKey:@"originY"] doubleValue];+ double bottomRightX = [[square valueForKey:@"bottomRightX"] doubleValue];+ double bottomRightY = [[square valueForKey:@"bottomRightY"] doubleValue];+ int classIndex = [[square valueForKey:@"classIndex"] intValue];- NSDictionary *frameDict = @{- @"frame_timeStamp": @(frameTimeStamp),- @"aspect_ratio": @(aspectRatio),- @"res": @(res),- @"squares": squareDicts+ NSDictionary *squareDict = @{+ @"originX": @(originX),+ @"originY": @(originY),+ @"bottomRightX": @(bottomRightX),+ @"bottomRightY": @(bottomRightY),+ @"classIndex": @(classIndex)};- [frameDicts addObject:frameDict];+ [squareDicts addObject:squareDict];}- NSDictionary *segmentDict = @{- @"url": url,- @"timeStamp": @(timeStamp),- @"duration": @(duration),- @"frames": frameDicts+ NSDictionary *frameDict = @{+ @"frame_timeStamp": @(frameTimeStamp),+ @"aspect_ratio": @(aspectRatio),+ @"res": @(res),+ @"squares": squareDicts};- [tempSegmentDicts addObject:segmentDict];+ [frameDicts addObject:frameDict];}- // Assign tempSegmentDicts to the final array- self.segmentsDict[dateParam] = tempSegmentDicts;+ NSDictionary *segmentDict = @{+ @"url": url,+ @"timeStamp": @(timeStamp),+ @"duration": @(duration),+ @"frames": frameDicts+ };++ [tempSegmentDicts addObject:segmentDict];+ }++ // Assign tempSegmentDicts to the final array+ self.segmentsDict[dateParam] = tempSegmentDicts;- // Log the results- NSLog(@"rory length of init segments = %lu", (unsigned long)tempSegmentDicts.count);- NSLog(@"Fetched and processed %lu segments for date %@", (unsigned long)tempSegmentDicts.count,dateParam);- }];+ // Log the results+ NSLog(@"rory length of init segments = %lu", (unsigned long)tempSegmentDicts.count);+ NSLog(@"Fetched and processed %lu segments for date %@", (unsigned long)tempSegmentDicts.count,dateParam);}- (void)startHTTPServerWithBasePath:(NSString *)basePath {