Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
S
strategy_embedding
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
rank
strategy_embedding
Commits
77e6719a
Commit
77e6719a
authored
Oct 30, 2020
by
赵威
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add monitor
parent
1a4e0fff
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
43 additions
and
2 deletions
+43
-2
message.py
utils/message.py
+32
-0
tests.py
word_vector/tests.py
+1
-1
word_to_vec.py
word_vector/word_to_vec.py
+10
-1
No files found.
utils/message.py
0 → 100644
View file @
77e6719a
import
base64
import
hashlib
import
hmac
import
json
import
time
import
urllib
import
requests
def
send_msg_to_dingtalk
(
msg
,
mobiles
=
[]):
try
:
secret
=
"SECffcdd05c1bb9ca2e6268b2593e4891872c5d0a8adf6751915bc77583076ed0b7"
timestamp
=
str
(
round
(
time
.
time
()
*
1000
))
secret_enc
=
secret
.
encode
(
"utf-8"
)
string_to_sign
=
"{}
\n
{}"
.
format
(
timestamp
,
secret
)
string_to_sign_enc
=
string_to_sign
.
encode
(
"utf-8"
)
hmac_code
=
hmac
.
new
(
secret_enc
,
string_to_sign_enc
,
digestmod
=
hashlib
.
sha256
)
.
digest
()
sign
=
urllib
.
parse
.
quote_plus
(
base64
.
b64encode
(
hmac_code
))
headers
=
{
"Content-Type"
:
"application/json"
}
data
=
{
"msgtype"
:
"text"
,
"text"
:
{
"content"
:
msg
}}
if
mobiles
:
data
=
{
"msgtype"
:
"text"
,
"text"
:
{
"content"
:
msg
},
"at"
:
{
"atMobiles"
:
mobiles
,
"isAtAll"
:
False
}}
json_data
=
json
.
dumps
(
data
)
url
=
"https://oapi.dingtalk.com/robot/send?access_token=661cf4d772916d54597d5cd1636fbc6890ef220908dd1f81fe074f44896b6aa2&sign={}×tamp={}"
.
format
(
sign
,
timestamp
)
response
=
requests
.
post
(
url
=
url
,
data
=
json_data
,
headers
=
headers
)
return
str
(
response
.
status_code
)
+
" "
+
str
(
response
.
content
.
decode
(
"utf-8"
))
except
Exception
as
e
:
print
(
e
)
return
str
(
e
)
word_vector/tests.py
View file @
77e6719a
...
...
@@ -9,7 +9,7 @@ model_dir = os.path.join(base_dir, "_models")
data_dir
=
os
.
path
.
join
(
base_dir
,
"_data"
)
if
__name__
==
"__main__"
:
id1
=
[
"202647"
,
"386735"
]
# 下颚角
5
/1252645
id1
=
[
"202647"
,
"386735"
]
# 下颚角
9
/1252645
id2
=
[
"87874"
,
"84198"
]
# 双眼皮 95
with
open
(
os
.
path
.
join
(
data_dir
,
"click_tractate_ids.csv"
),
"r"
)
as
f
:
...
...
word_vector/word_to_vec.py
View file @
77e6719a
import
multiprocessing
import
os
import
time
import
traceback
from
gensim.models
import
Word2Vec
,
word2vec
from
gm_rpcd.all
import
bind
from
utils.es
import
es_scan
from
utils.message
import
send_msg_to_dingtalk
base_dir
=
os
.
getcwd
()
print
(
"base_dir: "
+
base_dir
)
...
...
@@ -48,7 +50,12 @@ def w2v_train(f_name, model_output_name):
@bind
(
"strategy_embedding/word_vector/word_similarity"
)
def
word_similarity
(
word
):
return
WORD2VEC_MODEL
.
wv
.
most_similar
(
word
)
try
:
return
WORD2VEC_MODEL
.
wv
.
most_similar
(
word
)
except
Exception
as
e
:
send_msg_to_dingtalk
(
str
(
e
)
+
"
\n
"
+
str
(
traceback
.
format_exc
()))
print
(
traceback
.
format_exc
())
return
[]
def
get_user_portrait_projects
(
score_limit
=
5
):
...
...
@@ -106,6 +113,8 @@ def clicked_tractate_ids_item2vec_model(id, n=5):
try
:
return
TRACTATE_CLICK_IDS_MODEL
.
wv
.
most_similar
(
id
,
topn
=
n
)
except
Exception
as
e
:
send_msg_to_dingtalk
(
str
(
e
)
+
"
\n
"
+
str
(
traceback
.
format_exc
()))
print
(
traceback
.
format_exc
())
return
[]
...
...
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