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
钟尚武
physical
Commits
69df59b5
Commit
69df59b5
authored
Nov 26, 2018
by
段英荣
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
modify
parent
e7f3beb8
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
147 additions
and
21 deletions
+147
-21
error.py
libs/error.py
+18
-0
topic.py
search/utils/topic.py
+25
-0
topic.py
search/views/topic.py
+19
-8
pick_celebrity.json
trans2es/mapping/pick_celebrity.json
+12
-0
group.py
trans2es/models/group.py
+2
-2
pick_celebrity.py
trans2es/models/pick_celebrity.py
+24
-0
pickuserrecord.py
trans2es/models/pickuserrecord.py
+3
-3
user.py
trans2es/models/user.py
+2
-2
user_follow.py
trans2es/models/user_follow.py
+2
-2
type_info.py
trans2es/type_info.py
+13
-1
pick_celebrity_transfer.py
trans2es/utils/pick_celebrity_transfer.py
+27
-0
topic_transfer.py
trans2es/utils/topic_transfer.py
+0
-3
No files found.
libs/error.py
0 → 100644
View file @
69df59b5
from
gm_rpcd.all
import
RPCDFaultException
from
gm_types.doris.error
import
ERROR
from
raven.contrib.django.raven_compat.models
import
client
as
_sentry_client
def
raise_error
(
error_code
,
message
=
None
):
assert
error_code
!=
0
if
message
is
None
:
message
=
ERROR
.
getDesc
(
error_code
)
raise
RPCDFaultException
(
code
=
error_code
,
message
=
message
)
def
logging_exception
(
send_to_sentry
=
True
):
try
:
# send exception info to sentry, fail silently
_sentry_client
.
captureException
()
except
:
pass
search/utils/topic.py
View file @
69df59b5
...
...
@@ -33,3 +33,27 @@ class TopicUtils(object):
return
None
@classmethod
def
analyze_related_user_id_list
(
cls
,
related_user_id_list
):
"""
:remark:获取指定用户关联的 用户列表
:param related_user_id_list:
:return:
"""
try
:
chinese_user_id_list
=
list
()
japan_user_id_list
=
list
()
korea_user_id_list
=
list
()
for
item
in
related_user_id_list
:
if
item
[
"country_id"
]
==
0
:
chinese_user_id_list
.
append
(
item
[
"user_id"
])
elif
item
[
"country_id"
]
==
1
:
japan_user_id_list
.
append
(
item
[
"user_id"
])
elif
item
[
"country_id"
]
==
2
:
korea_user_id_list
.
append
(
item
[
"user_id"
])
return
(
chinese_user_id_list
,
japan_user_id_list
,
korea_user_id_list
)
except
:
logging
.
error
(
"catch exception,err_msg:
%
s"
%
traceback
.
format_exc
())
return
([],[],[])
\ No newline at end of file
search/views/topic.py
View file @
69df59b5
...
...
@@ -14,16 +14,22 @@ def home_recommend(user_id=-1,offset=0,size=10):
:return:
"""
try
:
# 获取user_id 关注的用户集合
attention_user_id_list
=
list
()
# 获取user_id pick的用户集合
pick_user_id_list
=
list
()
# 参与的小组发帖
# 马甲账号集合
vest_account_list
=
list
()
result_dict
=
TopicUtils
.
get_related_user_info
(
user_id
,
offset
,
size
)
if
len
(
result_dict
[
"hits"
])
==
0
:
logging
.
error
(
"Not find user_id:
%
d in es!"
%
int
(
user_id
))
return
{
"recommend_topic_ids"
:[]}
attention_user_info_list
=
result_dict
[
"hits"
][
0
][
"attention_user_id_list"
]
(
attention_chinese_user_id_list
,
attention_japan_user_id_list
,
attention_korea_user_id_list
)
=
TopicUtils
.
analyze_related_user_id_list
(
related_user_id_list
=
attention_user_info_list
)
pick_user_info_list
=
result_dict
[
"hits"
][
0
][
"pick_user_id_list"
]
(
pick_chinese_user_id_list
,
pick_japan_user_id_list
,
pick_korea_user_id_list
)
=
TopicUtils
.
analyze_related_user_id_list
(
pick_user_info_list
)
same_group_user_info_list
=
result_dict
[
"hits"
][
0
][
"same_group_user_id_list"
]
(
same_group_chinese_user_id_list
,
same_group_japan_user_id_list
,
same_group_korea_user_id_list
)
=
TopicUtils
.
analyze_related_user_id_list
(
same_group_user_info_list
)
q
=
dict
()
q
[
"filter"
]
=
{
...
...
@@ -32,13 +38,17 @@ def home_recommend(user_id=-1,offset=0,size=10):
query_function_score
=
dict
()
functions
=
[
{
"filter"
:{
"match"
:{
"user_id"
:
attention_user_id_list
}},
"filter"
:{
"match"
:{
"user_id"
:
attention_
chinese_
user_id_list
}},
"weight"
:
5
,
},
{
"filter"
:{
"match"
:{
"user_id"
:
pick_user_id_list
}},
"filter"
:{
"match"
:{
"user_id"
:
pick_
chinese_
user_id_list
}},
"weight"
:
3
},
{
"filter"
:
{
"match"
:
{
"user_id"
:
same_group_chinese_user_id_list
}},
"weight"
:
2
},
{
"filter"
:
{
"match"
:
{
"user_id"
:
vest_account_list
}},
"weight"
:
0.5
...
...
@@ -62,4 +72,5 @@ def home_recommend(user_id=-1,offset=0,size=10):
except
:
logging
.
error
(
"catch exception,err_msg:
%
s"
%
traceback
.
format_exc
())
return
{
"recommend_topic_ids"
:
[]}
trans2es/mapping/pick_celebrity.json
0 → 100644
View file @
69df59b5
{
"dynamic"
:
"strict"
,
"properties"
:{
"id"
:{
"type"
:
"long"
},
"rank"
:{
"type"
:
"long"
},
"celebrity_id"
:{
"type"
:
"long"
},
"pick_id"
:{
"type"
:
"long"
},
"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/models/group.py
View file @
69df59b5
...
...
@@ -23,8 +23,8 @@ class Group(models.Model):
topic_num
=
models
.
IntegerField
(
verbose_name
=
u'帖子数'
,
default
=
0
)
is_online
=
models
.
BooleanField
(
verbose_name
=
u"是否有效"
,
default
=
True
,
db_index
=
True
)
is_recommend
=
models
.
BooleanField
(
verbose_name
=
u"是否推荐"
,
default
=
False
,
db_index
=
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
))
create_time
=
models
.
DateTimeField
(
verbose_name
=
u'创建时间'
,
default
=
datetime
.
datetime
.
fromtimestamp
(
0
))
update_time
=
models
.
DateTimeField
(
verbose_name
=
u'更新时间'
,
default
=
datetime
.
datetime
.
fromtimestamp
(
0
))
def
detail
(
self
):
result
=
{
...
...
trans2es/models/pick_celebrity.py
0 → 100644
View file @
69df59b5
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from
django.conf
import
settings
from
django.core.management.base
import
BaseCommand
,
CommandError
import
traceback
import
logging
from
libs.es
import
ESPerform
from
django.db
import
models
import
datetime
class
PickCelebrity
(
models
.
Model
):
class
Meta
:
verbose_name
=
u"pick明星"
db_table
=
u"pickcelebrity"
app_label
=
"api"
id
=
models
.
IntegerField
(
primary_key
=
True
,
verbose_name
=
u"主键ID"
)
celebrity_id
=
models
.
IntegerField
(
verbose_name
=
u"明星ID"
)
pick_id
=
models
.
IntegerField
(
verbose_name
=
u"榜ID"
)
rank
=
models
.
IntegerField
(
verbose_name
=
u"排名"
)
create_time
=
models
.
DateTimeField
(
verbose_name
=
u'创建时间'
,
default
=
datetime
.
datetime
.
fromtimestamp
(
0
))
update_time
=
models
.
DateTimeField
(
verbose_name
=
u'更新时间'
,
default
=
datetime
.
datetime
.
fromtimestamp
(
0
))
trans2es/models/pickuserrecord.py
View file @
69df59b5
...
...
@@ -12,7 +12,7 @@ from .user import User
class
PickUserRecord
(
models
.
Model
):
class
Meta
:
verbose_name
=
u'
pickuserrecord
'
verbose_name
=
u'
用户之间pick
'
verbose_name_plural
=
u'pickuserrecord'
db_table
=
'pickuserrecord'
app_label
=
'api'
...
...
@@ -20,6 +20,6 @@ class PickUserRecord(models.Model):
pickuser_id
=
models
.
IntegerField
(
verbose_name
=
"pick user id"
)
is_deleted
=
models
.
BooleanField
(
verbose_name
=
"是否删除"
)
is_pick
=
models
.
BooleanField
(
verbose_name
=
"is_pick"
)
create_time
=
models
.
DateTimeField
(
verbose_name
=
u'
日记
创建时间'
,
default
=
datetime
.
datetime
.
fromtimestamp
(
0
))
update_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
))
user
=
models
.
ForeignKey
(
User
,
related_name
=
"user_pick"
,
verbose_name
=
"pick用户信息"
)
trans2es/models/user.py
View file @
69df59b5
...
...
@@ -26,8 +26,8 @@ class User(models.Model):
city_id
=
models
.
IntegerField
(
verbose_name
=
u'城市id'
)
country_id
=
models
.
IntegerField
(
verbose_name
=
'国家id'
)
is_online
=
models
.
BooleanField
(
verbose_name
=
"是否上线"
)
create_time
=
models
.
DateTimeField
(
verbose_name
=
u'
日记
创建时间'
,
default
=
datetime
.
datetime
.
fromtimestamp
(
0
))
update_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
))
def
get_follow_user_id_list
(
self
):
...
...
trans2es/models/user_follow.py
View file @
69df59b5
...
...
@@ -21,5 +21,5 @@ class UserFollow(models.Model):
follow_id
=
models
.
IntegerField
(
verbose_name
=
"关注的用户ID"
)
is_online
=
models
.
BooleanField
(
verbose_name
=
"是否上线"
)
is_deleted
=
models
.
BooleanField
(
verbose_name
=
"是否删除"
)
create_time
=
models
.
DateTimeField
(
verbose_name
=
u'
日记
创建时间'
,
default
=
datetime
.
datetime
.
fromtimestamp
(
0
))
update_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
))
trans2es/type_info.py
View file @
69df59b5
...
...
@@ -12,9 +12,10 @@ import elasticsearch
import
elasticsearch.helpers
import
sys
from
trans2es.models
import
topic
,
user
from
trans2es.models
import
topic
,
user
,
pick_celebrity
from
trans2es.utils.topic_transfer
import
TopicTransfer
from
trans2es.utils.user_transfer
import
UserTransfer
from
trans2es.utils.pick_celebrity_transfer
import
PickCelebrityTransfer
from
libs.es
import
ESPerform
...
...
@@ -254,6 +255,17 @@ def get_type_info_map():
bulk_insert_chunk_size
=
100
,
round_insert_chunk_size
=
5
,
round_insert_period
=
2
,
),
TypeInfo
(
name
=
"pick_celebrity"
,
# 打榜明星
type
=
"pick_celebrity"
,
model
=
pick_celebrity
.
PickCelebrity
,
# query_deferred=lambda:user.User.objects.all().query,
query_deferred
=
lambda
:
pick_celebrity
.
PickCelebrity
.
objects
.
all
()
.
query
,
get_data_func
=
PickCelebrityTransfer
.
get_pick_celebrity_data
,
bulk_insert_chunk_size
=
100
,
round_insert_chunk_size
=
5
,
round_insert_period
=
2
,
)
]
...
...
trans2es/utils/pick_celebrity_transfer.py
0 → 100644
View file @
69df59b5
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import
os
import
sys
import
logging
import
traceback
from
libs.tools
import
tzlc
class
PickCelebrityTransfer
(
object
):
@classmethod
def
get_pick_celebrity_data
(
cls
,
instance
):
try
:
res
=
dict
()
res
[
"id"
]
=
instance
.
id
res
[
"rank"
]
=
instance
.
rank
res
[
"celebrity_id"
]
=
instance
.
celebrity_id
res
[
"pick_id"
]
=
instance
.
pick_id
res
[
"create_time"
]
=
tzlc
(
instance
.
create_time
)
res
[
"update_time"
]
=
tzlc
(
instance
.
update_time
)
return
res
except
:
logging
.
error
(
"catch exception,err_msg:
%
s"
%
traceback
.
format_exc
())
return
None
\ No newline at end of file
trans2es/utils/topic_transfer.py
View file @
69df59b5
...
...
@@ -8,9 +8,6 @@ from libs.tools import tzlc
class
TopicTransfer
(
object
):
def
__init__
(
self
):
pass
@classmethod
def
get_topic_data
(
cls
,
instance
):
try
:
...
...
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