Skip to content

Commit

Permalink
maybe this will work
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexHalbesleben committed Sep 17, 2022
1 parent 609582a commit b3dab0e
Showing 1 changed file with 13 additions and 31 deletions.
44 changes: 13 additions & 31 deletions src/store/index.vuex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,16 +55,21 @@ export class Store extends VuexModule {
* Splits the tasks into chunks
*/
@mutation updateChunks() {
const startTime = performance.now();

// Each day is referenced by a number (the number of days after the current day) and has a list of chunks
const chunksByDay: Record<number, Chunk[]> = {};

const getTotalTime = (day: Chunk[]) => {
return day.reduce((prev, curr) => prev + curr.duration, 0);
const getTotalTime = (day: number) => {
if (!chunksByDay[day]) {
chunksByDay[day] = [];
}
return chunksByDay[day].reduce((prev, curr) => prev + curr.duration, 0);
};
const getTotalEffort = (day: number) => {
if (!chunksByDay[day]) {
chunksByDay[day] = [];
}
return chunksByDay[day].reduce((prev, curr) => prev + curr.effort, 0);
};
const getTotalEffort = (day: Chunk[]) =>
day.reduce((prev, curr) => prev + curr.effort, 0);

for (const task of this.tasks) {
for (const lockedChunk of task.lockedChunks) {
Expand All @@ -83,14 +88,6 @@ export class Store extends VuexModule {
}
}

const intermediateTime1 = performance.now();
console.log(
`After dealing with locked chunks: ${intermediateTime1 - startTime}`
);

const intermediateTime2 = performance.now();
console.log(`After sorting tasks: ${intermediateTime2 - startTime}ms`);

const lastTask = this.tasks[this.tasks.length - 1];
const totalDays = DateUtils.daysBetween(
DateUtils.currentDate,
Expand All @@ -103,11 +100,6 @@ export class Store extends VuexModule {
}
}

const intermediateTime3 = performance.now();
console.log(
`After creating empty days: ${intermediateTime3 - startTime}ms`
);

const eventTimes: Record<number, number> = {};
for (let i = 0; i <= totalDays; i++) {
eventTimes[i] = 0;
Expand Down Expand Up @@ -239,21 +231,9 @@ export class Store extends VuexModule {
)
);
}

const intermediateTime4 = performance.now();
console.log(
`After assigning task ${i}: ${intermediateTime4 - startTime}ms`
);
}

const intermediateTime5 = performance.now();
console.log(`After assigning chunks: ${intermediateTime5 - startTime}ms`);

// Get the values of the chunksByDay object (a nested array of Chunks) and flatten
this.chunks = (Object.values(chunksByDay) as Chunk[][]).flat(1);

const endTime = performance.now();
console.log(`Chunking took ${endTime - startTime}ms`);
}

@action async uploadTasks() {
Expand Down Expand Up @@ -348,6 +328,8 @@ export class Store extends VuexModule {
alert(`message: ${e.message}`);
alert(`stack:\n ${e.stack}`);
alert(`cause: ${e.cause}`);

this.tasks.sort((a, b) => a.due.getTime() - b.due.getTime());
}
}
}
Expand Down

0 comments on commit b3dab0e

Please sign in to comment.