# %% folder = r'\\192.168.1.242\ftp\hummingbird\2021\08\\08' import os dest_path = r'C:\\Users\\TheBears\\Desktop\\' files = os.listdir(folder) import numpy as np f_jsons = list() for f in files: if f.endswith('.json'): f_jsons.append(os.path.join(folder,f)) import json import datetime as dt def get_obs_in_json(curr_js): all_obs = list() curf = os.path.basename(curr_js) curf = curf.split('.')[0].replace('_trimmed','').split('_')[-1] dt_obj = dt.datetime.strptime(curf, '%Y%m%d%H%M%S') with open(curr_js,'r') as ff: data = json.load(ff) for i in data: test_field = 'frame_number_original' if test_field in i: sec_offset = i[test_field]/30 else: sec_offset = i['frame_number'] if sec_offset == 'thumbnail': continue if len(i['boxes']) > 0: obs = [dt_obj + dt.timedelta(seconds=sec_offset/2), max(i['scores'])] all_obs.append(obs) cob = all_obs ret_this = [] if len(cob) > 0: tie = np.asarray([x[0].timestamp() for x in cob]) tavg = dt.datetime.fromtimestamp(int(np.average(tie))) scavg = np.max([x[1] for x in cob]) ret_this = [tavg, scavg] return all_obs, ret_this entire_obs = list() obs_sep = list() obs_fnames = list() for curr_js in f_jsons: cc, avgg = get_obs_in_json(curr_js) if len(avgg) > 0: obs_sep.append(avgg) obs_fnames.append(curr_js.replace('.json','.mp4')) entire_obs.extend(cc) def scatter_dt(entire_obs, fname, hover_data = None): import numpy as np obs_array = np.asarray(entire_obs) x = np.asarray(obs_array[:,0], dtype=np.datetime64) y = obs_array[:,1] import plotly.express as px #fig = px.scatter(x = x,y = y, hovertext=obs_fnames) import plotly.graph_objects as go fig = go.Figure() fig.add_trace(go.Scatter( x=x, y=y, hovertext=hover_data, hoverinfo="text", marker=dict( color="green" ), mode='markers', showlegend=False )) fig.write_html(os.path.join(dest_path,fname)) scatter_dt(entire_obs, 'hbirds.html') scatter_dt(obs_sep, 'indiv.html', hover_data = obs_fnames) import plotly.express as px scores = np.asarray([x[1] for x in obs_sep]) scors= np.sort(scores) cumu_total = len(scores) - np.arange(0,len(scores)) fig = px.scatter( x= scors, y = cumu_total) fig.write_html(os.path.join(dest_path, 'cumul.html')) # %%