Reduce stats to 30 days max
This commit is contained in:
parent
ac5b72f35d
commit
80ccccb951
|
@ -20,6 +20,11 @@ const ID = {
|
|||
'COMMENT': 3
|
||||
};
|
||||
|
||||
const statsPeriod = {
|
||||
'WEEK': 7,
|
||||
'MONTH': 30
|
||||
};
|
||||
|
||||
class Stats extends React.Component {
|
||||
|
||||
static propTypes = {
|
||||
|
@ -33,14 +38,14 @@ class Stats extends React.Component {
|
|||
return {
|
||||
name: name,
|
||||
values: []
|
||||
}
|
||||
}
|
||||
}),
|
||||
showed: [0],
|
||||
period: 0
|
||||
};
|
||||
|
||||
componentDidMount() {
|
||||
this.retrieve(7);
|
||||
this.retrieve('WEEK');
|
||||
}
|
||||
|
||||
render() {
|
||||
|
@ -58,7 +63,7 @@ class Stats extends React.Component {
|
|||
'stats': true,
|
||||
'stats_staff': this.props.type === 'staff'
|
||||
};
|
||||
|
||||
|
||||
return classNames(classes);
|
||||
}
|
||||
|
||||
|
@ -90,7 +95,7 @@ class Stats extends React.Component {
|
|||
|
||||
getDropDownProps() {
|
||||
return {
|
||||
items: ['LAST_7_DAYS', 'LAST_30_DAYS', 'LAST_90_DAYS', 'LAST_365_DAYS'].map((name) => {
|
||||
items: Object.keys(statsPeriod).map(key => 'LAST_' + statsPeriod[key] + '_DAYS').map((name) => {
|
||||
return {
|
||||
content: i18n(name),
|
||||
icon: ''
|
||||
|
@ -102,9 +107,7 @@ class Stats extends React.Component {
|
|||
}
|
||||
|
||||
onDropDownChange(event) {
|
||||
let val = [7, 30, 90, 365];
|
||||
|
||||
this.retrieve(val[event.index]);
|
||||
this.retrieve(Object.keys(statsPeriod)[event.index]);
|
||||
}
|
||||
|
||||
getStatsChartProps() {
|
||||
|
@ -116,23 +119,7 @@ class Stats extends React.Component {
|
|||
};
|
||||
}
|
||||
|
||||
retrieve(period) {
|
||||
let periodName;
|
||||
|
||||
switch (period) {
|
||||
case 30:
|
||||
periodName = 'MONTH';
|
||||
break;
|
||||
case 90:
|
||||
periodName = 'QUARTER';
|
||||
break;
|
||||
case 365:
|
||||
periodName = 'YEAR';
|
||||
break;
|
||||
default:
|
||||
periodName = 'WEEK';
|
||||
}
|
||||
|
||||
retrieve(periodName) {
|
||||
API.call({
|
||||
path: '/system/get-stats',
|
||||
data: this.getApiCallData(periodName)
|
||||
|
@ -172,7 +159,7 @@ class Stats extends React.Component {
|
|||
|
||||
return showed;
|
||||
}
|
||||
|
||||
|
||||
getStrokes() {
|
||||
return this.props.type === 'general' ? generalStrokes : staffStrokes;
|
||||
}
|
||||
|
@ -196,4 +183,4 @@ class Stats extends React.Component {
|
|||
}
|
||||
}
|
||||
|
||||
export default Stats;
|
||||
export default Stats;
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
<?php
|
||||
use Respect\Validation\Validator as DataValidator;
|
||||
use RedBeanPHP\Facade as RedBean;
|
||||
|
||||
/**
|
||||
* @api {post} /system/get-stats Get stats
|
||||
|
@ -40,7 +41,8 @@ class GetStatsController extends Controller {
|
|||
}
|
||||
|
||||
public function handler() {
|
||||
$this->generationNewStats();
|
||||
$this->generateNewStats();
|
||||
$this->deleteLastStats();
|
||||
|
||||
$staffId = Controller::request('staffId');
|
||||
|
||||
|
@ -56,7 +58,7 @@ class GetStatsController extends Controller {
|
|||
}
|
||||
}
|
||||
|
||||
public function generationNewStats() {
|
||||
public function generateNewStats() {
|
||||
$lastStatDay = Setting::getSetting('last-stat-day');
|
||||
$previousCurrentDate = floor(Date::getPreviousDate() / 10000);
|
||||
$currentDate = floor(Date::getCurrentDate() / 10000);
|
||||
|
@ -109,6 +111,13 @@ class GetStatsController extends Controller {
|
|||
}
|
||||
}
|
||||
|
||||
public function deleteLastStats() {
|
||||
$removeOlderThanDays = 31;
|
||||
$oldDate = floor(Date::getPreviousDate($removeOlderThanDays) / 10000);
|
||||
|
||||
RedBean::exec("DELETE FROM stat WHERE date < $oldDate");
|
||||
}
|
||||
|
||||
public function generateGeneralStat($type, $date) {
|
||||
$value = Log::count('type=? AND date LIKE ?',[$type, $date->format('Ymd') . '%']);
|
||||
$stat = new Stat();
|
||||
|
@ -161,4 +170,4 @@ class GetStatsController extends Controller {
|
|||
|
||||
return $daysToRetrieve;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@ class Date {
|
|||
return date('YmdHi');
|
||||
}
|
||||
|
||||
public static function getPreviousDate() {
|
||||
return date('YmdHi', strtotime(' -1 day '));
|
||||
public static function getPreviousDate($days = 1) {
|
||||
return date('YmdHi', strtotime(" -$days day "));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -85,25 +85,25 @@ describe'/system/get-stats' do
|
|||
|
||||
d = Date.today.prev_day
|
||||
yesterday = d.strftime("%Y%m%d")
|
||||
d = Date.today.prev_day.prev_day
|
||||
d = Date.today.prev_day(2)
|
||||
yesterday2 = d.strftime("%Y%m%d")
|
||||
d = Date.today.prev_day.prev_day.prev_day
|
||||
d = Date.today.prev_day(3)
|
||||
yesterday3 = d.strftime("%Y%m%d")
|
||||
d = Date.today.prev_day.prev_day.prev_day.prev_day
|
||||
d = Date.today.prev_day(4)
|
||||
yesterday4 = d.strftime("%Y%m%d")
|
||||
d = Date.today.prev_day.prev_day.prev_day.prev_day.prev_day
|
||||
d = Date.today.prev_day(5)
|
||||
yesterday5 = d.strftime("%Y%m%d")
|
||||
d = Date.today.prev_day.prev_day.prev_day.prev_day.prev_day.prev_day
|
||||
d = Date.today.prev_day(6)
|
||||
yesterday6 = d.strftime("%Y%m%d")
|
||||
d = Date.today.prev_day.prev_day.prev_day.prev_day.prev_day.prev_day.prev_day
|
||||
d = Date.today.prev_day(7)
|
||||
yesterday7 = d.strftime("%Y%m%d")
|
||||
d = Date.today.prev_day.prev_day.prev_day.prev_day.prev_day.prev_day.prev_day.prev_day
|
||||
d = Date.today.prev_day(8)
|
||||
yesterday8 = d.strftime("%Y%m%d")
|
||||
d = Date.today.prev_day.prev_day.prev_day.prev_day.prev_day.prev_day.prev_day.prev_day.prev_day
|
||||
d = Date.today.prev_day(9)
|
||||
yesterday9 = d.strftime("%Y%m%d")
|
||||
d = Date.today.prev_day.prev_day.prev_day.prev_day.prev_day.prev_day.prev_day.prev_day.prev_day.prev_day
|
||||
d = Date.today.prev_day(10)
|
||||
yesterday10 = d.strftime("%Y%m%d")
|
||||
d = Date.today.prev_day.prev_day.prev_day.prev_day.prev_day.prev_day.prev_day.prev_day.prev_day.prev_day.prev_day
|
||||
d = Date.today.prev_day(11)
|
||||
yesterday11 = d.strftime("%Y%m%d")
|
||||
|
||||
assertData(11, yesterday3, 'CREATE_TICKET', '1')
|
||||
|
@ -157,4 +157,26 @@ describe'/system/get-stats' do
|
|||
assertData(20, yesterday11, 'CLOSE', '0')
|
||||
assertData(21, yesterday11, 'ASSIGN', '0')
|
||||
end
|
||||
|
||||
it 'should remove very old stats' do
|
||||
prev_days_to_remove = 32;
|
||||
|
||||
stats_count = $database.query('SELECT COUNT(*) as qt FROM stat').fetch_hash['qt'];
|
||||
date = Date.today.prev_day(prev_days_to_remove).strftime("%Y%m%d");
|
||||
|
||||
$database.query('INSERT INTO stat VALUES(\'\', '+ date +', \'CLOSE\', 1, 0, NULL)');
|
||||
$database.query('INSERT INTO stat VALUES(\'\', '+ date +', \'SINGUP\', 1, 0, NULL)');
|
||||
$database.query('INSERT INTO stat VALUES(\'\', '+ date +', \'COMMENT\', 1, 0, NULL)');
|
||||
stats_count_updated = $database.query('SELECT COUNT(*) as qt FROM stat').fetch_hash['qt'];
|
||||
(stats_count).should.not.equal(stats_count_updated)
|
||||
|
||||
request('/system/get-stats', {
|
||||
csrf_userid: $csrf_userid,
|
||||
csrf_token: $csrf_token,
|
||||
period: 'MONTH',
|
||||
staffId: '1'
|
||||
})
|
||||
stats_count_updated = $database.query('SELECT COUNT(*) as qt FROM stat').fetch_hash['qt'];
|
||||
(stats_count).should.equal(stats_count_updated)
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue