def view_user_delete(user_id): user_message = get_user_message({"id": user_id}) if user_message is None: return json_response_error(401, 'The user is not exist.'), 200 else : ModelUtil.hard_delete(db_name, table_name, {"id": user_id}) return json_response_ok('success')
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 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 view_user_create(): form = request.get_json() user_message = get_user_message({"username": form["username"]}) if user_message is None: form['mark_list'] = [] form['review_list'] = [] ModelUtil.add(db_name, table_name, form) return json_response_ok('success') else: return json_response_error(403, 'The username is exist.'), 200
def load_task_list(): anno_dir = './nfs/lidar_data/raw_data/' for path in os.listdir(anno_dir): item = { "marker": '', "reviewer": '', "bag_name": "bag-" + path.replace('.bag', ''), "status": 0 } if ModelUtil.exists(db_name, table_name, {"bag_name": "bag-" + path.replace('.bag', '')}): continue ModelUtil.add(db_name, table_name, item) ModelUtil.create_index(db_name, table_name, ['bag_name']) print('update done')
def view_user_update(user_id): form = request.get_json() user_message = get_user_message({"id": user_id}) user_error = get_user_message({"username": form["username"]}) if user_message is None: return json_response_error(401, 'The user is not exist.'), 200 elif user_error is not None: return json_response_error(403, 'The user is exist.'), 200 else: user_message["id"] = user_id user_message['username'] = form['username'] user_message['password'] = form['password'] user_message['role'] = form['role'] user_message['remark'] = form['remark'] if 'remark' in form else user_message['remark'] ModelUtil.update(db_name, table_name, user_message) return json_response_ok('success')
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 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 get_task_list(): result = [] conditions = {} args = request.get_json() if args.get('start_time'): conditions["updated_time"] = {"$gte": int(args.get('start_time'))} if args.get('end_time'): conditions["updated_time"] = {"$lte": int(args.get('end_time'))} if args.get('start_time') and args.get('end_time'): conditions["updated_time"] = { "$gte": int(args.get('start_time')), "$lte": int(args.get('end_time')) } if args.get('bag_name'): conditions["bag_name"] = args.get('bag_name') if args.get('marker'): conditions["marker"] = args.get('marker') if args.get('reviewer'): conditions["reviewer"] = args.get('reviewer') lists = ModelUtil.query_many(db_name, table_name, conditions) for item in lists: item.pop('_id') result.append(item) return json_response_ok(result)
def delete_user(cls, id): item = ModelUtil.delete(map_name, table_name, {"id": id}) return item
def update_user_data(item): ModelUtil.update("User", "user", item)
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 create_user(cls, data): u = list(ModelUtil.query_many(map_name, table_name)) data['id'] = int(u[len(u) - 1]['id']) + 1 item = ModelUtil.create(map_name, table_name, data) item.pop("_id") return item
def get_user(cls, id): conditions = {"id": id} if id else None s = ModelUtil.query_many(map_name, table_name, conditions, {'_id': 0}) return s
form = request.get_json() user_message = get_user_message({ "username": form["username"], "password": form["password"] }) if user_message is None: return json_response_error(402, 'The username or password is error.'), 200 else: register_login(user_message) user_message.pop("_id") return json_response_ok(user_message) @user.route('/logout/', methods=['POST']) @login_required def view_logout(): logout_user() return json_response_ok('success') if __name__ == "__main__": item = {} item["username"] = "******" item["password"] = "******" item["mark_list"] = [] item["review_list"] = [] item["role"] = 1 item["remark"] = 1 ModelUtil.add(db_name, table_name, item)
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)