Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
ydl_ai_recommender
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
闫发泽
ydl_ai_recommender
Commits
6fe86fc6
Commit
6fe86fc6
authored
May 18, 2023
by
王金柱
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
精排序
parent
2af6c8c1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
0 additions
and
58 deletions
+0
-58
recommend_service.py
src/service/recommend_service.py
+0
-58
No files found.
src/service/recommend_service.py
View file @
6fe86fc6
...
...
@@ -16,7 +16,6 @@ from ydl_ai_recommender.src.core.recommender import UserCFRecommender
logger
=
create_logger
(
__name__
,
'service.log'
,
is_rotating
=
True
)
recommender
=
UserCFRecommender
(
top_n
=
2
,
k
=
50
,
u2c
=
'order'
)
recommenderByXgb
=
RecommendByXgboost
()
class
RecommendHandler
(
tornado
.
web
.
RequestHandler
):
executor
=
ThreadPoolExecutor
(
1
)
...
...
@@ -74,63 +73,6 @@ class RecommendHandler(tornado.web.RequestHandler):
logger
.
info
(
'response@@uid=
%
s@@ret=
%
s'
,
uid
,
ret_str
)
return
ret
class
RecommendXgbHandler
(
tornado
.
web
.
RequestHandler
):
executor
=
ThreadPoolExecutor
(
1
)
@tornado.gen.coroutine
def
get
(
self
):
uid
=
self
.
get_argument
(
'uid'
,
None
)
if
uid
is
None
:
logger
.
warn
(
'请求参数不正确,无uid'
)
size
=
self
.
get_argument
(
'size'
,
100
)
try
:
size
=
int
(
size
)
except
Exception
as
e
:
logger
.
warn
(
'size=
%
s 不是数字'
,
size
)
size
=
100
ret
=
yield
self
.
run
(
uid
,
size
)
self
.
write
(
ret
)
@tornado.gen.coroutine
def
post
(
self
):
param
=
json
.
loads
(
self
.
request
.
body
.
decode
(
'utf-8'
))
uid
=
param
.
get
(
'uid'
,
None
)
size
=
param
.
get
(
'size'
,
100
)
if
uid
is
None
:
logger
.
warn
(
'请求参数不正确,无uid'
)
ret
=
yield
self
.
run
(
uid
,
size
)
self
.
write
(
ret
)
@run_on_executor
def
run
(
self
,
uid
,
size
=
100
):
logger
.
info
(
'request@@uid=
%
s@@size=
%
s'
,
uid
,
size
)
try
:
start_time
=
time
.
time
()
recommend_result
=
recommenderByXgb
.
recommend
(
uid
,
size
=
size
,
is_merge
=
True
)
logger
.
info
(
'request@@uid=
%
s@@size=
%
s, cost
%
s ms'
,
uid
,
size
,
(
time
.
time
()
-
start_time
)
*
1000
)
ret
=
{
'status'
:
'success'
,
'code'
:
0
,
'data'
:
recommend_result
,
'total_count'
:
len
(
recommend_result
),
}
except
Exception
as
e
:
logger
.
error
(
'执行推荐函数报错'
,
exc_info
=
True
)
ret
=
{
'status'
:
'error'
,
'code'
:
1
,
'data'
:
[],
'total_count'
:
0
,
}
ret_str
=
json
.
dumps
(
ret
,
ensure_ascii
=
False
)
logger
.
info
(
'response@@uid=
%
s@@ret=
%
s'
,
uid
,
ret_str
)
return
ret
if
__name__
==
'__main__'
:
tornado
.
options
.
define
(
'port'
,
default
=
8868
,
type
=
int
,
help
=
'服务启动的端口号'
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment