Skip to content

Commit

Permalink
implement extrapolation
Browse files Browse the repository at this point in the history
  • Loading branch information
wwsalmon committed Feb 12, 2023
1 parent 68c5624 commit 3a9daec
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 12 deletions.
10 changes: 0 additions & 10 deletions models/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,6 @@ const VaxEventSchema = new mongoose.Schema<IVaxEvent>({
userId: mongoose.Schema.Types.ObjectId,
}, {timestamps: true});

const VaxSchema = new mongoose.Schema<IVax>({
brand: {type: String, required: true},
product: {type: String, required: true},
}, {timestamps: true});

export const UserModel = mongoose.models.user || mongoose.model("user", UserSchema);
export const VaxEventModel = mongoose.models.vaxEvent || mongoose.model("vaxEvent", VaxEventSchema);

Expand All @@ -30,9 +25,4 @@ export interface IVaxEvent {
date: string,
vaxId: string,
userId: string,
}

export interface IVax {
brand: string,
product: string,
}
27 changes: 25 additions & 2 deletions pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,34 @@ function addImmunity(svg: d3.Selection<SVGSVGElement | null, unknown, null, unde
}[type];

const immunitySeries = vaxEvents.sort((a, b) => +new Date(a.date) - +new Date(b.date)).map((d, i, a) => {
const numDays = differenceInDays(a[i + 1] ? dateOnly(a[i+1].date) : addDays(new Date(), 365), dateOnly(d.date));
const thisData = primary.filter(x => x.vaccine === d.vaxId && x.outcome_category === type).filter(x => x.days < numDays).map(x => ({
const endDate = a[i + 1] ? dateOnly(a[i+1].date) : addDays(new Date(), 365);
const numDays = differenceInDays(endDate, dateOnly(d.date));
const thisSeriesData = primary.filter(x => x.vaccine === d.vaxId && x.outcome_category === type);
let thisData = thisSeriesData.filter(x => x.days < numDays).map(x => ({
...x,
date: addDays(dateOnly(d.date), x.days),
}));
if (thisData.length < thisSeriesData.length) {
const lastPoint = thisData[thisData.length - 1];
const nextPoint = thisSeriesData[thisData.length];
const diffDays = nextPoint.days - lastPoint.days;
const extraDays = numDays - lastPoint.days;

let extraPoint = {
date: endDate,
VE: 0,
UCL: 0,
LCL: 0,
}

for (let property of ["VE", "UCL", "LCL"]) {
const change = nextPoint[property] - lastPoint[property];
const rate = change / diffDays;
extraPoint[property] = lastPoint[property] + rate * extraDays;
}

thisData.push(extraPoint);
}
return thisData;
});

Expand Down

0 comments on commit 3a9daec

Please sign in to comment.