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
7e31a292
Commit
7e31a292
authored
Apr 11, 2019
by
Kai
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update
parent
8e05c45d
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
42 additions
and
19 deletions
+42
-19
es.py
libs/es.py
+12
-1
collect_data.py
linucb/views/collect_data.py
+30
-18
No files found.
libs/es.py
View file @
7e31a292
...
@@ -265,6 +265,14 @@ class ESPerform(object):
...
@@ -265,6 +265,14 @@ class ESPerform(object):
@classmethod
@classmethod
def
get_tag_topic_list
(
cls
,
tag_id
):
def
get_tag_topic_list
(
cls
,
tag_id
):
for
id
in
tag_id
:
functions_list
.
append
(
{
"filter"
:
{
"term"
:
{
"tag_list"
:
id
}},
"weight"
:
1
}
)
try
:
try
:
q
=
{
q
=
{
"query"
:{
"query"
:{
...
@@ -273,14 +281,17 @@ class ESPerform(object):
...
@@ -273,14 +281,17 @@ class ESPerform(object):
{
"range"
:
{
"content_level"
:
{
"gte"
:
4
,
"lte"
:
5
}}},
{
"range"
:
{
"content_level"
:
{
"gte"
:
4
,
"lte"
:
5
}}},
{
"term"
:{
"is_online"
:
True
}},
{
"term"
:{
"is_online"
:
True
}},
{
"term"
:{
"is_deleted"
:
False
}},
{
"term"
:{
"is_deleted"
:
False
}},
{
"term"
:{
"tag_list"
:
tag_id
}}
{
"term
s
"
:{
"tag_list"
:
tag_id
}}
]
]
}
}
},
},
"score_mode"
:
"sum"
,
"functions"
:
functions_list
,
"_source"
:{
"_source"
:{
"include"
:[
"id"
]
"include"
:[
"id"
]
},
},
"sort"
:[
"sort"
:[
{
"_score"
:
{
"order"
:
"desc"
}},
{
"create_time_val"
:{
"order"
:
"desc"
}},
{
"create_time_val"
:{
"order"
:
"desc"
}},
{
"language_type"
:{
"order"
:
"asc"
}},
{
"language_type"
:{
"order"
:
"asc"
}},
]
]
...
...
linucb/views/collect_data.py
View file @
7e31a292
...
@@ -75,23 +75,31 @@ class CollectData(object):
...
@@ -75,23 +75,31 @@ class CollectData(object):
recommend_topic_id_list
=
list
()
recommend_topic_id_list
=
list
()
for
index
in
range
(
0
,
100
):
for
index
in
range
(
0
,
100
):
recommend_topic_id_list_random
=
list
()
recommend_topic_id_list_es
=
list
()
for
tag_id
in
recommend_tag_list
[
0
:
100
]:
# for tag_id in recommend_tag_list[0:100]:
redis_tag_id_key
=
self
.
tag_topic_id_redis_prefix
+
str
(
tag_id
)
# redis_tag_id_key = self.tag_topic_id_redis_prefix + str(tag_id)
redis_tag_id_data
=
redis_client
.
get
(
redis_tag_id_key
)
# redis_tag_id_data = redis_client.get(redis_tag_id_key)
tag_topic_id_list
=
json
.
loads
(
redis_tag_id_data
)
if
redis_tag_id_data
else
[]
# tag_topic_id_list = json.loads(redis_tag_id_data) if redis_tag_id_data else []
if
not
redis_tag_id_data
:
# if not redis_tag_id_data:
tag_topic_id_list
=
ESPerform
.
get_tag_topic_list
(
tag_id
)
# tag_topic_id_list = ESPerform.get_tag_topic_list(tag_id)
redis_client
.
set
(
redis_tag_id_key
,
json
.
dumps
(
tag_topic_id_list
))
# redis_client.set(redis_tag_id_key,json.dumps(tag_topic_id_list))
redis_client
.
expire
(
redis_tag_id_key
,
1
*
24
*
60
*
60
)
# redis_client.expire(redis_tag_id_key,1*24*60*60)
#
if
len
(
tag_topic_id_list
)
>
index
:
# if len(tag_topic_id_list)>index:
for
topic_id
in
tag_topic_id_list
[
index
:]:
# for topic_id in tag_topic_id_list[index:]:
if
topic_id
not
in
have_read_topic_id_list
and
topic_id
not
in
recommend_topic_id_list_random
and
topic_id
not
in
recommend_topic_id_list
:
# if topic_id not in have_read_topic_id_list and topic_id not in recommend_topic_id_list_random and topic_id not in recommend_topic_id_list:
recommend_topic_id_list_random
.
append
(
topic_id
)
# recommend_topic_id_list_random.append(topic_id)
break
# break
random
.
shuffle
(
recommend_topic_id_list_random
)
tag_id
=
recommend_tag_list
[
0
:
100
]
recommend_topic_id_list
.
extend
(
recommend_topic_id_list_random
)
tag_topic_id_list
=
ESPerform
.
get_tag_topic_list
(
tag_id
)
if
len
(
tag_topic_id_list
)
>
index
:
for
topic_id
in
tag_topic_id_list
[
index
:]:
if
topic_id
not
in
have_read_topic_id_list
and
topic_id
not
in
recommend_topic_id_list_es
and
topic_id
not
in
recommend_topic_id_list
:
recommend_topic_id_list_es
.
append
(
topic_id
)
if
len
(
recommend_topic_id_list_es
)
==
100
:
break
# random.shuffle(recommend_topic_id_list_random)
recommend_topic_id_list
.
extend
(
recommend_topic_id_list_es
)
topic_recommend_redis_key
=
self
.
linucb_recommend_topic_id_prefix
+
str
(
device_id
)
topic_recommend_redis_key
=
self
.
linucb_recommend_topic_id_prefix
+
str
(
device_id
)
redis_data_dict
=
{
redis_data_dict
=
{
...
@@ -179,7 +187,11 @@ class CollectData(object):
...
@@ -179,7 +187,11 @@ class CollectData(object):
exposure_sql_query_results
=
TopicTag
.
objects
.
using
(
settings
.
SLAVE_DB_NAME
)
.
filter
(
topic_id__in
=
exposure_topic_id_list
)
.
values_list
(
"topic_id"
,
"tag_id"
,
"is_online"
)
exposure_sql_query_results
=
TopicTag
.
objects
.
using
(
settings
.
SLAVE_DB_NAME
)
.
filter
(
topic_id__in
=
exposure_topic_id_list
)
.
values_list
(
"topic_id"
,
"tag_id"
,
"is_online"
)
for
topic_id
,
tag_id
,
is_online
in
exposure_sql_query_results
:
for
topic_id
,
tag_id
,
is_online
in
exposure_sql_query_results
:
if
is_online
:
if
is_online
:
tag_list
.
append
(
tag_id
)
tag_sql_query_results
=
Tag
.
objects
.
using
(
settings
.
SLAVE_DB_NAME
)
.
filter
(
id
=
tag_id
)
.
values_list
(
"id"
,
"collection"
,
"is_ai"
)
for
id
,
collection
,
is_ai
in
tag_sql_query_results
:
if
collection
==
1
or
is_ai
==
1
:
tag_list
.
append
(
id
)
if
topic_id
not
in
topic_tag_id_dict
:
if
topic_id
not
in
topic_tag_id_dict
:
topic_tag_id_dict
[
topic_id
]
=
list
()
topic_tag_id_dict
[
topic_id
]
=
list
()
...
...
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