Skip to content

Commit

Permalink
Fixing completed count to use group status
Browse files Browse the repository at this point in the history
  • Loading branch information
warrensplayer committed Jan 19, 2023
1 parent 998857c commit c8848e8
Showing 1 changed file with 22 additions and 7 deletions.
29 changes: 22 additions & 7 deletions packages/data-context/src/sources/RelevantRunSpecsDataSource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import debugLib from 'debug'
import { isEqual } from 'lodash'

import type { DataContext } from '../DataContext'
import type { CloudSpecStatus, Query, RelevantRun, CurrentProjectRelevantRunSpecs, CloudSpecRun, CloudRun } from '../gen/graphcache-config.gen'
import type { CloudSpecStatus, Query, RelevantRun, CurrentProjectRelevantRunSpecs, CloudSpecRun, CloudRun, CloudRunGroup, CloudRunGroupStatusEnum } from '../gen/graphcache-config.gen'
import { Poller } from '../polling'
import type { CloudRunStatus } from '@packages/graphql/src/gen/cloud-source-types.gen'

Expand All @@ -20,6 +20,10 @@ const RELEVANT_RUN_SPEC_OPERATION_DOC = gql`
status
groupIds
}
groups {
id
status
}
}
query RelevantRunSpecsDataSource_Specs(
Expand Down Expand Up @@ -86,15 +90,26 @@ export class RelevantRunSpecsDataSource {
return this.#cached.runSpecs
}

#calculateSpecMetadata (specs: CloudSpecRun[]) {
#calculateSpecMetadata (specs: CloudSpecRun[], groups: CloudRunGroup[]) {
//mimic logic in Cloud to sum up the count of groups per spec to give the total spec counts
const countGroupsForSpec = (specs: CloudSpecRun[]) => {
const countGroupsForSpecs = (specs: CloudSpecRun[]) => {
return specs.map((spec) => spec.groupIds?.length || 0).reduce((acc, curr) => acc += curr, 0)
}

const groupStatusById = groups.reduce<Record<string, CloudRunGroupStatusEnum>>((acc, curr) => {
acc[curr.id] = curr.status

return acc
}, {})

return {
totalSpecs: countGroupsForSpec(specs),
completedSpecs: countGroupsForSpec(specs.filter((spec) => !INCOMPLETE_STATUSES.includes(spec.status || 'UNCLAIMED'))),
totalSpecs: countGroupsForSpecs(specs),
completedSpecs:
specs.flatMap((spec) => spec.groupIds) // pull out the group ids
.filter((groupId): groupId is string => !!groupId) //make sure there are no undefined values
.map((groupId) => groupStatusById[groupId]) //find the status for that group
.filter((status) => !INCOMPLETE_STATUSES.includes(status || 'UNCLAIMED')) //filter to only "complete" statuses
.length, //count them
}
}

Expand Down Expand Up @@ -154,7 +169,7 @@ export class RelevantRunSpecsDataSource {

if (cloudProject.current && cloudProject.current.runNumber && cloudProject.current.status) {
runSpecsToReturn.runSpecs.current = {
...this.#calculateSpecMetadata(cloudProject.current.specs || []),
...this.#calculateSpecMetadata(cloudProject.current.specs || [], cloudProject.current.groups || []),
runNumber: cloudProject.current.runNumber,
}

Expand All @@ -163,7 +178,7 @@ export class RelevantRunSpecsDataSource {

if (cloudProject.next && cloudProject.next.runNumber && cloudProject.next.status) {
runSpecsToReturn.runSpecs.next = {
...this.#calculateSpecMetadata(cloudProject.next.specs || []),
...this.#calculateSpecMetadata(cloudProject.next.specs || [], cloudProject.next.groups || []),
runNumber: cloudProject.next.runNumber,
}

Expand Down

0 comments on commit c8848e8

Please sign in to comment.