it('gets no data', () => {
const chart = { dataset: [{}], options: {} };
component.preparePgStatus(chart, {
- pg_info: { pgs_per_osd: 0 }
+ pg_info: {}
});
expect(chart).toEqual(expectedChart([undefined, undefined, undefined, undefined]));
});
const chart = { dataset: [{}], options: {} };
component.preparePgStatus(chart, {
pg_info: {
- pgs_per_osd: 10,
statuses: {
'clean+active+scrubbing+nonMappedState': 4,
'clean+active+scrubbing': 2,
preparePgStatus(chart, data) {
const categoryPgAmount = {};
+ let totalPgs = 0;
_.forEach(data.pg_info.statuses, (pgAmount, pgStatesText) => {
const categoryType = this.pgCategoryService.getTypeByStates(pgStatesText);
categoryPgAmount[categoryType] = 0;
}
categoryPgAmount[categoryType] += pgAmount;
+ totalPgs += pgAmount;
});
chart.dataset[0].data = this.pgCategoryService
.map((categoryType) => categoryPgAmount[categoryType]);
chart.labels = [
- `${this.i18n('Clean')} (${this.calcPercentage(
- categoryPgAmount['clean'],
- data.pg_info.pgs_per_osd
- )}%)`,
- `${this.i18n('Working')} (${this.calcPercentage(
- categoryPgAmount['working'],
- data.pg_info.pgs_per_osd
- )}%)`,
- `${this.i18n('Warning')} (${this.calcPercentage(
- categoryPgAmount['warning'],
- data.pg_info.pgs_per_osd
- )}%)`,
- `${this.i18n('Unknown')} (${this.calcPercentage(
- categoryPgAmount['unknown'],
- data.pg_info.pgs_per_osd
- )}%)`
+ `${this.i18n('Clean')} (${this.calcPercentage(categoryPgAmount['clean'], totalPgs)}%)`,
+ `${this.i18n('Working')} (${this.calcPercentage(categoryPgAmount['working'], totalPgs)}%)`,
+ `${this.i18n('Warning')} (${this.calcPercentage(categoryPgAmount['warning'], totalPgs)}%)`,
+ `${this.i18n('Unknown')} (${this.calcPercentage(categoryPgAmount['unknown'], totalPgs)}%)`
];
}