Skip to content

Commit

Permalink
refactor(app): report robotType in select events (#17153)
Browse files Browse the repository at this point in the history
Closes EXEC-629 and RQA-2386
  • Loading branch information
mjhuff authored Dec 19, 2024
1 parent 78e4c5c commit ad0b586
Show file tree
Hide file tree
Showing 10 changed files with 59 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
LegacyStyledText,
TYPOGRAPHY,
} from '@opentrons/components'
import { FLEX_ROBOT_TYPE, OT2_ROBOT_TYPE } from '@opentrons/shared-data'

import { Slideout } from '/app/atoms/Slideout'
import { Divider } from '/app/atoms/structure'
Expand Down Expand Up @@ -107,7 +108,9 @@ export function DeviceResetSlideout({
e.preventDefault()
doTrackEvent({
name: ANALYTICS_CALIBRATION_DATA_DOWNLOADED,
properties: {},
properties: {
robotType: isFlex ? FLEX_ROBOT_TYPE : OT2_ROBOT_TYPE,
},
})
saveAs(
new Blob([
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { useSelector, useDispatch } from 'react-redux'
import { useNavigate } from 'react-router-dom'
import { useForm, Controller } from 'react-hook-form'
import { useTranslation } from 'react-i18next'

import {
COLORS,
Banner,
Expand All @@ -14,6 +15,8 @@ import {
SPACING,
} from '@opentrons/components'
import { useUpdateRobotNameMutation } from '@opentrons/react-api-client'
import { FLEX_ROBOT_TYPE, OT2_ROBOT_TYPE } from '@opentrons/shared-data'

import {
removeRobot,
getConnectableRobots,
Expand Down Expand Up @@ -152,6 +155,7 @@ export function RenameRobotSlideout({
properties: {
previousRobotName,
newRobotName: newRobotName,
robotType: isFlex ? FLEX_ROBOT_TYPE : OT2_ROBOT_TYPE,
},
})
handleSubmit(onSubmit)()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ import { MemoryRouter } from 'react-router-dom'
import { fireEvent, screen, waitFor } from '@testing-library/react'
import { describe, it, vi, expect, beforeEach } from 'vitest'
import '@testing-library/jest-dom/vitest'

import { OT2_ROBOT_TYPE } from '@opentrons/shared-data'

import { renderWithProviders } from '/app/__testing-utils__'
import { i18n } from '/app/i18n'
import { useTrackEvent, ANALYTICS_RENAME_ROBOT } from '/app/redux/analytics'
Expand All @@ -14,7 +17,6 @@ import {
mockConnectableRobot,
mockReachableRobot,
} from '/app/redux/discovery/__fixtures__'

import { RenameRobotSlideout } from '../RenameRobotSlideout'
import { useIsFlex } from '/app/redux-resources/robots'

Expand Down Expand Up @@ -111,7 +113,11 @@ describe('RobotSettings RenameRobotSlideout', () => {
await waitFor(() => {
expect(mockTrackEvent).toHaveBeenCalledWith({
name: ANALYTICS_RENAME_ROBOT,
properties: { newRobotName: 'mockInput', previousRobotName: 'otie' },
properties: {
newRobotName: 'mockInput',
previousRobotName: 'otie',
robotType: OT2_ROBOT_TYPE,
},
})
})
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import {
useInstrumentsQuery,
useModulesQuery,
} from '@opentrons/react-api-client'
import { FLEX_ROBOT_TYPE, OT2_ROBOT_TYPE } from '@opentrons/shared-data'

import { TertiaryButton } from '/app/atoms/buttons'
import {
useDeckCalibrationData,
Expand Down Expand Up @@ -72,7 +74,9 @@ export function CalibrationDataDownload({
e.preventDefault()
doTrackEvent({
name: ANALYTICS_CALIBRATION_DATA_DOWNLOADED,
properties: {},
properties: {
robotType: isFlex ? FLEX_ROBOT_TYPE : OT2_ROBOT_TYPE,
},
})
saveAs(
new Blob([
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
useModulesQuery,
} from '@opentrons/react-api-client'
import { instrumentsResponseFixture } from '@opentrons/api-client'
import { OT2_ROBOT_TYPE } from '@opentrons/shared-data'

import { i18n } from '/app/i18n'
import {
Expand Down Expand Up @@ -145,7 +146,7 @@ describe('CalibrationDataDownload', () => {
fireEvent.click(downloadButton)
expect(mockTrackEvent).toHaveBeenCalledWith({
name: ANALYTICS_CALIBRATION_DATA_DOWNLOADED,
properties: {},
properties: { robotType: OT2_ROBOT_TYPE },
})
})

Expand Down
2 changes: 2 additions & 0 deletions app/src/pages/ODD/NameRobot/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
TYPOGRAPHY,
} from '@opentrons/components'
import { useUpdateRobotNameMutation } from '@opentrons/react-api-client'
import { FLEX_ROBOT_TYPE } from '@opentrons/shared-data'

import {
removeRobot,
Expand Down Expand Up @@ -166,6 +167,7 @@ export function NameRobot(): JSX.Element {
properties: {
previousRobotName: previousName,
newRobotName: newRobotName,
robotType: FLEX_ROBOT_TYPE,
},
})
handleSubmit(onSubmit)()
Expand Down
10 changes: 7 additions & 3 deletions app/src/redux/analytics/__tests__/make-event.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { vi, describe, it, expect, beforeEach } from 'vitest'

import { OT2_ROBOT_TYPE } from '@opentrons/shared-data'

import { makeEvent } from '../make-event'
import * as selectors from '../selectors'

Expand Down Expand Up @@ -49,6 +51,7 @@ describe('analytics events map', () => {
name: 'pipetteOffsetCalibrationStarted',
properties: {
...action.payload,
robotType: OT2_ROBOT_TYPE,
},
})
})
Expand All @@ -65,6 +68,7 @@ describe('analytics events map', () => {
name: 'tipLengthCalibrationStarted',
properties: {
...action.payload,
robotType: OT2_ROBOT_TYPE,
},
})
})
Expand All @@ -77,6 +81,7 @@ describe('analytics events map', () => {
robotName: 'my-robot',
sessionId: 'seshid',
command: { command: 'calibration.exitSession' },
robotType: OT2_ROBOT_TYPE,
},
} as any
vi.mocked(selectors.getAnalyticsSessionExitDetails).mockReturnValue({
Expand All @@ -86,7 +91,7 @@ describe('analytics events map', () => {

return expect(makeEvent(action, state)).resolves.toEqual({
name: 'my-session-typeExit',
properties: { step: 'session-step' },
properties: { step: 'session-step', robotType: OT2_ROBOT_TYPE },
})
})

Expand Down Expand Up @@ -117,12 +122,11 @@ describe('analytics events map', () => {
properties: {
pipetteModel: 'my-pipette-model',
tipRackDisplayName: 'some display name',
robotType: OT2_ROBOT_TYPE,
},
})
})
})

describe('events with calibration data', () => {
it('analytics:RESOURCE_MONITOR_REPORT -> resourceMonitorReport event', () => {
const state = {} as any
const action = {
Expand Down
5 changes: 5 additions & 0 deletions app/src/redux/analytics/make-event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
getAnalyticsSessionExitDetails,
getSessionInstrumentAnalyticsData,
} from './selectors'
import { OT2_ROBOT_TYPE } from '@opentrons/shared-data'

import type { State, Action } from '../types'
import type { AnalyticsEvent } from './types'
Expand Down Expand Up @@ -180,6 +181,7 @@ export function makeEvent(
name: `${sessionDetails.sessionType}Exit`,
properties: {
step: sessionDetails.step,
robotType: OT2_ROBOT_TYPE,
},
}
: null
Expand All @@ -203,6 +205,7 @@ export function makeEvent(
'tiprackDefinition' in commandData
? commandData.tiprackDefinition.metadata.displayName
: null,
robotType: OT2_ROBOT_TYPE,
},
}
: null
Expand Down Expand Up @@ -234,6 +237,7 @@ export function makeEvent(
name: 'pipetteOffsetCalibrationStarted',
properties: {
...action.payload,
robotType: OT2_ROBOT_TYPE,
},
})
}
Expand All @@ -243,6 +247,7 @@ export function makeEvent(
name: 'tipLengthCalibrationStarted',
properties: {
...action.payload,
robotType: OT2_ROBOT_TYPE,
},
})
}
Expand Down
23 changes: 20 additions & 3 deletions app/src/redux/analytics/selectors.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
import * as Sessions from '../sessions'

import { getViewableRobots, getRobotApiVersion } from '../discovery'
import { FLEX_ROBOT_TYPE, OT2_ROBOT_TYPE } from '@opentrons/shared-data'

import { getViewableRobots, getRobotApiVersion } from '../discovery'
import {
getRobotUpdateVersion,
getRobotUpdateRobot,
getRobotUpdateSession,
getRobotSystemType,
} from '../robot-update'

import { getRobotSessionById } from '../sessions/selectors'

import type { State } from '../types'

import type {
AnalyticsConfig,
BuildrootAnalyticsData,
AnalyticsSessionExitDetails,
SessionInstrumentAnalyticsData,
} from './types'
import type { RobotType } from '@opentrons/shared-data'

export function getBuildrootAnalyticsData(
state: State,
Expand All @@ -40,12 +40,29 @@ export function getBuildrootAnalyticsData(
const currentVersion = getRobotApiVersion(robot) ?? 'unknown'
const currentSystem = getRobotSystemType(robot) ?? 'unknown'

const getRobotType = (): RobotType | undefined => {
switch (currentSystem) {
case 'flex':
return FLEX_ROBOT_TYPE
case 'ot2-buildroot':
case 'ot2-balena':
return OT2_ROBOT_TYPE
case 'unknown':
return undefined
default: {
console.error('Unexpected system type: ', currentSystem)
return undefined
}
}
}

return {
currentVersion,
currentSystem,
updateVersion: updateVersion ?? 'unknown',
error: session != null && 'error' in session ? session.error : null,
robotSerialNumber,
robotType: getRobotType(),
}
}

Expand Down
3 changes: 2 additions & 1 deletion app/src/redux/analytics/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { PipetteMount as Mount } from '@opentrons/shared-data'
import type { PipetteMount as Mount, RobotType } from '@opentrons/shared-data'
import type { CalibrationCheckComparisonsPerCalibration } from '../sessions/types'
import type { DeckCalibrationStatus } from '../calibration/types'
import type { Config } from '../config/types'
Expand Down Expand Up @@ -42,6 +42,7 @@ export interface BuildrootAnalyticsData {
updateVersion: string
error: string | null
robotSerialNumber: string | null
robotType: RobotType | undefined
}

export interface PipetteOffsetCalibrationAnalyticsData {
Expand Down

0 comments on commit ad0b586

Please sign in to comment.