def load_data(): ''' load data from database and do processing ''' rate_type = RATE_TYPE.USER_RATE.value #rate_value = RATE_VALUE.DISLIKE rate_value = None page = None items, _ = get_items(rate_type=rate_type, rate_value=rate_value, page=page) return items
def test_tagit_all(): rate_type = None rate_value = None page = None items, _ = get_items(rate_type=rate_type, rate_value=rate_value, page=page) for item in items: fanhao = item.fanhao rate_type = RATE_TYPE.USER_RATE rate_value = RATE_VALUE.DISLIKE ItemRate.saveit(rate_type, rate_value, fanhao)
def test_get_items2(): rate_type = None rate_value = None page = None items, page_info = get_items(rate_type=rate_type, rate_value=rate_value, page=page) assert len(items) > 0 print(f'item count:{len(items)}') print( f'total_items: {page_info[0]}, total_page: {page_info[1]}, current_page: {page_info[2]}, page_size:{page_info[3]}' )
def test_get_items(): rate_type = RATE_TYPE.USER_RATE rate_value = RATE_VALUE.LIKE page = None items, page_info = get_items(rate_type=rate_type, rate_value=rate_value, page=page) assert len(items) > 0 print(f'item count:{len(items)}') print( f'total_items: {page_info[0]}, total_page: {page_info[1]}, current_page: {page_info[2]}, page_size:{page_info[3]}' )
def prepare_predict_data(): # get not rated data rate_type = None rate_value = None page = None unrated_items, _ = get_items(rate_type=rate_type, rate_value=rate_value, page=page) #mlb = load_model(get_data_path(MODEL_FILE)) dicts = as_dict(unrated_items) lfw = create_data(dicts) n_samples = lfw.data.shape[0] if n_samples < MIN_TRAIN_NUM: raise ValueError(f'训练数据不足, 无法训练模型. 需要{MIN_TRAIN_NUM}, 当前{n_samples}') return lfw.ids, dimension(lfw.data)
def test_download_items(): rate_type = RATE_TYPE.USER_RATE rate_value = RATE_VALUE.LIKE page = None items, _ = get_items(rate_type=rate_type, rate_value=rate_value, page=page) assert len(items) > 0 try: for item in items: for face in item.faces_dict: if face.value == None: face.value = parse_face(face.url) face = Face.updateit(face) print('update face') except Exception as e: print('system error') traceback.print_exc()
def index(): rate_type = RATE_TYPE.SYSTEM_RATE.value rate_value = int(request.query.get('like', RATE_VALUE.LIKE.value)) page = int(request.query.get('page', 1)) items, page_info = get_items(rate_type=rate_type, rate_value=rate_value, page=page) for item in items: _remove_extra_tags(item) today_update_count = db.get_today_update_count() today_recommend_count = db.get_today_recommend_count() msg = f'今日更新 {today_update_count} , 今日推荐 {today_recommend_count}' return template('index', items=items, page_info=page_info, like=rate_value, path=request.path, msg=msg)
def tagit(): rate_value = request.query.get('like', None) rate_value = None if rate_value == 'None' else rate_value rate_type = None if rate_value: rate_value = int(rate_value) rate_type = RATE_TYPE.USER_RATE page = int(request.query.get('page', 1)) items, page_info = get_items(rate_type=rate_type, rate_value=rate_value, page=page) for item in items: _remove_extra_tags(item) return template('tagit', items=items, page_info=page_info, like=rate_value, path=request.path)
def test_download_face(): rate_type = RATE_TYPE.USER_RATE rate_value = RATE_VALUE.LIKE page = None items, _ = get_items(rate_type=rate_type, rate_value=rate_value, page=page) assert len(items) > 0 item = items[0] face = item.faces_dict[0] face_url = face.url inputImg = url_to_image(face_url) h, w = inputImg.shape[:2] scale = 1 if h > 600 or w > 800: scale = 600 / max(h, w) dims = (int(w * scale), int(h * scale)) interpln = cv2.INTER_LINEAR if scale > 1.0 else cv2.INTER_AREA inputImg = cv2.resize(inputImg, dims, interpolation=interpln) faces = fd.detect_faces_dnn(inputImg) faces