Round score to 1 decimal instead of 0

[MAILPOET-3525]
This commit is contained in:
Pavel Dohnal
2021-04-21 10:21:01 +02:00
committed by Veljko V
parent a2c1b4f8bc
commit 3f91c40594
7 changed files with 36 additions and 19 deletions

View File

@ -7,12 +7,24 @@ interface Props {
}
export const ListingsEngagementScore: React.FunctionComponent<Props> = ({ subscriber }) => (
<div className="mailpoet-listing-stats-opened-clicked">
{subscriber.engagement_score != null && (
<div className="mailpoet-listing-stats-percentages">
{subscriber.engagement_score}
%
</div>
)}
<div className="mailpoet-listing-stats">
<div className="mailpoet-listing-stats-opened-clicked">
{subscriber.engagement_score != null && (
<div className="mailpoet-listing-stats-percentages">
{
subscriber
.engagement_score
.toLocaleString(
undefined,
{
minimumFractionDigits: 1,
maximumFractionDigits: 1,
}
)
}
%
</div>
)}
</div>
</div>
);

View File

@ -216,7 +216,7 @@ class Migrator {
'count_confirmations int(11) unsigned NOT NULL DEFAULT 0,',
'unsubscribe_token char(15) NULL,',
'link_token char(32) NULL,',
'engagement_score tinyint unsigned NULL,',
'engagement_score FLOAT unsigned NULL,',
'engagement_score_updated_at timestamp NULL,',
'PRIMARY KEY (id),',
'UNIQUE KEY email (email),',

View File

@ -39,6 +39,7 @@ class SubscribersEngagementScore extends SimpleWorker {
if ($subscribers) {
$this->schedule();
}
return true;
}
public function getNextRunDate() {

View File

@ -126,8 +126,8 @@ class SubscriberEntity {
private $linkToken;
/**
* @ORM\Column(type="integer")
* @var int|null
* @ORM\Column(type="float", nullable=true)
* @var float|null
*/
private $engagementScore;
@ -410,16 +410,16 @@ class SubscriberEntity {
}
/**
* @return int|null
* @return float|null
*/
public function getEngagementScore(): ?int {
public function getEngagementScore(): ?float {
return $this->engagementScore;
}
/**
* @param int|null $engagementScore
* @param float|null $engagementScore
*/
public function setEngagementScore(?int $engagementScore): void {
public function setEngagementScore(?float $engagementScore): void {
$this->engagementScore = $engagementScore;
}

View File

@ -9,7 +9,7 @@ use MailPoet\Entities\SubscriberEntity;
use MailPoet\Tasks\Sending;
/**
* @extends Repository<StatisticsOpensEntity>
* @extends Repository<StatisticsOpenEntity>
*/
class StatisticsOpensRepository extends Repository {
protected function getEntityClassName(): string {
@ -43,7 +43,7 @@ class StatisticsOpensRepository extends Repository {
->setParameter('subscriberId', $subscriber)
->getQuery()
->getSingleScalarResult();
$score = (int)round(($opens / $newslettersSentCount) * 100);
$score = ($opens / $newslettersSentCount) * 100;
$subscriber->setEngagementScore($score);
$this->entityManager->flush();
}

View File

@ -33,16 +33,21 @@ class Clicks {
/** @var LinkShortcodeCategory */
private $linkShortcodeCategory;
/** @var Opens */
private $opens;
public function __construct(
SettingsController $settingsController,
Cookies $cookies,
Shortcodes $shortcodes,
Opens $opens,
LinkShortcodeCategory $linkShortcodeCategory
) {
$this->settingsController = $settingsController;
$this->cookies = $cookies;
$this->shortcodes = $shortcodes;
$this->linkShortcodeCategory = $linkShortcodeCategory;
$this->opens = $opens;
}
/**
@ -73,8 +78,7 @@ class Clicks {
$this->sendRevenueCookie($statisticsClicks);
$this->sendAbandonedCartCookie($subscriber);
// track open event
$openEvent = new Opens();
$openEvent->track($data, $displayImage = false);
$this->opens->track($data, $displayImage = false);
}
$url = $this->processUrl($link->getUrl(), $newsletter, $subscriber, $queue, $wpUserPreview);
$this->redirectToUrl($url);

View File

@ -12,7 +12,7 @@ use MailPoet\Subscribers\SubscribersRepository;
use MailPoet\Tasks\Sending;
use MailPoetVendor\Carbon\CarbonImmutable;
class StatisticsFormsRepositoryTest extends \MailPoetTest {
class StatisticsOpensRepositoryTest extends \MailPoetTest {
/** @var StatisticsOpensRepository */
private $repository;