-
Notifications
You must be signed in to change notification settings - Fork 9
#4215 Add work package factory and process #4304
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| import { Faker } from '@faker-js/faker'; | ||
| import { Prisma, WBS_Element_Status, Work_Package_Stage } from '@prisma/client'; | ||
| import { DateRange } from '../context.js'; | ||
| import { clampDate, daysBetween } from '../dates.js'; | ||
| import { addDaysToDate } from 'shared'; | ||
|
|
||
| const DAYS_PER_WEEK = 7; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Cant we just use the one from dates |
||
|
|
||
| export const generateWorkPackageCount = (faker: Faker): number => | ||
| // Each project gets 0–8 work packages. Average work package count is around 5. | ||
| faker.helpers.weightedArrayElement([ | ||
| { weight: 3, value: 0 }, | ||
| { weight: 5, value: 1 }, | ||
| { weight: 8, value: 2 }, | ||
| { weight: 14, value: 3 }, | ||
| { weight: 18, value: 4 }, | ||
| { weight: 22, value: 5 }, | ||
| { weight: 16, value: 6 }, | ||
| { weight: 9, value: 7 }, | ||
| { weight: 5, value: 8 } | ||
| ]); | ||
|
|
||
| export const generateWorkPackageStage = (faker: Faker): Work_Package_Stage => | ||
| faker.helpers.arrayElement(Object.values(Work_Package_Stage)); | ||
|
|
||
| export const generateWorkPackageTimeline = (faker: Faker, projectTimeline: DateRange, blockerEndDate?: Date): DateRange => { | ||
| const start = | ||
| blockerEndDate && blockerEndDate < projectTimeline.end | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could there be an edge case here when |
||
| ? addDaysToDate(blockerEndDate, 1) | ||
| : addDaysToDate( | ||
| projectTimeline.start, | ||
| faker.number.int({ | ||
| min: 0, | ||
| max: Math.max(0, daysBetween(projectTimeline) - DAYS_PER_WEEK) | ||
| }) | ||
| ); | ||
|
|
||
| // duration saved in WEEKS instead of days | ||
| const maxDuration = Math.max(1, daysBetween({ start, end: projectTimeline.end }) / DAYS_PER_WEEK); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maxDuration can be fractional because it divides days by DAYS_PER_WEEK, but then it is passed to faker.number.int. Could we floor it first so the max is definitely an integer? |
||
| const duration = faker.number.int({ min: 1, max: Math.min(12, maxDuration) }); | ||
|
|
||
| return { start, end: clampDate(addDaysToDate(start, duration * DAYS_PER_WEEK), { start, end: projectTimeline.end }) }; | ||
| }; | ||
|
|
||
| export const workPackageCreateInput = ( | ||
| organizationId: string, | ||
| carNumber: number, | ||
| projectNumber: number, | ||
| workPackageNumber: number, | ||
| projectId: string, | ||
| orderInProject: number, | ||
| name: string, | ||
| startDate: Date, | ||
| duration: number, | ||
| stage: Work_Package_Stage, | ||
| leadId?: string, | ||
| managerId?: string, | ||
| blockedByWbsElementIds: string[] = [] | ||
| ): Prisma.Work_PackageCreateInput => ({ | ||
| orderInProject, | ||
| startDate, | ||
| duration, | ||
| stage, | ||
| project: { connect: { projectId } }, | ||
| ...(blockedByWbsElementIds.length > 0 | ||
| ? { | ||
| blockedBy: { | ||
| connect: blockedByWbsElementIds.map((wbsElementId) => ({ wbsElementId })) | ||
| } | ||
| } | ||
| : {}), | ||
| wbsElement: { | ||
| create: { | ||
| name, | ||
| carNumber, | ||
| projectNumber, | ||
| workPackageNumber, | ||
| status: WBS_Element_Status.ACTIVE, | ||
| organization: { connect: { organizationId } }, | ||
| ...(leadId ? { lead: { connect: { userId: leadId } } } : {}), | ||
| ...(managerId ? { manager: { connect: { userId: managerId } } } : {}) | ||
| } | ||
| } | ||
| }); | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
since ora is imported from backend seed code, should it be declared in the backend workspace package rather than only in the root package.json not sure just a thought