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
439f4043
Commit
439f4043
authored
Jun 13, 2019
by
段英荣
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'test' into 'master'
Test See merge request
!366
parents
580c06fe
08f92bb5
Hide whitespace changes
Inline
Side-by-side
Showing
15 changed files
with
465 additions
and
94 deletions
+465
-94
Project.xml
.idea/codeStyles/Project.xml
+25
-0
app_conf.xml
app_conf.xml
+1
-0
tasks.py
injection/data_sync/tasks.py
+25
-6
group.py
search/utils/group.py
+72
-2
group.py
search/views/group.py
+24
-0
search_hotword.py
search/views/search_hotword.py
+65
-0
topic.py
search/views/topic.py
+0
-2
user.py
search/views/user.py
+124
-16
pictorial.json
trans2es/mapping/pictorial.json
+3
-1
user.json
trans2es/mapping/user.json
+4
-1
pictorial.py
trans2es/models/pictorial.py
+26
-6
tag.py
trans2es/models/tag.py
+37
-26
user.py
trans2es/models/user.py
+45
-23
pictorial_transfer.py
trans2es/utils/pictorial_transfer.py
+9
-7
user_transfer.py
trans2es/utils/user_transfer.py
+5
-4
No files found.
.idea/codeStyles/Project.xml
View file @
439f4043
...
...
@@ -24,5 +24,29 @@
<option
name=
"ITERATION_ELEMENTS_WRAPPING"
value=
"chop_down_if_not_single"
/>
</formatting-settings>
</DBN-SQL>
<DBN-PSQL>
<case-options
enabled=
"false"
>
<option
name=
"KEYWORD_CASE"
value=
"lower"
/>
<option
name=
"FUNCTION_CASE"
value=
"lower"
/>
<option
name=
"PARAMETER_CASE"
value=
"lower"
/>
<option
name=
"DATATYPE_CASE"
value=
"lower"
/>
<option
name=
"OBJECT_CASE"
value=
"preserve"
/>
</case-options>
<formatting-settings
enabled=
"false"
/>
</DBN-PSQL>
<DBN-SQL>
<case-options
enabled=
"false"
>
<option
name=
"KEYWORD_CASE"
value=
"lower"
/>
<option
name=
"FUNCTION_CASE"
value=
"lower"
/>
<option
name=
"PARAMETER_CASE"
value=
"lower"
/>
<option
name=
"DATATYPE_CASE"
value=
"lower"
/>
<option
name=
"OBJECT_CASE"
value=
"preserve"
/>
</case-options>
<formatting-settings
enabled=
"false"
>
<option
name=
"STATEMENT_SPACING"
value=
"one_line"
/>
<option
name=
"CLAUSE_CHOP_DOWN"
value=
"chop_down_if_statement_long"
/>
<option
name=
"ITERATION_ELEMENTS_WRAPPING"
value=
"chop_down_if_not_single"
/>
</formatting-settings>
</DBN-SQL>
</code_scheme>
</component>
\ No newline at end of file
app_conf.xml
View file @
439f4043
...
...
@@ -17,5 +17,6 @@
<element
value=
"search.views.contrast_similar"
/>
<element
value=
"injection.data_sync.tasks"
/>
<element
value=
"search.views.contrast_similar"
/>
<element
value=
"search.views.search_hotword"
/>
</config>
</gm_rpcd_config>
injection/data_sync/tasks.py
View file @
439f4043
...
...
@@ -15,6 +15,7 @@ from libs.es import ESPerform
from
libs.cache
import
redis_client
from
trans2es.models.face_user_contrast_similar
import
FaceUserContrastSimilar
,
UserSimilarScore
from
linucb.utils.register_user_tag
import
RegisterUserTag
from
trans2es.models.tag
import
RegisterShowTag
,
Tag
@shared_task
...
...
@@ -63,17 +64,17 @@ def sync_face_similar_data_to_redis():
weight_score
=
int
(
item
.
similarity
*
100
)
item_list
.
append
(
{
"filter"
:{
"constant_score"
:{
"filter"
:{
"term"
:{
"user_id"
:
item
.
contrast_user_id
}
"filter"
:
{
"constant_score"
:
{
"filter"
:
{
"term"
:
{
"user_id"
:
item
.
contrast_user_id
}
}
}
},
"weight"
:
weight_score
*
2
"weight"
:
weight_score
*
2
}
)
if
len
(
item_list
)
>=
100
:
if
len
(
item_list
)
>=
100
:
break
redis_client
.
set
(
redis_key
,
json
.
dumps
(
item_list
))
...
...
@@ -107,3 +108,21 @@ def sync_user_similar_score():
except
:
logging
.
error
(
"catch exception,err_msg:
%
s"
%
traceback
.
format_exc
())
@shared_task
def
get_tag_count
():
try
:
# 获取搜索推荐热词
results_registr_tag
=
RegisterShowTag
.
objects
.
filter
(
is_deleted
=
False
,
is_online
=
1
)
.
count
()
# 获取符合条件的核心词
results_tag
=
Tag
.
objects
.
filter
(
is_online
=
True
,
collection
=
1
)
.
count
()
redis_registr_tag
=
"physical:search_hotword:results_registr_tag"
redis_tag
=
"physical:search_hotword:results_tag"
redis_client
.
set
(
redis_registr_tag
,
str
(
results_registr_tag
))
redis_client
.
set
(
redis_tag
,
str
(
results_tag
))
except
:
logging
.
error
(
"catch exception,err_msg:
%
s"
%
traceback
.
format_exc
())
search/utils/group.py
View file @
439f4043
...
...
@@ -109,8 +109,6 @@ class GroupUtils(object):
"script"
:
{
"lang"
:
"expression"
,
"source"
:
"_score+doc['offline_score']"
# "lang":"painless",
# "source":"_score+params._source.offline_score"
},
"order"
:
"desc"
}
...
...
@@ -214,3 +212,75 @@ class GroupUtils(object):
except
:
logging
.
error
(
"catch exception,err_msg:
%
s"
%
traceback
.
format_exc
())
return
[]
@classmethod
def
get_search_pictorial_topic
(
cls
,
query
,
offset
,
size
):
try
:
q
=
dict
()
multi_fields
=
{
'name'
:
4
,
'description'
:
4
,
'tag_name'
:
4
}
query_fields
=
[
'^'
.
join
((
k
,
str
(
v
)))
for
(
k
,
v
)
in
multi_fields
.
items
()]
multi_match
=
{
'query'
:
query
,
'type'
:
'cross_fields'
,
'operator'
:
'and'
,
'fields'
:
query_fields
,
}
q
[
'query'
]
=
{
'bool'
:
{
"must"
:
[
{
"term"
:
{
"is_online"
:
True
}},
{
"term"
:
{
"is_deleted"
:
False
}},
{
"term"
:
{
"is_default"
:
0
}},
{
"range"
:
{
"topic_id_list"
:
{
"gte"
:
0
}}},
{
"term"
:
{
"is_cover"
:
True
}}
],
"should"
:
[
{
'multi_match'
:
multi_match
}
],
"minimum_should_match"
:
1
}
}
q
[
"_source"
]
=
{
"includes"
:
[
"id"
,
"is_online"
,
"is_deleted"
,
"is_default"
,
"topic_id_list"
,
"is_cover"
,
"offline_score"
,
"is_default"
]
}
q
[
"sort"
]
=
[
{
"_script"
:
{
"type"
:
"number"
,
"script"
:
{
"lang"
:
"expression"
,
"source"
:
"_score+doc['offline_score']"
},
"order"
:
"desc"
}
},
{
"_score"
:
{
"order"
:
"desc"
}
}
]
q
=
{}
q
[
"query"
]
=
{
"term"
:
{
"is_online"
:
True
}
}
logging
.
info
(
"get qqqqqqqq:
%
s"
%
q
)
es_cli_obj
=
ESPerform
.
get_cli
()
result_dict
=
ESPerform
.
get_search_results
(
es_cli_obj
,
"pictorial"
,
q
,
offset
,
size
)
logging
.
info
(
"get result_dict:
%
s"
%
result_dict
)
return
result_dict
except
:
logging
.
error
(
"catch exception,err_msg:
%
s"
%
traceback
.
format_exc
())
return
None
search/views/group.py
View file @
439f4043
...
...
@@ -261,3 +261,27 @@ def pictorial_topic_sort(pictorial_id=-1, offset=0, size=10):
except
:
logging
.
error
(
"catch exception,err_msg:
%
s"
%
traceback
.
format_exc
())
return
{
"pict_pictorial_ids_list"
:
[]}
@bind
(
"physical/search/search_physical"
)
def
search_physical
(
query
=
""
,
offset
=
0
,
size
=
10
):
"""
搜索页面搜索画报
:param query:
:param offset:
:param size:
:return:
1. query识别:允许模糊匹配
2. 召回部分:去掉无封面、无帖子、下线的、默认画报
3. rank部分:(和之前一样,下面只是粘贴过来)
"""
try
:
result_dicts
=
GroupUtils
.
get_search_pictorial_topic
(
query
,
offset
,
size
)
group_ids_list
=
[]
if
len
(
result_dicts
[
"hits"
])
>
0
:
group_ids_list
=
[
item
[
"_source"
][
"id"
]
for
item
in
result_dicts
[
"hits"
]]
return
{
"search_pictorial_ids"
:
group_ids_list
}
except
:
logging
.
error
(
"catch exception,err_msg:
%
s"
%
traceback
.
format_exc
())
return
{
"search_pictorial_ids"
:
[]}
search/views/search_hotword.py
0 → 100644
View file @
439f4043
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from
gm_rpcd.all
import
bind
import
logging
import
traceback
import
random
import
json
from
libs.cache
import
redis_client
from
libs.es
import
ESPerform
from
search.utils.group
import
GroupUtils
from
search.utils.common
import
GroupSortTypes
from
libs.es
import
ESPerform
from
trans2es.models.pictorial
import
PictorialTopics
from
trans2es.models.tag
import
RegisterShowTag
,
Tag
from
libs.cache
import
redis_client
@bind
(
"physical/search/search_hotword"
)
def
search_hotword
(
device_id
=-
1
):
"""
:remark:搜索页的热门灵感
内容组成:搜索推荐热词register_show_tag
个性化标签physical:linucb:tag_recommend:device_id:
核心词,需要去重community_tag collection 1
①先从后台随机取最多6个搜索推荐热词,不够6个则有多少取多少
②然后随机取和推荐热词一样数量的linUCB标签,取不够数则取核心标签,linUCB+核心词去重后的数量要和搜索推荐热词的数量一样
③最后打乱顺序填入到热门灵感中,超过3行的标签弃掉,不够3行不用管
:param query:
:param offset:
:param size:
:return:
"""
try
:
all_tag_name_list
=
set
()
results_registr_tag
=
int
(
redis_client
.
get
(
"physical:search_hotword:results_registr_tag"
))
results_tag
=
int
(
redis_client
.
get
(
"physical:search_hotword:results_tag"
))
tag_id
=
random
.
sample
(
range
(
1
,
results_registr_tag
),
6
)
results_tag_chose
=
Tag
.
objects
.
filter
(
id__in
=
tag_id
)
.
values_list
(
"name"
,
flat
=
True
)
for
i
in
results_tag_chose
:
all_tag_name_list
.
add
(
i
)
# 获取个性化标签
linucb_recommend_redis_prefix
=
"physical:linucb:tag_recommend:device_id:"
tag_recommend_redis_key
=
linucb_recommend_redis_prefix
+
str
(
device_id
)
linucb_recommend_tag_data
=
redis_client
.
get
(
tag_recommend_redis_key
)
linucb_recommend_tag_list
=
json
.
loads
(
linucb_recommend_tag_data
)
if
linucb_recommend_tag_data
else
[]
for
item
in
linucb_recommend_tag_list
:
results_tag_recommend
=
Tag
.
objects
.
filter
(
id
=
item
,
is_online
=
True
)
.
values_list
(
"name"
,
flat
=
True
)
all_tag_name_list
.
add
(
results_tag_recommend
[
0
])
if
len
(
all_tag_name_list
)
==
12
:
return
{
"recommend_tag_name"
:
list
(
all_tag_name_list
)}
# 取不够数则取核心标签
if
len
(
all_tag_name_list
)
<
12
:
for
i
in
range
(
0
,
12
):
tag_id
=
random
.
sample
(
range
(
1
,
results_tag
),
12
-
len
(
all_tag_name_list
))
results_tag_hexin
=
Tag
.
objects
.
filter
(
id__in
=
tag_id
)
.
values_list
(
"name"
,
flat
=
True
)
if
results_tag_hexin
not
in
all_tag_name_list
:
all_tag_name_list
.
add
(
results_tag_hexin
[
0
])
if
len
(
all_tag_name_list
)
>=
12
:
return
{
"recommend_tag_name"
:
list
(
all_tag_name_list
)}
except
:
logging
.
error
(
"catch exception,err_msg:
%
s"
%
traceback
.
format_exc
())
return
{
"recommend_tag_name"
:
[]}
search/views/topic.py
View file @
439f4043
...
...
@@ -14,8 +14,6 @@ from search.utils.common import *
from
libs.es
import
ESPerform
from
django.conf
import
settings
def
get_discover_page_topic_ids
(
user_id
,
device_id
,
size
,
query_type
=
TopicPageType
.
FIND_PAGE
):
try
:
if
user_id
==
-
1
:
...
...
search/views/user.py
View file @
439f4043
...
...
@@ -14,7 +14,7 @@ from libs.es import ESPerform
@bind
(
"physical/search/recommend_user"
)
def
recommend_user
(
self_user_id
,
interesting_user_id
,
offset
=
0
,
size
=
10
):
def
recommend_user
(
self_user_id
,
interesting_user_id
,
offset
=
0
,
size
=
10
):
"""
:remark 点关注推荐用户
:param self_user_id:
...
...
@@ -29,25 +29,29 @@ def recommend_user(self_user_id,interesting_user_id,offset=0,size=10):
if
not
isinstance
(
interesting_user_id
,
int
):
interesting_user_id
=
-
1
#获取es链接对象
#
获取es链接对象
es_cli_obj
=
ESPerform
.
get_cli
()
#获取关注用户列表
(
self_attention_user_id_list
,
recursion_attention_user_id_list
)
=
UserUtils
.
get_attention_user_list
([
self_user_id
,
interesting_user_id
],
self_user_id
,
es_cli_obj
)
# 获取关注用户列表
(
self_attention_user_id_list
,
recursion_attention_user_id_list
)
=
UserUtils
.
get_attention_user_list
(
[
self_user_id
,
interesting_user_id
],
self_user_id
,
es_cli_obj
)
#去除自身及感兴趣的用户ID
#
去除自身及感兴趣的用户ID
self_attention_user_id_list
.
append
(
self_user_id
)
self_attention_user_id_list
.
append
(
interesting_user_id
)
recommend_user_list
=
UserUtils
.
get_recommend_user_list
(
self_attention_user_id_list
,
recursion_attention_user_id_list
,
offset
,
size
,
es_cli_obj
)
recommend_user_list
=
UserUtils
.
get_recommend_user_list
(
self_attention_user_id_list
,
recursion_attention_user_id_list
,
offset
,
size
,
es_cli_obj
)
return
recommend_user_list
except
:
logging
.
error
(
"catch exception,err_msg:
%
s"
%
traceback
.
format_exc
())
return
[]
@bind
(
"physical/search/batch_recommend_user"
)
def
batch_recommend_user
(
self_user_id
,
interesting_user_id_list
,
offset
=
0
,
size
=
10
):
def
batch_recommend_user
(
self_user_id
,
interesting_user_id_list
,
offset
=
0
,
size
=
10
):
"""
:remark 点关注推荐用户 - 批量接口
:param self_user_id:
...
...
@@ -57,23 +61,128 @@ def batch_recommend_user(self_user_id,interesting_user_id_list,offset=0,size=10)
:return:
"""
try
:
if
not
isinstance
(
self_user_id
,
int
):
if
not
isinstance
(
self_user_id
,
int
):
self_user_id
=
-
1
#获取es链接对象
#
获取es链接对象
es_cli_obj
=
ESPerform
.
get_cli
()
#获取关注用户列表
(
need_filter_attention_user_id_list
,
attention_user_dict_list
,
attention_user_id_list
)
=
UserUtils
.
get_batch_attention_user_list
(
interesting_user_id_list
,
self_user_id
,
es_cli_obj
)
# 获取关注用户列表
(
need_filter_attention_user_id_list
,
attention_user_dict_list
,
attention_user_id_list
)
=
UserUtils
.
get_batch_attention_user_list
(
interesting_user_id_list
,
self_user_id
,
es_cli_obj
)
#去除自身及感兴趣的用户ID
# 去除自身及感兴趣的用户ID
need_filter_attention_user_id_list
.
append
(
self_user_id
)
recommend_user_dict
=
UserUtils
.
get_batch_recommend_user_dict
(
need_filter_attention_user_id_list
=
need_filter_attention_user_id_list
,
attention_user_id_list
=
attention_user_id_list
,
attention_user_dict_list
=
attention_user_dict_list
,
self_user_id
=
self_user_id
,
offset
=
offset
,
size
=
size
,
es_cli_obj
=
es_cli_obj
)
recommend_user_dict
=
UserUtils
.
get_batch_recommend_user_dict
(
need_filter_attention_user_id_list
=
need_filter_attention_user_id_list
,
attention_user_id_list
=
attention_user_id_list
,
attention_user_dict_list
=
attention_user_dict_list
,
self_user_id
=
self_user_id
,
offset
=
offset
,
size
=
size
,
es_cli_obj
=
es_cli_obj
)
logging
.
info
(
"duan add,recommend_user_dict:
%
s"
%
str
(
recommend_user_dict
))
return
recommend_user_dict
except
:
logging
.
error
(
"catch exception,err_msg:
%
s"
%
traceback
.
format_exc
())
return
{}
\ No newline at end of file
return
{}
@bind
(
"physical/search/search_user"
)
def
search_user
(
query
=
""
,
offset
=
0
,
size
=
10
):
"""
:remark 搜索用户
:param query:
:param offset:
:param size:
:return:
搜索域:用户名称
1.识别query:允许模糊匹配
2.召回部分:全部 线上状态用户
3.rank部分:一级-是否推荐,二级-发帖数
"""
try
:
es_cli_obj
=
ESPerform
.
get_cli
()
q
=
{}
# 先获取完全匹配的用户ID
sheer_user_id
=
[]
q
[
"query"
]
=
{
"bool"
:
{
"must"
:
[
{
"term"
:
{
"nick_name_pre"
:
query
}
},
{
"term"
:
{
"is_recommend"
:
True
}
}
]
}
}
q
[
"sort"
]
=
{
"count_topic"
:
{
"order"
:
"desc"
}
}
# que = {"query": {"term": {"nick_name_pre": query}}}
result_dict
=
ESPerform
.
get_search_results
(
es_cli_obj
,
"user"
,
q
,
0
,
10
)
res
=
result_dict
[
"hits"
]
if
len
(
res
)
>
0
:
sheer_user_id
=
[
item
[
"_source"
][
"user_id"
]
for
item
in
res
]
logging
.
info
(
"get res:
%
s"
%
res
)
# 获取模糊匹配的用户ID
multi_match
=
{
"fields"
:
[
"nick_name"
],
"type"
:
"cross_fields"
,
"operator"
:
"and"
,
"query"
:
query
}
q
=
{}
q
[
"query"
]
=
{
"bool"
:
{
"must"
:
[{
"multi_match"
:
multi_match
},
{
"term"
:
{
"is_online"
:
True
}
}
]
}
}
q
[
"sort"
]
=
{
"is_recommend"
:
{
"order"
:
"desc"
},
"count_topic"
:
{
"order"
:
"desc"
},
}
logging
.
info
(
"get q:
%
s"
%
q
)
result_dict
=
ESPerform
.
get_search_results
(
es_cli_obj
,
"user"
,
q
,
offset
,
size
)
logging
.
info
(
"get result_dict:
%
s"
%
result_dict
)
search_user_id
=
[]
res
=
result_dict
[
"hits"
]
if
len
(
res
)
>
0
:
search_user_id
=
[
item
[
"_source"
][
"user_id"
]
for
item
in
res
]
return
{
"sheer_user_id"
:
sheer_user_id
,
"search_user_id"
:
search_user_id
}
except
:
logging
.
error
(
"catch exception,err_msg:
%
s"
%
traceback
.
format_exc
())
return
{
"sheer_user_id"
:
[],
"search_user_id"
:
[]}
trans2es/mapping/pictorial.json
View file @
439f4043
...
...
@@ -18,6 +18,7 @@
"topic_id_list"
:{
"type"
:
"long"
},
"effective"
:{
"type"
:
"boolean"
},
"offline_score"
:{
"type"
:
"long"
},
"is_default"
:{
"type"
:
"long"
}
"is_default"
:{
"type"
:
"long"
},
"is_cover"
:{
"type"
:
"boolean"
}
}
}
\ No newline at end of file
trans2es/mapping/user.json
View file @
439f4043
...
...
@@ -4,6 +4,7 @@
"id"
:{
"type"
:
"long"
},
"user_id"
:{
"type"
:
"long"
},
"nick_name"
:{
"type"
:
"text"
,
"analyzer"
:
"gm_default_index"
,
"search_analyzer"
:
"gm_default_index"
},
//昵称
"nick_name_pre"
:{
"type"
:
"text"
,
"analyzer"
:
"not_analyzed"
},
//昵称
"profile_pic"
:{
"type"
:
"text"
},
//头像
"gender"
:{
"type"
:
"integer"
},
"is_online"
:{
"type"
:
"boolean"
},
//是否上线
...
...
@@ -60,6 +61,7 @@
"create_time"
:{
"type"
:
"date"
,
"format"
:
"date_time_no_millis"
},
"update_time"
:{
"type"
:
"date"
,
"format"
:
"date_time_no_millis"
},
"create_time_val"
:{
"type"
:
"long"
},
"update_time_val"
:{
"type"
:
"long"
}
"update_time_val"
:{
"type"
:
"long"
},
"count_topic"
:{
"type"
:
"long"
}
}
}
\ No newline at end of file
trans2es/models/pictorial.py
View file @
439f4043
...
...
@@ -63,27 +63,27 @@ class Pictorial(models.Model):
def
get_topic_id
(
self
):
try
:
topic_id_list
=
list
(
PictorialTopics
.
objects
.
filter
(
pictorial_id
=
self
.
id
,
is_online
=
True
,
is_deleted
=
False
)
.
values_list
(
"topic_id"
,
flat
=
True
))
topic_id_list
=
list
(
PictorialTopics
.
objects
.
filter
(
pictorial_id
=
self
.
id
,
is_online
=
True
,
is_deleted
=
False
)
.
values_list
(
"topic_id"
,
flat
=
True
))
return
topic_id_list
except
:
logging
.
error
(
"catch exception,err_msg:
%
s"
%
traceback
.
format_exc
())
return
[]
def
get_effective
(
self
,
topic_id_list
):
def
get_effective
(
self
,
topic_id_list
):
try
:
effective_num
=
0
ret
=
False
for
topic_id
in
topic_id_list
:
topic_id_object
=
Topic
.
objects
.
filter
(
id
=
int
(
topic_id
))
.
first
()
if
topic_id_object
and
topic_id_object
.
is_online
and
int
(
topic_id_object
.
content_level
)
in
[
0
,
3
,
4
,
5
]:
if
topic_id_object
and
topic_id_object
.
is_online
and
int
(
topic_id_object
.
content_level
)
in
[
0
,
3
,
4
,
5
]:
effective_num
+=
1
if
effective_num
>=
5
:
ret
=
True
break
return
ret
except
:
logging
.
error
(
"catch exception,err_msg:
%
s"
%
traceback
.
format_exc
())
...
...
@@ -109,7 +109,8 @@ class Pictorial(models.Model):
def
get_tag_by_id
(
self
):
try
:
tag_id_list
=
list
(
PictorialTag
.
objects
.
filter
(
pictorial_id
=
self
.
id
,
is_online
=
True
)
.
values_list
(
"tag_id"
,
flat
=
True
))
tag_id_list
=
list
(
PictorialTag
.
objects
.
filter
(
pictorial_id
=
self
.
id
,
is_online
=
True
)
.
values_list
(
"tag_id"
,
flat
=
True
))
return
tag_id_list
except
:
...
...
@@ -125,6 +126,25 @@ class Pictorial(models.Model):
logging
.
error
(
"catch exception,err_msg:
%
s"
%
traceback
.
format_exc
())
return
[]
def
get_is_cover
(
self
,
topic_id_list
):
try
:
effective_num
=
0
ret
=
False
for
topic_id
in
topic_id_list
:
topic_id_object
=
Topic
.
objects
.
filter
(
id
=
int
(
topic_id
))
.
first
()
if
topic_id_object
and
topic_id_object
.
is_online
and
int
(
topic_id_object
.
content_level
)
in
[
3
,
4
,
5
,
6
]:
effective_num
+=
1
if
effective_num
>=
5
:
ret
=
True
break
return
ret
except
:
logging
.
error
(
"catch exception,err_msg:
%
s"
%
traceback
.
format_exc
())
return
False
class
PictorialTag
(
models
.
Model
):
"""画报关注标签"""
...
...
trans2es/models/tag.py
View file @
439f4043
...
...
@@ -12,10 +12,10 @@ import datetime
class
TopicTag
(
models
.
Model
):
class
Meta
:
verbose_name
=
u"帖子标签"
db_table
=
"community_topictag"
verbose_name
=
u"帖子标签"
db_table
=
"community_topictag"
id
=
models
.
IntegerField
(
primary_key
=
True
,
verbose_name
=
u"主键ID"
)
id
=
models
.
IntegerField
(
primary_key
=
True
,
verbose_name
=
u"主键ID"
)
tag_id
=
models
.
IntegerField
(
verbose_name
=
u"标签ID"
)
topic_id
=
models
.
IntegerField
(
verbose_name
=
u"帖子ID"
)
is_online
=
models
.
BooleanField
(
verbose_name
=
u"是否在线"
)
...
...
@@ -25,73 +25,84 @@ class TopicTag(models.Model):
class
AccountUserTag
(
models
.
Model
):
class
Meta
:
verbose_name
=
u"用户标签"
db_table
=
"account_user_tag"
verbose_name
=
u"用户标签"
db_table
=
"account_user_tag"
id
=
models
.
IntegerField
(
primary_key
=
True
,
verbose_name
=
u"主键ID"
)
id
=
models
.
IntegerField
(
primary_key
=
True
,
verbose_name
=
u"主键ID"
)
tag_id
=
models
.
IntegerField
(
verbose_name
=
u"标签ID"
)
user
=
models
.
IntegerField
(
verbose_name
=
u"用户ID"
)
is_deleted
=
models
.
BooleanField
(
verbose_name
=
u"是否删除"
)
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
))
is_body_esthetics
=
models
.
IntegerField
(
verbose_name
=
u"是否有用标签"
)
class
Tag
(
models
.
Model
):
class
Meta
:
verbose_name
=
u"标签"
db_table
=
"community_tag"
verbose_name
=
u"标签"
db_table
=
"community_tag"
id
=
models
.
IntegerField
(
primary_key
=
True
,
verbose_name
=
u"主键ID"
)
id
=
models
.
IntegerField
(
primary_key
=
True
,
verbose_name
=
u"主键ID"
)
is_deleted
=
models
.
BooleanField
(
verbose_name
=
u"是否删除"
)
is_online
=
models
.
BooleanField
(
verbose_name
=
u"是否上线"
)
name
=
models
.
CharField
(
verbose_name
=
u"标签名称"
,
max_length
=
128
)
name
=
models
.
CharField
(
verbose_name
=
u"标签名称"
,
max_length
=
128
)
description
=
models
.
TextField
(
verbose_name
=
u"标签描述"
)
icon_url
=
models
.
CharField
(
verbose_name
=
u"icon_url"
,
max_length
=
120
)
icon_url
=
models
.
CharField
(
verbose_name
=
u"icon_url"
,
max_length
=
120
)
collection
=
models
.
IntegerField
(
verbose_name
=
u"是否编辑"
)
is_ai
=
models
.
IntegerField
(
verbose_name
=
u"是否ai"
)
is_own
=
models
.
IntegerField
(
verbose_name
=
u"是否ins上自带"
)
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
))
class
CommunityTagFollow
(
models
.
Model
):
class
Meta
:
verbose_name
=
u"用户关注标签"
db_table
=
"community_tag_follow"
id
=
models
.
IntegerField
(
primary_key
=
True
,
verbose_name
=
u"主键ID"
)
verbose_name
=
u"用户关注标签"
db_table
=
"community_tag_follow"
id
=
models
.
IntegerField
(
primary_key
=
True
,
verbose_name
=
u"主键ID"
)
is_deleted
=
models
.
BooleanField
(
verbose_name
=
u"是否删除"
)
is_online
=
models
.
BooleanField
(
verbose_name
=
u"是否上线"
)
user_id
=
models
.
IntegerField
(
verbose_name
=
u"用户ID"
)
tag_id
=
models
.
IntegerField
(
verbose_name
=
u"帖子ID"
)
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
))
class
CommunityTagTypeRelation
(
models
.
Model
):
class
Meta
:
verbose_name
=
u"标签类型对应关系"
db_table
=
"community_tag_type_relation"
verbose_name
=
u"标签类型对应关系"
db_table
=
"community_tag_type_relation"
id
=
models
.
IntegerField
(
primary_key
=
True
,
verbose_name
=
u"主键ID"
)
id
=
models
.
IntegerField
(
primary_key
=
True
,
verbose_name
=
u"主键ID"
)
is_deleted
=
models
.
BooleanField
(
verbose_name
=
u"是否删除"
)
is_online
=
models
.
BooleanField
(
verbose_name
=
u"是否上线"
)
tag_id
=
models
.
IntegerField
(
verbose_name
=
u"标签ID"
)
tag_type_id
=
models
.
IntegerField
(
verbose_name
=
u"标签类型ID"
)
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
))
class
CommunityTagType
(
models
.
Model
):
class
Meta
:
verbose_name
=
u"标签类型"
db_table
=
"community_tag_type"
verbose_name
=
u"标签类型"
db_table
=
"community_tag_type"
id
=
models
.
IntegerField
(
primary_key
=
True
,
verbose_name
=
u"主键ID"
)
id
=
models
.
IntegerField
(
primary_key
=
True
,
verbose_name
=
u"主键ID"
)
is_deleted
=
models
.
BooleanField
(
verbose_name
=
u"是否删除"
)
is_online
=
models
.
BooleanField
(
verbose_name
=
u"是否上线"
)
name
=
models
.
CharField
(
verbose_name
=
u"名称"
,
max_length
=
64
)
create_time
=
models
.
DateTimeField
(
verbose_name
=
u'创建时间'
,
default
=
datetime
.
datetime
.
fromtimestamp
(
0
))
name
=
models
.
CharField
(
verbose_name
=
u"名称"
,
max_length
=
64
)
create_time
=
models
.
DateTimeField
(
verbose_name
=
u'创建时间'
,
default
=
datetime
.
datetime
.
fromtimestamp
(
0
))
update_time
=
models
.
DateTimeField
(
verbose_name
=
u'更新时间'
,
default
=
datetime
.
datetime
.
fromtimestamp
(
0
))
class
RegisterShowTag
(
models
.
Model
):
class
Meta
:
verbose_name
=
"搜索热词"
db_table
=
"register_show_tag"
id
=
models
.
IntegerField
(
primary_key
=
True
,
verbose_name
=
u"主键ID"
)
is_deleted
=
models
.
IntegerField
(
verbose_name
=
u"是否删除"
)
is_online
=
models
.
IntegerField
(
verbose_name
=
u"是否在线"
)
tag_id
=
models
.
IntegerField
(
verbose_name
=
"标签ID"
)
trans2es/models/user.py
View file @
439f4043
...
...
@@ -16,6 +16,8 @@ from .tag import AccountUserTag
from
.topic
import
Topic
from
.user_extra
import
UserExtra
from
.pictorial
import
PictorialFollow
from
.topic
import
Topic
class
User
(
models
.
Model
):
class
Meta
:
...
...
@@ -35,9 +37,10 @@ class User(models.Model):
update_time
=
models
.
DateTimeField
(
verbose_name
=
u'更新时间'
,
default
=
datetime
.
datetime
.
fromtimestamp
(
0
))
@classmethod
def
get_user_nick_name
(
cls
,
user_id
):
def
get_user_nick_name
(
cls
,
user_id
):
try
:
nick_name
=
User
.
objects
.
using
(
settings
.
SLAVE_DB_NAME
)
.
filter
(
user_id
=
user_id
)
.
values_list
(
"nick_name"
)
.
first
()
nick_name
=
User
.
objects
.
using
(
settings
.
SLAVE_DB_NAME
)
.
filter
(
user_id
=
user_id
)
.
values_list
(
"nick_name"
)
.
first
()
return
nick_name
[
0
]
except
:
...
...
@@ -47,7 +50,8 @@ class User(models.Model):
def
get_is_recommend_flag
(
self
):
is_shadow
=
False
is_recommend
=
False
query_sql
=
UserExtra
.
objects
.
using
(
settings
.
SLAVE_DB_NAME
)
.
filter
(
user_id
=
self
.
user_id
,
is_deleted
=
False
,
is_online
=
True
)
query_sql
=
UserExtra
.
objects
.
using
(
settings
.
SLAVE_DB_NAME
)
.
filter
(
user_id
=
self
.
user_id
,
is_deleted
=
False
,
is_online
=
True
)
for
record
in
query_sql
:
is_recommend
=
record
.
is_recommend
is_shadow
=
record
.
is_shadow
...
...
@@ -58,8 +62,9 @@ class User(models.Model):
latest_topic_time_val
=
-
1
# 获取该用户最新发帖时间
topic_records
=
Topic
.
objects
.
using
(
settings
.
SLAVE_DB_NAME
)
.
filter
(
user_id
=
self
.
user_id
)
.
order_by
(
"-update_time"
)
.
values_list
(
"update_time"
,
flat
=
True
)
.
first
()
topic_records
=
Topic
.
objects
.
using
(
settings
.
SLAVE_DB_NAME
)
.
filter
(
user_id
=
self
.
user_id
)
.
order_by
(
"-update_time"
)
.
values_list
(
"update_time"
,
flat
=
True
)
.
first
()
if
topic_records
:
tzlc_topic_update_time
=
tzlc
(
topic_records
)
latest_topic_time_val
=
int
(
time
.
mktime
(
tzlc_topic_update_time
.
timetuple
()))
...
...
@@ -75,7 +80,8 @@ class User(models.Model):
logging
.
info
(
"get follow_user_id_list :
%
s"
%
follow_user_id_list
)
for
i
in
range
(
0
,
len
(
follow_user_id_list
),
1000
):
logging
.
info
(
"get follow_user_id_list :
%
s"
%
follow_user_id_list
[
i
:
i
+
1000
])
sql_data_list
=
User
.
objects
.
using
(
settings
.
SLAVE_DB_NAME
)
.
filter
(
user_id__in
=
follow_user_id_list
[
i
:
i
+
1000
])
sql_data_list
=
User
.
objects
.
using
(
settings
.
SLAVE_DB_NAME
)
.
filter
(
user_id__in
=
follow_user_id_list
[
i
:
i
+
1000
])
for
detail_data
in
sql_data_list
:
item
=
{
"user_id"
:
detail_data
.
user_id
,
...
...
@@ -88,7 +94,8 @@ class User(models.Model):
def
get_attention_group_id_list
(
self
):
try
:
attention_group_id_list
=
list
()
query_results
=
GroupUserRole
.
objects
.
using
(
settings
.
SLAVE_DB_NAME
)
.
filter
(
is_online
=
True
,
user_id
=
self
.
user_id
)
query_results
=
GroupUserRole
.
objects
.
using
(
settings
.
SLAVE_DB_NAME
)
.
filter
(
is_online
=
True
,
user_id
=
self
.
user_id
)
for
item
in
query_results
:
item_dict
=
{
"group_id"
:
item
.
group_id
,
...
...
@@ -104,15 +111,16 @@ class User(models.Model):
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
)
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 user_id:
%
s"
%
self
.
user_id
)
logging
.
info
(
"get same_pictorial_user_id_list:
%
s"
%
attention_pictorial_id_list
)
...
...
@@ -149,25 +157,29 @@ class User(models.Model):
def
get_same_pictorial_user_id_list
(
self
):
#todo 有的同组数据过大,导致celery cpu过高,暂时限制同组的数据大小,后续可能会去掉同组的数据
#
todo 有的同组数据过大,导致celery cpu过高,暂时限制同组的数据大小,后续可能会去掉同组的数据
same_pictorial_user_id_list
=
list
()
pictorial_items_list
=
list
(
PictorialFollow
.
objects
.
using
(
settings
.
SLAVE_DB_NAME
)
.
filter
(
user_id
=
self
.
user_id
)
.
values_list
(
"pictorial_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
pictorial_id
in
pictorial_items_list
:
user_items_list
=
list
(
PictorialFollow
.
objects
.
using
(
settings
.
SLAVE_DB_NAME
)
.
filter
(
pictorial_id
=
pictorial_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
:
same_pictorial_user_id_list
.
append
(
user_id
)
if
len
(
same_pictorial_user_id_list
)
>=
100
:
if
len
(
same_pictorial_user_id_list
)
>=
100
:
break
if
len
(
same_pictorial_user_id_list
)
>=
100
:
if
len
(
same_pictorial_user_id_list
)
>=
100
:
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
)
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_pictorial_detail_list
=
list
()
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_pictorial_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
:
item
=
{
"user_id"
:
detail_data
.
user_id
,
...
...
@@ -181,7 +193,8 @@ class User(models.Model):
try
:
user_tag_id_list
=
list
()
query_results
=
AccountUserTag
.
objects
.
using
(
settings
.
SLAVE_DB_NAME
)
.
filter
(
user
=
self
.
user_id
,
is_deleted
=
False
)
query_results
=
AccountUserTag
.
objects
.
using
(
settings
.
SLAVE_DB_NAME
)
.
filter
(
user
=
self
.
user_id
,
is_deleted
=
False
)
for
item
in
query_results
:
user_tag_id_list
.
append
(
item
.
tag_id
)
...
...
@@ -194,11 +207,21 @@ class User(models.Model):
try
:
user_useful_tag_id_list
=
list
()
query_results
=
AccountUserTag
.
objects
.
using
(
settings
.
SLAVE_DB_NAME
)
.
filter
(
user
=
self
.
user_id
,
is_body_esthetics
=
1
,
is_deleted
=
False
)
query_results
=
AccountUserTag
.
objects
.
using
(
settings
.
SLAVE_DB_NAME
)
.
filter
(
user
=
self
.
user_id
,
is_body_esthetics
=
1
,
is_deleted
=
False
)
for
item
in
query_results
:
user_useful_tag_id_list
.
append
(
item
.
tag_id
)
return
user_useful_tag_id_list
except
:
logging
.
error
(
"catch exception,err_msg:
%
s"
%
traceback
.
format_exc
())
return
[]
\ No newline at end of file
return
[]
def
get_topic_number
(
self
):
try
:
number
=
Topic
.
objects
.
filter
(
user_id
=
self
.
user_id
)
.
count
()
return
number
except
:
logging
.
error
(
"catch exception,err_msg:
%
s"
%
traceback
.
format_exc
())
return
0
trans2es/utils/pictorial_transfer.py
View file @
439f4043
...
...
@@ -7,26 +7,27 @@ import traceback
from
libs.tools
import
tzlc
from
trans2es.models.topic
import
Topic
class
PictorialTransfer
(
object
):
def
__init__
(
self
):
pass
@classmethod
def
get_offline_score
(
cls
,
instance
,
topic_id_list
):
def
get_offline_score
(
cls
,
instance
,
topic_id_list
):
try
:
total_offline_score
=
0
topic_image_num
=
0
for
topic_id
in
topic_id_list
:
topic_image_num
+=
Topic
.
get_topic_image_num
(
topic_id
)
if
topic_image_num
>=
6
and
topic_image_num
<=
10
:
if
topic_image_num
>=
6
and
topic_image_num
<=
10
:
total_offline_score
+=
30
elif
topic_image_num
>
10
and
topic_image_num
<=
20
:
elif
topic_image_num
>
10
and
topic_image_num
<=
20
:
total_offline_score
+=
60
elif
topic_image_num
>
20
and
topic_image_num
<=
50
:
elif
topic_image_num
>
20
and
topic_image_num
<=
50
:
total_offline_score
+=
80
elif
topic_image_num
>
50
:
elif
topic_image_num
>
50
:
total_offline_score
+=
100
total_offline_score
+=
instance
.
add_score
...
...
@@ -62,10 +63,11 @@ class PictorialTransfer(object):
tag_id_list
=
instance
.
get_tag_by_id
()
res
[
"tag_id"
]
=
tag_id_list
res
[
"tag_name"
]
=
instance
.
get_tag_by_name
(
tag_id_list
)
res
[
"topic_id_list"
]
=
instance
.
get_topic_id
()
res
[
"topic_id_list"
]
=
instance
.
get_topic_id
()
res
[
"effective"
]
=
instance
.
get_effective
(
res
[
"topic_id_list"
])
res
[
"offline_score"
]
=
cls
.
get_offline_score
(
instance
,
res
[
"topic_id_list"
])
res
[
"offline_score"
]
=
cls
.
get_offline_score
(
instance
,
res
[
"topic_id_list"
])
res
[
"is_default"
]
=
instance
.
is_default
res
[
"is_cover"
]
=
instance
.
get_is_cover
(
res
[
"topic_id_list"
])
return
res
except
:
logging
.
error
(
"catch exception,err_msg:
%
s"
%
traceback
.
format_exc
())
...
...
trans2es/utils/user_transfer.py
View file @
439f4043
...
...
@@ -21,8 +21,9 @@ class UserTransfer(object):
follow_user_detail_list
=
list
()
for
i
in
range
(
0
,
len
(
follow_user_id_list
),
1000
):
sql_data_list
=
User
.
objects
.
using
(
settings
.
SLAVE_DB_NAME
)
.
filter
(
user_id__in
=
follow_user_id_list
[
i
:
i
+
1000
],
is_online
=
True
,
is_deleted
=
False
)
sql_data_list
=
User
.
objects
.
using
(
settings
.
SLAVE_DB_NAME
)
.
filter
(
user_id__in
=
follow_user_id_list
[
i
:
i
+
1000
],
is_online
=
True
,
is_deleted
=
False
)
for
detail_data
in
sql_data_list
:
item
=
{
"user_id"
:
detail_data
.
user_id
,
...
...
@@ -40,13 +41,14 @@ class UserTransfer(object):
res
[
"id"
]
=
instance
.
id
res
[
"user_id"
]
=
instance
.
user_id
res
[
"nick_name"
]
=
instance
.
nick_name
res
[
"nick_name_pre"
]
=
instance
.
nick_name
res
[
"profile_pic"
]
=
instance
.
profile_pic
res
[
"gender"
]
=
instance
.
gender
res
[
"city_id"
]
=
instance
.
city_id
res
[
"country_id"
]
=
instance
.
country_id
res
[
"is_online"
]
=
instance
.
is_online
res
[
"is_deleted"
]
=
instance
.
is_deleted
res
[
"count_topic"
]
=
instance
.
get_topic_number
()
try
:
(
is_recommend
,
is_shadow
)
=
instance
.
get_is_recommend_flag
()
res
[
"is_recommend"
]
=
is_recommend
...
...
@@ -95,7 +97,6 @@ class UserTransfer(object):
res
[
"attention_pictorial_id_list"
]
=
[]
res
[
"same_pictorial_user_id_list"
]
=
[]
return
res
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