Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
D
demo-go
Project
Overview
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
彭芳
demo-go
Commits
f493fde3
Commit
f493fde3
authored
Feb 21, 2023
by
彭芳
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[minor]: format return data
parent
8d68ce9a
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
213 additions
and
35 deletions
+213
-35
page.go
internal/biz/common/page.go
+2
-2
report.go
internal/biz/report.go
+190
-31
civil_time.go
internal/util/civil_time.go
+9
-0
second.go
internal/util/second.go
+12
-2
No files found.
internal/biz/common/page.go
View file @
f493fde3
...
...
@@ -10,8 +10,8 @@ const (
type
PageRequest
struct
{
Page
int
`form:"page" json:"page"`
// 页码
PageSize
int
`form:"page_size" json:"page_size" `
// 每页大小
OrderBy
string
// 排序字段
OrderByMode
string
// 排序方式 desc asc
OrderBy
string
`form:"order_by" json:"order_by"`
// 排序字段
OrderByMode
string
`form:"order_by_mode" json:"order_by_mode"`
// 排序方式 desc asc
}
func
(
p
*
PageRequest
)
Offset
()
int
{
...
...
internal/biz/report.go
View file @
f493fde3
...
...
@@ -34,55 +34,64 @@ type ListCampaignResponse struct {
type
CampaignList
[]
*
Campaign
func
(
p
CampaignList
)
PrepareRateAndCost
()
{
for
_
,
campaign
:=
range
p
{
campaign
.
AvgShowCost
=
campaign
.
getAvgShowCost
()
campaign
.
AvgClickCost
=
campaign
.
getAvgClickCost
()
campaign
.
Ctr
=
campaign
.
getCtr
()
campaign
.
ConvertCost
=
campaign
.
getConvertCost
()
campaign
.
ConvertRate
=
campaign
.
getConvertRate
()
campaign
.
DeepConvertCost
=
campaign
.
getDeepConvertCost
()
campaign
.
DeepConvertRate
=
campaign
.
getDeepConvertRate
()
campaign
.
AttributionConvertCost
=
campaign
.
getAttributionConvertCost
()
campaign
.
AttributionDeepConvertCost
=
campaign
.
getAttributionDeepConvertCost
()
campaign
.
DownloadStartCost
=
campaign
.
getDownloadStartCost
()
campaign
.
DownloadStartRate
=
campaign
.
getDownloadStartRate
()
campaign
.
DownloadFinishCost
=
campaign
.
getDownloadFinishCost
()
campaign
.
DownloadFinishRate
=
campaign
.
getDownloadFinishRate
()
campaign
.
InstallFinishCost
=
campaign
.
getInstallFinishCost
()
campaign
.
InstallFinishRate
=
campaign
.
getInstallFinishRate
()
campaign
.
ActiveCost
=
campaign
.
getActiveCost
()
campaign
.
ActiveRate
=
campaign
.
getActiveRate
()
campaign
.
ActiveRegisterCost
=
campaign
.
getActiveRegisterCost
()
campaign
.
ActiveRegisterRate
=
campaign
.
getActiveRegisterRate
()
campaign
.
AttributionNextDayOpenCost
=
campaign
.
getAttributionNextDayOpenCost
()
campaign
.
AttributionNextDayOpenRate
=
campaign
.
getAttributionNextDayOpenRate
()
campaign
.
GameAddictionCost
=
campaign
.
getGameAddictionCost
()
campaign
.
GameAddictionRate
=
campaign
.
getGameAddictionRate
()
campaign
.
ActivePayCost
=
campaign
.
getActivePayCost
()
campaign
.
ActivePayRate
=
campaign
.
getActivePayRate
()
campaign
.
ValidPlayCost
=
campaign
.
getValidPlayCost
()
campaign
.
ValidPlayRate
=
campaign
.
getValidPlayRate
()
campaign
.
AveragePlayTimePerPlay
=
campaign
.
getAveragePlayTimePerPlay
()
campaign
.
PlayOverRate
=
campaign
.
getPlayOverRate
()
}
}
type
Campaign
struct
{
CampaignId
string
`json:"campaign_id"`
// 广告组ID
CampaignName
string
`json:"campaign_name"`
// 广告主组名称
AdvertiserId
string
`json:"advertiser_id"`
// 广告主id
StatDatetime
string
`json:"stat_datetime"`
// 数据起始时间(yyyy-MM-dd HH:mm:ss)
StatDatetime
util
.
Second
`json:"stat_datetime"`
// 数据起始时间(yyyy-MM-dd HH:mm:ss)
Cost
float64
`json:"cost"`
// 花费
Show
int
`json:"show"`
// 展示量
AvgShowCost
float64
`json:"avg_show_cost"`
// 千次展示成本
Click
int
`json:"click"`
// 点击量
AvgClickCost
float64
`json:"avg_click_cost"`
// 点击成本
Ctr
float64
`json:"ctr"`
// 点击率
Convert
int
`json:"convert"`
// 转化数
ConvertCost
float64
`json:"convert_cost"`
// 转化成本
ConvertRate
float64
`json:"convert_rate"`
// 转化率
DeepConvert
int
`json:"deep_convert"`
// 深度转化数
DeepConvertCost
float64
`json:"deep_convert_cost"`
// 深度转化成本
DeepConvertRate
float64
`json:"deep_convert_rate"`
// 深度转化率
AttributionConvert
int
`json:"attribution_convert"`
// 转化数(计费时间)
AttributionConvertCost
float64
`json:"attribution_convert_cost"`
// 转化成本(计费时间)
AttributionDeepConvert
int
`json:"attribution_deep_convert"`
// 深度转化数(计费时间)
AttributionDeepConvertCost
float64
`json:"attribution_deep_convert_cost"`
// 深度转化成本(计费时间)
DownloadStart
int
`json:"download_start"`
// 安卓下载开始数
DownloadStartCost
float64
`json:"download_start_cost"`
// 安卓下载开始成本
DownloadStartRate
float64
`json:"download_start_rate"`
// 安卓下载开始率
DownloadFinish
int
`json:"download_finish"`
// 安卓下载完成数
DownloadFinishCost
float64
`json:"download_finish_cost"`
// 安卓下载完成成本
DownloadFinishRate
float64
`json:"download_finish_rate"`
// 安卓下载完成率
ClickInstall
int
`json:"click_install"`
// 点击安装数
InstallFinish
int
`json:"install_finish"`
// 安卓安装完成数
InstallFinishCost
float64
`json:"install_finish_cost"`
// 安卓安装完成成本
InstallFinishRate
float64
`json:"install_finish_rate"`
// 安卓安装完成率
Active
int
`json:"active"`
// 激活数
ActiveCost
float64
`json:"active_cost"`
// 激活成本
ActiveRate
float64
`json:"active_rate"`
// 激活率
Register
int
`json:"register"`
// 注册数
ActiveRegisterCost
float64
`json:"active_register_cost"`
// 注册成本
ActiveRegisterRate
float64
`json:"active_register_rate"`
// 注册率
NextDayOpen
int
`json:"next_day_open"`
// 次留数
NextDayOpenCost
float64
`json:"next_day_open_cost"`
// 次留成本
NextDayOpenRate
float64
`json:"next_day_open_rate"`
// 次留率
AttributionNextDayOpenCnt
int
`json:"attribution_next_day_open_cnt"`
// 次留回传数
AttributionNextDayOpenCost
float64
`json:"attribution_next_day_open_cost"`
// 次留成本
AttributionNextDayOpenRate
float64
`json:"attribution_next_day_open_rate"`
// 次留率
GameAddiction
int
`json:"game_addiction"`
// 关键行为数
GameAddictionCost
float64
`json:"game_addiction_cost"`
// 关键行为成本
GameAddictionRate
float64
`json:"game_addiction_rate"`
// 关键行为率
PayCount
int
`json:"pay_count"`
// 首次付费次数
ActivePayCost
float64
`json:"active_pay_cost"`
// 首次付费成本
ActivePayRate
float64
`json:"active_pay_rate"`
// 首次付费率
InAppUv
int
`json:"in_app_uv"`
// APP内访问
InAppDetailUv
int
`json:"in_app_detail_uv"`
// APP内访问详情页
InAppCart
int
`json:"in_app_cart"`
// APP内加入购物车
...
...
@@ -92,18 +101,167 @@ type Campaign struct {
GamePayCount
int
`json:"game_pay_count"`
// 付费次数
TotalPlay
int
`json:"total_play"`
// 视频数据-播放数
ValidPlay
int
`json:"valid_play"`
// 视频数据-有效播放数
ValidPlayCost
float64
`json:"valid_play_cost"`
// 有效播放成本
ValidPlayRate
float64
`json:"valid_play_rate"`
// 有效播放率
Play25FeedBreak
int
`json:"play_25_feed_break"`
// 视频数据-25%进度播放数
Play50FeedBreak
int
`json:"play_50_feed_break"`
// 视频数据-50%进度播放数
Play75FeedBreak
int
`json:"play_75_feed_break"`
// 视频数据-75%进度播放数
Play100FeedBreak
int
`json:"play_100_feed_break"`
// 视频数据-99%进度播放数
AveragePlayTimePerPlay
float64
`json:"average_play_time_per_play"`
// 视频数据-平均单次播放时长,单位:秒
PlayOverRate
float64
`json:"play_over_rate"`
// 播完率
PlayDurationSum
int
`json:"play_duration_sum"`
// 视频数据-播放时长,单位ms
AttributionActivePayIntraOneDayCount
int
`json:"attribution_active_pay_intra_one_day_count"`
// 游戏行业-激活后24h首次付费数
AttributionActivePayIntraOneDayAmount
float64
`json:"attribution_active_pay_intra_one_day_amount"`
// 游戏行业-激活后24h付费金额
Timestamp
time
.
Time
`json:"timestamp"`
// 创建时间
Timestamp
util
.
CivilTime
`json:"timestamp"`
// 创建时间(yyyy-MM-dd HH:mm:ss)
// 计算字段
AvgShowCost
float64
`json:"avg_show_cost"`
// 千次展示成本
AvgClickCost
float64
`json:"avg_click_cost"`
// 点击成本
Ctr
float64
`json:"ctr"`
// 点击率
ConvertCost
float64
`json:"convert_cost"`
// 转化成本
ConvertRate
float64
`json:"convert_rate"`
// 转化率
DeepConvertCost
float64
`json:"deep_convert_cost"`
// 深度转化成本
DeepConvertRate
float64
`json:"deep_convert_rate"`
// 深度转化率
AttributionConvertCost
float64
`json:"attribution_convert_cost"`
// 转化成本(计费时间)
AttributionDeepConvertCost
float64
`json:"attribution_deep_convert_cost"`
// 深度转化成本(计费时间)
DownloadStartCost
float64
`json:"download_start_cost"`
// 安卓下载开始成本
DownloadStartRate
float64
`json:"download_start_rate"`
// 安卓下载开始率
DownloadFinishCost
float64
`json:"download_finish_cost"`
// 安卓下载完成成本
DownloadFinishRate
float64
`json:"download_finish_rate"`
// 安卓下载完成率
InstallFinishCost
float64
`json:"install_finish_cost"`
// 安卓安装完成成本
InstallFinishRate
float64
`json:"install_finish_rate"`
// 安卓安装完成率
ActiveCost
float64
`json:"active_cost"`
// 激活成本
ActiveRate
float64
`json:"active_rate"`
// 激活率
ActiveRegisterCost
float64
`json:"active_register_cost"`
// 注册成本
ActiveRegisterRate
float64
`json:"active_register_rate"`
// 注册率
AttributionNextDayOpenCost
float64
`json:"attribution_next_day_open_cost"`
// 次留成本
AttributionNextDayOpenRate
float64
`json:"attribution_next_day_open_rate"`
// 次留率
GameAddictionCost
float64
`json:"game_addiction_cost"`
// 关键行为成本
GameAddictionRate
float64
`json:"game_addiction_rate"`
// 关键行为率
ActivePayCost
float64
`json:"active_pay_cost"`
// 首次付费成本
ActivePayRate
float64
`json:"active_pay_rate"`
// 首次付费率
ValidPlayCost
float64
`json:"valid_play_cost"`
// 有效播放成本
ValidPlayRate
float64
`json:"valid_play_rate"`
// 有效播放率
AveragePlayTimePerPlay
float64
`json:"average_play_time_per_play"`
// 视频数据-平均单次播放时长,单位:秒
PlayOverRate
float64
`json:"play_over_rate"`
// 播完率
}
func
(
p
*
Campaign
)
getAvgShowCost
()
float64
{
return
calcRate
(
p
.
Cost
,
float64
(
p
.
Show
))
}
func
(
p
*
Campaign
)
getAvgClickCost
()
float64
{
return
calcRate
(
p
.
Cost
,
float64
(
p
.
Click
))
}
func
(
p
*
Campaign
)
getCtr
()
float64
{
return
calcRate
(
float64
(
p
.
Click
),
float64
(
p
.
Show
))
}
func
(
p
*
Campaign
)
getConvertCost
()
float64
{
return
calcRate
(
p
.
Cost
,
float64
(
p
.
Convert
))
}
func
(
p
*
Campaign
)
getConvertRate
()
float64
{
return
calcRate
(
float64
(
p
.
Convert
),
float64
(
p
.
Click
))
}
func
(
p
*
Campaign
)
getDeepConvertCost
()
float64
{
return
calcRate
(
p
.
Cost
,
float64
(
p
.
DeepConvert
))
}
func
(
p
*
Campaign
)
getDeepConvertRate
()
float64
{
return
calcRate
(
float64
(
p
.
DeepConvert
),
float64
(
p
.
Convert
))
}
func
(
p
*
Campaign
)
getAttributionConvertCost
()
float64
{
return
calcRate
(
p
.
Cost
,
float64
(
p
.
AttributionConvert
))
}
func
(
p
*
Campaign
)
getAttributionDeepConvertCost
()
float64
{
return
calcRate
(
p
.
Cost
,
float64
(
p
.
AttributionDeepConvert
))
}
func
(
p
*
Campaign
)
getDownloadStartCost
()
float64
{
return
calcRate
(
p
.
Cost
,
float64
(
p
.
DownloadStart
))
}
func
(
p
*
Campaign
)
getDownloadStartRate
()
float64
{
return
calcRate
(
float64
(
p
.
DownloadStart
),
float64
(
p
.
Click
))
}
func
(
p
*
Campaign
)
getDownloadFinishCost
()
float64
{
return
calcRate
(
p
.
Cost
,
float64
(
p
.
DownloadFinish
))
}
func
(
p
*
Campaign
)
getDownloadFinishRate
()
float64
{
return
calcRate
(
float64
(
p
.
DownloadFinish
),
float64
(
p
.
DownloadStart
))
}
func
(
p
*
Campaign
)
getInstallFinishCost
()
float64
{
return
calcRate
(
p
.
Cost
,
float64
(
p
.
InstallFinish
))
}
func
(
p
*
Campaign
)
getInstallFinishRate
()
float64
{
return
calcRate
(
float64
(
p
.
InstallFinish
),
float64
(
p
.
DownloadFinish
))
}
func
(
p
*
Campaign
)
getActiveCost
()
float64
{
return
calcRate
(
p
.
Cost
,
float64
(
p
.
Active
))
}
func
(
p
*
Campaign
)
getActiveRate
()
float64
{
return
calcRate
(
float64
(
p
.
Active
),
float64
(
p
.
Click
))
}
func
(
p
*
Campaign
)
getActiveRegisterCost
()
float64
{
return
calcRate
(
p
.
Cost
,
float64
(
p
.
Register
))
}
func
(
p
*
Campaign
)
getActiveRegisterRate
()
float64
{
return
calcRate
(
float64
(
p
.
Register
),
float64
(
p
.
Active
))
}
func
(
p
*
Campaign
)
getAttributionNextDayOpenCost
()
float64
{
return
calcRate
(
p
.
Cost
,
float64
(
p
.
AttributionNextDayOpenCnt
))
}
func
(
p
*
Campaign
)
getAttributionNextDayOpenRate
()
float64
{
return
calcRate
(
float64
(
p
.
AttributionNextDayOpenCnt
),
float64
(
p
.
Active
))
}
func
(
p
*
Campaign
)
getGameAddictionCost
()
float64
{
return
calcRate
(
p
.
Cost
,
float64
(
p
.
GameAddiction
))
}
func
(
p
*
Campaign
)
getGameAddictionRate
()
float64
{
return
calcRate
(
float64
(
p
.
GameAddiction
),
float64
(
p
.
Active
))
}
func
(
p
*
Campaign
)
getActivePayCost
()
float64
{
return
calcRate
(
p
.
Cost
,
float64
(
p
.
PayCount
))
}
func
(
p
*
Campaign
)
getActivePayRate
()
float64
{
return
calcRate
(
float64
(
p
.
PayCount
),
float64
(
p
.
Active
))
}
func
(
p
*
Campaign
)
getValidPlayCost
()
float64
{
return
calcRate
(
p
.
Cost
,
float64
(
p
.
ValidPlay
))
}
func
(
p
*
Campaign
)
getValidPlayRate
()
float64
{
return
calcRate
(
float64
(
p
.
ValidPlay
),
float64
(
p
.
Show
))
}
func
(
p
*
Campaign
)
getAveragePlayTimePerPlay
()
float64
{
return
calcRate
(
float64
(
p
.
PlayDurationSum
),
float64
(
p
.
TotalPlay
))
}
func
(
p
*
Campaign
)
getPlayOverRate
()
float64
{
return
calcRate
(
float64
(
p
.
Play100FeedBreak
),
float64
(
p
.
TotalPlay
))
}
func
calcRate
(
x
float64
,
y
float64
)
float64
{
if
y
==
0
{
return
0
}
return
x
/
y
}
// CampaignRepo is a Report camRepo.
...
...
@@ -144,6 +302,7 @@ func (p *ReportUsecase) ListCampaignData(ctx context.Context, customerId int64,
if
err
!=
nil
{
return
nil
,
err
}
list
.
PrepareRateAndCost
()
return
&
ListCampaignResponse
{
List
:
list
,
PageInfo
:
req
.
PageInfo
(
total
),
...
...
internal/util/civil_time.go
0 → 100644
View file @
f493fde3
package
util
import
"time"
type
CivilTime
time
.
Time
func
(
c
CivilTime
)
MarshalJSON
()
([]
byte
,
error
)
{
return
[]
byte
(
`"`
+
time
.
Time
(
c
)
.
Format
(
"2006-01-02 15:04:05"
)
+
`"`
),
nil
}
internal/util/second.go
View file @
f493fde3
package
util
import
(
"fmt"
"strconv"
"time"
)
const
layout
=
`20060102150405`
type
Second
int64
func
NewSecond
(
ts
...
time
.
Time
)
Second
{
...
...
@@ -12,7 +15,14 @@ func NewSecond(ts ...time.Time) Second {
if
len
(
ts
)
>
0
{
t
=
ts
[
0
]
}
v
:=
t
.
Format
(
`20060102150405`
)
minute
,
_
:=
strconv
.
Atoi
(
v
)
minute
,
_
:=
strconv
.
Atoi
(
t
.
Format
(
layout
))
return
Second
(
minute
)
}
func
(
p
Second
)
MarshalJSON
()
([]
byte
,
error
)
{
t
,
err
:=
time
.
ParseInLocation
(
layout
,
fmt
.
Sprint
(
p
),
time
.
Local
)
if
err
!=
nil
{
return
nil
,
err
}
return
[]
byte
(
`"`
+
t
.
Format
(
"2006-01-02 15:04:05"
)
+
`"`
),
nil
}
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