Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
M
meta_base_code
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
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
黎涛
meta_base_code
Commits
10337cb5
Commit
10337cb5
authored
Sep 14, 2020
by
litaolemo
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update
parent
6ee2b797
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
39 additions
and
25 deletions
+39
-25
ecommerce_income_report.py
task/ecommerce_income_report.py
+39
-25
No files found.
task/ecommerce_income_report.py
View file @
10337cb5
...
...
@@ -132,8 +132,10 @@ for t in range(1, task_days):
print
(
quanzhong_dau_sql
)
quanzhong_dau_df
=
spark
.
sql
(
quanzhong_dau_sql
)
quanzhong_dau_df
.
createOrReplaceTempView
(
"quanzhong_dau_view"
)
# quanzhong_dau_df.show(1)
# sql_res = quanzhong_dau_df.collect()
quanzhong_dau_df
.
show
(
1
)
sql_res
=
quanzhong_dau_df
.
collect
()
for
res
in
sql_res
:
print
(
res
)
# DAU
DAU_sql
=
"""
...
...
@@ -164,8 +166,11 @@ for t in range(1, task_days):
print
(
DAU_sql
)
dau_df
=
spark
.
sql
(
DAU_sql
)
dau_df
.
createOrReplaceTempView
(
"dau_view"
)
# dau_df.show(1)
# sql_res = dau_df.collect()
dau_df
.
show
(
1
)
sql_res
=
dau_df
.
collect
()
for
res
in
sql_res
:
print
(
res
)
# CPT日均点击
cpc_daily_click_sql
=
r"""
SELECT partition_date,count(1) as pv
...
...
@@ -183,8 +188,10 @@ group BY partition_date
print
(
cpc_daily_click_sql
)
cpc_daily_click_df
=
spark
.
sql
(
cpc_daily_click_sql
)
cpc_daily_click_df
.
createOrReplaceTempView
(
"cpc_daily_click"
)
# cpc_daily_click_df.show(1)
# sql_res = cpc_daily_click_df.collect()
cpc_daily_click_df
.
show
(
1
)
sql_res
=
cpc_daily_click_df
.
collect
()
for
res
in
sql_res
:
print
(
res
)
# 商详页PV
...
...
@@ -256,8 +263,10 @@ group BY partition_date
print
(
bus_detail_sql
)
bus_detail_df
=
spark
.
sql
(
bus_detail_sql
)
bus_detail_df
.
createOrReplaceTempView
(
"bus_detail"
)
# bus_detail_df.show(1)
# sql_res = bus_detail_df.collect()
bus_detail_df
.
show
(
1
)
sql_res
=
bus_detail_df
.
collect
()
for
res
in
sql_res
:
print
(
res
)
# --cpc当日预算(有效口径)
...
...
@@ -316,8 +325,10 @@ GROUP BY day_id
print
(
cpc_budget_sql
)
cpc_budget_df
=
spark
.
sql
(
cpc_budget_sql
)
cpc_budget_df
.
createOrReplaceTempView
(
"cpc_budget"
)
# cpc_budget_df.show(1)
# sql_res = cpc_budget_df.collect()
cpc_budget_df
.
show
(
1
)
sql_res
=
cpc_budget_df
.
collect
()
for
res
in
sql_res
:
print
(
res
)
# cpc收入、广告总消耗
cpc_income_sql
=
r"""
...
...
@@ -347,24 +358,27 @@ group by partition_day
print
(
cpc_income_sql
)
cpc_income_df
=
spark
.
sql
(
cpc_income_sql
)
cpc_income_df
.
createOrReplaceTempView
(
"cpc_income"
)
# cpc_income_df.show(1)
# sql_res = cpc_income_df.collect()
out_put_sql
=
"""
SELECT bus_detail.referrer_search_welfare_pv / dau_view.dau as pv_div_dau,
bus_detail.referrer_search_welfare_pv / quanzhong_dau_view.quanzhong_dau as pv_div_quanzhong_dau,
(cpc_income.cpt_click_num + cpc_income.cpc_click_num) / bus_detail.referrer_search_welfare_pv as ad_flow_rat,
cpc_income.cpc_proportion_expend_amount/cpc_budget.budget as budget_consumption_rate,
cpc_income.cpc_proportion_expend_recharge_amount/cpc_income.cpc_click_num as cpc_item_pricing,
cpc_income.tol_proportion_expend_amount as tol_proportion_expend_amount
"""
out_df
=
spark
.
sql
(
out_put_sql
)
# out_df.createOrReplaceTempView("out_df")
out_df
.
show
(
1
)
sql_res
=
out_df
.
collect
()
cpc_income_df
.
show
(
1
)
sql_res
=
cpc_income_df
.
collect
()
for
res
in
sql_res
:
print
(
res
)
#
# out_put_sql = """
# select bus_detail.referrer_search_welfare_pv / dau_view.dau as pv_div_dau,
# bus_detail.referrer_search_welfare_pv / quanzhong_dau_view.quanzhong_dau as pv_div_quanzhong_dau,
# (cpc_income.cpt_click_num + cpc_income.cpc_click_num) / bus_detail.referrer_search_welfare_pv as ad_flow_rat,
# cpc_income.cpc_proportion_expend_amount/cpc_budget.budget as budget_consumption_rate,
# cpc_income.cpc_proportion_expend_recharge_amount/cpc_income.cpc_click_num as cpc_item_pricing,
# cpc_income.tol_proportion_expend_amount as tol_proportion_expend_amount
# """
# out_df = spark.sql(out_put_sql)
# # out_df.createOrReplaceTempView("out_df")
# out_df.show(1)
# sql_res = out_df.collect()
# for res in sql_res:
# print(res)
# for active_type in res_dict:
# db = pymysql.connect(host='172.16.40.158', port=4000, user='st_user', passwd='aqpuBLYzEV7tML5RPsN1pntUzFy',
...
...
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