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
8f74d01a
Commit
8f74d01a
authored
Aug 17, 2018
by
高雅喆
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add getClickOneUidRateDetail.py
parent
ad29164a
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
135 additions
and
6 deletions
+135
-6
getClickOneUidRateDetail.py
eda/recommended_indexs/getClickOneUidRateDetail.py
+129
-0
getClickZeroUidRateDetail.py
eda/recommended_indexs/getClickZeroUidRateDetail.py
+6
-6
No files found.
eda/recommended_indexs/getClickOneUidRateDetail.py
0 → 100644
View file @
8f74d01a
import
datetime
import
pymysql
#一周之前的timestamp(7)
my_date1
=
datetime
.
date
.
today
()
-
datetime
.
timedelta
(
days
=
7
)
my_tm1
=
int
(
my_date1
.
strftime
(
"
%
s"
))
#二周之前的timestamp(14)
my_date2
=
datetime
.
date
.
today
()
-
datetime
.
timedelta
(
days
=
14
)
my_tm2
=
int
(
my_date2
.
strftime
(
"
%
s"
))
#一个月之前的timestamp(30)
my_date3
=
datetime
.
date
.
today
()
-
datetime
.
timedelta
(
days
=
30
)
my_tm3
=
int
(
my_date3
.
strftime
(
"
%
s"
))
#两个月之前的timestamp(60)
my_date4
=
datetime
.
date
.
today
()
-
datetime
.
timedelta
(
days
=
60
)
my_tm4
=
int
(
my_date4
.
strftime
(
"
%
s"
))
#三个月之前的timestamp(90)
my_date5
=
datetime
.
date
.
today
()
-
datetime
.
timedelta
(
days
=
90
)
my_tm5
=
int
(
my_date5
.
strftime
(
"
%
s"
))
def
get_rate_detail
(
platform
):
if
platform
==
"ios"
:
platform
=
"='AppStore'"
elif
platform
==
"android"
:
platform
=
"!='AppStore'"
else
:
platform
=
" is not null"
db
=
pymysql
.
connect
(
host
=
'10.66.157.22'
,
port
=
4000
,
user
=
'root'
,
passwd
=
'3SYz54LS9#^9sBvC'
,
db
=
'jerry_test'
)
cursor
=
db
.
cursor
()
sql
=
"select '0-7' as label,count(distinct(device_id)) from data_feed_click
\
where device_type{0}
\
and from_unixtime(time,'
%
Y-
%
m-
%
d')=date_add(curdate(), interval -1 day)
\
and device_id in
\
(select distinct(device_id)
\
from data_feed_exposure
\
where device_id not in
\
(select distinct(device_id) from data_feed_exposure
\
where time < {1}))
\
union all
\
select '7-14' as label,count(distinct(device_id)) from data_feed_click
\
where device_type{0}
\
and from_unixtime(time,'
%
Y-
%
m-
%
d')=date_add(curdate(), interval -1 day)
\
and device_id in
\
(select distinct(device_id)
\
from data_feed_exposure
\
where device_id not in
\
(select distinct(device_id) from data_feed_exposure
\
where time < {2})
\
and device_id in
\
(select distinct(device_id) from data_feed_exposure
\
where time < {1}))
\
union all
\
select '14-30' as label,count(distinct(device_id)) from data_feed_click
\
where device_type{0}
\
and from_unixtime(time,'
%
Y-
%
m-
%
d')=date_add(curdate(), interval -1 day)
\
and device_id in
\
(select distinct(device_id)
\
from data_feed_exposure
\
where device_id not in
\
(select distinct(device_id) from data_feed_exposure
\
where time < {3})
\
and device_id in
\
(select distinct(device_id) from data_feed_exposure
\
where time < {2}))
\
union all
\
select '30-60' as label,count(distinct(device_id)) from data_feed_click
\
where device_type{0}
\
and from_unixtime(time,'
%
Y-
%
m-
%
d')=date_add(curdate(), interval -1 day)
\
and device_id in
\
(select distinct(device_id)
\
from data_feed_exposure
\
where device_id not in
\
(select distinct(device_id) from data_feed_exposure
\
where time < {4})
\
and device_id in
\
(select distinct(device_id) from data_feed_exposure
\
where time < {3}))
\
union all
\
select '60-90' as label,count(distinct(device_id)) from data_feed_click
\
where device_type{0}
\
and from_unixtime(time,'
%
Y-
%
m-
%
d')=date_add(curdate(), interval -1 day)
\
and device_id in
\
(select distinct(device_id)
\
from data_feed_exposure
\
where device_id not in
\
(select distinct(device_id) from data_feed_exposure
\
where time < {5})
\
and device_id in
\
(select distinct(device_id) from data_feed_exposure
\
where time < {4}))
\
union all
\
select '90+' as label,count(distinct(device_id)) from data_feed_click
\
where device_type{0}
\
and from_unixtime(time,'
%
Y-
%
m-
%
d')=date_add(curdate(), interval -1 day)
\
and device_id in
\
(select distinct(device_id)
\
from data_feed_exposure
\
where device_id in
\
(select distinct(device_id) from data_feed_exposure
\
where time < {5}))"
.
format
(
platform
,
my_tm1
,
my_tm2
,
my_tm3
,
my_tm4
,
my_tm5
)
cursor
.
execute
(
sql
)
result
=
cursor
.
fetchall
()
db
.
close
()
return
result
def
result2dict
(
result
):
"""
result : tuple2
rtype : dict
"""
dct
=
{}
sum_count
=
0
for
i
in
result
:
sum_count
+=
i
[
1
]
for
i
in
result
:
dct
[
i
[
0
]]
=
"{}
%
"
.
format
(
round
(
i
[
1
]
/
sum_count
*
100
,
2
))
print
(
"sum:{}"
.
format
(
sum_count
))
return
dct
if
__name__
==
'__main__'
:
have_click_uid_detail_all
=
result2dict
(
get_rate_detail
(
"all"
))
have_click_uid_detail_ios
=
result2dict
(
get_rate_detail
(
"ios"
))
have_click_uid_detail_android
=
result2dict
(
get_rate_detail
(
"android"
))
eda/recommended_indexs/getClickZeroUidRateDetail.py
View file @
8f74d01a
...
...
@@ -139,13 +139,13 @@ def result2dict(result):
sum_count
+=
i
[
1
]
for
i
in
result
:
dct
[
i
[
0
]]
=
"{}
%
"
.
format
(
round
(
i
[
1
]
/
sum_count
*
100
,
2
))
print
(
"sum:{}"
.
format
(
sum_count
))
return
dct
no_click_uid_detail_all
=
result2dict
(
get_rate_detail
(
"all"
))
no_click_uid_detail_ios
=
result2dict
(
get_rate_detail
(
"ios"
))
no_click_uid_detail_android
=
result2dict
(
get_rate_detail
(
"android"
))
if
__name__
==
'__main__'
:
no_click_uid_detail_all
=
result2dict
(
get_rate_detail
(
"all"
))
no_click_uid_detail_ios
=
result2dict
(
get_rate_detail
(
"ios"
))
no_click_uid_detail_android
=
result2dict
(
get_rate_detail
(
"android"
))
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