def update_task(): form = request.get_json() bag_list = form['bag_name'] marker = form['marker'] reviewer = form['reviewer'] mark_search = ModelUtil.query_one("User", "user", {'username': marker}) review_search = ModelUtil.query_one("User", "user", {'username': reviewer}) if mark_search is not None and review_search is not None: for bag in bag_list: message = ModelUtil.query_one(db_name, table_name, {'bag_name': bag}) message['marker'] = marker message['reviewer'] = reviewer message['status'] = 1 ModelUtil.update(db_name, table_name, message) mark_search['mark_list'] = list_set(mark_search['mark_list'], bag_list) update_user_data(mark_search) if marker == reviewer: review_search = mark_search review_search['review_list'] = list_set(review_search['review_list'], bag_list) update_user_data(review_search) return json_response_ok('success') else: return json_response_error(401, 'The user is not exist.'), 200
def load_work_list(): anno_dir = './nfs/lidar_data/labeled_data/' for path in os.listdir(anno_dir): subdir = os.path.join(anno_dir, path) if not os.path.exists(subdir) or path.find('lijie') > -1 or path.find('2018-01') > -1: continue bag_name = "bag-" + path.replace('.json', '') update_time = int(os.stat(subdir).st_mtime) create_time = int(os.stat(subdir).st_ctime) find_bag_name = ModelUtil.query_one(db_name, table_name, {"bag_name": bag_name}) if (find_bag_name is not None and find_bag_name['update_time'] != update_time) or find_bag_name is None: box_num = f_workload(subdir, ['0', '0', '0', '0', '0', '150']) box_num = str(int(round(box_num / 3.0, 2))) else: box_num = find_bag_name['box_num'] if find_bag_name is None: item = dict( bag_name=bag_name, box_num=box_num, update_time=update_time, create_time=create_time ) ModelUtil.add(db_name, table_name, item) ModelUtil.create_index(db_name, table_name, ['bag_name', 'box_num']) print('add %s' % item) elif find_bag_name is not None and find_bag_name['box_num'] != box_num: find_bag_name['box_num'] = box_num find_bag_name['update_time'] = update_time ModelUtil.update(db_name, table_name, find_bag_name) print('update: %s' % find_bag_name) update_request_work_time()
def update_user(cls, data): item = ModelUtil.query_one(map_name, table_name, {"id": data['id']}) for k, v in data.items(): if k in item.keys() and v: item[k] = v ModelUtil.update(map_name, table_name, item) item.pop("_id") return item
def get_work_list(): form = request.get_json() start_time = int(form['start_time']) if 'start_time' in form else 180000000 end_time = int(form['end_time']) if 'end_time' in form else 1800000000 marker = form['marker'] now_time = timestamp() last_update_time = ModelUtil.query_one(db_name, time_name, {}, False)['updated_time'] mark_list = ModelUtil.query_one('User', 'user', {"username": marker})['mark_list'] result = [] if mark_list is not None: if now_time - last_update_time >= 2000: load_work_list() lists = ModelUtil.query_many(db_name, table_name, {"update_time": {"$gte": start_time, "$lte": end_time}}) for item in lists: if (marker != '' and item['bag_name'] in mark_list) or marker == '': item.pop('_id') item.pop('deleted') result.append(item) return json_response_ok(result) else: return json_response_error(401, 'The user is not exist.'), 200
def update_request_work_time(): if not ModelUtil.exists(db_name, time_name, {}): ModelUtil.add(db_name, time_name, {'updated_time': timestamp()}) else: time = ModelUtil.query_one(db_name, time_name, {}, False) ModelUtil.update(db_name, time_name, time)
box_num = str(int(round(box_num / 3.0, 2))) else: box_num = find_bag_name['box_num'] if find_bag_name is None: item = dict( bag_name=bag_name, box_num=box_num, update_time=update_time, create_time=create_time ) ModelUtil.add(db_name, table_name, item) ModelUtil.create_index(db_name, table_name, ['bag_name', 'box_num']) print('add %s' % item) elif find_bag_name is not None and find_bag_name['box_num'] != box_num: find_bag_name['box_num'] = box_num find_bag_name['update_time'] = update_time ModelUtil.update(db_name, table_name, find_bag_name) print('update: %s' % find_bag_name) update_request_work_time() def update_request_work_time(): if not ModelUtil.exists(db_name, time_name, {}): ModelUtil.add(db_name, time_name, {'updated_time': timestamp()}) else: time = ModelUtil.query_one(db_name, time_name, {}, False) ModelUtil.update(db_name, time_name, time) if ModelUtil.query_one(db_name, table_name, {}, False) is None: update_request_work_time()
def get_user_message(conditions, many=False): if many: return ModelUtil.query_many(db_name, table_name, conditions) else: return ModelUtil.query_one(db_name, table_name, conditions)