Skip to content
Projects
Groups
Snippets
Help
Sign in / Register
Toggle navigation
Minds Backend - Engine
Project overview
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Locked Files
Issues
288
Merge Requests
31
CI / CD
Security & Compliance
Packages
Wiki
Snippets
Members
Collapse sidebar
Close sidebar
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Minds
Minds Backend - Engine
Commits
6bff170d
Commit
6bff170d
authored
2 days ago
by
Guy Thouret
Browse files
Options
Download
(feat) Implement Daily Cap for Boost Campaigns -
#1169
parent
c9b4b04f
feat-campaign-cap-1169
epic/boost-campaign
2 merge requests
!432
WIP: Max views per day for Boost Campaign
,
!417
WIP: Boost Campaigns
Pipeline
#104984845
failed with stages
in 12 minutes and 37 seconds
Changes
8
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
56 additions
and
6 deletions
+56
-6
Controllers/api/v2/boost/campaigns.php
View file @
6bff170d
...
...
@@ -99,7 +99,9 @@ class campaigns implements Interfaces\Api
->
setName
(
trim
(
$_POST
[
'name'
]
??
''
))
->
setStart
((
int
)
(
$_POST
[
'start'
]
??
0
))
->
setEnd
((
int
)
(
$_POST
[
'end'
]
??
0
))
->
setBudget
((
float
)
(
$_POST
[
'budget'
]
??
0
));
->
setBudget
((
float
)
(
$_POST
[
'budget'
]
??
0
))
->
setDailyCap
((
int
)
(
$_POST
[
'daily_cap'
]
??
0
))
->
setImpressions
(
$_POST
[
'impressions'
]
??
0
);
/** @var Manager $manager */
$manager
=
Di
::
_
()
->
get
(
'Boost\Network\Manager'
);
...
...
This diff is collapsed.
Core/Analytics/Views/Record.php
View file @
6bff170d
...
...
@@ -132,8 +132,6 @@ class Record
error_log
(
$e
);
}
return
true
;
}
...
...
This diff is collapsed.
Core/Boost/Network/Boost.php
View file @
6bff170d
...
...
@@ -207,6 +207,7 @@ class Boost
'type'
=>
$this
->
type
,
'rejection_reason'
=>
$this
->
rejectedReason
,
'boost_type'
=>
$this
->
boostType
,
'impressions_met'
=>
$this
->
impressionsMet
];
}
...
...
This diff is collapsed.
Core/Boost/Network/Campaign.php
View file @
6bff170d
...
...
@@ -68,6 +68,8 @@ use Minds\Traits\MagicAttributes;
* @method Campaign setDailyCap(int $dailyCap)
* @method int getPaused()
* @method Campaign setPaused(int $paused)
* @method int getTodayImpressions()
* @method Campaign setTodayImpressions($todayImpressions)
*/
class
Campaign
extends
Boost
implements
\JsonSerializable
{
...
...
@@ -89,6 +91,8 @@ class Campaign extends Boost implements \JsonSerializable
protected
$dailyCap
;
/** @var bool $paused */
protected
$paused
;
/** @var int $todayImpressions */
protected
$todayImpressions
=
0
;
public
function
export
(
$fields
=
[])
:
array
{
...
...
@@ -101,7 +105,8 @@ class Campaign extends Boost implements \JsonSerializable
'daily_cap'
=>
$this
->
dailyCap
,
'delivery_status'
=>
$this
->
getDeliveryStatus
(),
'cpm'
=>
$this
->
cpm
(),
'urn'
=>
$this
->
getUrn
()
'urn'
=>
$this
->
getUrn
(),
'today_impressions'
=>
$this
->
todayImpressions
];
return
array_merge
(
$boostExport
,
$campaignExport
);
...
...
This diff is collapsed.
Core/Boost/Network/CassandraRepository.php
View file @
6bff170d
...
...
@@ -80,6 +80,7 @@ class CassandraRepository
$boost
->
setEnd
(
$data
[
'end'
]);
$boost
->
setBudget
(
$data
[
'budget'
]);
$boost
->
setPaused
(
$data
[
'paused'
]);
$boost
->
setDailyCap
(
$data
[
'daily_cap'
]
??
0
);
}
else
{
$boost
=
new
Boost
();
}
...
...
This diff is collapsed.
Core/Boost/Network/ElasticRepository.php
View file @
6bff170d
...
...
@@ -231,6 +231,7 @@ class ElasticRepository
$boost
->
setEnd
(
$doc
[
'_source'
][
'@end'
]);
$boost
->
setBudget
(
$doc
[
'_source'
][
'budget'
]);
$boost
->
setPaused
(
$doc
[
'_source'
][
'paused'
]);
$boost
->
setDailyCap
(
$doc
[
'_source'
][
'daily_cap'
]
??
0
);
}
else
{
$boost
=
new
Boost
();
}
...
...
@@ -309,6 +310,7 @@ class ElasticRepository
$body
[
'doc'
][
'@start'
]
=
$boost
->
getStart
();
$body
[
'doc'
][
'@end'
]
=
$boost
->
getEnd
();
$body
[
'doc'
][
'paused'
]
=
$boost
->
getPaused
();
$body
[
'doc'
][
'daily_cap'
]
=
$boost
->
getDailyCap
();
}
if
(
$boost
->
getBidType
()
===
'tokens'
)
{
...
...
This diff is collapsed.
Core/Boost/Network/Manager.php
View file @
6bff170d
...
...
@@ -285,7 +285,20 @@ class Manager
'owner_guid'
=>
$this
->
actor
->
getGUID
(),
'boost_type'
=>
Boost
::
BOOST_TYPE_CAMPAIGN
],
$opts
);
return
$this
->
elasticRepository
->
getList
(
$opts
);
$response
=
$this
->
elasticRepository
->
getList
(
$opts
);
/** @var Metrics $metrics */
$metrics
=
Di
::
_
()
->
get
(
'Boost\Network\Metrics'
);
/** @var Campaign $campaign */
foreach
(
$response
as
$campaign
)
{
$todayImpressions
=
$metrics
->
getDailyViews
(
$campaign
);
$totalImpressions
=
$metrics
->
getTotalViews
(
$campaign
);
$campaign
->
setTodayImpressions
(
$todayImpressions
);
$campaign
->
setImpressionsMet
(
$totalImpressions
);
}
return
$response
;
}
public
function
setActor
(
User
$user
)
:
self
...
...
This diff is collapsed.
Core/Boost/Network/Metrics.php
View file @
6bff170d
...
...
@@ -16,7 +16,7 @@ class Metrics
Helpers\Counters
::
increment
((
string
)
$boost
->
getGuid
(),
$this
->
getTotalKey
(),
1
);
Helpers\Counters
::
increment
(
0
,
$this
->
getTotalKey
(),
1
);
return
Helpers\Counters
::
get
((
string
)
$boost
->
getGuid
(),
$this
->
getTotalKey
(),
false
);
return
$this
->
getTotalViews
(
$boost
);
}
/**
...
...
@@ -29,14 +29,42 @@ class Metrics
Helpers\Counters
::
increment
((
string
)
$boost
->
getGuid
(),
$this
->
getDailyKey
(),
1
);
Helpers\Counters
::
increment
(
0
,
$this
->
getDailyKey
(),
1
);
return
$this
->
getDailyViews
(
$boost
);
}
/**
* Get the boost total views value
* @param Boost|Campaign $boost
* @return int Total boost views
*/
public
function
getTotalViews
(
$boost
)
:
int
{
return
Helpers\Counters
::
get
((
string
)
$boost
->
getGuid
(),
$this
->
getTotalKey
(),
false
);
}
/**
* Get the boost daily views value
* @param Boost|Campaign $boost
* @return int Daily boost views
*/
public
function
getDailyViews
(
$boost
)
:
int
{
return
Helpers\Counters
::
get
((
string
)
$boost
->
getGuid
(),
$this
->
getDailyKey
(),
false
);
}
/**
* Returns key for boost impressions metric
* @return string
*/
public
function
getTotalKey
()
:
string
{
return
'boost_impressions'
;
}
/**
* Returns key for boost daily impressions metric
* @return string
*/
public
function
getDailyKey
()
:
string
{
return
'boost_impressions_'
.
date
(
'dmy'
);
...
...
This diff is collapsed.
Please
register
or
sign in
to comment