63 lines
1.2 KiB
Python
63 lines
1.2 KiB
Python
import json
|
|
import shutil
|
|
import os
|
|
source_path = '/srv/ftp/hummingbird/2021'
|
|
#target_path = '/home/thebears/Videos/ftp'
|
|
target_path = '/home/thebears/ftp_links'
|
|
|
|
|
|
|
|
have_json = set()
|
|
for di, _, fns in os.walk(source_path):
|
|
for fn in fns:
|
|
if fn.endswith('.json'):
|
|
have_json.add(os.path.join(di, fn))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
do_stop = False
|
|
fracs = dict()
|
|
|
|
for c_js in have_json:
|
|
hits = 0
|
|
total = 0
|
|
o = json.load(open(c_js,'r'))
|
|
for i in o:
|
|
total += 1
|
|
# if len([x for x in i['scores'] if x > 0.1]) > 0:
|
|
if len(i['boxes']) > 0:
|
|
hits += 1
|
|
|
|
fracs[c_js] = [hits, total]
|
|
|
|
|
|
if do_stop:
|
|
break
|
|
|
|
|
|
|
|
ratios = dict()
|
|
for x,y in fracs.items():
|
|
ratios[x] = y[0]/y[1]
|
|
# %%
|
|
import math
|
|
dir_created = set()
|
|
for fname, ratio in ratios.items():
|
|
cr = math.floor(ratio * 10)/10
|
|
target_dir = os.path.join(target_path, str(cr))
|
|
if not os.path.exists(target_dir) and target_dir not in dir_created:
|
|
os.mkdir(target_dir)
|
|
dir_created.add(target_dir)
|
|
else:
|
|
dir_created.add(target_dir)
|
|
|
|
|
|
|
|
source_file = fname.replace('.json','.mp4')
|
|
target_file = os.path.join(target_dir, os.path.basename(source_file))
|
|
|
|
os.symlink(source_file, target_file)
|