Bucket counting of bugs per week instead of per day
This commit is contained in:
Родитель
64ac2a0be8
Коммит
1c5e70dc89
|
@ -27,6 +27,7 @@
|
|||
"@material-ui/icons": "^3.0.1",
|
||||
"@mozilla-frontend-infra/components": "^2.0.0",
|
||||
"chart.js": "^2.7.3",
|
||||
"moment": "^2.23.0",
|
||||
"prop-types": "^15",
|
||||
"query-string": "^6.2.0",
|
||||
"react": "^16",
|
||||
|
|
|
@ -1,26 +1,22 @@
|
|||
import queryBugzilla from './queryBugzilla';
|
||||
import generateDatasetStyle from '../chartJs/generateDatasetStyle';
|
||||
import toDayOfWeek from '../toDayOfWeek';
|
||||
import COLORS from '../chartJs/colors';
|
||||
|
||||
const newDate = (datetime, startDate) => {
|
||||
const onlyDate = datetime.substring(0, 10);
|
||||
return startDate && (onlyDate < startDate) ? startDate : onlyDate;
|
||||
};
|
||||
|
||||
/* eslint-disable camelcase */
|
||||
// Count bugs created on each day
|
||||
// Count bugs created/closed each week
|
||||
// startDate allow us to group bugs older than such date
|
||||
const bugsPerDay = (bugs, startDate) => (
|
||||
const bugsGroupedByWeek = (bugs, startDate) => (
|
||||
bugs.reduce((result, { creation_time, cf_last_resolved }) => {
|
||||
const newResult = Object.assign({}, result);
|
||||
const createdDate = newDate(creation_time, startDate);
|
||||
const createdDate = toDayOfWeek(creation_time, startDate);
|
||||
if (!newResult[createdDate]) {
|
||||
newResult[createdDate] = 0;
|
||||
}
|
||||
newResult[createdDate] += 1;
|
||||
|
||||
if (cf_last_resolved) {
|
||||
const resolvedDate = newDate(cf_last_resolved, startDate);
|
||||
const resolvedDate = toDayOfWeek(cf_last_resolved, startDate);
|
||||
if (!newResult[resolvedDate]) {
|
||||
newResult[resolvedDate] = 0;
|
||||
}
|
||||
|
@ -32,14 +28,16 @@ const bugsPerDay = (bugs, startDate) => (
|
|||
);
|
||||
/* eslint-enable camelcase */
|
||||
|
||||
const sortDates = (a, b) => new Date(a) - new Date(b);
|
||||
|
||||
const bugsByCreationDate = (bugs, startDate) => {
|
||||
// Count bugs created on each day
|
||||
const byCreationDate = bugsPerDay(bugs, startDate);
|
||||
// Count bugs created on each week
|
||||
const byCreationDate = bugsGroupedByWeek(bugs, startDate);
|
||||
|
||||
let count = 0;
|
||||
let lastDataPoint;
|
||||
const accumulatedCount = Object.keys(byCreationDate)
|
||||
.sort().reduce((result, date) => {
|
||||
.sort(sortDates).reduce((result, date) => {
|
||||
count += byCreationDate[date];
|
||||
// Read more here http://momentjs.com/guides/#/warnings/js-date/
|
||||
lastDataPoint = { x: new Date(date), y: count };
|
||||
|
@ -48,9 +46,9 @@ const bugsByCreationDate = (bugs, startDate) => {
|
|||
}, []);
|
||||
|
||||
// This guarantees that the line goes all the way to the end of the graph
|
||||
const today = new Date();
|
||||
const today = toDayOfWeek();
|
||||
if (lastDataPoint.x !== today) {
|
||||
accumulatedCount.push({ x: today, y: count });
|
||||
accumulatedCount.push({ x: new Date(today), y: count });
|
||||
}
|
||||
|
||||
return accumulatedCount;
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
import moment from 'moment';
|
||||
|
||||
// By default it changes the day to Friday
|
||||
// We're interested to know the state of bucket by the end of the week
|
||||
const toDayOfWeek = (dt = new Date(), dayOfWeek = 5) => {
|
||||
let increment = 0;
|
||||
// isoWeekDay represents Sunday as 7 instead of 0
|
||||
const day = moment(dt).isoWeekday();
|
||||
if (day > dayOfWeek) {
|
||||
increment = 7;
|
||||
}
|
||||
return moment(dt).add(increment, 'days').isoWeekday(dayOfWeek).format('YYYY-MM-DD');
|
||||
};
|
||||
|
||||
export default toDayOfWeek;
|
|
@ -0,0 +1,29 @@
|
|||
import toDayOfWeek from '../../src/utils/toDayOfWeek';
|
||||
|
||||
it('Monday to Friday', () => {
|
||||
const newDate = toDayOfWeek('2018-12-31');
|
||||
expect(newDate).toBe('2019-01-04');
|
||||
});
|
||||
|
||||
it('Friday to Friday', () => {
|
||||
const newDate = toDayOfWeek('2019-01-04');
|
||||
expect(newDate).toBe('2019-01-04');
|
||||
});
|
||||
|
||||
it('Saturday to next week Friday', () => {
|
||||
const newDate = toDayOfWeek('2018-12-29');
|
||||
expect(newDate).toBe('2019-01-04');
|
||||
});
|
||||
|
||||
it('Sunday to Friday', () => {
|
||||
const newDate = toDayOfWeek('2018-12-30');
|
||||
expect(newDate).toBe('2019-01-04');
|
||||
});
|
||||
|
||||
it('Current - To Friday of current week', () => {
|
||||
const newDate = toDayOfWeek();
|
||||
const myTempDate = new Date();
|
||||
const distance = 5 - myTempDate.getDay(); // 5 represents Friday
|
||||
myTempDate.setDate(myTempDate.getDate() + distance);
|
||||
expect(newDate).toBe((myTempDate).toISOString().split('T')[0]);
|
||||
});
|
|
@ -5982,7 +5982,7 @@ mkdirp@0.5.1, mkdirp@0.5.x, mkdirp@^0.5.0, mkdirp@^0.5.1, mkdirp@~0.5.0:
|
|||
dependencies:
|
||||
minimist "0.0.8"
|
||||
|
||||
moment@^2.10.2:
|
||||
moment@^2.10.2, moment@^2.23.0:
|
||||
version "2.23.0"
|
||||
resolved "https://registry.yarnpkg.com/moment/-/moment-2.23.0.tgz#759ea491ac97d54bac5ad776996e2a58cc1bc225"
|
||||
integrity sha512-3IE39bHVqFbWWaPOMHZF98Q9c3LDKGTmypMiTM2QygGXXElkFWIH7GxfmlwmY2vwa+wmNsoYZmG2iusf1ZjJoA==
|
||||
|
|
Загрузка…
Ссылка в новой задаче