Skip to content
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

feat(app): collect pipette and module load analytics from protocol runs #5675

Merged
merged 1 commit into from
May 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 62 additions & 0 deletions app/src/analytics/__tests__/selectors.test.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
// @flow

import * as Protocol from '../../protocol'
import * as RobotSelectors from '../../robot/selectors'
import * as Hash from '../hash'

import { getProtocolAnalyticsData } from '../selectors'

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

jest.mock('../../protocol/selectors')
jest.mock('../../robot/selectors')
jest.mock('../hash')

describe('analytics selectors', () => {
Expand Down Expand Up @@ -59,6 +61,16 @@ describe('analytics selectors', () => {
$Call<typeof Protocol.getProtocolContents, State>
> = Protocol.getProtocolContents

const getModules: JestMockFn<
[State],
$Call<typeof RobotSelectors.getModules, State>
> = RobotSelectors.getModules

const getPipettes: JestMockFn<
[State],
$Call<typeof RobotSelectors.getPipettes, State>
> = RobotSelectors.getPipettes

beforeEach(() => {
hash.mockImplementation(source => Promise.resolve(`hash:${source}`))
getProtocolType.mockReturnValue(null)
Expand All @@ -68,6 +80,8 @@ describe('analytics selectors', () => {
getProtocolSource.mockReturnValue(null)
getProtocolAuthor.mockReturnValue(null)
getProtocolContents.mockReturnValue(null)
getModules.mockReturnValue([])
getPipettes.mockReturnValue([])
})

it('should have information about the protocol', () => {
Expand All @@ -82,6 +96,8 @@ describe('analytics selectors', () => {
protocolSource: '',
protocolAuthor: '',
protocolText: '',
pipettes: '',
modules: '',
})
})

Expand Down Expand Up @@ -124,5 +140,51 @@ describe('analytics selectors', () => {
})
})
})

it('should collect pipette requestedAs (or actual) names', () => {
getPipettes.mockReturnValue([
{
_id: 0,
mount: 'left',
channels: 8,
name: 'p300_single_v2.0',
tipRacks: [],
requestedAs: 'p300_single',
probed: true,
tipOn: false,
modelSpecs: null,
},
{
_id: 1,
mount: 'right',
channels: 8,
name: 'p20_multi_v2.0',
tipRacks: [],
requestedAs: null,
probed: true,
tipOn: false,
modelSpecs: null,
},
])

const result = getProtocolAnalyticsData(mockState)

return expect(result).resolves.toMatchObject({
pipettes: 'p300_single,p20_multi_v2.0',
})
})

it('should collect module models', () => {
getModules.mockReturnValue([
{ _id: 0, slot: '1', model: 'temperatureModuleV1' },
{ _id: 1, slot: '2', model: 'magneticModuleV2' },
])

const result = getProtocolAnalyticsData(mockState)

return expect(result).resolves.toMatchObject({
modules: 'temperatureModuleV1,magneticModuleV2',
})
})
})
})
17 changes: 16 additions & 1 deletion app/src/analytics/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import {

import { getRobotSettings } from '../robot-settings'
import { getAttachedPipettes } from '../pipettes'
import { getPipettes, getModules } from '../robot/selectors'

import { hash } from './hash'

Expand All @@ -51,7 +52,19 @@ const _getUnhashedProtocolAnalyticsData: ProtocolDataSelector = createSelector(
getProtocolSource,
getProtocolAuthor,
getProtocolContents,
(type, app, apiVersion, name, source, author, contents) => ({
getPipettes,
getModules,
(
type,
app,
apiVersion,
name,
source,
author,
contents,
pipettes,
modules
) => ({
protocolType: type || '',
protocolAppName: app.name || '',
protocolAppVersion: app.version || '',
Expand All @@ -60,6 +73,8 @@ const _getUnhashedProtocolAnalyticsData: ProtocolDataSelector = createSelector(
protocolSource: source || '',
protocolAuthor: author || '',
protocolText: contents || '',
pipettes: pipettes.map(p => p.requestedAs ?? p.name).join(','),
modules: modules.map(m => m.model).join(','),
})
)

Expand Down
2 changes: 2 additions & 0 deletions app/src/analytics/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ export type ProtocolAnalyticsData = {|
protocolName: string,
protocolAuthor: string,
protocolText: string,
pipettes: string,
modules: string,
|}

export type RobotAnalyticsData = {|
Expand Down