Skip to content

Add object detection, tracking, mobile notifications, and search to any security camera.

log all changes

roryclear35a302179e62
diff --git a/clearcam/SceneState.m b/clearcam/SceneState.m
index 732e73c..dc2695a 100644
--- a/clearcam/SceneState.m
+++ b/clearcam/SceneState.m
@@ -32,39 +32,30 @@
frameValue = self.lastN[0][self.events[i][0]] ?: @0;
self.lastN_total[self.events[i][0]] = @(totalValue.intValue - frameValue.intValue);
}
-
- //NSLog(@"rory event %d = %@",i,self.events[i][0]);
- //NSLog(@"rory event total = %@",self.lastN_total[self.events[i][0]]);
-
int current_state = (int)roundf((self.lastN_total[self.events[i][0]] ? [self.lastN_total[self.events[i][0]] floatValue] : 0.0) / 10.0);
- //NSLog(@"rory current state = %d", current_state);
if(!self.lastN_state[self.events[i][0]]){
self.lastN_state[self.events[i][0]] = 0;
}
if(current_state != [self.lastN_state[self.events[i][0]] intValue]){
- if(current_state > [self.lastN_state[self.events[i][0]] intValue]){
- NSLog(@"INCREASE");
- if(current_state >= [self.events[i][1] intValue]){
- //todo, move elsewhere
- NSLog(@"event threshold");
- // Get the path to the documents directory
- NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
- NSString *documentsDirectory = [paths firstObject];
- NSString *filePath = [documentsDirectory stringByAppendingPathComponent:@"events.txt"];
-
- NSFileManager *fileManager = [NSFileManager defaultManager];
- if (![fileManager fileExistsAtPath:filePath]) {
- [fileManager createFileAtPath:filePath contents:nil attributes:nil];
- }
- NSString *timestamp = [[NSDate date] description];
- NSString *contentToWrite = [NSString stringWithFormat:@"%@ %@ x%@\n", timestamp, self.events[i][0],@(current_state)];
- NSFileHandle *fileHandle = [NSFileHandle fileHandleForWritingAtPath:filePath];
- [fileHandle seekToEndOfFile];
- [fileHandle writeData:[contentToWrite dataUsingEncoding:NSUTF8StringEncoding]];
- [fileHandle closeFile];
- }
+ NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
+ NSString *documentsDirectory = [paths firstObject];
+ NSString *filePath = [documentsDirectory stringByAppendingPathComponent:@"events.txt"];
+
+ NSFileManager *fileManager = [NSFileManager defaultManager];
+ if (![fileManager fileExistsAtPath:filePath]) {
+ [fileManager createFileAtPath:filePath contents:nil attributes:nil];
}
+
+ NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
+ [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
+ NSString *timestamp = [dateFormatter stringFromDate:[NSDate date]];
+
+ NSString *contentToWrite = [NSString stringWithFormat:@"%@ class: %@ x%@\n", timestamp, self.events[i][0], @(current_state)];
+ NSFileHandle *fileHandle = [NSFileHandle fileHandleForWritingAtPath:filePath];
+ [fileHandle seekToEndOfFile];
+ [fileHandle writeData:[contentToWrite dataUsingEncoding:NSUTF8StringEncoding]];
+ [fileHandle closeFile];
self.lastN_state[self.events[i][0]] = @(current_state);
}
@@ -72,32 +63,5 @@
if(self.lastN.count > 10){
[self.lastN removeObjectAtIndex:0];
}
-
- return;
}
-
-- (void)writeToFileWithString:(NSString *)customString { //todo
- NSString *filePath = [NSHomeDirectory() stringByAppendingPathComponent:@"events.txt"];
- NSFileManager *fileManager = [NSFileManager defaultManager];
-
- // Check if file exists
- if (![fileManager fileExistsAtPath:filePath]) {
- // Create file if it doesn't exist
- [fileManager createFileAtPath:filePath contents:nil attributes:nil];
- }
-
- // Get the current timestamp
- NSString *timestamp = [[NSDate date] description];
-
- // Create the string to be written
- NSString *contentToWrite = [NSString stringWithFormat:@"%@ %@\n", timestamp, customString];
-
- // Write the content to the file
- NSFileHandle *fileHandle = [NSFileHandle fileHandleForWritingAtPath:filePath];
- [fileHandle seekToEndOfFile];
- [fileHandle writeData:[contentToWrite dataUsingEncoding:NSUTF8StringEncoding]];
- [fileHandle closeFile];
-}
-
@end
-