Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
P
physical
Project
Project
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
alpha
physical
Commits
75a8b0bf
Commit
75a8b0bf
authored
Feb 12, 2019
by
段英荣
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'only_no_see' into 'master'
Only no see See merge request
!106
parents
8b4823e2
d6089859
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
87 additions
and
7 deletions
+87
-7
topic.py
search/utils/topic.py
+13
-5
trans2es_data2es_parallel.py
trans2es/management/commands/trans2es_data2es_parallel.py
+74
-2
No files found.
search/utils/topic.py
View file @
75a8b0bf
...
...
@@ -93,7 +93,7 @@ class TopicUtils(object):
return
[]
@classmethod
def
get_recommend_topic_ids
(
cls
,
user_id
,
offset
,
size
,
query
=
None
,
query_type
=
TopicPageType
.
FIND_PAGE
,
filter_topic_id_list
=
[]):
def
get_recommend_topic_ids
(
cls
,
user_id
,
offset
,
size
,
query
=
None
,
query_type
=
TopicPageType
.
FIND_PAGE
,
filter_topic_id_list
=
[]
,
test_score
=
False
):
"""
:需增加打散逻辑
:remark:获取首页推荐帖子列表
...
...
@@ -254,11 +254,19 @@ class TopicUtils(object):
result_dict
=
ESPerform
.
get_search_results
(
ESPerform
.
get_cli
(),
sub_index_name
=
"topic"
,
query_body
=
q
,
offset
=
offset
,
size
=
size
)
topic_id_dict
=
dict
()
for
item
in
result_dict
[
"hits"
]:
topic_id_dict
[
item
[
"_source"
][
"id"
]]
=
[
item
[
"_source"
][
"group_id"
],
item
[
"_source"
][
"user_id"
]]
if
not
test_score
:
topic_id_dict
=
dict
()
for
item
in
result_dict
[
"hits"
]:
topic_id_dict
[
item
[
"_source"
][
"id"
]]
=
[
item
[
"_source"
][
"group_id"
],
item
[
"_source"
][
"user_id"
]]
return
topic_id_dict
else
:
topic_id_dict
=
dict
()
for
item
in
result_dict
[
"hits"
]:
topic_id_dict
[
item
[
"_source"
][
"id"
]]
=
[
item
[
"_source"
][
"group_id"
],
item
[
"_source"
][
"user_id"
],
item
[
"_score"
]]
return
topic_id_dict
return
topic_id_dict
except
:
logging
.
error
(
"catch exception,err_msg:
%
s"
%
traceback
.
format_exc
())
return
dict
()
...
...
trans2es/management/commands/trans2es_data2es_parallel.py
View file @
75a8b0bf
...
...
@@ -19,6 +19,13 @@ from libs.cache import redis_client
from
trans2es.models.face_user_contrast_similar
import
FaceUserContrastSimilar
import
json
from
search.utils.topic
import
TopicUtils
from
trans2es.models.pick_topic
import
PickTopic
from
trans2es.models.tag
import
TopicTag
,
Tag
from
trans2es.models.user_extra
import
UserExtra
from
trans2es.models.group
import
Group
from
trans2es.models.topic
import
Topic
,
ActionSumAboutTopic
class
Job
(
object
):
__es
=
None
...
...
@@ -97,7 +104,9 @@ class Command(BaseCommand):
make_option
(
'-s'
,
'--pks'
,
dest
=
'pks'
,
help
=
'specify sync pks, comma separated'
,
metavar
=
'PKS'
,
default
=
''
),
make_option
(
'--streaming-slicing'
,
dest
=
'streaming_slicing'
,
action
=
'store_true'
,
default
=
True
),
make_option
(
'--no-streaming-slicing'
,
dest
=
'streaming_slicing'
,
action
=
'store_false'
,
default
=
True
),
make_option
(
'-S'
,
'--sync_type'
,
dest
=
'sync_type'
,
help
=
'sync data to es'
,
metavar
=
'TYPE'
,
default
=
''
)
make_option
(
'-S'
,
'--sync_type'
,
dest
=
'sync_type'
,
help
=
'sync data to es'
,
metavar
=
'TYPE'
,
default
=
''
),
make_option
(
'-T'
,
'--test_score'
,
dest
=
'test_score'
,
help
=
'test_score'
,
metavar
=
'TYPE'
,
default
=
''
)
)
def
__sync_data_by_type
(
self
,
type_name
):
...
...
@@ -116,6 +125,68 @@ class Command(BaseCommand):
except
:
logging
.
error
(
"catch exception,err_msg:
%
s"
%
traceback
.
format_exc
())
def
generate_topic_score_detail
(
self
):
try
:
topic_id_dict
=
TopicUtils
.
get_recommend_topic_ids
(
-
1
,
0
,
500
,
test_score
=
True
)
for
topic_id
in
topic_id_dict
:
offline_score
=
0.0
user_is_shadow
=
False
topic_sql_item
=
Topic
.
objects
.
filter
(
id
=
topic_id
)
user_is_recommend
=
0.0
# 是否官方推荐用户
user_query_results
=
UserExtra
.
objects
.
filter
(
user_id
=
topic_sql_item
[
0
]
.
user_id
)
if
user_query_results
.
count
()
>
0
:
if
user_query_results
[
0
]
.
is_recommend
:
offline_score
+=
2.0
user_is_recommend
=
2.0
elif
user_query_results
[
0
]
.
is_shadow
:
user_is_shadow
=
True
group_is_recommend
=
0.0
# 是否官方推荐小组
if
topic_sql_item
[
0
]
.
group
and
topic_sql_item
[
0
]
.
group
.
is_recommend
:
offline_score
+=
4.0
group_is_recommend
=
4.0
topic_level_score
=
0.0
# 帖子等级
if
topic_sql_item
[
0
]
.
content_level
==
'5'
:
offline_score
+=
5.0
topic_level_score
=
5.0
elif
topic_sql_item
[
0
]
.
content_level
==
'4'
:
offline_score
+=
3.0
topic_level_score
=
3.0
elif
topic_sql_item
[
0
]
.
content_level
==
'3'
:
offline_score
+=
2.0
topic_level_score
=
2.0
exposure_count
=
ActionSumAboutTopic
.
objects
.
filter
(
topic_id
=
topic_id
,
data_type
=
1
)
.
count
()
click_count
=
ActionSumAboutTopic
.
objects
.
filter
(
topic_id
=
topic_id
,
data_type
=
2
)
.
count
()
uv_num
=
ActionSumAboutTopic
.
objects
.
filter
(
topic_id
=
topic_id
,
data_type
=
3
)
.
count
()
exposure_score
=
0.0
uv_score
=
0.0
if
exposure_count
>
0
:
offline_score
+=
click_count
/
exposure_count
exposure_score
=
click_count
/
exposure_count
if
uv_num
>
0
:
offline_score
+=
(
topic_sql_item
[
0
]
.
vote_num
/
uv_num
+
topic_sql_item
[
0
]
.
reply_num
/
uv_num
)
uv_score
=
(
topic_sql_item
[
0
]
.
vote_num
/
uv_num
+
topic_sql_item
[
0
]
.
reply_num
/
uv_num
)
"""
1:马甲账号是否对总分降权?
"""
if
user_is_shadow
:
offline_score
=
offline_score
*
0.5
logging
.
info
(
"test_score######score:
%
f,offline_score:
%
f,user_is_recommend:
%
f,group_is_recommend:
%
f,topic_level_score:
%
f,exposure_score:
%
f,uv_score:
%
f"
%
(
topic_id_dict
[
topic_id
][
2
],
offline_score
,
user_is_recommend
,
group_is_recommend
,
topic_level_score
,
exposure_score
,
uv_score
))
except
:
logging
.
error
(
"catch exception,err_msg:
%
s"
%
traceback
.
format_exc
())
def
handle
(
self
,
*
args
,
**
options
):
try
:
type_name_list
=
get_type_info_map
()
.
keys
()
...
...
@@ -129,6 +200,7 @@ class Command(BaseCommand):
if
len
(
options
[
"sync_type"
])
and
options
[
"sync_type"
]
==
"sync_data_to_es"
:
SyncDataToRedis
.
sync_face_similar_data_to_redis
()
if
len
(
options
[
"test_score"
]):
self
.
generate_topic_score_detail
()
except
:
logging
.
error
(
"catch exception,err_msg:
%
s"
%
traceback
.
format_exc
())
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