-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Collect statistics when Rewards sent - MEED-2890 - Meeds-io/mee…
…ds#1266 (#454) This change will introduce a new listener to collect statistics when rewards are sent for a past period.
- Loading branch information
Showing
6 changed files
with
127 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 90 additions & 0 deletions
90
.../src/main/java/org/exoplatform/wallet/reward/listener/RewardSucceedAnalyticsListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
/* | ||
* This file is part of the Meeds project (https://meeds.io/). | ||
* | ||
* Copyright (C) 2023 Meeds Association [email protected] | ||
* | ||
* This program is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU Lesser General Public | ||
* License as published by the Free Software Foundation; either | ||
* version 3 of the License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with this program; if not, write to the Free Software Foundation, | ||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
*/ | ||
package org.exoplatform.wallet.reward.listener; | ||
|
||
import java.time.Instant; | ||
import java.util.Date; | ||
import java.util.Map; | ||
import java.util.Set; | ||
import java.util.stream.Collectors; | ||
|
||
import org.apache.commons.lang.StringUtils; | ||
|
||
import org.exoplatform.analytics.model.StatisticData; | ||
import org.exoplatform.analytics.utils.AnalyticsUtils; | ||
import org.exoplatform.commons.api.persistence.ExoTransactional; | ||
import org.exoplatform.services.listener.Asynchronous; | ||
import org.exoplatform.services.listener.Event; | ||
import org.exoplatform.services.listener.Listener; | ||
import org.exoplatform.wallet.model.reward.RewardReport; | ||
import org.exoplatform.wallet.model.reward.WalletPluginReward; | ||
import org.exoplatform.wallet.model.reward.WalletReward; | ||
|
||
/** | ||
* A listener that is triggered when rewards has been successfully sent. This | ||
* will collect reward statistics. | ||
*/ | ||
@Asynchronous | ||
public class RewardSucceedAnalyticsListener extends Listener<RewardReport, Object> { | ||
|
||
@ExoTransactional | ||
public void onEvent(Event<RewardReport, Object> event) throws Exception { | ||
RewardReport rewardReport = event.getSource(); | ||
StatisticData statisticData = new StatisticData(); | ||
statisticData.setModule("wallet"); | ||
statisticData.setSubModule("reward"); | ||
statisticData.setOperation("sendPeriodRewards"); | ||
statisticData.addParameter("rewardPeriodStartDate", | ||
Date.from(Instant.ofEpochSecond(rewardReport.getPeriod().getStartDateInSeconds()))); | ||
statisticData.addParameter("rewardPeriodEndDate", | ||
Date.from(Instant.ofEpochSecond(rewardReport.getPeriod().getEndDateInSeconds()))); | ||
statisticData.addParameter("rewardPeriodTimeZone", rewardReport.getPeriod().getTimeZone()); | ||
statisticData.addParameter("rewardPeriodType", rewardReport.getPeriod().getRewardPeriodType().name().toLowerCase()); | ||
statisticData.addParameter("rewardTransactionsCount", rewardReport.getSuccessTransactionCount()); | ||
statisticData.addParameter("rewardTokensSent", rewardReport.getTokensSent()); | ||
statisticData.addParameter("rewardTokensToSend", rewardReport.getTokensToSend()); | ||
statisticData.addParameter("rewardRecipientWalletCount", rewardReport.getValidRewardCount()); | ||
statisticData.addParameter("rewardParticipantWalletCount", rewardReport.getRewards().size()); | ||
|
||
Map<String, Double> rewardPluginPoints = rewardReport.getValidRewards() | ||
.stream() | ||
.map(WalletReward::getRewards) | ||
.flatMap(Set::stream) | ||
.collect(Collectors.toMap(WalletPluginReward::getPluginId, | ||
WalletPluginReward::getPoints, | ||
Double::sum)); | ||
rewardPluginPoints.forEach((pId, | ||
points) -> statisticData.addParameter("rewardPlugin" + StringUtils.capitalize(pId) + "Points", | ||
points)); | ||
Map<String, Double> rewardPluginAmounts = rewardReport.getValidRewards() | ||
.stream() | ||
.map(WalletReward::getRewards) | ||
.flatMap(Set::stream) | ||
.collect(Collectors.toMap(WalletPluginReward::getPluginId, | ||
WalletPluginReward::getAmount, | ||
Double::sum)); | ||
rewardPluginAmounts.forEach((pId, | ||
amount) -> statisticData.addParameter("rewardPlugin" + StringUtils.capitalize(pId) + "Amount", | ||
amount)); | ||
|
||
AnalyticsUtils.addStatisticData(statisticData); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
wallet-webapps/src/main/resources/locale/portlet/Analytics_en.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
analytics.field.label.rewardPeriodStartDate=Reward period start date | ||
analytics.field.label.rewardPeriodEndDate=Reward period end date | ||
analytics.field.label.rewardPeriodTimeZone=Reward period time zone | ||
analytics.field.label.rewardPeriodType=Reward period type | ||
analytics.field.label.rewardTransactionsCount=Reward transactions count | ||
analytics.field.label.rewardTokensSent=Reward tokens sent | ||
analytics.field.label.rewardTokensToSend=Reward tokens to sent | ||
analytics.field.label.rewardRecipientWalletCount=Reward recipients count | ||
analytics.field.label.rewardParticipantWalletCount=Reward participants count | ||
analytics.field.label.rewardPluginGamificationPoints=Gamification reward: total points | ||
analytics.field.label.rewardPluginGamificationAmount=Gamification reward: tokens sent | ||
|
||
analytics.wallet=Wallet | ||
analytics.reward=Reward | ||
analytics.sendPeriodRewards=Period rewards sent | ||
analytics.week=Week | ||
analytics.month=Month | ||
analytics.quarter=Quarter | ||
analytics.semester=Semester | ||
analytics.year=Year |