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
c83f87aa
Commit
c83f87aa
authored
Jan 10, 2023
by
柴鹏飞
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
优化查询sql
parent
3e0d2dec
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
23 additions
and
4 deletions
+23
-4
profile_manager.py
src/core/manager/profile_manager.py
+8
-1
recommender.py
src/core/recommender.py
+8
-1
mysql_client.py
src/data/mysql_client.py
+7
-2
No files found.
src/core/manager/profile_manager.py
View file @
c83f87aa
...
@@ -18,6 +18,13 @@ class ProfileManager(DatabaseDataManager):
...
@@ -18,6 +18,13 @@ class ProfileManager(DatabaseDataManager):
def
__init__
(
self
,
client
=
None
)
->
None
:
def
__init__
(
self
,
client
=
None
)
->
None
:
super
()
.
__init__
(
client
,
create_logger
(
__name__
,
'profile_manager.log'
))
super
()
.
__init__
(
client
,
create_logger
(
__name__
,
'profile_manager.log'
))
self
.
select_items_str
=
', '
.
join
([
'uid'
,
'country_code'
,
'channel_id_type'
,
'ffrom_login'
,
'user_preference_cate'
,
'consult_pay_money'
,
'listen_pay_money'
,
'test_items_pay_money'
,
'course_pay_money'
,
'consult_order_num'
,
'listen_order_num'
,
'test_items_order_num'
,
'course_order_num'
,
'aidi_cst_bias_city'
,
'aidi_cst_bias_sex'
,
'aidi_cst_bias_price'
,
'aidi_cst_bias_server_type'
,
'user_login_city'
,
'd30_inquire_order_num'
,
'd30_session_num'
,
])
def
_make_query_sql
(
self
,
conditions
=
None
):
def
_make_query_sql
(
self
,
conditions
=
None
):
...
@@ -25,7 +32,7 @@ class ProfileManager(DatabaseDataManager):
...
@@ -25,7 +32,7 @@ class ProfileManager(DatabaseDataManager):
if
conditions
:
if
conditions
:
condition_sql
=
' WHERE '
+
' AND '
.
join
(
conditions
)
condition_sql
=
' WHERE '
+
' AND '
.
join
(
conditions
)
sql
=
'SELECT
* FROM ads.ads_register_user_profiles'
sql
=
'SELECT
{} FROM ads.ads_register_user_profiles'
.
format
(
self
.
select_items_str
)
sql
+=
' WHERE uid IN (SELECT DISTINCT uid FROM ods.ods_ydl_standard_order{})'
.
format
(
condition_sql
)
sql
+=
' WHERE uid IN (SELECT DISTINCT uid FROM ods.ods_ydl_standard_order{})'
.
format
(
condition_sql
)
return
sql
return
sql
...
...
src/core/recommender.py
View file @
c83f87aa
...
@@ -50,6 +50,13 @@ class UserCFRecommender(Recommender):
...
@@ -50,6 +50,13 @@ class UserCFRecommender(Recommender):
c2c: [咨询师->咨询师] 索引方法,None 表示不使用咨询师拓展
c2c: [咨询师->咨询师] 索引方法,None 表示不使用咨询师拓展
"""
"""
super
()
.
__init__
()
super
()
.
__init__
()
self
.
select_items_str
=
', '
.
join
([
'uid'
,
'country_code'
,
'channel_id_type'
,
'ffrom_login'
,
'user_preference_cate'
,
'consult_pay_money'
,
'listen_pay_money'
,
'test_items_pay_money'
,
'course_pay_money'
,
'consult_order_num'
,
'listen_order_num'
,
'test_items_order_num'
,
'course_order_num'
,
'aidi_cst_bias_city'
,
'aidi_cst_bias_sex'
,
'aidi_cst_bias_price'
,
'aidi_cst_bias_server_type'
,
'user_login_city'
,
'd30_inquire_order_num'
,
'd30_session_num'
,
])
# 召回 top_n 个相似用户
# 召回 top_n 个相似用户
self
.
top_n
=
top_n
self
.
top_n
=
top_n
# 每个召回的用户取 k 个相关咨询师
# 每个召回的用户取 k 个相关咨询师
...
@@ -100,7 +107,7 @@ class UserCFRecommender(Recommender):
...
@@ -100,7 +107,7 @@ class UserCFRecommender(Recommender):
if
user_id
==
'0'
:
if
user_id
==
'0'
:
return
[]
return
[]
sql
=
'SELECT
* FROM ads.ads_register_user_profiles'
sql
=
'SELECT
{} FROM ads.ads_register_user_profiles'
.
format
(
self
.
select_items_str
)
sql
+=
' WHERE uid={}'
.
format
(
user_id
)
sql
+=
' WHERE uid={}'
.
format
(
user_id
)
try
:
try
:
_
,
all_data
=
self
.
client
.
query
(
sql
)
_
,
all_data
=
self
.
client
.
query
(
sql
)
...
...
src/data/mysql_client.py
View file @
c83f87aa
# -*- coding: utf-8 -*-
# -*- coding: utf-8 -*-
import
time
import
configparser
import
configparser
import
pymysql
import
pymysql
...
@@ -30,10 +31,12 @@ class MySQLClient():
...
@@ -30,10 +31,12 @@ class MySQLClient():
def
query
(
self
,
sql
):
def
query
(
self
,
sql
):
# sql += ' limit 1000'
# sql += ' limit 1000'
st
=
time
.
time
()
self
.
logger
.
debug
(
'begin execute sql:
%
s'
,
sql
)
self
.
logger
.
debug
(
'begin execute sql:
%
s'
,
sql
)
row_count
=
self
.
cursor
.
execute
(
sql
)
row_count
=
self
.
cursor
.
execute
(
sql
)
data
=
self
.
cursor
.
fetchall
()
data
=
self
.
cursor
.
fetchall
()
self
.
logger
.
debug
(
'fetch row count:
%
s'
,
row_count
)
cost_time
=
time
.
time
()
-
st
self
.
logger
.
debug
(
'fetch row count:
%
s, cost time
%
s'
,
row_count
,
cost_time
)
return
row_count
,
data
return
row_count
,
data
...
@@ -96,12 +99,14 @@ class MySQLClientPool():
...
@@ -96,12 +99,14 @@ class MySQLClientPool():
def
query
(
self
,
sql
,
args
=
None
):
def
query
(
self
,
sql
,
args
=
None
):
# sql += ' limit 1000'
# sql += ' limit 1000'
st
=
time
.
time
()
self
.
logger
.
debug
(
'begin execute sql:
%
s'
,
sql
)
self
.
logger
.
debug
(
'begin execute sql:
%
s'
,
sql
)
conn
,
cur
=
self
.
open
()
conn
,
cur
=
self
.
open
()
row_count
=
cur
.
execute
(
sql
,
args
)
row_count
=
cur
.
execute
(
sql
,
args
)
data
=
cur
.
fetchall
()
data
=
cur
.
fetchall
()
self
.
close
(
conn
,
cur
)
self
.
close
(
conn
,
cur
)
self
.
logger
.
debug
(
'fetch row count:
%
s'
,
row_count
)
cost_time
=
time
.
time
()
-
st
self
.
logger
.
debug
(
'fetch row count:
%
s, cost time
%
s'
,
row_count
,
cost_time
)
return
row_count
,
data
return
row_count
,
data
@classmethod
@classmethod
...
...
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