def processFilelistFolder(doOverall): for flfolder in FOLDERS_FILELIST: # eg [['data2015filetl.json','filelist2015gfs1/']] storage = flfolder.pop(0) #find out the year: year = '2015' if '2014' in storage: year = '2014' folder = flfolder.pop(0) base = os.path.splitext( storage )[0] for i in range(3,-1,-1): filter = TARCAMFILTER + str(i) #eg Cam_0 storageFile = base+filter+'.json' files = os.listdir(folder) files.sort() timeline = [] tt = timelineTools.timelineTools() if not os.path.isfile(storageFile): for f in [x for x in files if os.path.splitext( x )[1] == FILETYPE]: timeline = timeline + tt.checkFile(filter, folder + f) with open(storageFile, 'wb') as output: tl = json.dumps(timeline) output.write(tl) else: with open(storageFile, 'rb') as input: tl = input.read() timeline = json.loads(tl) #for x in timeline: # print x, datetime.datetime.fromtimestamp(int(x)).strftime('%Y-%m-%d %H:%M:%S') timeline = tt.deleteMidnightGapsAndZeroGaps(timeline) timeline = tt.fixtl(timeline, []) bukits = tt.splitTl(timeline) if doOverall==1: outfile = base + filter + '_overall.html' tt.tablefy([timeline], 'Overall season '+year+', by files',outfile,'',MAINTENANCE) else: outfile = base + filter + '_daily.html' tt.tablefy(bukits, '',outfile, 'Daily timelines of '+year+', by files',MAINTENANCE)
def compare(fileA, fileB): ftl = [] vtl = [] with open(fileA, 'rb') as input: tl = input.read() ftl = json.loads(tl) with open(fileB, 'rb') as input: tl = input.read() vtl = json.loads(tl) tt = timelineTools.timelineTools() ftl = tt.deleteMidnightGapsAndZeroGaps(ftl) vtl = tt.deleteMidnightGapsAndZeroGaps(vtl) #convrtz vrt to a touple list to iterate it more easily. vtl2 = [] while len(vtl)>0: a = vtl.pop(0) b = vtl.pop(0) vtl2.append([a,b]) while len(ftl)>0: a = ftl.pop(0) b = ftl.pop(0) match = 0 for v in vtl2: if a == v[0] and b == v[1]: print 'match: ' +datetime.datetime.fromtimestamp(int(a)).strftime('%Y-%m-%d %H:%M:%S') \ + ' TO '+ datetime.datetime.fromtimestamp(int(b)).strftime('%Y-%m-%d %H:%M:%S') match = 1 elif a == v[0] or b == v[1]: print 'partial match: '+datetime.datetime.fromtimestamp(int(a)).strftime('%Y-%m-%d %H:%M:%S') \ + ' TO ' +datetime.datetime.fromtimestamp(int(b)).strftime('%Y-%m-%d %H:%M:%S') \ + ' and ' + datetime.datetime.fromtimestamp(int(v[0])).strftime('%Y-%m-%d %H:%M:%S') \ + ' TO ' +datetime.datetime.fromtimestamp(int(v[1])).strftime('%Y-%m-%d %H:%M:%S') match = 2 if match == 0: print 'no match: ' +datetime.datetime.fromtimestamp(int(a)).strftime('%Y-%m-%d %H:%M:%S') \ + ' TO ' +datetime.datetime.fromtimestamp(int(b)).strftime('%Y-%m-%d %H:%M:%S')
def processVideos(doOverall): for folder in FOLDERS: timeline = [] tt = timelineTools.timelineTools() STORAGE_VIDEOTL = folder.pop(0) #find out the year: year = '2015' if '2014' in STORAGE_VIDEOTL: year = '2014' if not os.path.isfile(STORAGE_VIDEOTL): for f in folder: #print "Analyzing folder: " + f timeline = tt.processVideoFolder(f,timeline) with open(STORAGE_VIDEOTL, 'wb') as output: tl = json.dumps(timeline) output.write(tl) output.write('\n') else: with open(STORAGE_VIDEOTL, 'rb') as input: tl = input.read() timeline = json.loads(tl) timeline = tt.fixtl(timeline,[]) bukits = tt.splitTl(timeline) base = os.path.splitext( STORAGE_VIDEOTL )[0] if doOverall==1: outfile = base + '_overall.html' tt.tablefy([timeline], 'Overall season '+year+', by videos', outfile,'',MAINTENANCE) else: outfile = base + '_daily.html' tt.tablefy(bukits, '', outfile, 'Daily timelines of '+year+', by videos',MAINTENANCE)