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
6e61fe82
Commit
6e61fe82
authored
Feb 22, 2023
by
彭芳
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[minor]: format calc data
parent
8531d67b
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
102 additions
and
80 deletions
+102
-80
go.mod
go.mod
+1
-0
go.sum
go.sum
+2
-0
report.go
internal/biz/report.go
+85
-80
float64.go
internal/util/float64.go
+14
-0
No files found.
go.mod
View file @
6e61fe82
...
@@ -18,6 +18,7 @@ require (
...
@@ -18,6 +18,7 @@ require (
github.com/gin-contrib/pprof v1.4.0
github.com/gin-contrib/pprof v1.4.0
github.com/gin-gonic/gin v1.8.2
github.com/gin-gonic/gin v1.8.2
github.com/google/uuid v1.3.0
github.com/google/uuid v1.3.0
github.com/shopspring/decimal v1.3.1
)
)
require (
require (
...
...
go.sum
View file @
6e61fe82
...
@@ -132,6 +132,8 @@ github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTE
...
@@ -132,6 +132,8 @@ github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTE
github.com/rogpeppe/go-internal v1.8.0 h1:FCbCCtXNOY3UtUuHUYaghJg4y7Fd14rXifAYUAtL9R8=
github.com/rogpeppe/go-internal v1.8.0 h1:FCbCCtXNOY3UtUuHUYaghJg4y7Fd14rXifAYUAtL9R8=
github.com/rogpeppe/go-internal v1.8.0/go.mod h1:WmiCO8CzOY8rg0OYDC4/i/2WRWAB6poM+XZ2dLUbcbE=
github.com/rogpeppe/go-internal v1.8.0/go.mod h1:WmiCO8CzOY8rg0OYDC4/i/2WRWAB6poM+XZ2dLUbcbE=
github.com/shirou/gopsutil/v3 v3.21.8/go.mod h1:YWp/H8Qs5fVmf17v7JNZzA0mPJ+mS2e9JdiUF9LlKzQ=
github.com/shirou/gopsutil/v3 v3.21.8/go.mod h1:YWp/H8Qs5fVmf17v7JNZzA0mPJ+mS2e9JdiUF9LlKzQ=
github.com/shopspring/decimal v1.3.1 h1:2Usl1nmF/WZucqkFZhnfFYxxxu8LG21F6nPQBE5gKV8=
github.com/shopspring/decimal v1.3.1/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o=
github.com/sirupsen/logrus v1.9.0 h1:trlNQbNUG3OdDrDil03MCb1H2o9nJ1x4/5LYw7byDE0=
github.com/sirupsen/logrus v1.9.0 h1:trlNQbNUG3OdDrDil03MCb1H2o9nJ1x4/5LYw7byDE0=
github.com/sirupsen/logrus v1.9.0/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
github.com/sirupsen/logrus v1.9.0/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
...
...
internal/biz/report.go
View file @
6e61fe82
...
@@ -20,7 +20,7 @@ const (
...
@@ -20,7 +20,7 @@ const (
type
ListReportRequest
struct
{
type
ListReportRequest
struct
{
common
.
PageRequest
common
.
PageRequest
TimeGranularity
TimeGranularity
`form:"time_granularity" json:"time_granularity"`
// 时间粒度(
0:按天维度;1:按小时维度
)
TimeGranularity
TimeGranularity
`form:"time_granularity" json:"time_granularity"`
// 时间粒度(
允许值:STAT_TIME_GRANULARITY_DAILY (按天维度),STAT_TIME_GRANULARITY_HOURLY (按小时维度)
)
StartDate
string
`form:"start_date" json:"start_date"`
// 开始时间(格式YYYY-MM-DD)
StartDate
string
`form:"start_date" json:"start_date"`
// 开始时间(格式YYYY-MM-DD)
EndDate
string
`form:"end_date" json:"end_date"`
// 结束时间(格式YYYY-MM-DD)
EndDate
string
`form:"end_date" json:"end_date"`
// 结束时间(格式YYYY-MM-DD)
StartDateLong
util
.
Second
`json:"-"`
// 开始时间
StartDateLong
util
.
Second
`json:"-"`
// 开始时间
...
@@ -28,20 +28,25 @@ type ListReportRequest struct {
...
@@ -28,20 +28,25 @@ type ListReportRequest struct {
}
}
func
(
p
*
ListReportRequest
)
Validate
()
error
{
func
(
p
*
ListReportRequest
)
Validate
()
error
{
if
p
.
StartDate
!=
""
{
// set default data today
today
:=
time
.
Now
()
.
Format
(
"2006-01-02"
)
if
p
.
StartDate
==
""
{
p
.
StartDate
=
today
}
if
p
.
EndDate
==
""
{
p
.
EndDate
=
today
}
parse
,
err
:=
time
.
Parse
(
"2006-01-02"
,
p
.
StartDate
)
parse
,
err
:=
time
.
Parse
(
"2006-01-02"
,
p
.
StartDate
)
if
err
!=
nil
{
if
err
!=
nil
{
return
errs
.
ErrorArgs
.
WithMessage
(
"开始时间格式错误"
)
return
errs
.
ErrorArgs
.
WithMessage
(
"开始时间格式错误"
)
}
}
p
.
StartDateLong
=
util
.
NewSecond
(
parse
)
p
.
StartDateLong
=
util
.
NewSecond
(
parse
)
}
if
p
.
EndDate
!=
""
{
parse
,
err
=
time
.
Parse
(
"2006-01-02"
,
p
.
EndDate
)
parse
,
err
:=
time
.
Parse
(
"2006-01-02"
,
p
.
EndDate
)
if
err
!=
nil
{
if
err
!=
nil
{
return
errs
.
ErrorArgs
.
WithMessage
(
"结束时间格式错误"
)
return
errs
.
ErrorArgs
.
WithMessage
(
"结束时间格式错误"
)
}
}
p
.
EndDateLong
=
util
.
NewSecond
(
parse
)
p
.
EndDateLong
=
util
.
NewSecond
(
parse
)
}
return
nil
return
nil
}
}
...
@@ -100,35 +105,35 @@ type Campaign struct {
...
@@ -100,35 +105,35 @@ type Campaign struct {
AttributionActivePayIntraOneDayAmount
float64
`json:"attribution_active_pay_intra_one_day_amount"`
// 游戏行业-激活后24h付费金额
AttributionActivePayIntraOneDayAmount
float64
`json:"attribution_active_pay_intra_one_day_amount"`
// 游戏行业-激活后24h付费金额
Timestamp
util
.
CivilTime
`json:"timestamp"`
// 创建时间(yyyy-MM-dd HH:mm:ss)
Timestamp
util
.
CivilTime
`json:"timestamp"`
// 创建时间(yyyy-MM-dd HH:mm:ss)
// 计算字段
// 计算字段
AvgShowCost
f
loat64
`json:"avg_show_cost"`
// 千次展示成本
AvgShowCost
util
.
F
loat64
`json:"avg_show_cost"`
// 千次展示成本
AvgClickCost
f
loat64
`json:"avg_click_cost"`
// 点击成本
AvgClickCost
util
.
F
loat64
`json:"avg_click_cost"`
// 点击成本
Ctr
f
loat64
`json:"ctr"`
// 点击率
Ctr
util
.
F
loat64
`json:"ctr"`
// 点击率
ConvertCost
f
loat64
`json:"convert_cost"`
// 转化成本
ConvertCost
util
.
F
loat64
`json:"convert_cost"`
// 转化成本
ConvertRate
f
loat64
`json:"convert_rate"`
// 转化率
ConvertRate
util
.
F
loat64
`json:"convert_rate"`
// 转化率
DeepConvertCost
f
loat64
`json:"deep_convert_cost"`
// 深度转化成本
DeepConvertCost
util
.
F
loat64
`json:"deep_convert_cost"`
// 深度转化成本
DeepConvertRate
f
loat64
`json:"deep_convert_rate"`
// 深度转化率
DeepConvertRate
util
.
F
loat64
`json:"deep_convert_rate"`
// 深度转化率
AttributionConvertCost
f
loat64
`json:"attribution_convert_cost"`
// 转化成本(计费时间)
AttributionConvertCost
util
.
F
loat64
`json:"attribution_convert_cost"`
// 转化成本(计费时间)
AttributionDeepConvertCost
f
loat64
`json:"attribution_deep_convert_cost"`
// 深度转化成本(计费时间)
AttributionDeepConvertCost
util
.
F
loat64
`json:"attribution_deep_convert_cost"`
// 深度转化成本(计费时间)
DownloadStartCost
f
loat64
`json:"download_start_cost"`
// 安卓下载开始成本
DownloadStartCost
util
.
F
loat64
`json:"download_start_cost"`
// 安卓下载开始成本
DownloadStartRate
f
loat64
`json:"download_start_rate"`
// 安卓下载开始率
DownloadStartRate
util
.
F
loat64
`json:"download_start_rate"`
// 安卓下载开始率
DownloadFinishCost
f
loat64
`json:"download_finish_cost"`
// 安卓下载完成成本
DownloadFinishCost
util
.
F
loat64
`json:"download_finish_cost"`
// 安卓下载完成成本
DownloadFinishRate
f
loat64
`json:"download_finish_rate"`
// 安卓下载完成率
DownloadFinishRate
util
.
F
loat64
`json:"download_finish_rate"`
// 安卓下载完成率
InstallFinishCost
f
loat64
`json:"install_finish_cost"`
// 安卓安装完成成本
InstallFinishCost
util
.
F
loat64
`json:"install_finish_cost"`
// 安卓安装完成成本
InstallFinishRate
f
loat64
`json:"install_finish_rate"`
// 安卓安装完成率
InstallFinishRate
util
.
F
loat64
`json:"install_finish_rate"`
// 安卓安装完成率
ActiveCost
f
loat64
`json:"active_cost"`
// 激活成本
ActiveCost
util
.
F
loat64
`json:"active_cost"`
// 激活成本
ActiveRate
f
loat64
`json:"active_rate"`
// 激活率
ActiveRate
util
.
F
loat64
`json:"active_rate"`
// 激活率
ActiveRegisterCost
f
loat64
`json:"active_register_cost"`
// 注册成本
ActiveRegisterCost
util
.
F
loat64
`json:"active_register_cost"`
// 注册成本
ActiveRegisterRate
f
loat64
`json:"active_register_rate"`
// 注册率
ActiveRegisterRate
util
.
F
loat64
`json:"active_register_rate"`
// 注册率
AttributionNextDayOpenCost
f
loat64
`json:"attribution_next_day_open_cost"`
// 次留成本
AttributionNextDayOpenCost
util
.
F
loat64
`json:"attribution_next_day_open_cost"`
// 次留成本
AttributionNextDayOpenRate
f
loat64
`json:"attribution_next_day_open_rate"`
// 次留率
AttributionNextDayOpenRate
util
.
F
loat64
`json:"attribution_next_day_open_rate"`
// 次留率
GameAddictionCost
f
loat64
`json:"game_addiction_cost"`
// 关键行为成本
GameAddictionCost
util
.
F
loat64
`json:"game_addiction_cost"`
// 关键行为成本
GameAddictionRate
f
loat64
`json:"game_addiction_rate"`
// 关键行为率
GameAddictionRate
util
.
F
loat64
`json:"game_addiction_rate"`
// 关键行为率
ActivePayCost
f
loat64
`json:"active_pay_cost"`
// 首次付费成本
ActivePayCost
util
.
F
loat64
`json:"active_pay_cost"`
// 首次付费成本
ActivePayRate
f
loat64
`json:"active_pay_rate"`
// 首次付费率
ActivePayRate
util
.
F
loat64
`json:"active_pay_rate"`
// 首次付费率
ValidPlayCost
f
loat64
`json:"valid_play_cost"`
// 有效播放成本
ValidPlayCost
util
.
F
loat64
`json:"valid_play_cost"`
// 有效播放成本
ValidPlayRate
f
loat64
`json:"valid_play_rate"`
// 有效播放率
ValidPlayRate
util
.
F
loat64
`json:"valid_play_rate"`
// 有效播放率
AveragePlayTimePerPlay
f
loat64
`json:"average_play_time_per_play"`
// 视频数据-平均单次播放时长,单位:秒
AveragePlayTimePerPlay
util
.
F
loat64
`json:"average_play_time_per_play"`
// 视频数据-平均单次播放时长,单位:秒
PlayOverRate
f
loat64
`json:"play_over_rate"`
// 播完率
PlayOverRate
util
.
F
loat64
`json:"play_over_rate"`
// 播完率
}
}
func
(
p
*
Campaign
)
PrepareRateAndCost
()
{
func
(
p
*
Campaign
)
PrepareRateAndCost
()
{
...
@@ -163,127 +168,127 @@ func (p *Campaign) PrepareRateAndCost() {
...
@@ -163,127 +168,127 @@ func (p *Campaign) PrepareRateAndCost() {
p
.
PlayOverRate
=
p
.
getPlayOverRate
()
p
.
PlayOverRate
=
p
.
getPlayOverRate
()
}
}
func
(
p
*
Campaign
)
getAvgShowCost
()
f
loat64
{
func
(
p
*
Campaign
)
getAvgShowCost
()
util
.
F
loat64
{
return
calcRate
(
p
.
Cost
,
float64
(
p
.
Show
))
return
calcRate
(
p
.
Cost
,
float64
(
p
.
Show
))
*
1000
}
}
func
(
p
*
Campaign
)
getAvgClickCost
()
f
loat64
{
func
(
p
*
Campaign
)
getAvgClickCost
()
util
.
F
loat64
{
return
calcRate
(
p
.
Cost
,
float64
(
p
.
Click
))
return
calcRate
(
p
.
Cost
,
float64
(
p
.
Click
))
}
}
func
(
p
*
Campaign
)
getCtr
()
f
loat64
{
func
(
p
*
Campaign
)
getCtr
()
util
.
F
loat64
{
return
calcRate
(
float64
(
p
.
Click
),
float64
(
p
.
Show
))
return
calcRate
(
float64
(
p
.
Click
),
float64
(
p
.
Show
))
*
100
}
}
func
(
p
*
Campaign
)
getConvertCost
()
f
loat64
{
func
(
p
*
Campaign
)
getConvertCost
()
util
.
F
loat64
{
return
calcRate
(
p
.
Cost
,
float64
(
p
.
Convert
))
return
calcRate
(
p
.
Cost
,
float64
(
p
.
Convert
))
}
}
func
(
p
*
Campaign
)
getConvertRate
()
f
loat64
{
func
(
p
*
Campaign
)
getConvertRate
()
util
.
F
loat64
{
return
calcRate
(
float64
(
p
.
Convert
),
float64
(
p
.
Click
))
return
calcRate
(
float64
(
p
.
Convert
),
float64
(
p
.
Click
))
*
100
}
}
func
(
p
*
Campaign
)
getDeepConvertCost
()
f
loat64
{
func
(
p
*
Campaign
)
getDeepConvertCost
()
util
.
F
loat64
{
return
calcRate
(
p
.
Cost
,
float64
(
p
.
DeepConvert
))
return
calcRate
(
p
.
Cost
,
float64
(
p
.
DeepConvert
))
}
}
func
(
p
*
Campaign
)
getDeepConvertRate
()
f
loat64
{
func
(
p
*
Campaign
)
getDeepConvertRate
()
util
.
F
loat64
{
return
calcRate
(
float64
(
p
.
DeepConvert
),
float64
(
p
.
Convert
))
return
calcRate
(
float64
(
p
.
DeepConvert
),
float64
(
p
.
Convert
))
*
100
}
}
func
(
p
*
Campaign
)
getAttributionConvertCost
()
f
loat64
{
func
(
p
*
Campaign
)
getAttributionConvertCost
()
util
.
F
loat64
{
return
calcRate
(
p
.
Cost
,
float64
(
p
.
AttributionConvert
))
return
calcRate
(
p
.
Cost
,
float64
(
p
.
AttributionConvert
))
}
}
func
(
p
*
Campaign
)
getAttributionDeepConvertCost
()
f
loat64
{
func
(
p
*
Campaign
)
getAttributionDeepConvertCost
()
util
.
F
loat64
{
return
calcRate
(
p
.
Cost
,
float64
(
p
.
AttributionDeepConvert
))
return
calcRate
(
p
.
Cost
,
float64
(
p
.
AttributionDeepConvert
))
}
}
func
(
p
*
Campaign
)
getDownloadStartCost
()
f
loat64
{
func
(
p
*
Campaign
)
getDownloadStartCost
()
util
.
F
loat64
{
return
calcRate
(
p
.
Cost
,
float64
(
p
.
DownloadStart
))
return
calcRate
(
p
.
Cost
,
float64
(
p
.
DownloadStart
))
}
}
func
(
p
*
Campaign
)
getDownloadStartRate
()
f
loat64
{
func
(
p
*
Campaign
)
getDownloadStartRate
()
util
.
F
loat64
{
return
calcRate
(
float64
(
p
.
DownloadStart
),
float64
(
p
.
Click
))
return
calcRate
(
float64
(
p
.
DownloadStart
),
float64
(
p
.
Click
))
*
100
}
}
func
(
p
*
Campaign
)
getDownloadFinishCost
()
f
loat64
{
func
(
p
*
Campaign
)
getDownloadFinishCost
()
util
.
F
loat64
{
return
calcRate
(
p
.
Cost
,
float64
(
p
.
DownloadFinish
))
return
calcRate
(
p
.
Cost
,
float64
(
p
.
DownloadFinish
))
}
}
func
(
p
*
Campaign
)
getDownloadFinishRate
()
f
loat64
{
func
(
p
*
Campaign
)
getDownloadFinishRate
()
util
.
F
loat64
{
return
calcRate
(
float64
(
p
.
DownloadFinish
),
float64
(
p
.
DownloadStart
))
return
calcRate
(
float64
(
p
.
DownloadFinish
),
float64
(
p
.
DownloadStart
))
*
100
}
}
func
(
p
*
Campaign
)
getInstallFinishCost
()
f
loat64
{
func
(
p
*
Campaign
)
getInstallFinishCost
()
util
.
F
loat64
{
return
calcRate
(
p
.
Cost
,
float64
(
p
.
InstallFinish
))
return
calcRate
(
p
.
Cost
,
float64
(
p
.
InstallFinish
))
}
}
func
(
p
*
Campaign
)
getInstallFinishRate
()
f
loat64
{
func
(
p
*
Campaign
)
getInstallFinishRate
()
util
.
F
loat64
{
return
calcRate
(
float64
(
p
.
InstallFinish
),
float64
(
p
.
DownloadFinish
))
return
calcRate
(
float64
(
p
.
InstallFinish
),
float64
(
p
.
DownloadFinish
))
*
100
}
}
func
(
p
*
Campaign
)
getActiveCost
()
f
loat64
{
func
(
p
*
Campaign
)
getActiveCost
()
util
.
F
loat64
{
return
calcRate
(
p
.
Cost
,
float64
(
p
.
Active
))
return
calcRate
(
p
.
Cost
,
float64
(
p
.
Active
))
}
}
func
(
p
*
Campaign
)
getActiveRate
()
f
loat64
{
func
(
p
*
Campaign
)
getActiveRate
()
util
.
F
loat64
{
return
calcRate
(
float64
(
p
.
Active
),
float64
(
p
.
Click
))
return
calcRate
(
float64
(
p
.
Active
),
float64
(
p
.
Click
))
*
100
}
}
func
(
p
*
Campaign
)
getActiveRegisterCost
()
f
loat64
{
func
(
p
*
Campaign
)
getActiveRegisterCost
()
util
.
F
loat64
{
return
calcRate
(
p
.
Cost
,
float64
(
p
.
Register
))
return
calcRate
(
p
.
Cost
,
float64
(
p
.
Register
))
}
}
func
(
p
*
Campaign
)
getActiveRegisterRate
()
f
loat64
{
func
(
p
*
Campaign
)
getActiveRegisterRate
()
util
.
F
loat64
{
return
calcRate
(
float64
(
p
.
Register
),
float64
(
p
.
Active
))
return
calcRate
(
float64
(
p
.
Register
),
float64
(
p
.
Active
))
*
100
}
}
func
(
p
*
Campaign
)
getAttributionNextDayOpenCost
()
f
loat64
{
func
(
p
*
Campaign
)
getAttributionNextDayOpenCost
()
util
.
F
loat64
{
return
calcRate
(
p
.
Cost
,
float64
(
p
.
AttributionNextDayOpenCnt
))
return
calcRate
(
p
.
Cost
,
float64
(
p
.
AttributionNextDayOpenCnt
))
}
}
func
(
p
*
Campaign
)
getAttributionNextDayOpenRate
()
f
loat64
{
func
(
p
*
Campaign
)
getAttributionNextDayOpenRate
()
util
.
F
loat64
{
return
calcRate
(
float64
(
p
.
AttributionNextDayOpenCnt
),
float64
(
p
.
Active
))
return
calcRate
(
float64
(
p
.
AttributionNextDayOpenCnt
),
float64
(
p
.
Active
))
*
100
}
}
func
(
p
*
Campaign
)
getGameAddictionCost
()
f
loat64
{
func
(
p
*
Campaign
)
getGameAddictionCost
()
util
.
F
loat64
{
return
calcRate
(
p
.
Cost
,
float64
(
p
.
GameAddiction
))
return
calcRate
(
p
.
Cost
,
float64
(
p
.
GameAddiction
))
}
}
func
(
p
*
Campaign
)
getGameAddictionRate
()
f
loat64
{
func
(
p
*
Campaign
)
getGameAddictionRate
()
util
.
F
loat64
{
return
calcRate
(
float64
(
p
.
GameAddiction
),
float64
(
p
.
Active
))
return
calcRate
(
float64
(
p
.
GameAddiction
),
float64
(
p
.
Active
))
*
100
}
}
func
(
p
*
Campaign
)
getActivePayCost
()
f
loat64
{
func
(
p
*
Campaign
)
getActivePayCost
()
util
.
F
loat64
{
return
calcRate
(
p
.
Cost
,
float64
(
p
.
PayCount
))
return
calcRate
(
p
.
Cost
,
float64
(
p
.
PayCount
))
}
}
func
(
p
*
Campaign
)
getActivePayRate
()
f
loat64
{
func
(
p
*
Campaign
)
getActivePayRate
()
util
.
F
loat64
{
return
calcRate
(
float64
(
p
.
PayCount
),
float64
(
p
.
Active
))
return
calcRate
(
float64
(
p
.
PayCount
),
float64
(
p
.
Active
))
*
100
}
}
func
(
p
*
Campaign
)
getValidPlayCost
()
f
loat64
{
func
(
p
*
Campaign
)
getValidPlayCost
()
util
.
F
loat64
{
return
calcRate
(
p
.
Cost
,
float64
(
p
.
ValidPlay
))
return
calcRate
(
p
.
Cost
,
float64
(
p
.
ValidPlay
))
}
}
func
(
p
*
Campaign
)
getValidPlayRate
()
f
loat64
{
func
(
p
*
Campaign
)
getValidPlayRate
()
util
.
F
loat64
{
return
calcRate
(
float64
(
p
.
ValidPlay
),
float64
(
p
.
Show
))
return
calcRate
(
float64
(
p
.
ValidPlay
),
float64
(
p
.
Show
))
*
100
}
}
func
(
p
*
Campaign
)
getAveragePlayTimePerPlay
()
f
loat64
{
func
(
p
*
Campaign
)
getAveragePlayTimePerPlay
()
util
.
F
loat64
{
return
calcRate
(
float64
(
p
.
PlayDurationSum
),
float64
(
p
.
TotalPlay
))
return
calcRate
(
float64
(
p
.
PlayDurationSum
),
float64
(
p
.
TotalPlay
))
}
}
func
(
p
*
Campaign
)
getPlayOverRate
()
f
loat64
{
func
(
p
*
Campaign
)
getPlayOverRate
()
util
.
F
loat64
{
return
calcRate
(
float64
(
p
.
Play100FeedBreak
),
float64
(
p
.
TotalPlay
))
return
calcRate
(
float64
(
p
.
Play100FeedBreak
),
float64
(
p
.
TotalPlay
))
*
100
}
}
func
calcRate
(
x
float64
,
y
float64
)
f
loat64
{
func
calcRate
(
x
float64
,
y
float64
)
util
.
F
loat64
{
if
y
==
0
{
if
y
==
0
{
return
0
return
0
}
}
return
x
/
y
return
util
.
Float64
(
x
/
y
)
}
}
// CampaignRepo is a Report camRepo.
// CampaignRepo is a Report camRepo.
...
...
internal/util/float64.go
0 → 100644
View file @
6e61fe82
package
util
import
(
"fmt"
"github.com/shopspring/decimal"
)
type
Float64
float64
func
(
f
Float64
)
MarshalJSON
()
([]
byte
,
error
)
{
out
,
_
:=
decimal
.
NewFromFloat
(
float64
(
f
))
.
Round
(
2
)
.
Float64
()
return
[]
byte
(
fmt
.
Sprint
(
out
)),
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