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
286
Merge Requests
38
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
13a62c92
Commit
13a62c92
authored
4 minutes ago
by
Guy Thouret
Browse files
Options
Download
Boost Campaign Preview Endpoint -
#1201
parent
4ecc1fb3
epic/boost-campaign
1 merge request
!417
WIP: Boost Campaigns
Pipeline
#102045404
running with stages
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
95 additions
and
0 deletions
+95
-0
Controllers/api/v2/boost/campaigns/preview.php
0 → 100644
View file @
13a62c92
<?php
namespace
Minds\Controllers\api\v2\boost\campaigns
;
use
Minds\Api\AbstractApi
;
use
Minds\Common\Urn
;
use
Minds\Core\Boost\Network\Campaign
;
use
Minds\Core\Boost\Network\CampaignStats
;
class
preview
extends
AbstractApi
{
/**
* Equivalent to HTTP POST method
* @param array $pages
* @return mixed|null
*/
public
function
post
(
$pages
)
:
void
{
$urns
=
$_POST
[
'entity_urns'
]
??
[];
if
(
empty
(
$urns
))
{
$this
->
sendNotAcceptable
(
'No entity_urns'
);
return
;
}
try
{
$urn
=
new
Urn
(
$urns
[
0
]);
$entityGuid
=
(
string
)
$urn
->
getNss
();
}
catch
(
\Exception
$e
)
{
$this
->
sendNotAcceptable
(
$e
->
getMessage
());
return
;
}
$campaign
=
(
new
Campaign
())
->
setType
(
$_POST
[
'type'
]
??
''
)
->
setEntityGuid
(
$entityGuid
)
->
setStart
((
int
)(
$_POST
[
'start'
]
??
0
))
->
setEnd
((
int
)(
$_POST
[
'end'
]
??
0
))
->
setBudget
((
float
)(
$_POST
[
'budget'
]
??
0
))
->
setImpressions
(
$_POST
[
'impressions'
]);
$this
->
send
([
'preview'
=>
(
new
CampaignStats
())
->
setCampaign
(
$campaign
)
->
getAll
()
]);
}
}
This diff is collapsed.
Core/Boost/Network/CampaignStats.php
0 → 100644
View file @
13a62c92
<?php
namespace
Minds\Core\Boost\Network
;
use
Minds\Core\Analytics\EntityCentric\BoostViewsDaily
;
use
Minds\Helpers\Time
;
class
CampaignStats
{
/** @var Campaign */
protected
$campaign
;
/** @var BoostViewsDaily */
protected
$boostViewsDaily
;
public
function
__construct
(
BoostViewsDaily
$boostViewsDaily
=
null
)
{
$this
->
boostViewsDaily
=
$boostViewsDaily
?:
new
BoostViewsDaily
();
}
/**
* @param Campaign $campaign
* @return CampaignStats
*/
public
function
setCampaign
(
Campaign
$campaign
)
:
self
{
$this
->
campaign
=
$campaign
;
return
$this
;
}
/**
* @return array
*/
public
function
getAll
()
:
array
{
/* TODO: Evaluate the campaign targeting parameters against our data */
$campaignDurationDays
=
(
$this
->
campaign
->
getEnd
()
-
$this
->
campaign
->
getStart
())
/
Time
::
ONE_DAY_MS
;
$campaignViewsPerDayReq
=
(
$campaignDurationDays
>
0
)
?
$this
->
campaign
->
getImpressions
()
/
$campaignDurationDays
:
0
;
$globalViewsPerDay
=
$this
->
boostViewsDaily
->
getAvg
();
return
[
'canBeDelivered'
=>
(
$campaignViewsPerDayReq
<
$globalViewsPerDay
),
'durationDays'
=>
$campaignDurationDays
,
'viewsPerDayRequested'
=>
$campaignViewsPerDayReq
,
'globalViewsPerDay'
=>
$globalViewsPerDay
];
}
}
This diff is collapsed.
Please
register
or
sign in
to comment