feat(users): calculate the user hourly scores income

This commit is contained in:
OldHawk
2018-06-03 23:51:31 +08:00
parent 717acfc98b
commit b9900a9b7c
23 changed files with 385 additions and 47 deletions

View File

@@ -6,10 +6,12 @@
.controller('ScoreController', ScoreController);
ScoreController.$inject = ['$rootScope', '$scope', '$state', '$translate', '$timeout', 'Authentication', '$window', 'ScoreLevelService', 'getStorageLangService',
'MeanTorrentConfig', 'ModalConfirmService', 'NotifycationService', 'InvitationsService', '$templateRequest', 'marked', '$filter'];
'MeanTorrentConfig', 'ModalConfirmService', 'NotifycationService', 'InvitationsService', '$templateRequest', 'marked', '$filter', 'PeersService', 'moment',
'DebugConsoleService'];
function ScoreController($rootScope, $scope, $state, $translate, $timeout, Authentication, $window, ScoreLevelService, getStorageLangService, MeanTorrentConfig,
ModalConfirmService, NotifycationService, InvitationsService, $templateRequest, marked, $filter) {
ModalConfirmService, NotifycationService, InvitationsService, $templateRequest, marked, $filter, PeersService, moment,
mtDebug) {
var vm = this;
vm.scoreConfig = MeanTorrentConfig.meanTorrentConfig.score;
vm.inviteConfig = MeanTorrentConfig.meanTorrentConfig.invite;
@@ -111,7 +113,10 @@
closeButtonText: $translate.instant('EXCHANGE_INVITATION_CONFIRM_CANCEL'),
actionButtonText: $translate.instant('EXCHANGE_INVITATION_CONFIRM_OK'),
headerText: $translate.instant('EXCHANGE_INVITATION_CONFIRM_HEADER_TEXT'),
bodyText: $translate.instant('EXCHANGE_INVITATION_CONFIRM_BODY_TEXT', {score: vm.inviteConfig.scoreExchange, hours: vm.inviteConfig.expires_str})
bodyText: $translate.instant('EXCHANGE_INVITATION_CONFIRM_BODY_TEXT', {
score: vm.inviteConfig.scoreExchange,
hours: vm.inviteConfig.expires_str
})
};
ModalConfirmService.showModal({}, modalOptions)
@@ -138,5 +143,212 @@
}
});
};
/**
* getMyPeers
*/
vm.getMyPeers = function () {
PeersService.getMyPeers(function (items) {
vm.myPeers = items;
mtDebug.info(items);
vm.countByStatus = $filter('countBy')(vm.myPeers, 'peer_status');
vm.groupByStatus = $filter('groupBy')(vm.myPeers, 'peer_status');
vm.sumCUSpeed = vm.myPeers.map(function (x) {
return x.peer_cuspeed;
}).reduce(function (a, b) {
return a + b;
});
vm.sumCDSpeed = vm.myPeers.map(function (x) {
return x.peer_cdspeed;
}).reduce(function (a, b) {
return a + b;
});
});
};
/**
* getMarkedCurrDownloadingString
* @returns {*}
*/
vm.getMarkedCurrDownloadingString = function () {
if (vm.countByStatus) {
var tmp = $translate.instant('CURR_LEECHING_TORRENTS', {count_leech: vm.countByStatus.leecher || 0});
return marked(tmp, {sanitize: false});
}
};
/**
* getMarkedCurrSeedingString
* @returns {*}
*/
vm.getMarkedCurrSeedingString = function () {
if (vm.countByStatus) {
var tmp = $translate.instant('CURR_SEEDING_TORRENTS', {count_seed: vm.countByStatus.seeder || 0});
return marked(tmp, {sanitize: false});
}
};
/**
* getMarkedVipStatusString
* @returns {*}
*/
vm.getMarkedVipStatusString = function () {
var tmp = $translate.instant('CURR_VIP_STATE', {vip_status: vm.user.isVip ? 'VALUE_TRUE' : 'VALUE_FALSE'});
return marked(tmp, {sanitize: false});
};
/**
* getMarkedCurrUpSpeedString
* @returns {*}
*/
vm.getMarkedCurrUpSpeedString = function () {
var tmp = $translate.instant('CURR_UP_TOTAL_SPEED', {up_speed: vm.sumCUSpeed});
return marked(tmp, {sanitize: false});
};
/**
* getMarkedCurrDownSpeedString
* @returns {*}
*/
vm.getMarkedCurrDownSpeedString = function () {
var tmp = $translate.instant('CURR_DOWN_TOTAL_SPEED', {down_speed: vm.sumCDSpeed});
return marked(tmp, {sanitize: false});
};
/**
* getMarkedCurrScoreString
* @returns {*}
*/
vm.getMarkedCurrScoreString = function () {
var timedScore = getTimedScore();
var speedScore = getSpeedScore();
var seedScoreTotal = timedScore + speedScore;
seedScoreTotal = Math.round(seedScoreTotal * 100) / 100;
var tmp = $translate.instant('CURR_SCORE_INCOME_HOURS', {score_hour: seedScoreTotal});
return marked(tmp, {sanitize: false});
};
/**
* getTimedScore
* @returns {number}
*/
function getTimedScore() {
var timedScore = 0;
var action = vm.scoreConfig.action.seedTimed;
var slAction = vm.scoreConfig.action.seedSeederAndLife;
if (action.enable && vm.groupByStatus) {
angular.forEach(vm.groupByStatus.seeder, function (seed) {
if (seed.torrent.torrent_status === 'reviewed') {
var seedUnit = (60 * 60 * 1000) / action.additionTime;
var seedScore = seedUnit * action.timedValue;
if (seedScore > 0) {
//vip addition
if (action.vipRatio && vm.user.isVip) {
seedScore = seedScore * action.vipRatio;
}
if (slAction.enable) {
//torrent seeders count addition
if (seed.torrent.torrent_seeds <= slAction.seederCount) {
var seederUnit = slAction.seederBasicRatio + slAction.seederCoefficient * (slAction.seederCount - seed.torrent.torrent_seeds + 1);
seedScore = seedScore * seederUnit;
}
//torrent life addition
var life = moment(Date.now()) - moment(seed.torrent.createdat);
var days = life / (60 * 60 * 1000 * 24);
var lifeUnit = slAction.lifeBasicRatio + slAction.lifeCoefficientOfDay * days;
lifeUnit = lifeUnit > slAction.lifeMaxRatio ? slAction.lifeMaxRatio : lifeUnit;
seedScore = seedScore * lifeUnit;
}
}
timedScore = timedScore + seedScore;
}
});
}
return timedScore;
}
/**
* getSpeedScore
* @returns {number}
*/
function getSpeedScore() {
var totalScore = 0;
var action = vm.scoreConfig.action.seedUpDownload;
var slAction = vm.scoreConfig.action.seedSeederAndLife;
if (action.enable && vm.myPeers) {
angular.forEach(vm.myPeers, function (peer) {
var udScore = 0;
var upUnitScore = 1;
var downUnitScore = 1;
var seederUnit = 1;
var lifeUnit = 1;
var usize = peer.peer_cuspeed * 60 * 60;
var dsize = peer.peer_cdspeed * 60 * 60;
var uploadScore = 0;
var downloadScore = 0;
if (usize > 0 && action.uploadEnable) {
if (peer.torrent.torrent_size > action.additionSize) {
upUnitScore = Math.sqrt(peer.torrent.torrent_size / action.additionSize);
}
var upScore = usize / action.perlSize;
uploadScore = upUnitScore * action.uploadValue * upScore;
//uploader addition
if (vm.user._id == peer.torrent.user) {
uploadScore = uploadScore * action.uploaderRatio;
}
}
if (dsize > 0 && action.downloadEnable) {
if (peer.torrent.torrent_size > action.additionSize) {
downUnitScore = Math.sqrt(peer.torrent.torrent_size / action.additionSize);
}
var downScore = dsize / action.perlSize;
downloadScore = downUnitScore * action.downloadValue * downScore;
}
udScore = uploadScore + downloadScore;
if (udScore > 0) {
//vip addition
if (action.vipRatio && vm.user.isVip) {
udScore = udScore * action.vipRatio;
}
if (slAction.enable) {
//torrent seeders count addition
if (peer.torrent.torrent_seeds <= slAction.seederCount) {
seederUnit = slAction.seederBasicRatio + slAction.seederCoefficient * (slAction.seederCount - peer.torrent.torrent_seeds + 1);
udScore = udScore * seederUnit;
}
//torrent life addition
var life = moment(Date.now()) - moment(peer.torrent.createdat);
var days = life / (60 * 60 * 1000 * 24);
lifeUnit = slAction.lifeBasicRatio + slAction.lifeCoefficientOfDay * days;
lifeUnit = lifeUnit > slAction.lifeMaxRatio ? slAction.lifeMaxRatio : lifeUnit;
udScore = udScore * lifeUnit;
}
}
totalScore = totalScore + udScore;
});
}
return totalScore;
}
}
}());

View File

@@ -44,4 +44,17 @@
height: 150px;
line-height: 0.8;
overflow-y: scroll;
}
}
.curr-score-info {
p {
margin-bottom: 0;
}
h5 {
line-height: 1.5;
margin: 0;
}
li {
line-height: 1.8;
}
}

View File

@@ -1,6 +1,6 @@
1. 用戶積分級別數學計算公式為: `sqrt(score number / %(scoreConfig.levelStep)s)`.
1. 級別`1` 需要積分累計: `1 * 1 * %(scoreConfig.levelStep)s`.
1. 級別`2` 需要積分累計: `2 * 2 * %(scoreConfig.levelStep)s`.
1. 級別`3` 需要積分累計: `3 * 3 * %(scoreConfig.levelStep)s`.
1. 級別`4` 需要積分累計: `4 * 4 * %(scoreConfig.levelStep)s`.
1. 級別`x` 需要積分累計: `x * x * %(scoreConfig.levelStep)s`.
1. 用戶積分級別數學計算公式為: `sqrt(score number / %(scoreConfig.levelStep)s)`
1. 級別`1` 需要積分累計: `1 * 1 * %(scoreConfig.levelStep)s`
1. 級別`2` 需要積分累計: `2 * 2 * %(scoreConfig.levelStep)s`
1. 級別`3` 需要積分累計: `3 * 3 * %(scoreConfig.levelStep)s`
1. 級別`4` 需要積分累計: `4 * 4 * %(scoreConfig.levelStep)s`
1. 級別`x` 需要積分累計: `x * x * %(scoreConfig.levelStep)s`

View File

@@ -1,6 +1,6 @@
1. 用户积分级别数学计算公式为: `sqrt(score number / %(scoreConfig.levelStep)s)`.
1. 级别`1` 需要积分累计: `1 * 1 * %(scoreConfig.levelStep)s`.
1. 级别`2` 需要积分累计: `2 * 2 * %(scoreConfig.levelStep)s`.
1. 级别`3` 需要积分累计: `3 * 3 * %(scoreConfig.levelStep)s`.
1. 级别`4` 需要积分累计: `4 * 4 * %(scoreConfig.levelStep)s`.
1. 级别`x` 需要积分累计: `x * x * %(scoreConfig.levelStep)s`.
1. 用户积分级别数学计算公式为: `sqrt(score number / %(scoreConfig.levelStep)s)`
1. 级别`1` 需要积分累计: `1 * 1 * %(scoreConfig.levelStep)s`
1. 级别`2` 需要积分累计: `2 * 2 * %(scoreConfig.levelStep)s`
1. 级别`3` 需要积分累计: `3 * 3 * %(scoreConfig.levelStep)s`
1. 级别`4` 需要积分累计: `4 * 4 * %(scoreConfig.levelStep)s`
1. 级别`x` 需要积分累计: `x * x * %(scoreConfig.levelStep)s`

View File

@@ -1,5 +1,5 @@
1. 系統提供多種獲取積分的方式, 像每日簽到, 社群活動, 系統任務等.
1. 儘可能多的下載和上傳量.
1. 上傳種子檔案並長時間的為其它用戶做種.
1. 在論壇積極回答用戶的問題.
1. 系統提供多種獲取積分的方式, 像每日簽到, 社群活動, 系統任務等
1. 儘可能多的下載和上傳量
1. 上傳種子檔案並長時間的為其它用戶做種
1. 在論壇積極回答用戶的問題
1. 其它更多...

View File

@@ -1,5 +1,5 @@
1. 系统提供多种获取积分的方式, 像每日签到, 社区活动, 系统任务等.
1. 尽可能多的下载和上传量.
1. 上传种子文件并长时间的其它用户做种.
1. 在论坛积极回答用户的问题.
1. 系统提供多种获取积分的方式, 像每日签到, 社区活动, 系统任务等
1. 尽可能多的下载和上传量
1. 上传种子文件并长时间的其它用户做种
1. 在论坛积极回答用户的问题
1. 其它更多...

View File

@@ -6,7 +6,7 @@
</div>
<div class="row margin-top-30">
<div class="col-sm-8 col-sm-offset-2">
<div class="col-md-8 col-md-offset-2">
<div>
<span>{{ vm.scoreLevelData.currLevelValue | number: 2 }}</span>
<span class="pull-right">{{ vm.scoreLevelData.nextLevelValue | number: 2 }}</span>
@@ -24,8 +24,8 @@
</div>
<div class="row margin-top-30" ng-show="vm.inviteConfig.openInvite">
<div class="col-sm-8 col-sm-offset-2 text-center">
<button class="btn btn-default" ng-disabled="vm.user.score < vm.inviteConfig.scoreExchange"
<div class="col-md-8 col-md-offset-2 text-center">
<button class="btn btn-success" ng-disabled="vm.user.score < vm.inviteConfig.scoreExchange"
translate="EXCHANGE_INVITATION" translate-values='{ score: vm.inviteConfig.scoreExchange}'
ng-click="vm.exchangeInvitation();">
</button>
@@ -33,25 +33,41 @@
</div>
<div class="row margin-top-30" ng-hide="vm.inviteConfig.openInvite">
<div class="col-sm-8 col-sm-offset-2 text-center">
<div class="col-md-8 col-md-offset-2 text-center">
<div class="alert alert-warning" role="alert">
<strong>{{ 'NOTE_CAPTION' | translate }}</strong> {{ 'INVITE_CLOSED' | translate }}
</div>
</div>
</div>
<div class="row margin-top-30 padding-top-30"
<div class="row margin-top-30" ng-init="vm.getMyPeers()">
<div class="col-md-8 col-md-offset-2 curr-score-info">
<legend class="small-legend"><i class="fa fa-caret-right"></i> {{'SCORE.INCOME_ESTIMATE' | translate}}</legend>
<ul>
<li ng-bind-html="vm.getMarkedCurrDownloadingString()"></li>
<li ng-bind-html="vm.getMarkedCurrSeedingString()"></li>
<li ng-bind-html="vm.getMarkedVipStatusString()"></li>
<li ng-bind-html="vm.getMarkedCurrUpSpeedString()"></li>
<li ng-bind-html="vm.getMarkedCurrDownSpeedString()"></li>
</ul>
<div class="alert alert-warning">
<h5 ng-bind-html="vm.getMarkedCurrScoreString()"></h5>
</div>
</div>
</div>
<div class="row margin-top-30"
ng-init="vm.getTemplateScoreFileContent('/modules/users/client/templates/how-level-'+vm.lang+'.md')">
<div class="col-sm-8 col-sm-offset-2">
<legend class="small-legend" translate="SCORE.HOW_TO_GET_LEVEL"></legend>
<div class="col-md-8 col-md-offset-2 curr-score-info">
<legend class="small-legend"><i class="fa fa-caret-right"></i> {{'SCORE.HOW_TO_GET_LEVEL' | translate}}</legend>
<span ng-bind-html="vm.getTemplateMarkedContent(vm.templateScoreFileContent)"></span>
</div>
</div>
<div class="row margin-top-30 margin-bottom-30"
ng-init="vm.getTemplateLevelFileContent('/modules/users/client/templates/how-score-'+vm.lang+'.md')">
<div class="col-sm-8 col-sm-offset-2">
<legend class="small-legend" translate="SCORE.HOW_TO_GET_SCORE"></legend>
<div class="col-md-8 col-md-offset-2 curr-score-info">
<legend class="small-legend"><i class="fa fa-caret-right"></i> {{'SCORE.HOW_TO_GET_SCORE' | translate}}</legend>
<span ng-bind-html="vm.getTemplateMarkedContent(vm.templateLevelFileContent)"></span>
</div>
</div>