Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
F
ffm-baseline
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
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ML
ffm-baseline
Commits
65dafb4e
Commit
65dafb4e
authored
Oct 17, 2018
by
张彦钊
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' of git.wanmeizhensuo.com:ML/ffm-baseline
修改统计指标
parents
d098277b
f66d8dec
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
102 additions
and
1 deletion
+102
-1
all_ctr.py
eda/node2vec/stat/all_ctr.py
+101
-0
node2vec_ctr.py
eda/node2vec/stat/node2vec_ctr.py
+1
-1
No files found.
eda/node2vec/stat/all_ctr.py
0 → 100644
View file @
65dafb4e
# -*- coding: UTF-8 -*-
import
time
import
pymysql
import
datetime
def
con_sql
(
sql
):
#从数据库的表里获取数据
"""
:type sql : str
:rtype : tuple
"""
db
=
pymysql
.
connect
(
host
=
'10.66.157.22'
,
port
=
4000
,
user
=
'root'
,
passwd
=
'3SYz54LS9#^9sBvC'
,
db
=
'jerry_prod'
)
cursor
=
db
.
cursor
()
cursor
.
execute
(
sql
)
result
=
cursor
.
fetchall
()
db
.
close
()
return
result
def
get_yesterday_date
():
#自动获取昨天的日期,如"2018-08-08"
"""
:rtype : str
"""
today
=
datetime
.
date
.
today
()
yesterday
=
today
-
datetime
.
timedelta
(
days
=
1
)
yesterday
=
yesterday
.
strftime
(
"
%
Y-
%
m-
%
d"
)
return
yesterday
OUTPUT_PATH
=
"/data2/models/eda/node2vec/"
class
AllStat
(
object
):
def
__init__
(
self
,
cid_type
,
uid_type
,
ndays
=
get_yesterday_date
()):
"""
cid_type : diary,answer,question
uid_type : 8:_8结尾;6:_6结尾;6|8:_6或者_8结尾;^68:不是6或者8结尾的
ndays : '2018-08-30'....
"""
self
.
cid_type
=
cid_type
self
.
uid_type
=
uid_type
self
.
ndays
=
ndays
def
get_uid_count
(
self
):
sql
=
"select count(distinct(device_id)) from data_feed_click
\
where stat_date='{0}'
\
and (cid_type='{1}' or cid_type='diary_video')
\
and device_id regexp '[{2}]$'
\
and device_id not in (select distinct(device_id) from jerry_test.bl_device_list)
\
and device_id not in (select distinct(device_id) from jerry_prod.blacklist)"
.
format
(
self
.
ndays
,
\
self
.
cid_type
,
self
.
uid_type
)
uid_count
=
con_sql
(
sql
)[
0
][
0
]
return
uid_count
def
get_uid_clk_times
(
self
):
sql
=
"select count(device_id) from data_feed_click
\
where stat_date='{0}'
\
and (cid_type='{1}' or cid_type='diary_video')
\
and device_id regexp '[{2}]$'
\
and device_id not in (select distinct(device_id) from jerry_test.bl_device_list)
\
and device_id not in (select distinct(device_id) from jerry_prod.blacklist)"
.
format
(
self
.
ndays
,
\
self
.
cid_type
,
self
.
uid_type
)
uid_clk_times
=
con_sql
(
sql
)[
0
][
0
]
return
uid_clk_times
def
get_uid_imp_times
(
self
):
sql
=
"select count(device_id) from data_feed_exposure
\
where stat_date='{0}'
\
and cid_type='{1}'
\
and device_id regexp '[{2}]$'
\
and device_id not in (select distinct(device_id) from jerry_test.bl_device_list)
\
and device_id not in (select distinct(device_id) from jerry_prod.blacklist)"
.
format
(
self
.
ndays
,
\
self
.
cid_type
,
self
.
uid_type
)
uid_imp_times
=
con_sql
(
sql
)[
0
][
0
]
return
uid_imp_times
def
main
():
output
=
OUTPUT_PATH
+
"all_ctr.csv"
with
open
(
output
,
"a+"
)
as
f
:
tail_nu
=
[
"1|2"
,
"3|4"
,
"5|6"
,
"7|8"
,
"0-9"
]
resulst_ctr
=
[]
for
i
in
tail_nu
:
class_tail
=
AllStat
(
"diary"
,
i
)
ctr_tail
=
round
(
class_tail
.
get_uid_clk_times
()
/
class_tail
.
get_uid_imp_times
(),
4
)
resulst_ctr
.
append
(
str
(
ctr_tail
))
line
=
get_yesterday_date
()
+
','
+
','
.
join
([
i
for
i
in
resulst_ctr
])
+
'
\n
'
f
.
write
(
line
)
if
__name__
==
'__main__'
:
main
()
eda/node2vec/stat/node2vec_ctr.py
View file @
65dafb4e
...
...
@@ -133,7 +133,7 @@ class AllStat(object):
def
main
():
output
=
OUTPUT_PATH
+
"ctr.csv"
output
=
OUTPUT_PATH
+
"
nd_
ctr.csv"
with
open
(
output
,
"a+"
)
as
f
:
print
(
"stat"
+
" "
+
get_yesterday_date
())
g_class
=
GrayStat
(
"diary"
,
"3|4"
)
...
...
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