bugfix and periods percents
This commit is contained in:
@@ -129,7 +129,7 @@ const deserialize = function(rawData) {
|
|||||||
text: subData2[3],
|
text: subData2[3],
|
||||||
};
|
};
|
||||||
}),
|
}),
|
||||||
newPeriod: NEW_PERIOD,
|
newPeriod: JSON.parse(JSON.stringify(NEW_PERIOD)),
|
||||||
};
|
};
|
||||||
}),
|
}),
|
||||||
};
|
};
|
||||||
@@ -204,7 +204,7 @@ let app = {
|
|||||||
let text = `${date.getFullYear()} (Week ${date.getWeek()})<br>Age: ${row}`;
|
let text = `${date.getFullYear()} (Week ${date.getWeek()})<br>Age: ${row}`;
|
||||||
const views = this.getViews(row, col);
|
const views = this.getViews(row, col);
|
||||||
for (const view in views) {
|
for (const view in views) {
|
||||||
text += `<br>${view}: ${views[view].text}`; //TODO percent
|
text += `<br>${view}: ${views[view].text} (${views[view].percent})`;
|
||||||
}
|
}
|
||||||
this.getEvents(row, col).forEach(event => {
|
this.getEvents(row, col).forEach(event => {
|
||||||
text += `<br>- ${new Date(event.date).formatSimple()}: ${event.text}`;
|
text += `<br>- ${new Date(event.date).formatSimple()}: ${event.text}`;
|
||||||
@@ -252,7 +252,7 @@ let app = {
|
|||||||
this.views.push({
|
this.views.push({
|
||||||
name: 'New View',
|
name: 'New View',
|
||||||
periods: [],
|
periods: [],
|
||||||
newPeriod: NEW_PERIOD,
|
newPeriod: JSON.parse(JSON.stringify(NEW_PERIOD)),
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
deletePeriod(viewIndex, periodIndex) {
|
deletePeriod(viewIndex, periodIndex) {
|
||||||
@@ -271,6 +271,19 @@ let app = {
|
|||||||
this.views = [];
|
this.views = [];
|
||||||
this.$force;
|
this.$force;
|
||||||
},
|
},
|
||||||
|
updateStatistics() {
|
||||||
|
const total = (new Date() - this.birthdate);
|
||||||
|
this.views.forEach(view => {
|
||||||
|
console.log(view);
|
||||||
|
const data = {};
|
||||||
|
view.periods.forEach(period => {
|
||||||
|
data[period.text + period.color] = (data[period.text + period.color] ?? 0) + ((period.endDate ? new Date(period.endDate) : new Date()) - (new Date(period.startDate)));
|
||||||
|
});
|
||||||
|
view.periods.forEach(period => {
|
||||||
|
period.percent = `${(100 * data[period.text + period.color] / total).toFixed(3)}%`;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
},
|
||||||
},
|
},
|
||||||
beforeMount() {
|
beforeMount() {
|
||||||
this.life = Array(90).fill(Array(52));
|
this.life = Array(90).fill(Array(52));
|
||||||
@@ -288,10 +301,14 @@ let app = {
|
|||||||
this.events = data.events;
|
this.events = data.events;
|
||||||
this.views = data.views;
|
this.views = data.views;
|
||||||
}
|
}
|
||||||
|
this.updateStatistics();
|
||||||
},
|
},
|
||||||
mounted() {
|
mounted() {
|
||||||
setTimeout(this.showApp);
|
setTimeout(this.showApp);
|
||||||
},
|
},
|
||||||
|
beforeUpdate() {
|
||||||
|
this.updateStatistics();
|
||||||
|
},
|
||||||
updated() {
|
updated() {
|
||||||
const data = serialize(this.birtdate, this.view, this.events, this.views);
|
const data = serialize(this.birtdate, this.view, this.events, this.views);
|
||||||
const url = new URL(window.location);
|
const url = new URL(window.location);
|
||||||
|
|||||||
Reference in New Issue
Block a user