def stat(): df = read(queries.stats) df.columns = [column.upper() for column in df.columns] df = df[df.CATEGORY != 'miscellaneous'] df['CATEGORY'] = [item.upper() for item in df['CATEGORY']] df['SUBCATEGORY'] = [item.capitalize() for item in df['SUBCATEGORY']] df = df.pivot_table( index=['CATEGORY', 'SUBCATEGORY'], margins=True, margins_name='======= TOTAL =======', # defaults to 'All' aggfunc=sum) return render_template( 'stats.html', tables=[df.to_html(table_id='stats', classes='data', header="true")])
def make_dataset_1(path): data = read(queries.select_dataset) with open(os.path.join(path, 'label.csv'), 'w') as f: for idx, item in tqdm(data.iterrows()): filename = "%08d" % item['id'] + '.obj' if os.path.isfile(item['file']): copyfile(item['file'], os.path.join(path, filename)) item['subcategory'] = item['subcategory'] if item[ 'category'] else 'null' f.write(','.join([ filename, 'null', purify(item['category']), purify(item['subcategory']) ]) + '\n') else: print(filename, item['id'])
def get_zip(id): obj_path = read(queries.select_object_by_id.format(id=id))['file'][0] zip_path = obj_path.replace('.obj', 'zip') with ZipFile(zip_path, 'w') as zip: zip.write(obj_path) @after_this_request def remove_zipfile(response): try: os.remove(zip_path) except Exception as e: print(e) return response return send_from_directory(os.path.dirname(zip_path), os.path.basename(zip_path))
def make_dataset_2(path, categories=None): data = read(queries.select_dataset) if categories: data = data[data['category'].isin(categories)] eval_portion = 0.1 test_portion = 0.2 data['subcategory'] = [ item if item else data.loc[idx, 'category'] for idx, item in enumerate(data['subcategory']) ] subcategories = list(set(data['subcategory'].tolist())) f_train = open(os.path.join(path, 'train.csv'), 'w') f_test = open(os.path.join(path, 'test.csv'), 'w') f_eval = open(os.path.join(path, 'eval.csv'), 'w') for subcategory in tqdm(subcategories): if subcategory == 'None': continue subcat_set = data[data['subcategory'] == subcategory] subcat_set = shuffle(subcat_set) num_subcat_set = len(subcat_set) num_subset_eval_set = int(num_subcat_set * eval_portion) num_subset_test_set = int(num_subcat_set * test_portion) if num_subset_eval_set < 3: continue for idx, (_, item) in enumerate(subcat_set.iterrows()): filename = "%08d" % item['id'] + '.obj' item['subcategory'] = purify(item['subcategory']) item['category'] = purify(item['category']) if idx < num_subset_eval_set: data_type = 'eval' file = f_eval elif idx < num_subset_eval_set + num_subset_test_set: data_type = 'test' file = f_test else: data_type = 'train' file = f_train dst_path = os.path.join(path, data_type, item['subcategory']) make_dir(dst_path) obj_file = os.path.join(dst_path, filename) copyfile(item['file'], obj_file) normalized_mesh = normalize_mesh(obj_file) with open(obj_file, 'w') as f: f.write(normalized_mesh) file.write(','.join( [filename, 'null', item['category'], item['subcategory']]) + '\n') f_test.close() f_train.close() f_eval.close()
def get_keywords(): return read(queries.select_keywords)
def update_thumbnail(): agent.read('select * from ')
def is_model(cadid): return not agent.read( f"SELECT * from cad_file WHERE source=2 and source_id='{cadid}'").empty
def get_img(id): img_path = read(queries.select_object_by_id.format(id=id))['image'][0] return send_from_directory(os.path.dirname(img_path), os.path.basename(img_path))
def get_obj(id): obj_path = read(queries.select_object_by_id.format(id=id))['file'][0] return send_from_directory(os.path.dirname(obj_path), os.path.basename(obj_path))
def get_miscellaneous(): return read("SELECT * FROM keyword WHERE parent=214")
def get_subcategory(parent): return read(queries.select_category.format(parent=parent))
def get_dataset(): return read(queries.select_taxonomy)
def get_category(): return read(queries.select_category.format(parent=0))
def get_unlabeled_imgs(): return read(queries.select_unlabeled)
def get_keyword_id(keyword): return read(f"SELECT * from keyword where name = '{keyword}'")['id'][0]
def get_exist_files(output_dir): return agent.read(queries.check_trace_part_data.format(file=output_dir))['name'].to_list()
def get_cad_imgs(label, cad_type): return read(queries.select_images.format(label=label, cad_type=cad_type))