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
fe5b73b7
Commit
fe5b73b7
authored
Mar 21, 2019
by
lixiaofang
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'huabao' into test
parents
095c5750
b6b3c0d6
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
17 changed files
with
321 additions
and
115 deletions
+321
-115
workspace.xml
.idea/workspace.xml
+0
-0
group.py
search/utils/group.py
+16
-15
topic.py
search/utils/topic.py
+16
-15
group.py
search/views/group.py
+17
-17
topic.py
search/views/topic.py
+2
-2
trans2es_data2es_parallel.py
trans2es/management/commands/trans2es_data2es_parallel.py
+0
-1
pictorial.json
trans2es/mapping/pictorial.json
+18
-0
user.json
trans2es/mapping/user.json
+17
-3
group.py
trans2es/models/group.py
+9
-9
pictorial.py
trans2es/models/pictorial.py
+76
-14
topic.py
trans2es/models/topic.py
+36
-15
user.py
trans2es/models/user.py
+37
-14
type_info.py
trans2es/type_info.py
+14
-1
group_transfer.py
trans2es/utils/group_transfer.py
+1
-1
pictorial_transfer.py
trans2es/utils/pictorial_transfer.py
+40
-0
topic_transfer.py
trans2es/utils/topic_transfer.py
+8
-4
user_transfer.py
trans2es/utils/user_transfer.py
+14
-4
No files found.
.idea/workspace.xml
View file @
fe5b73b7
This diff is collapsed.
Click to expand it.
search/utils/group.py
View file @
fe5b73b7
...
@@ -47,7 +47,7 @@ class GroupUtils(object):
...
@@ -47,7 +47,7 @@ class GroupUtils(object):
return
{
"total_count"
:
0
,
"hits"
:[]}
return
{
"total_count"
:
0
,
"hits"
:[]}
@classmethod
@classmethod
def
get_hot_
group
_recommend_result_list
(
cls
,
offset
,
size
,
es_cli_obj
=
None
):
def
get_hot_
pictorial
_recommend_result_list
(
cls
,
offset
,
size
,
es_cli_obj
=
None
):
try
:
try
:
if
not
es_cli_obj
:
if
not
es_cli_obj
:
es_cli_obj
=
ESPerform
.
get_cli
()
es_cli_obj
=
ESPerform
.
get_cli
()
...
@@ -68,19 +68,19 @@ class GroupUtils(object):
...
@@ -68,19 +68,19 @@ class GroupUtils(object):
"includes"
:[
"id"
]
"includes"
:[
"id"
]
}
}
result_dict
=
ESPerform
.
get_search_results
(
es_cli_obj
,
"
group
"
,
q
,
offset
,
size
)
result_dict
=
ESPerform
.
get_search_results
(
es_cli_obj
,
"
pictorial
"
,
q
,
offset
,
size
)
group
_ids_list
=
[]
pictorial
_ids_list
=
[]
if
len
(
result_dict
[
"hits"
])
>
0
:
if
len
(
result_dict
[
"hits"
])
>
0
:
group
_ids_list
=
[
item
[
"_source"
][
"id"
]
for
item
in
result_dict
[
"hits"
]]
pictorial
_ids_list
=
[
item
[
"_source"
][
"id"
]
for
item
in
result_dict
[
"hits"
]]
return
group
_ids_list
return
pictorial
_ids_list
except
:
except
:
logging
.
error
(
"catch exception,err_msg:
%
s"
%
traceback
.
format_exc
())
logging
.
error
(
"catch exception,err_msg:
%
s"
%
traceback
.
format_exc
())
return
[]
return
[]
@classmethod
@classmethod
def
get_user_attention_
group
_list
(
cls
,
user_id
,
offset
=
0
,
size
=
10
,
es_cli_obj
=
None
):
def
get_user_attention_
pictorial
_list
(
cls
,
user_id
,
offset
=
0
,
size
=
10
,
es_cli_obj
=
None
):
"""
"""
:remark: 获取用户关注小组列表
:remark: 获取用户关注小组列表
:return:
:return:
...
@@ -100,12 +100,12 @@ class GroupUtils(object):
...
@@ -100,12 +100,12 @@ class GroupUtils(object):
}
}
}
}
q
[
"_source"
]
=
{
q
[
"_source"
]
=
{
"includes"
:[
"attention_
group
_id_list"
]
"includes"
:[
"attention_
pictorial
_id_list"
]
}
}
result_dict
=
ESPerform
.
get_search_results
(
es_cli_obj
,
"user"
,
q
,
offset
,
size
)
result_dict
=
ESPerform
.
get_search_results
(
es_cli_obj
,
"user"
,
q
,
offset
,
size
)
if
len
(
result_dict
[
"hits"
])
>
0
:
if
len
(
result_dict
[
"hits"
])
>
0
:
return
result_dict
[
"hits"
][
0
][
"_source"
][
"attention_
group
_id_list"
]
return
result_dict
[
"hits"
][
0
][
"_source"
][
"attention_
pictorial
_id_list"
]
else
:
else
:
return
[]
return
[]
except
:
except
:
...
@@ -113,7 +113,7 @@ class GroupUtils(object):
...
@@ -113,7 +113,7 @@ class GroupUtils(object):
return
[]
return
[]
@classmethod
@classmethod
def
get_
group_ids_by_aggs
(
cls
,
group_id
_list
,
es_cli_obj
=
None
):
def
get_
pictorial_ids_by_aggs
(
cls
,
pictorial_ids
_list
,
es_cli_obj
=
None
):
"""
"""
:remark:聚合查询获取小组列表
:remark:聚合查询获取小组列表
:param group_id_list:
:param group_id_list:
...
@@ -127,13 +127,13 @@ class GroupUtils(object):
...
@@ -127,13 +127,13 @@ class GroupUtils(object):
q
[
"size"
]
=
0
q
[
"size"
]
=
0
q
[
"query"
]
=
{
q
[
"query"
]
=
{
"terms"
:{
"terms"
:{
"
group_id"
:
group_id
_list
"
pictorial_id"
:
pictorial_ids
_list
}
}
}
}
q
[
"aggs"
]
=
{
q
[
"aggs"
]
=
{
"
group
_ids"
:{
"
pictorial
_ids"
:{
"terms"
:{
"terms"
:{
"field"
:
"
group
_id"
"field"
:
"
pictorial
_id"
},
},
"aggs"
:{
"aggs"
:{
"max_date"
:{
"max_date"
:{
...
@@ -146,12 +146,12 @@ class GroupUtils(object):
...
@@ -146,12 +146,12 @@ class GroupUtils(object):
}
}
result_dict
=
ESPerform
.
get_search_results
(
es_cli_obj
,
"topic"
,
q
,
aggregations_query
=
True
)
result_dict
=
ESPerform
.
get_search_results
(
es_cli_obj
,
"topic"
,
q
,
aggregations_query
=
True
)
buckets_list
=
result_dict
[
"aggregations"
][
"
group
_ids"
][
"buckets"
]
buckets_list
=
result_dict
[
"aggregations"
][
"
pictorial
_ids"
][
"buckets"
]
sorted_buckets_list
=
sorted
(
buckets_list
,
key
=
lambda
item
:
item
[
"max_date"
][
"value"
],
reverse
=
True
)
sorted_buckets_list
=
sorted
(
buckets_list
,
key
=
lambda
item
:
item
[
"max_date"
][
"value"
],
reverse
=
True
)
sorted_
group
_id_list
=
[
item
[
"key"
]
for
item
in
sorted_buckets_list
]
sorted_
pictorial
_id_list
=
[
item
[
"key"
]
for
item
in
sorted_buckets_list
]
return
sorted_
group
_id_list
return
sorted_
pictorial
_id_list
except
:
except
:
logging
.
error
(
"catch exception,err_msg:
%
s"
%
traceback
.
format_exc
())
logging
.
error
(
"catch exception,err_msg:
%
s"
%
traceback
.
format_exc
())
return
[]
return
[]
\ No newline at end of file
search/utils/topic.py
View file @
fe5b73b7
...
@@ -32,7 +32,7 @@ class TopicUtils(object):
...
@@ -32,7 +32,7 @@ class TopicUtils(object):
}
}
}
}
q
[
"_source"
]
=
[
"tag_list"
,
"attention_user_id_list"
,
"pick_user_id_list"
,
"same_
group
_user_id_list"
]
q
[
"_source"
]
=
[
"tag_list"
,
"attention_user_id_list"
,
"pick_user_id_list"
,
"same_
pictorial
_user_id_list"
]
result_dict
=
ESPerform
.
get_search_results
(
ESPerform
.
get_cli
(),
"user"
,
q
,
offset
,
size
)
result_dict
=
ESPerform
.
get_search_results
(
ESPerform
.
get_cli
(),
"user"
,
q
,
offset
,
size
)
...
@@ -101,7 +101,7 @@ class TopicUtils(object):
...
@@ -101,7 +101,7 @@ class TopicUtils(object):
}
}
},
},
"_source"
:{
"_source"
:{
"includes"
:
[
"id"
,
"
group
_id"
,
"offline_score"
,
"user_id"
,
"edit_tag_list"
]
"includes"
:
[
"id"
,
"
pictorial
_id"
,
"offline_score"
,
"user_id"
,
"edit_tag_list"
]
}
}
}
}
result_dict
=
ESPerform
.
get_search_results
(
ESPerform
.
get_cli
(),
sub_index_name
=
"topic"
,
query_body
=
q
,
result_dict
=
ESPerform
.
get_search_results
(
ESPerform
.
get_cli
(),
sub_index_name
=
"topic"
,
query_body
=
q
,
...
@@ -135,7 +135,7 @@ class TopicUtils(object):
...
@@ -135,7 +135,7 @@ class TopicUtils(object):
try
:
try
:
attention_user_id_list
=
list
()
attention_user_id_list
=
list
()
pick_user_id_list
=
list
()
pick_user_id_list
=
list
()
same_
group
_id_list
=
list
()
same_
pictorial
_id_list
=
list
()
user_tag_list
=
list
()
user_tag_list
=
list
()
result_dict
=
TopicUtils
.
get_related_user_info
(
user_id
,
0
,
1
)
result_dict
=
TopicUtils
.
get_related_user_info
(
user_id
,
0
,
1
)
...
@@ -148,12 +148,13 @@ class TopicUtils(object):
...
@@ -148,12 +148,13 @@ class TopicUtils(object):
pick_user_info_list
=
result_dict
[
"hits"
][
0
][
"_source"
][
"pick_user_id_list"
]
pick_user_info_list
=
result_dict
[
"hits"
][
0
][
"_source"
][
"pick_user_id_list"
]
pick_user_id_list
=
[
item
[
"user_id"
]
for
item
in
pick_user_info_list
]
pick_user_id_list
=
[
item
[
"user_id"
]
for
item
in
pick_user_info_list
]
same_
group_user_info_list
=
result_dict
[
"hits"
][
0
][
"_source"
][
"same_group
_user_id_list"
]
same_
pictorial_user_info_list
=
result_dict
[
"hits"
][
0
][
"_source"
][
"same_pictorial
_user_id_list"
]
same_
group_id_list
=
[
item
[
"user_id"
]
for
item
in
same_group
_user_info_list
]
same_
pictorial_id_list
=
[
item
[
"user_id"
]
for
item
in
same_pictorial
_user_info_list
]
same_
group_id_list
=
same_group
_id_list
[:
100
]
same_
pictorial_id_list
=
same_pictorial
_id_list
[:
100
]
user_tag_list
=
result_dict
[
"hits"
][
0
][
"_source"
][
"tag_list"
]
user_tag_list
=
result_dict
[
"hits"
][
0
][
"_source"
][
"tag_list"
]
logging
.
info
(
"get same_pictorial_id_list :
%
s"
%
same_pictorial_id_list
)
q
=
dict
()
q
=
dict
()
q
[
"query"
]
=
dict
()
q
[
"query"
]
=
dict
()
...
@@ -204,11 +205,11 @@ class TopicUtils(object):
...
@@ -204,11 +205,11 @@ class TopicUtils(object):
"weight"
:
2
"weight"
:
2
}
}
)
)
if
len
(
same_
group
_id_list
)
>
0
:
if
len
(
same_
pictorial
_id_list
)
>
0
:
functions_list
.
append
(
functions_list
.
append
(
{
{
"filter"
:
{
"bool"
:
{
"filter"
:
{
"bool"
:
{
"should"
:
{
"terms"
:{
"user_id"
:
same_
group
_id_list
}}}},
"should"
:
{
"terms"
:{
"user_id"
:
same_
pictorial
_id_list
}}}},
"weight"
:
1
"weight"
:
1
}
}
)
)
...
@@ -304,7 +305,7 @@ class TopicUtils(object):
...
@@ -304,7 +305,7 @@ class TopicUtils(object):
"field"
:
"user_id"
"field"
:
"user_id"
}
}
q
[
"_source"
]
=
{
q
[
"_source"
]
=
{
"includes"
:[
"id"
,
"
group
_id"
,
"offline_score"
,
"user_id"
,
"edit_tag_list"
]
"includes"
:[
"id"
,
"
pictorial
_id"
,
"offline_score"
,
"user_id"
,
"edit_tag_list"
]
}
}
q
[
"sort"
]
=
[
q
[
"sort"
]
=
[
{
{
...
@@ -325,7 +326,7 @@ class TopicUtils(object):
...
@@ -325,7 +326,7 @@ class TopicUtils(object):
offset
=
offset
,
size
=
size
)
offset
=
offset
,
size
=
size
)
topic_id_list
=
list
()
topic_id_list
=
list
()
same_
group
_id_set
=
set
()
same_
pictorial
_id_set
=
set
()
same_user_id_set
=
set
()
same_user_id_set
=
set
()
for
item
in
result_dict
[
"hits"
]:
for
item
in
result_dict
[
"hits"
]:
...
@@ -362,7 +363,7 @@ class TopicUtils(object):
...
@@ -362,7 +363,7 @@ class TopicUtils(object):
return
list
()
return
list
()
@classmethod
@classmethod
def
get_topic_detail_recommend_list
(
cls
,
user_id
,
topic_id
,
topic_tag_list
,
topic_
group
_id
,
topic_user_id
,
filter_topic_user_id
,
have_read_topic_list
,
offset
,
size
,
es_cli_obj
=
None
):
def
get_topic_detail_recommend_list
(
cls
,
user_id
,
topic_id
,
topic_tag_list
,
topic_
pictorial
_id
,
topic_user_id
,
filter_topic_user_id
,
have_read_topic_list
,
offset
,
size
,
es_cli_obj
=
None
):
"""
"""
:remark 帖子详情页推荐列表,缺少按时间衰减
:remark 帖子详情页推荐列表,缺少按时间衰减
:param user_id:
:param user_id:
...
@@ -395,11 +396,11 @@ class TopicUtils(object):
...
@@ -395,11 +396,11 @@ class TopicUtils(object):
}
}
}
}
]
]
if
isinstance
(
topic_
group_id
,
int
)
and
topic_group
_id
>
0
:
if
isinstance
(
topic_
pictorial_id
,
int
)
and
topic_pictorial
_id
>
0
:
functions_list
.
append
(
functions_list
.
append
(
{
{
"filter"
:
{
"term"
:
{
"filter"
:
{
"term"
:
{
"
group_id"
:
topic_group
_id
}},
"
pictorial_id"
:
topic_pictorial
_id
}},
"weight"
:
1
,
"weight"
:
1
,
}
}
)
)
...
@@ -435,7 +436,7 @@ class TopicUtils(object):
...
@@ -435,7 +436,7 @@ class TopicUtils(object):
}
}
q
[
"query"
][
"function_score"
]
=
query_function_score
q
[
"query"
][
"function_score"
]
=
query_function_score
q
[
"_source"
]
=
{
q
[
"_source"
]
=
{
"includes"
:[
"id"
,
"
group
_id"
,
"user_id"
,
"_score"
]
"includes"
:[
"id"
,
"
pictorial
_id"
,
"user_id"
,
"_score"
]
}
}
result_dict
=
ESPerform
.
get_search_results
(
es_cli_obj
,
sub_index_name
=
"topic"
,
query_body
=
q
,
result_dict
=
ESPerform
.
get_search_results
(
es_cli_obj
,
sub_index_name
=
"topic"
,
query_body
=
q
,
...
@@ -547,7 +548,7 @@ class TopicUtils(object):
...
@@ -547,7 +548,7 @@ class TopicUtils(object):
"function_score"
:
query_function_score
"function_score"
:
query_function_score
}
}
q
[
"_source"
]
=
{
q
[
"_source"
]
=
{
"includes"
:[
"id"
,
"
group
_id"
,
"user_id"
,
"_score"
,
"offline_score"
,
"manual_score"
]
"includes"
:[
"id"
,
"
pictorial
_id"
,
"user_id"
,
"_score"
,
"offline_score"
,
"manual_score"
]
}
}
q
[
"sort"
]
=
[
q
[
"sort"
]
=
[
{
{
...
...
search/views/group.py
View file @
fe5b73b7
...
@@ -12,7 +12,7 @@ from search.utils.common import GroupSortTypes
...
@@ -12,7 +12,7 @@ from search.utils.common import GroupSortTypes
from
libs.es
import
ESPerform
from
libs.es
import
ESPerform
@bind
(
"physical/search/query_
group
"
)
@bind
(
"physical/search/query_
pictorial
"
)
def
query_group
(
query
=
""
,
offset
=
0
,
size
=
10
):
def
query_group
(
query
=
""
,
offset
=
0
,
size
=
10
):
"""
"""
:remark:小组搜索排序策略,缺少排序策略
:remark:小组搜索排序策略,缺少排序策略
...
@@ -33,8 +33,8 @@ def query_group(query="",offset=0,size=10):
...
@@ -33,8 +33,8 @@ def query_group(query="",offset=0,size=10):
logging
.
error
(
"catch exception,err_msg:
%
s"
%
traceback
.
format_exc
())
logging
.
error
(
"catch exception,err_msg:
%
s"
%
traceback
.
format_exc
())
return
{
"group_ids"
:[]}
return
{
"group_ids"
:[]}
@bind
(
"physical/search/
group
_sort"
)
@bind
(
"physical/search/
pictorial
_sort"
)
def
group
_sort
(
user_id
=-
1
,
sort_type
=
GroupSortTypes
.
HOT_RECOMMEND
,
offset
=
0
,
size
=
10
):
def
pictorial
_sort
(
user_id
=-
1
,
sort_type
=
GroupSortTypes
.
HOT_RECOMMEND
,
offset
=
0
,
size
=
10
):
"""
"""
:remark 小组排序,缺少:前1天发评论人数*x
:remark 小组排序,缺少:前1天发评论人数*x
:param user_id:
:param user_id:
...
@@ -51,27 +51,27 @@ def group_sort(user_id=-1,sort_type=GroupSortTypes.HOT_RECOMMEND,offset=0,size=1
...
@@ -51,27 +51,27 @@ def group_sort(user_id=-1,sort_type=GroupSortTypes.HOT_RECOMMEND,offset=0,size=1
es_cli_obj
=
ESPerform
.
get_cli
()
es_cli_obj
=
ESPerform
.
get_cli
()
if
sort_type
==
GroupSortTypes
.
HOT_RECOMMEND
:
if
sort_type
==
GroupSortTypes
.
HOT_RECOMMEND
:
group_ids_list
=
GroupUtils
.
get_hot_group
_recommend_result_list
(
offset
,
size
,
es_cli_obj
)
pictorial_ids_list
=
GroupUtils
.
get_hot_pictorial
_recommend_result_list
(
offset
,
size
,
es_cli_obj
)
return
{
"
group_recommend_ids"
:
group
_ids_list
}
return
{
"
pictorial_recommend_ids"
:
pictorial
_ids_list
}
elif
sort_type
==
GroupSortTypes
.
ATTENTION_RECOMMEND
:
elif
sort_type
==
GroupSortTypes
.
ATTENTION_RECOMMEND
:
attention_
group_list
=
GroupUtils
.
get_user_attention_group
_list
(
user_id
,
offset
=
0
,
size
=
1
,
es_cli_obj
=
es_cli_obj
)
attention_
pictorial_list
=
GroupUtils
.
get_user_attention_pictorial
_list
(
user_id
,
offset
=
0
,
size
=
1
,
es_cli_obj
=
es_cli_obj
)
if
len
(
attention_
group
_list
)
==
0
:
if
len
(
attention_
pictorial
_list
)
==
0
:
return
{
"
group
_recommend_ids"
:
[]}
return
{
"
pictorial
_recommend_ids"
:
[]}
else
:
else
:
attention_
group_id_list
=
[
item
[
"group_id"
]
for
item
in
attention_group
_list
]
attention_
pictorial_id_list
=
[
item
[
"pictorial_id"
]
for
item
in
attention_pictorial
_list
]
sorted_
group_ids_list
=
GroupUtils
.
get_group_ids_by_aggs
(
attention_group
_id_list
,
es_cli_obj
)
sorted_
pictorial_ids_list
=
GroupUtils
.
get_pictorial_ids_by_aggs
(
attention_pictorial
_id_list
,
es_cli_obj
)
group_recommend_ids_list
=
sorted_group
_ids_list
pictorial_recommend_ids_list
=
sorted_pictorial
_ids_list
#if len(group_recommend_ids_list) < size and len(group_recommend_ids_list)<len(attention_group_list):
#if len(group_recommend_ids_list) < size and len(group_recommend_ids_list)<len(attention_group_list):
sorted_attention_
group_list
=
sorted
(
attention_group
_list
,
key
=
lambda
item
:
item
[
"update_time_val"
],
reverse
=
True
)
sorted_attention_
pictorial_list
=
sorted
(
attention_pictorial
_list
,
key
=
lambda
item
:
item
[
"update_time_val"
],
reverse
=
True
)
for
item
in
sorted_attention_
group
_list
:
for
item
in
sorted_attention_
pictorial
_list
:
if
item
[
"
group_id"
]
not
in
group
_recommend_ids_list
:
if
item
[
"
pictorial_id"
]
not
in
pictorial
_recommend_ids_list
:
group_recommend_ids_list
.
append
(
item
[
"group
_id"
])
pictorial_recommend_ids_list
.
append
(
item
[
"pictorial
_id"
])
return
{
"
group_recommend_ids"
:
group
_recommend_ids_list
[
offset
:(
offset
+
size
)]}
return
{
"
pictorial_recommend_ids"
:
pictorial
_recommend_ids_list
[
offset
:(
offset
+
size
)]}
except
:
except
:
logging
.
error
(
"catch exception,err_msg:
%
s"
%
traceback
.
format_exc
())
logging
.
error
(
"catch exception,err_msg:
%
s"
%
traceback
.
format_exc
())
return
{
"
group
_recommend_ids"
:[]}
return
{
"
pictorial
_recommend_ids"
:[]}
search/views/topic.py
View file @
fe5b73b7
...
@@ -225,7 +225,7 @@ def home_query(device_id="", tag_id=-1, user_id=-1, query="", offset=0, size=10)
...
@@ -225,7 +225,7 @@ def home_query(device_id="", tag_id=-1, user_id=-1, query="", offset=0, size=10)
@bind
(
"physical/search/topic_detail_page_recommend"
)
@bind
(
"physical/search/topic_detail_page_recommend"
)
def
topic_detail_page_recommend
(
device_id
=
""
,
user_id
=-
1
,
topic_id
=-
1
,
topic_
group
_id
=-
1
,
topic_user_id
=-
1
,
def
topic_detail_page_recommend
(
device_id
=
""
,
user_id
=-
1
,
topic_id
=-
1
,
topic_
pictorial
_id
=-
1
,
topic_user_id
=-
1
,
filter_topic_user_id
=
False
,
offset
=
0
,
size
=
10
):
filter_topic_user_id
=
False
,
offset
=
0
,
size
=
10
):
"""
"""
:remark:帖子详情页推荐策略,缺少第一个卡片策略
:remark:帖子详情页推荐策略,缺少第一个卡片策略
...
@@ -249,7 +249,7 @@ def topic_detail_page_recommend(device_id="", user_id=-1, topic_id=-1, topic_gro
...
@@ -249,7 +249,7 @@ def topic_detail_page_recommend(device_id="", user_id=-1, topic_id=-1, topic_gro
# 获取帖子标签列表
# 获取帖子标签列表
topic_tag_list
=
TopicUtils
.
get_topic_tag_id_list
(
topic_id
,
es_cli_obj
)
topic_tag_list
=
TopicUtils
.
get_topic_tag_id_list
(
topic_id
,
es_cli_obj
)
result_list
=
TopicUtils
.
get_topic_detail_recommend_list
(
user_id
,
topic_id
,
topic_tag_list
,
topic_
group
_id
,
result_list
=
TopicUtils
.
get_topic_detail_recommend_list
(
user_id
,
topic_id
,
topic_tag_list
,
topic_
pictorial
_id
,
topic_user_id
,
filter_topic_user_id
,
topic_user_id
,
filter_topic_user_id
,
have_read_topic_list
,
offset
,
size
,
es_cli_obj
)
have_read_topic_list
,
offset
,
size
,
es_cli_obj
)
recommend_topic_ids_list
=
list
()
recommend_topic_ids_list
=
list
()
...
...
trans2es/management/commands/trans2es_data2es_parallel.py
View file @
fe5b73b7
...
@@ -49,7 +49,6 @@ class Job(object):
...
@@ -49,7 +49,6 @@ class Job(object):
def
__call__
(
self
):
def
__call__
(
self
):
type_info
=
get_type_info_map
()[
self
.
_type_name
]
type_info
=
get_type_info_map
()[
self
.
_type_name
]
assert
isinstance
(
type_info
,
TypeInfo
)
assert
isinstance
(
type_info
,
TypeInfo
)
result
=
type_info
.
insert_table_chunk
(
result
=
type_info
.
insert_table_chunk
(
sub_index_name
=
self
.
_sub_index_name
,
sub_index_name
=
self
.
_sub_index_name
,
table_chunk
=
self
.
_chunk
,
table_chunk
=
self
.
_chunk
,
...
...
trans2es/mapping/pictorial.json
0 → 100644
View file @
fe5b73b7
{
"dynamic"
:
"strict"
,
"properties"
:
{
"id"
:{
"type"
:
"long"
},
"is_online"
:{
"type"
:
"boolean"
},
//上线
"is_deleted"
:{
"type"
:
"boolean"
},
"is_recommend"
:{
"type"
:
"boolean"
},
"name"
:{
"type"
:
"text"
,
"analyzer"
:
"gm_default_index"
,
"search_analyzer"
:
"gm_default_index"
},
"description"
:{
"type"
:
"text"
,
"analyzer"
:
"gm_default_index"
,
"search_analyzer"
:
"gm_default_index"
},
"topic_num"
:{
"type"
:
"long"
},
"creator_id"
:{
"type"
:
"long"
},
"icon"
:{
"type"
:
"text"
},
"high_quality_topic_num"
:{
"type"
:
"long"
},
//前一天该小组
4
&
5
星帖子数量
"create_time"
:{
"type"
:
"date"
,
"format"
:
"date_time_no_millis"
},
"update_time"
:{
"type"
:
"date"
,
"format"
:
"date_time_no_millis"
}
}
}
\ No newline at end of file
trans2es/mapping/user.json
View file @
fe5b73b7
...
@@ -28,17 +28,31 @@
...
@@ -28,17 +28,31 @@
"country_id"
:{
"type"
:
"text"
}
"country_id"
:{
"type"
:
"text"
}
}
}
},
},
"same_group_user_id_list"
:{
//同组用户列表
//
"same_group_user_id_list"
:{
//同组用户列表
//
"type"
:
"nested"
,
//
"properties"
:{
//
"user_id"
:{
"type"
:
"long"
},
//
"country_id"
:{
"type"
:
"text"
}
//
}
//
},
//
"attention_group_id_list"
:{
//关注小组列表
//
"type"
:
"nested"
,
//
"properties"
:{
//
"group_id"
:{
"type"
:
"long"
},
//
"update_time_val"
:{
"type"
:
"long"
}
//
}
//
},
"same_pictorial_user_id_list"
:{
//同画报用户列表
"type"
:
"nested"
,
"type"
:
"nested"
,
"properties"
:{
"properties"
:{
"user_id"
:{
"type"
:
"long"
},
"user_id"
:{
"type"
:
"long"
},
"country_id"
:{
"type"
:
"text"
}
"country_id"
:{
"type"
:
"text"
}
}
}
},
},
"attention_
group_id_list"
:{
//关注小组
列表
"attention_
pictorial_id_list"
:{
//关注画报
列表
"type"
:
"nested"
,
"type"
:
"nested"
,
"properties"
:{
"properties"
:{
"
group
_id"
:{
"type"
:
"long"
},
"
pictorial
_id"
:{
"type"
:
"long"
},
"update_time_val"
:{
"type"
:
"long"
}
"update_time_val"
:{
"type"
:
"long"
}
}
}
},
},
...
...
trans2es/models/group.py
View file @
fe5b73b7
...
@@ -27,15 +27,15 @@ class Group(models.Model):
...
@@ -27,15 +27,15 @@ class Group(models.Model):
create_time
=
models
.
DateTimeField
(
verbose_name
=
u'创建时间'
,
default
=
datetime
.
datetime
.
fromtimestamp
(
0
))
create_time
=
models
.
DateTimeField
(
verbose_name
=
u'创建时间'
,
default
=
datetime
.
datetime
.
fromtimestamp
(
0
))
update_time
=
models
.
DateTimeField
(
verbose_name
=
u'更新时间'
,
default
=
datetime
.
datetime
.
fromtimestamp
(
0
))
update_time
=
models
.
DateTimeField
(
verbose_name
=
u'更新时间'
,
default
=
datetime
.
datetime
.
fromtimestamp
(
0
))
#获取前一天4,5星发帖数
#
#
获取前一天4,5星发帖数
def
get_high_quality_topic_num
(
self
):
#
def get_high_quality_topic_num(self):
yesterday
=
datetime
.
datetime
.
now
()
-
datetime
.
timedelta
(
days
=
1
)
#
yesterday = datetime.datetime.now()-datetime.timedelta(days=1)
yesterday_begin_time
=
"
%
s-
%
s-
%
s 00:00:00"
%
(
yesterday
.
year
,
yesterday
.
month
,
yesterday
.
day
)
#
yesterday_begin_time = "%s-%s-%s 00:00:00" % (yesterday.year, yesterday.month, yesterday.day)
yesterday_end_time
=
"
%
s-
%
s-
%
s 23:59:59"
%
(
yesterday
.
year
,
yesterday
.
month
,
yesterday
.
day
)
#
yesterday_end_time = "%s-%s-%s 23:59:59" % (yesterday.year, yesterday.month, yesterday.day)
#
topic_num
=
self
.
group_topics
.
filter
(
content_level__in
=
(
"4"
,
"5"
),
create_time__gte
=
yesterday_begin_time
,
create_time__lte
=
yesterday_end_time
)
.
count
()
#
topic_num = self.group_topics.filter(content_level__in=("4","5"),create_time__gte=yesterday_begin_time,create_time__lte=yesterday_end_time).count()
#
return
topic_num
#
return topic_num
def
detail
(
self
):
def
detail
(
self
):
result
=
{
result
=
{
...
...
trans2es/models/pictorial.py
View file @
fe5b73b7
# from django.db import models
from
django.db
import
models
import
datetime
import
logging
import
traceback
# from .topic import Topic
class
PictorialTopic
(
models
.
Model
):
"""画报帖子关系"""
# class PictorialTopic(models.Model):
class
Meta
:
# """画报帖子关系"""
verbose_name
=
u'画报帖子关系'
app_label
=
'community'
db_table
=
'community_pictorial_topic'
# class Meta:
id
=
models
.
IntegerField
(
verbose_name
=
u'日记ID'
,
primary_key
=
True
)
# verbose_name = u'画报帖子关系'
pictorial_id
=
models
.
BigIntegerField
(
verbose_name
=
u'画报ID'
)
# app_label = 'community'
topic_id
=
models
.
BigIntegerField
(
verbose_name
=
u'帖子ID'
)
# db_table = 'community_pictorial_topic'
is_online
=
models
.
BooleanField
(
verbose_name
=
u"是否有效"
,
default
=
True
)
is_online
=
models
.
BooleanField
(
verbose_name
=
u'是否上线'
)
is_deleted
=
models
.
BooleanField
(
verbose_name
=
u'是否删除'
)
# id = models.IntegerField(verbose_name=u'日记ID', primary_key=True)
# pictorial_id = models.BigIntegerField(verbose_name=u'画报ID')
class
PictorialFollow
(
models
.
Model
):
# topic_id = models.BigIntegerField(verbose_name=u'帖子ID')
"""画报关注"""
# user_id = models.BigIntegerField(verbose_name=u'用户ID')
# is_online = models.BooleanField(verbose_name=u"是否有效", default=True)
class
Meta
:
# is_online = models.BooleanField(verbose_name=u'是否上线')
verbose_name
=
u"画报用户关系"
# is_deleted = models.BooleanField(verbose_name=u'是否删除')
app_label
=
"community"
db_table
=
"community_pictorial_follow"
id
=
models
.
IntegerField
(
verbose_name
=
u'关注ID'
,
primary_key
=
True
)
create_time
=
models
.
DateTimeField
(
verbose_name
=
u'创建时间'
,
default
=
datetime
.
datetime
.
fromtimestamp
(
0
))
update_time
=
models
.
DateTimeField
(
verbose_name
=
u'更新时间'
,
default
=
datetime
.
datetime
.
fromtimestamp
(
0
))
is_online
=
models
.
BooleanField
(
verbose_name
=
u'是否上线'
)
is_deleted
=
models
.
BooleanField
(
verbose_name
=
u'是否删除'
)
pictorial_id
=
models
.
BigIntegerField
(
verbose_name
=
u'画报ID'
)
user_id
=
models
.
BigIntegerField
(
verbose_name
=
u'用户ID'
)
class
Pictorial
(
models
.
Model
):
"""画报关注"""
class
Meta
:
verbose_name
=
u"画报"
app_label
=
"community"
db_table
=
"community_pictorial"
id
=
models
.
IntegerField
(
verbose_name
=
u'关注ID'
,
primary_key
=
True
)
create_time
=
models
.
DateTimeField
(
verbose_name
=
u'创建时间'
,
default
=
datetime
.
datetime
.
fromtimestamp
(
0
))
update_time
=
models
.
DateTimeField
(
verbose_name
=
u'更新时间'
,
default
=
datetime
.
datetime
.
fromtimestamp
(
0
))
is_online
=
models
.
BooleanField
(
verbose_name
=
u'是否上线'
)
is_deleted
=
models
.
BooleanField
(
verbose_name
=
u'是否删除'
)
is_recommend
=
models
.
BooleanField
(
verbose_name
=
u'推荐'
)
name
=
models
.
CharField
(
verbose_name
=
u'画报名称'
,
max_length
=
100
)
description
=
models
.
CharField
(
verbose_name
=
u'画报描述'
,
max_length
=
200
)
creator_id
=
models
.
BigIntegerField
(
verbose_name
=
u'画报用户ID'
)
icon
=
models
.
CharField
(
verbose_name
=
u'画报名称'
,
max_length
=
255
)
topic_num
=
models
.
IntegerField
(
verbose_name
=
u'次数'
)
# 获取前一天4,5星发帖数
def
get_high_quality_topic_num
(
self
):
try
:
yesterday
=
datetime
.
datetime
.
now
()
-
datetime
.
timedelta
(
days
=
1
)
yesterday_begin_time
=
"
%
s-
%
s-
%
s 00:00:00"
%
(
yesterday
.
year
,
yesterday
.
month
,
yesterday
.
day
)
yesterday_end_time
=
"
%
s-
%
s-
%
s 23:59:59"
%
(
yesterday
.
year
,
yesterday
.
month
,
yesterday
.
day
)
topic_id_list
=
PictorialTopic
.
objects
.
filter
(
pictorial_id
=
self
.
id
)
.
values_list
(
"topic_id"
,
flat
=
True
)
logging
.
info
(
"get topic_id_list:
%
s"
%
topic_id_list
)
# topic_num = Topic.filter(content_level__in=("4", "5"), create_time__gte=yesterday_begin_time,
# create_time__lte=yesterday_end_time, topic_id_in=topic_id_list).count()
#
# logging.info("get topic_num:%s" % topic_num)
#
# return topic_num
except
:
logging
.
error
(
"catch exception,err_msg:
%
s"
%
traceback
.
format_exc
())
return
False
trans2es/models/topic.py
View file @
fe5b73b7
...
@@ -16,6 +16,7 @@ from .pick_topic import PickTopic
...
@@ -16,6 +16,7 @@ from .pick_topic import PickTopic
from
.tag
import
TopicTag
,
Tag
from
.tag
import
TopicTag
,
Tag
from
.user_extra
import
UserExtra
from
.user_extra
import
UserExtra
from
.group
import
Group
from
.group
import
Group
from
.pictorial
import
PictorialTopic
class
ActionSumAboutTopic
(
models
.
Model
):
class
ActionSumAboutTopic
(
models
.
Model
):
...
@@ -53,9 +54,9 @@ class Topic(models.Model):
...
@@ -53,9 +54,9 @@ class Topic(models.Model):
id
=
models
.
IntegerField
(
verbose_name
=
u'日记ID'
,
primary_key
=
True
)
id
=
models
.
IntegerField
(
verbose_name
=
u'日记ID'
,
primary_key
=
True
)
name
=
models
.
CharField
(
verbose_name
=
u'日记名称'
,
max_length
=
100
)
name
=
models
.
CharField
(
verbose_name
=
u'日记名称'
,
max_length
=
100
)
# group_id = models.IntegerField(verbose_name='用户所在组ID',default=-1)
# group_id = models.IntegerField(verbose_name='用户所在组ID',default=-1)
group
=
models
.
ForeignKey
(
#
group = models.ForeignKey(
Group
,
verbose_name
=
u"关联的小组"
,
related_name
=
u"group_topics"
,
null
=
True
,
blank
=
True
,
default
=
None
,
#
Group, verbose_name=u"关联的小组", related_name=u"group_topics", null=True, blank=True, default=None,
on_delete
=
models
.
CASCADE
)
#
on_delete=models.CASCADE)
user_id
=
models
.
IntegerField
(
verbose_name
=
u'用户ID'
)
user_id
=
models
.
IntegerField
(
verbose_name
=
u'用户ID'
)
has_video
=
models
.
BooleanField
(
verbose_name
=
u'是否是视频日记'
)
has_video
=
models
.
BooleanField
(
verbose_name
=
u'是否是视频日记'
)
drop_score
=
models
.
IntegerField
(
verbose_name
=
u'人工赋分'
,
default
=
0
)
drop_score
=
models
.
IntegerField
(
verbose_name
=
u'人工赋分'
,
default
=
0
)
...
@@ -83,6 +84,21 @@ class Topic(models.Model):
...
@@ -83,6 +84,21 @@ class Topic(models.Model):
platform
=
models
.
IntegerField
(
verbose_name
=
u'平台来源'
,
choices
=
GRAP_PLATFORM
,
default
=
GRAP_PLATFORM
.
ALPHA
)
platform
=
models
.
IntegerField
(
verbose_name
=
u'平台来源'
,
choices
=
GRAP_PLATFORM
,
default
=
GRAP_PLATFORM
.
ALPHA
)
platform_id
=
models
.
BigIntegerField
(
verbose_name
=
'用平台ID'
,
null
=
True
)
platform_id
=
models
.
BigIntegerField
(
verbose_name
=
'用平台ID'
,
null
=
True
)
def
get_pictorial_id
(
self
):
try
:
logging
.
info
(
"get user id :
%
s"
%
self
.
id
)
pictorial_id_list
=
[]
pictorial_id
=
PictorialTopic
.
objects
.
filter
(
topic_id
=
self
.
id
)
.
values_list
(
"pictorial_id"
,
flat
=
True
)
for
i
in
pictorial_id
:
pictorial_id_list
.
append
(
i
)
if
len
(
pictorial_id_list
)
>
0
:
logging
.
info
(
"get user attention pictorial id :
%
s"
%
pictorial_id_list
)
return
pictorial_id_list
except
:
logging
.
error
(
"catch exception,err_msg:
%
s"
%
traceback
.
format_exc
())
return
[]
@property
@property
def
is_complaint
(
self
):
def
is_complaint
(
self
):
"""是否被举报"""
"""是否被举报"""
...
@@ -96,7 +112,8 @@ class Topic(models.Model):
...
@@ -96,7 +112,8 @@ class Topic(models.Model):
try
:
try
:
has_image
=
False
has_image
=
False
query_list
=
TopicImage
.
objects
.
using
(
settings
.
SLAVE_DB_NAME
)
.
filter
(
topic_id
=
self
.
id
,
is_deleted
=
False
,
is_online
=
True
)
query_list
=
TopicImage
.
objects
.
using
(
settings
.
SLAVE_DB_NAME
)
.
filter
(
topic_id
=
self
.
id
,
is_deleted
=
False
,
is_online
=
True
)
if
len
(
query_list
)
>
0
:
if
len
(
query_list
)
>
0
:
has_image
=
True
has_image
=
True
...
@@ -122,12 +139,13 @@ class Topic(models.Model):
...
@@ -122,12 +139,13 @@ class Topic(models.Model):
topic_tag_id_list
=
list
()
topic_tag_id_list
=
list
()
edit_tag_id_list
=
list
()
edit_tag_id_list
=
list
()
tag_id_list
=
TopicTag
.
objects
.
using
(
settings
.
SLAVE_DB_NAME
)
.
filter
(
topic_id
=
self
.
id
)
.
values_list
(
"tag_id"
,
flat
=
True
)
tag_id_list
=
TopicTag
.
objects
.
using
(
settings
.
SLAVE_DB_NAME
)
.
filter
(
topic_id
=
self
.
id
)
.
values_list
(
"tag_id"
,
flat
=
True
)
tag_query_results
=
Tag
.
objects
.
using
(
settings
.
SLAVE_DB_NAME
)
.
filter
(
id__in
=
tag_id_list
)
tag_query_results
=
Tag
.
objects
.
using
(
settings
.
SLAVE_DB_NAME
)
.
filter
(
id__in
=
tag_id_list
)
for
tag_item
in
tag_query_results
:
for
tag_item
in
tag_query_results
:
is_online
=
tag_item
.
is_online
is_online
=
tag_item
.
is_online
is_deleted
=
tag_item
.
is_deleted
is_deleted
=
tag_item
.
is_deleted
collection
=
tag_item
.
collection
collection
=
tag_item
.
collection
if
is_online
and
not
is_deleted
:
if
is_online
and
not
is_deleted
:
topic_tag_id_list
.
append
(
tag_item
.
id
)
topic_tag_id_list
.
append
(
tag_item
.
id
)
...
@@ -137,7 +155,7 @@ class Topic(models.Model):
...
@@ -137,7 +155,7 @@ class Topic(models.Model):
return
(
topic_tag_id_list
,
edit_tag_id_list
)
return
(
topic_tag_id_list
,
edit_tag_id_list
)
except
:
except
:
logging
.
error
(
"catch exception,err_msg:
%
s"
%
traceback
.
format_exc
())
logging
.
error
(
"catch exception,err_msg:
%
s"
%
traceback
.
format_exc
())
return
([],[])
return
([],
[])
def
get_tag_name_list
(
self
,
tag_id_list
):
def
get_tag_name_list
(
self
,
tag_id_list
):
try
:
try
:
...
@@ -177,9 +195,12 @@ class Topic(models.Model):
...
@@ -177,9 +195,12 @@ class Topic(models.Model):
elif
self
.
content_level
==
'3'
:
elif
self
.
content_level
==
'3'
:
offline_score
+=
2.0
offline_score
+=
2.0
exposure_count
=
ActionSumAboutTopic
.
objects
.
using
(
settings
.
SLAVE_DB_NAME
)
.
filter
(
topic_id
=
self
.
id
,
data_type
=
1
)
.
count
()
exposure_count
=
ActionSumAboutTopic
.
objects
.
using
(
settings
.
SLAVE_DB_NAME
)
.
filter
(
topic_id
=
self
.
id
,
click_count
=
ActionSumAboutTopic
.
objects
.
using
(
settings
.
SLAVE_DB_NAME
)
.
filter
(
topic_id
=
self
.
id
,
data_type
=
2
)
.
count
()
data_type
=
1
)
.
count
()
uv_num
=
ActionSumAboutTopic
.
objects
.
using
(
settings
.
SLAVE_DB_NAME
)
.
filter
(
topic_id
=
self
.
id
,
data_type
=
3
)
.
count
()
click_count
=
ActionSumAboutTopic
.
objects
.
using
(
settings
.
SLAVE_DB_NAME
)
.
filter
(
topic_id
=
self
.
id
,
data_type
=
2
)
.
count
()
uv_num
=
ActionSumAboutTopic
.
objects
.
using
(
settings
.
SLAVE_DB_NAME
)
.
filter
(
topic_id
=
self
.
id
,
data_type
=
3
)
.
count
()
if
exposure_count
>
0
:
if
exposure_count
>
0
:
offline_score
+=
click_count
/
exposure_count
offline_score
+=
click_count
/
exposure_count
...
@@ -210,6 +231,7 @@ class TopicComplaint(models.Model):
...
@@ -210,6 +231,7 @@ class TopicComplaint(models.Model):
id
=
models
.
IntegerField
(
verbose_name
=
'日记图片ID'
,
primary_key
=
True
)
id
=
models
.
IntegerField
(
verbose_name
=
'日记图片ID'
,
primary_key
=
True
)
user_id
=
models
.
BigIntegerField
(
verbose_name
=
u'用户ID'
,
db_index
=
True
)
user_id
=
models
.
BigIntegerField
(
verbose_name
=
u'用户ID'
,
db_index
=
True
)
topic
=
models
.
ForeignKey
(
topic
=
models
.
ForeignKey
(
Topic
,
verbose_name
=
u"关联的帖子"
,
null
=
True
,
blank
=
True
,
default
=
None
,
on_delete
=
models
.
CASCADE
,
related_name
=
'complaints'
)
Topic
,
verbose_name
=
u"关联的帖子"
,
null
=
True
,
blank
=
True
,
default
=
None
,
on_delete
=
models
.
CASCADE
,
related_name
=
'complaints'
)
is_online
=
models
.
BooleanField
(
verbose_name
=
u"是否有效"
,
default
=
True
)
is_online
=
models
.
BooleanField
(
verbose_name
=
u"是否有效"
,
default
=
True
)
\ No newline at end of file
trans2es/models/user.py
View file @
fe5b73b7
...
@@ -15,7 +15,7 @@ from .group_user_role import GroupUserRole
...
@@ -15,7 +15,7 @@ from .group_user_role import GroupUserRole
from
.tag
import
AccountUserTag
from
.tag
import
AccountUserTag
from
.topic
import
Topic
from
.topic
import
Topic
from
.user_extra
import
UserExtra
from
.user_extra
import
UserExtra
from
.pictorial
import
PictorialFollow
class
User
(
models
.
Model
):
class
User
(
models
.
Model
):
class
Meta
:
class
Meta
:
...
@@ -91,6 +91,26 @@ class User(models.Model):
...
@@ -91,6 +91,26 @@ class User(models.Model):
logging
.
error
(
"catch exception,err_msg:
%
s"
%
traceback
.
format_exc
())
logging
.
error
(
"catch exception,err_msg:
%
s"
%
traceback
.
format_exc
())
return
[]
return
[]
def
get_attention_pictorial_id_list
(
self
):
try
:
attention_pictorial_id_list
=
list
()
query_results
=
PictorialFollow
.
objects
.
using
(
settings
.
SLAVE_DB_NAME
)
.
filter
(
is_online
=
True
,
user_id
=
self
.
user_id
)
logging
.
info
(
"get PictorialFollow:
%
s"
%
query_results
)
for
item
in
query_results
:
item_dict
=
{
"pictorial_id"
:
item
.
pictorial_id
,
"update_time_val"
:
time
.
mktime
(
tzlc
(
item
.
update_time
)
.
timetuple
())
}
attention_pictorial_id_list
.
append
(
item_dict
)
logging
.
info
(
"get user_id:
%
s"
%
self
.
user_id
)
logging
.
info
(
"get same_pictorial_user_id_list:
%
s"
%
attention_pictorial_id_list
)
return
attention_pictorial_id_list
except
:
logging
.
error
(
"catch exception,err_msg:
%
s"
%
traceback
.
format_exc
())
return
[]
def
get_pick_user_id_list
(
self
):
def
get_pick_user_id_list
(
self
):
pick_topic_id_list
=
list
()
pick_topic_id_list
=
list
()
user_picks
=
self
.
user_pick
.
using
(
settings
.
SLAVE_DB_NAME
)
.
filter
(
is_deleted
=
False
,
is_pick
=
True
)
user_picks
=
self
.
user_pick
.
using
(
settings
.
SLAVE_DB_NAME
)
.
filter
(
is_deleted
=
False
,
is_pick
=
True
)
...
@@ -117,32 +137,35 @@ class User(models.Model):
...
@@ -117,32 +137,35 @@ class User(models.Model):
return
pick_user_detail_list
return
pick_user_detail_list
def
get_same_
group
_user_id_list
(
self
):
def
get_same_
pictorial
_user_id_list
(
self
):
#todo 有的同组数据过大,导致celery cpu过高,暂时限制同组的数据大小,后续可能会去掉同组的数据
#todo 有的同组数据过大,导致celery cpu过高,暂时限制同组的数据大小,后续可能会去掉同组的数据
same_
group
_user_id_list
=
list
()
same_
pictorial
_user_id_list
=
list
()
group_items_list
=
list
(
GroupUserRole
.
objects
.
using
(
settings
.
SLAVE_DB_NAME
)
.
filter
(
user_id
=
self
.
user_id
)
.
values_list
(
"group
_id"
,
flat
=
True
))
pictorial_items_list
=
list
(
PictorialFollow
.
objects
.
using
(
settings
.
SLAVE_DB_NAME
)
.
filter
(
user_id
=
self
.
user_id
)
.
values_list
(
"pictorial
_id"
,
flat
=
True
))
for
group_id
in
group
_items_list
:
for
pictorial_id
in
pictorial
_items_list
:
user_items_list
=
list
(
GroupUserRole
.
objects
.
using
(
settings
.
SLAVE_DB_NAME
)
.
filter
(
group_id
=
group
_id
)
.
values_list
(
"user_id"
,
flat
=
True
))
user_items_list
=
list
(
PictorialFollow
.
objects
.
using
(
settings
.
SLAVE_DB_NAME
)
.
filter
(
pictorial_id
=
pictorial
_id
)
.
values_list
(
"user_id"
,
flat
=
True
))
for
user_id
in
user_items_list
:
for
user_id
in
user_items_list
:
same_
group
_user_id_list
.
append
(
user_id
)
same_
pictorial
_user_id_list
.
append
(
user_id
)
if
len
(
same_
group
_user_id_list
)
>=
100
:
if
len
(
same_
pictorial
_user_id_list
)
>=
100
:
break
break
if
len
(
same_
group
_user_id_list
)
>=
100
:
if
len
(
same_
pictorial
_user_id_list
)
>=
100
:
break
break
logging
.
info
(
"get same user_id:
%
s"
%
self
.
user_id
)
logging
.
info
(
"get same_pictorial_user_id_list:
%
s"
%
same_pictorial_user_id_list
)
same_
group
_detail_list
=
list
()
same_
pictorial
_detail_list
=
list
()
for
i
in
range
(
0
,
len
(
same_
group
_user_id_list
),
200
):
for
i
in
range
(
0
,
len
(
same_
pictorial
_user_id_list
),
200
):
sql_data_list
=
User
.
objects
.
using
(
settings
.
SLAVE_DB_NAME
)
.
filter
(
user_id__in
=
same_
group
_user_id_list
[
i
:
i
+
1000
])
sql_data_list
=
User
.
objects
.
using
(
settings
.
SLAVE_DB_NAME
)
.
filter
(
user_id__in
=
same_
pictorial
_user_id_list
[
i
:
i
+
1000
])
for
detail_data
in
sql_data_list
:
for
detail_data
in
sql_data_list
:
item
=
{
item
=
{
"user_id"
:
detail_data
.
user_id
,
"user_id"
:
detail_data
.
user_id
,
"country_id"
:
detail_data
.
country_id
"country_id"
:
detail_data
.
country_id
}
}
same_
group
_detail_list
.
append
(
item
)
same_
pictorial
_detail_list
.
append
(
item
)
return
same_
group
_detail_list
return
same_
pictorial
_detail_list
def
get_user_tag_id_list
(
self
):
def
get_user_tag_id_list
(
self
):
try
:
try
:
...
...
trans2es/type_info.py
View file @
fe5b73b7
...
@@ -12,11 +12,12 @@ import elasticsearch
...
@@ -12,11 +12,12 @@ import elasticsearch
import
elasticsearch.helpers
import
elasticsearch.helpers
import
sys
import
sys
from
trans2es.models
import
topic
,
user
,
pick_celebrity
,
group
,
celebrity
,
tag
,
contrast_similar
from
trans2es.models
import
topic
,
user
,
pick_celebrity
,
group
,
celebrity
,
tag
,
contrast_similar
,
pictorial
from
trans2es.utils.user_transfer
import
UserTransfer
from
trans2es.utils.user_transfer
import
UserTransfer
from
trans2es.utils.pick_celebrity_transfer
import
PickCelebrityTransfer
from
trans2es.utils.pick_celebrity_transfer
import
PickCelebrityTransfer
from
trans2es.utils.group_transfer
import
GroupTransfer
from
trans2es.utils.group_transfer
import
GroupTransfer
from
trans2es.utils.topic_transfer
import
TopicTransfer
from
trans2es.utils.topic_transfer
import
TopicTransfer
from
trans2es.utils.pictorial_transfer
import
PictorialTransfer
from
trans2es.utils.celebrity_transfer
import
CelebrityTransfer
from
trans2es.utils.celebrity_transfer
import
CelebrityTransfer
from
trans2es.utils.tag_transfer
import
TagTransfer
from
trans2es.utils.tag_transfer
import
TagTransfer
from
trans2es.utils.contrast_similar_transfer
import
Contrast_Similar_Transfer
from
trans2es.utils.contrast_similar_transfer
import
Contrast_Similar_Transfer
...
@@ -330,7 +331,18 @@ def get_type_info_map():
...
@@ -330,7 +331,18 @@ def get_type_info_map():
bulk_insert_chunk_size
=
100
,
bulk_insert_chunk_size
=
100
,
round_insert_chunk_size
=
5
,
round_insert_chunk_size
=
5
,
round_insert_period
=
2
round_insert_period
=
2
),
TypeInfo
(
name
=
"pictorial"
,
# 画报
type
=
"pictorial"
,
model
=
pictorial
.
Pictorial
,
query_deferred
=
lambda
:
pictorial
.
Pictorial
.
objects
.
all
()
.
query
,
get_data_func
=
PictorialTransfer
.
get_poctorial_data
,
bulk_insert_chunk_size
=
100
,
round_insert_chunk_size
=
5
,
round_insert_period
=
2
,
)
)
]
]
type_info_map
=
{
type_info_map
=
{
...
@@ -340,3 +352,4 @@ def get_type_info_map():
...
@@ -340,3 +352,4 @@ def get_type_info_map():
_get_type_info_map_result
=
type_info_map
_get_type_info_map_result
=
type_info_map
return
type_info_map
return
type_info_map
trans2es/utils/group_transfer.py
View file @
fe5b73b7
...
@@ -33,7 +33,7 @@ class GroupTransfer(object):
...
@@ -33,7 +33,7 @@ class GroupTransfer(object):
update_time
=
instance
.
update_time
update_time
=
instance
.
update_time
tzlc_udpate_time
=
tzlc
(
update_time
)
tzlc_udpate_time
=
tzlc
(
update_time
)
res
[
"update_time"
]
=
tzlc_udpate_time
res
[
"update_time"
]
=
tzlc_udpate_time
res
[
"high_quality_topic_num"
]
=
instance
.
get_high_quality_topic_num
()
#
res["high_quality_topic_num"] = instance.get_high_quality_topic_num()
return
res
return
res
except
:
except
:
...
...
trans2es/utils/pictorial_transfer.py
0 → 100644
View file @
fe5b73b7
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import
os
import
sys
import
logging
import
traceback
from
libs.tools
import
tzlc
class
PictorialTransfer
(
object
):
def
__init__
(
self
):
pass
@classmethod
def
get_poctorial_data
(
cls
,
instance
):
try
:
res
=
dict
()
res
[
"id"
]
=
instance
.
id
res
[
"is_online"
]
=
instance
.
is_online
res
[
"is_deleted"
]
=
instance
.
is_deleted
res
[
"is_recommend"
]
=
instance
.
is_recommend
res
[
"name"
]
=
instance
.
name
res
[
"description"
]
=
instance
.
description
res
[
"topic_num"
]
=
instance
.
topic_num
res
[
"creator_id"
]
=
instance
.
creator_id
res
[
"icon"
]
=
instance
.
icon
create_time
=
instance
.
create_time
tzlc_create_time
=
tzlc
(
create_time
)
res
[
"create_time"
]
=
tzlc_create_time
update_time
=
instance
.
update_time
tzlc_udpate_time
=
tzlc
(
update_time
)
res
[
"update_time"
]
=
tzlc_udpate_time
res
[
"high_quality_topic_num"
]
=
instance
.
get_high_quality_topic_num
()
return
res
except
:
logging
.
error
(
"catch exception,err_msg:
%
s"
%
traceback
.
format_exc
())
return
dict
()
\ No newline at end of file
trans2es/utils/topic_transfer.py
View file @
fe5b73b7
...
@@ -28,10 +28,14 @@ class TopicTransfer(object):
...
@@ -28,10 +28,14 @@ class TopicTransfer(object):
res
[
"content_level"
]
=
instance
.
content_level
res
[
"content_level"
]
=
instance
.
content_level
res
[
"user_id"
]
=
instance
.
user_id
res
[
"user_id"
]
=
instance
.
user_id
if
instance
.
group
:
# if instance.group:
res
[
"group_id"
]
=
instance
.
group
.
id
# res["group_id"] = instance.group.id
else
:
# else:
res
[
"group_id"
]
=
-
1
# res["group_id"] = -1
res
[
"pictorial_id"
]
=
instance
.
get_pictorial_id
()
res
[
"share_num"
]
=
instance
.
share_num
res
[
"share_num"
]
=
instance
.
share_num
begin
=
time
.
time
()
begin
=
time
.
time
()
...
...
trans2es/utils/user_transfer.py
View file @
fe5b73b7
...
@@ -74,16 +74,26 @@ class UserTransfer(object):
...
@@ -74,16 +74,26 @@ class UserTransfer(object):
try
:
try
:
res
[
"tag_list"
]
=
instance
.
get_user_tag_id_list
()
res
[
"tag_list"
]
=
instance
.
get_user_tag_id_list
()
res
[
"attention_user_id_list"
]
=
cls
.
get_follow_user_id_list
(
userInstance
=
instance
)
res
[
"attention_user_id_list"
]
=
cls
.
get_follow_user_id_list
(
userInstance
=
instance
)
res
[
"attention_group_id_list"
]
=
instance
.
get_attention_group_id_list
()
# res["attention_group_id_list"] = instance.get_attention_group_id_list()
res
[
"pick_user_id_list"
]
=
instance
.
get_pick_user_id_list
()
res
[
"pick_user_id_list"
]
=
instance
.
get_pick_user_id_list
()
res
[
"same_group_user_id_list"
]
=
instance
.
get_same_group_user_id_list
()
res
[
"attention_pictorial_id_list"
]
=
instance
.
get_attention_pictorial_id_list
()
# res["same_group_user_id_list"] = instance.get_same_group_user_id_list()
res
[
"same_pictorial_user_id_list"
]
=
instance
.
get_same_pictorial_user_id_list
()
except
:
except
:
logging
.
error
(
"catch exception,err_msg:
%
s"
%
traceback
.
format_exc
())
logging
.
error
(
"catch exception,err_msg:
%
s"
%
traceback
.
format_exc
())
res
[
"tag_list"
]
=
[]
res
[
"tag_list"
]
=
[]
res
[
"attention_user_id_list"
]
=
[]
res
[
"attention_user_id_list"
]
=
[]
res
[
"attention_group_id_list"
]
=
[]
#
res["attention_group_id_list"] = []
res
[
"pick_user_id_list"
]
=
[]
res
[
"pick_user_id_list"
]
=
[]
res
[
"same_group_user_id_list"
]
=
[]
# res["same_group_user_id_list"] = []
res
[
"attention_pictorial_id_list"
]
=
[]
res
[
"same_pictorial_user_id_list"
]
=
[]
return
res
return
res
except
:
except
:
...
...
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