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
947c354b
Commit
947c354b
authored
Aug 17, 2018
by
高雅喆
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
optimize the sql statement in get_click_times_to_count_uid_df()
parent
74dba4be
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
10 additions
and
10 deletions
+10
-10
utils.py
eda/recommended_indexs_v2/utils.py
+10
-10
No files found.
eda/recommended_indexs_v2/utils.py
View file @
947c354b
# -*- coding: UTF-8 -*-
import
pymysql
import
datetime
import
pandas
as
pd
def
con_sql
(
sql
):
#从数据库的表里获取数据
...
...
@@ -72,15 +71,16 @@ def get_activate_uid_ctr(platform, ndays=1):
return
[
platform
,
clk_count
,
imp_count
,
clk_rate
]
#获取
{点击次数 : 独立用户数}
#获取
(点击次数 : 独立用户数)
def
get_click_times_to_count_uid_df
():
"""
rtype :
pandas.DataFram
e
rtype :
tupl
e
"""
sql
=
"select device_id,count(cid_type) click_times from data_feed_click where from_unixtime(time,'
%
Y-
%
m-
%
d')=date_add(curdate(), interval -1 day) group by device_id order by click_times desc"
uid_click_times
=
con_sql
(
sql
)
uid_lst
=
[
i
[
0
]
for
i
in
uid_click_times
]
click_times_lst
=
[
i
[
1
]
for
i
in
uid_click_times
]
uid_click_times_df
=
pd
.
DataFrame
({
"uid"
:
uid_lst
,
"click_times"
:
click_times_lst
})
df
=
uid_click_times_df
.
groupby
(
by
=
"click_times"
,
as_index
=
False
)
.
count
()
return
df
sql
=
"select times,count(device_id)
\
from (select device_id,count(cid_type) as times
\
from data_feed_click
\
where from_unixtime(time,'
%
Y-
%
m-
%
d')=date_add(curdate(), interval -1 day)
\
group by device_id) as t
\
group by times order by times"
result
=
con_sql
(
sql
)
return
result
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