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
035ea575
Commit
035ea575
authored
Aug 10, 2018
by
高雅喆
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add a new class getCidRate.py
parent
716da1d4
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
85 additions
and
17 deletions
+85
-17
getCidRate.py
eda/test/getCidRate.py
+70
-0
getClkCidUidRate.py
eda/test/getClkCidUidRate.py
+11
-15
getTopFeatures.py
eda/test/getTopFeatures.py
+4
-2
No files found.
eda/test/getCidRate.py
0 → 100644
View file @
035ea575
# -*- coding: UTF-8 -*-
from
utils
import
con_sql
class
CidRate
(
object
):
def
__init__
(
self
,
ndays
,
platform
,
cid_type
):
"""
ndays : 1;2;3;4.. #The number of days from the current time
platform : 'all';'ios';'android'
cid_type : 'diary';'answer';'question'...
"""
self
.
ndays
=
ndays
if
platform
==
"ios"
:
self
.
platform
=
"='AppStore'"
elif
platform
==
"android"
:
self
.
platform
=
"!='AppStore'"
else
:
self
.
platform
=
" is not null"
self
.
cid_type
=
cid_type
def
get_cid_clk_rate
(
self
,
platform
):
"""
platform : "所有";"苹果","安卓" #方便显示
rtype : list
"""
if
self
.
platform
[
-
2
]
==
'e'
:
self
.
platform
=
self
.
platform
.
replace
(
' '
,
''
)
sql_cid
=
"select count(cid) from data_feed_click
\
where from_unixtime(time,'
%
Y-
%
m-
%
d')=date_add(curdate(), interval -{0} day)
\
and device_type{1} and cid_type='{2}'"
.
format
(
self
.
ndays
,
self
.
platform
,
self
.
cid_type
)
cid_clk_count
=
con_sql
(
sql_cid
)[
0
][
0
]
sql_all
=
"select count(cid) from data_feed_click
\
where from_unixtime(time,'
%
Y-
%
m-
%
d')=date_add(curdate(), interval -{0} day)
\
and device_type{1}"
.
format
(
self
.
ndays
,
self
.
platform
)
all_clk_count
=
con_sql
(
sql_all
)[
0
][
0
]
cid_clk_rate
=
round
(
cid_clk_count
/
all_clk_count
,
4
)
return
[
platform
,
cid_clk_count
,
all_clk_count
,
cid_clk_rate
]
def
get_cid_imp_rate
(
self
,
platform
):
"""
platform : "所有";"苹果","安卓" #方便显示
rtype : list
"""
if
self
.
platform
[
-
2
]
==
'e'
:
#注意:曝光表中AppStore有空格
self
.
platform
=
self
.
platform
[:
-
6
]
+
' '
+
self
.
platform
[
-
6
:]
sql_cid
=
"select count(cid) from data_feed_exposure
\
where from_unixtime(time,'
%
Y-
%
m-
%
d')=date_add(curdate(), interval -{0} day)
\
and device_type{1} and cid_type='{2}'"
.
format
(
self
.
ndays
,
self
.
platform
,
self
.
cid_type
)
cid_imp_count
=
con_sql
(
sql_cid
)[
0
][
0
]
sql_all
=
"select count(cid) from data_feed_exposure
\
where from_unixtime(time,'
%
Y-
%
m-
%
d')=date_add(curdate(), interval -{0} day)
\
and device_type{1}"
.
format
(
self
.
ndays
,
self
.
platform
)
all_imp_count
=
con_sql
(
sql_all
)[
0
][
0
]
cid_imp_rate
=
round
(
cid_imp_count
/
all_imp_count
,
4
)
return
[
platform
,
cid_imp_count
,
all_imp_count
,
cid_imp_rate
]
def
main
():
answer_rate_all
=
CidRate
(
1
,
"all"
,
"answer"
)
.
get_cid_imp_rate
(
"所有"
)
answer_rate_ios
=
CidRate
(
1
,
"ios"
,
"answer"
)
.
get_cid_imp_rate
(
"苹果"
)
answer_rate_android
=
CidRate
(
1
,
"android"
,
"answer"
)
.
get_cid_imp_rate
(
"安卓"
)
answer_rate_result
=
[
answer_rate_all
,
answer_rate_ios
,
answer_rate_android
]
if
__name__
==
'__main__'
:
main
()
eda/test/getClkCidUidRate.py
View file @
035ea575
# -*- coding: UTF-8 -*-
from
utils
import
con_sql
,
tuple2dict
,
get_yesterday_date
from
config
import
DIRECTORY_PATH
from
utils
import
con_sql
class
ClkCidUidRate
(
object
):
...
...
@@ -8,7 +7,7 @@ class ClkCidUidRate(object):
"""
ndays : 1;2;3;4.. #The number of days from the current time
platform : 'all';'ios';'android'
cid_type : 'diary';'answer';'question';"
no
thing"...
cid_type : 'diary';'answer';'question';"
every
thing"...
"""
self
.
ndays
=
ndays
if
platform
==
"ios"
:
...
...
@@ -17,7 +16,7 @@ class ClkCidUidRate(object):
self
.
platform
=
"!='AppStore'"
else
:
self
.
platform
=
" is not null"
if
cid_type
==
"
no
thing"
:
if
cid_type
==
"
every
thing"
:
self
.
cid_type
=
" is not null"
else
:
self
.
cid_type
=
"='"
+
cid_type
+
"'"
...
...
@@ -43,11 +42,8 @@ class ClkCidUidRate(object):
and cid_type{2}"
.
format
(
self
.
ndays
,
self
.
platform
,
self
.
cid_type
)
imp_count
=
con_sql
(
sql_imp
)[
0
][
0
]
if
self
.
cid_type
==
" is not null"
:
no_clk_count
=
imp_count
-
clk_count
return
[
platform
,
no_clk_count
,
imp_count
,
round
(
no_clk_count
/
imp_count
,
4
)]
else
:
return
[
platform
,
clk_count
,
imp_count
,
round
(
clk_count
/
imp_count
,
4
)]
clk_rate
=
round
(
clk_count
/
imp_count
,
4
)
return
[
platform
,
clk_count
,
imp_count
,
clk_rate
]
def
result2file
(
self
,
result_lst
,
fpath
):
...
...
@@ -74,12 +70,12 @@ def main():
#click_question_android = ClkCidUidRate(1,"android","question").get_clk_cid_uid_rate("安卓")
#click_question_result = [click_question_all,click_question_ios,click_question_android]
#print("已获取点击question用户占比")
#4.
无
点击用户占比
click_
nothing_all
=
ClkCidUidRate
(
1
,
"all"
,
"no
thing"
)
.
get_clk_cid_uid_rate
(
"所有"
)
click_
nothing_ios
=
ClkCidUidRate
(
1
,
"ios"
,
"no
thing"
)
.
get_clk_cid_uid_rate
(
"苹果"
)
click_
nothing_android
=
ClkCidUidRate
(
1
,
"android"
,
"no
thing"
)
.
get_clk_cid_uid_rate
(
"安卓"
)
click_
nothing_result
=
[
click_nothing_all
,
click_nothing_ios
,
click_no
thing_android
]
print
(
"已获取
无
点击用户占比"
)
#4.
有
点击用户占比
click_
everything_all
=
ClkCidUidRate
(
1
,
"all"
,
"every
thing"
)
.
get_clk_cid_uid_rate
(
"所有"
)
click_
everything_ios
=
ClkCidUidRate
(
1
,
"ios"
,
"every
thing"
)
.
get_clk_cid_uid_rate
(
"苹果"
)
click_
everything_android
=
ClkCidUidRate
(
1
,
"android"
,
"every
thing"
)
.
get_clk_cid_uid_rate
(
"安卓"
)
click_
everything_result
=
[
click_everything_all
,
click_everything_ios
,
click_every
thing_android
]
print
(
"已获取
有
点击用户占比"
)
...
...
eda/test/getTopFeatures.py
View file @
035ea575
...
...
@@ -45,9 +45,10 @@ class TopFeatures(object):
imp_times
=
tuple2dict
(
con_sql
(
sql
))
return
imp_times
def
get_result
(
self
,
platform
,
clk
=
{},
imp
=
{},
clk_n
=
2
,
result_types
=
"ctr"
):
def
get_result
(
self
,
platform
,
c
id_type
,
c
lk
=
{},
imp
=
{},
clk_n
=
2
,
result_types
=
"ctr"
):
"""
platform : "所有";"苹果","安卓" #方便显示
cid_type : 'diary';'answer';'question';"everything"... #方便显示
clk : dict
imp : dict
clk_n : 获取topN点击率时,过滤的点击数
...
...
@@ -87,8 +88,9 @@ class TopFeatures(object):
topn
.
sort
(
key
=
lambda
x
:
x
[
4
],
reverse
=
True
)
return
topn
[:
int
(
self
.
top_n
)]
def
result2file
(
self
,
result_lst
,
fpath
):
def
result2file
(
self
,
cid_type
,
result_lst
,
fpath
):
"""
cid_type : 'diary';'answer';'question';"everything"... #方便显示
result_lst : [all_result,ios_result,android_result]
fpath : output filename
rtype : none
...
...
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