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
3b7c9de5
Commit
3b7c9de5
authored
Sep 26, 2019
by
张彦钊
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
change
parent
5c46110b
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
26 additions
and
2 deletions
+26
-2
ctr.py
tensnsorflow/ctr.py
+26
-2
No files found.
tensnsorflow/ctr.py
View file @
3b7c9de5
...
...
@@ -24,7 +24,31 @@ def get_ctr():
print
(
clicks
/
exposures
)
def
all_con_sql
(
db
,
sql
):
cursor
=
db
.
cursor
()
cursor
.
execute
(
sql
)
result
=
list
(
cursor
.
fetchall
())
return
result
def
get_feed_ctr
():
db
=
pymysql
.
connect
(
host
=
'172.16.40.158'
,
port
=
4000
,
user
=
'root'
,
passwd
=
'3SYz54LS9#^9sBvC'
,
db
=
'jerry_test'
)
sql
=
"select date_str,diary_exp,diary_click,post_exp,post_click,qa_exp,qa_click from feed_exp_click"
df
=
pd
.
DataFrame
(
all_con_sql
(
db
,
sql
))
db
.
close
()
print
(
df
.
head
(
2
))
df
=
df
.
rename
(
columns
=
{
0
:
"date_str"
,
1
:
"diary_exp"
,
2
:
"diary_click"
,
3
:
"post_exp"
,
4
:
"post_click"
,
5
:
"qa_exp"
,
6
:
"qa_click"
})
df
[
"total_exp"
]
=
df
[
"diary_exp"
]
+
df
[
"post_exp"
]
+
df
[
"qa_exp"
]
df
[
"total_click"
]
=
df
[
"diary_click"
]
+
df
[
"post_click"
]
+
df
[
"qa_click"
]
df
[
"total_ctr"
]
=
df
[
"total_click"
]
/
df
[
"total_exp"
]
df
[
"diary_ctr"
]
=
df
[
"diary_click"
]
/
df
[
"diary_exp"
]
df
[
"post_ctr"
]
=
df
[
"post_click"
]
/
df
[
"post_exp"
]
df
[
"qa_ctr"
]
=
df
[
"qa_click"
]
/
df
[
"qa_exp"
]
print
(
df
.
head
(
2
))
df
.
to_csv
(
"/home/gmuser/ctr.csv"
,
index
=
False
)
if
__name__
==
"__main__"
:
get_ctr
()
\ No newline at end of file
get_feed_ctr
()
\ No newline at end of file
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