|
| 1 | +/* eslint-disable perfectionist/sort-objects */ |
| 2 | + |
| 3 | +const { defineInstrument } = await import('/runtime/v1/@opendatacapture/runtime-core/index.js'); |
| 4 | +const { z } = await import('/runtime/v1/zod@3.23.x/index.js'); |
| 5 | + |
| 6 | +type BuryingItemType = "Food" | "Marbles" |
| 7 | + |
| 8 | + |
| 9 | +function createDependentField<const T>(field: T, fn: (buryingItemType?: BuryingItemType) => boolean) { |
| 10 | + return { |
| 11 | + kind: 'dynamic' as const, |
| 12 | + deps: ['itemBuried'] as const, |
| 13 | + render: (data: { itemBuried?: BuryingItemType }) => { |
| 14 | + if (fn(data.itemBuried)) { |
| 15 | + return field; |
| 16 | + } |
| 17 | + return null; |
| 18 | + } |
| 19 | + }; |
| 20 | +} |
| 21 | + |
| 22 | + |
| 23 | +export default defineInstrument({ |
| 24 | + kind: 'FORM', |
| 25 | + language: 'en', |
| 26 | + tags: ['Mouse', 'Marble burying', 'Food Burying'], |
| 27 | + internal: { |
| 28 | + edition: 1, |
| 29 | + name: 'MOUSE_BURYING_TASK_FORM' |
| 30 | + }, |
| 31 | + content: { |
| 32 | + roomNumber: { |
| 33 | + kind: 'string', |
| 34 | + variant: "input", |
| 35 | + label: "Room number" |
| 36 | + }, |
| 37 | + itemBuried: { |
| 38 | + kind: 'string', |
| 39 | + variant: "radio", |
| 40 | + label: "Item buried", |
| 41 | + options: { |
| 42 | + "Marbles": "Marbles", |
| 43 | + "Food": "Food" |
| 44 | + } |
| 45 | + }, |
| 46 | + cageNumber: createDependentField({ |
| 47 | + kind: 'string', |
| 48 | + variant: "input", |
| 49 | + label: "Cage number" |
| 50 | + }, (type) => type === "Marbles"), |
| 51 | + percentageMarblesBuried: createDependentField({ |
| 52 | + kind: 'string', |
| 53 | + variant: "radio", |
| 54 | + label: "Percentage range of marbles buried", |
| 55 | + options: { |
| 56 | + "100 %": "100 %", |
| 57 | + "100 - 75%": "100 - 75%", |
| 58 | + "75% - 0%":"75% - 0%" |
| 59 | + } |
| 60 | + },(type) => type === "Marbles"), |
| 61 | + foodBuryingTimeCutOff: createDependentField({ |
| 62 | + kind: "boolean", |
| 63 | + variant: "radio", |
| 64 | + label: "Did the task have a time cut off" |
| 65 | + }, (type) => type === "Food"), |
| 66 | + |
| 67 | + foodBuryingTimeCutOffDuration: { |
| 68 | + kind: "dynamic", |
| 69 | + deps: ["foodBuryingTimeCutOff"], |
| 70 | + render(data) { |
| 71 | + if (data.foodBuryingTimeCutOff){ |
| 72 | + return { |
| 73 | + kind: "number", |
| 74 | + variant: "input", |
| 75 | + label: "Duration of food burying task (seconds)" |
| 76 | + } |
| 77 | + } |
| 78 | + return null |
| 79 | + } |
| 80 | + }, |
| 81 | + foodPosition: createDependentField({ |
| 82 | + kind: "string", |
| 83 | + variant: "input", |
| 84 | + label: "Food position" |
| 85 | + }, (type) => type === "Food"), |
| 86 | + |
| 87 | + ethoVisionUsed: createDependentField({ |
| 88 | + kind: "boolean", |
| 89 | + variant: "radio", |
| 90 | + label: "Was Ethovision used for the task?" |
| 91 | + }, (type) => type === "Food"), |
| 92 | + |
| 93 | + ethoVisionDistanceTravelled: { |
| 94 | + kind: "dynamic", |
| 95 | + deps: ["ethoVisionUsed"], |
| 96 | + render(data) { |
| 97 | + if(data.ethoVisionUsed){ |
| 98 | + return { |
| 99 | + kind: "number", |
| 100 | + variant: "input", |
| 101 | + label: "Distance travelled (cm)" |
| 102 | + } |
| 103 | + } |
| 104 | + return null |
| 105 | + } |
| 106 | + }, |
| 107 | + ethoVisionLatency: { |
| 108 | + kind: "dynamic", |
| 109 | + deps: ["ethoVisionUsed"], |
| 110 | + render(data) { |
| 111 | + if(data.ethoVisionUsed){ |
| 112 | + return { |
| 113 | + kind: "number", |
| 114 | + variant: "input", |
| 115 | + label: "Ethovision latency (ms)" |
| 116 | + } |
| 117 | + } |
| 118 | + return null |
| 119 | + } |
| 120 | + }, |
| 121 | + |
| 122 | + additionalComments: { |
| 123 | + kind: "string", |
| 124 | + variant: "textarea", |
| 125 | + label: "Additional Comments" |
| 126 | + } |
| 127 | + }, |
| 128 | + clientDetails: { |
| 129 | + estimatedDuration: 2, |
| 130 | + instructions: ['To be filled in whenever the animal completes a burying task. Before the form is used the user must know what item the animal has buried as well as the location the task took place in'] |
| 131 | + }, |
| 132 | + details: { |
| 133 | + description: 'A form to track data from a burying related behavior task given to an animal', |
| 134 | + license: 'Apache-2.0', |
| 135 | + title: 'Mouse Behavioral Experiment Form' |
| 136 | + }, |
| 137 | + measures: { |
| 138 | + roomNumber: { |
| 139 | + kind: 'const', |
| 140 | + visibility: 'visible', |
| 141 | + ref: "roomNumber" |
| 142 | + }, |
| 143 | + itemBuried: { |
| 144 | + kind: 'const', |
| 145 | + visibility: 'visible', |
| 146 | + ref: "itemBuried" |
| 147 | + }, |
| 148 | + cageNumber: { |
| 149 | + kind: 'const', |
| 150 | + visibility: 'visible', |
| 151 | + ref: "cageNumber" |
| 152 | + }, |
| 153 | + percentageMarblesBuried: { |
| 154 | + kind: 'const', |
| 155 | + visibility: 'visible', |
| 156 | + ref: "percentageMarblesBuried" |
| 157 | + }, |
| 158 | + foodBuryingTimeCutOff: { |
| 159 | + kind: 'const', |
| 160 | + visibility: 'visible', |
| 161 | + ref: "foodBuryingTimeCutOff" |
| 162 | + }, |
| 163 | + foodBuryingTimeCutOffDuration: { |
| 164 | + kind: 'const', |
| 165 | + visibility: 'visible', |
| 166 | + ref: "foodBuryingTimeCutOffDuration" |
| 167 | + }, |
| 168 | + foodPosition: { |
| 169 | + kind: 'const', |
| 170 | + visibility: 'visible', |
| 171 | + ref: "foodPosition" |
| 172 | + }, |
| 173 | + ethoVisionUsed: { |
| 174 | + kind: 'const', |
| 175 | + visibility: 'visible', |
| 176 | + ref: "ethoVisionUsed" |
| 177 | + }, |
| 178 | + ethoVisionDistanceTravelled: { |
| 179 | + kind: 'const', |
| 180 | + visibility: 'visible', |
| 181 | + ref: "ethoVisionDistanceTravelled" |
| 182 | + }, |
| 183 | + ethoVisionLatency: { |
| 184 | + kind: 'const', |
| 185 | + visibility: 'visible', |
| 186 | + ref: "ethoVisionLatency" |
| 187 | + }, |
| 188 | + additionalComments: { |
| 189 | + kind: 'const', |
| 190 | + visibility: 'visible', |
| 191 | + ref: 'additionalComments' |
| 192 | + } |
| 193 | + |
| 194 | + }, |
| 195 | + validationSchema: z.object({ |
| 196 | + roomNumber: z.string(), |
| 197 | + itemBuried: z.enum(["Marbles","Food"]), |
| 198 | + cageNumber: z.string().optional(), |
| 199 | + percentageMarblesBuried: z.enum(["100 %","100 - 75%","75% - 0%"]).optional(), |
| 200 | + foodBuryingTimeCutOff: z.boolean(), |
| 201 | + foodBuryingTimeCutOffDuration: z.number().min(0).int().optional(), |
| 202 | + foodPosition: z.string().optional(), |
| 203 | + ethoVisionUsed: z.boolean().optional(), |
| 204 | + ethoVisionDistanceTravelled: z.number().min(0).optional(), |
| 205 | + ethoVisionLatency: z.number().min(0).optional(), |
| 206 | + additionalComments: z.string().optional() |
| 207 | + }) |
| 208 | +}); |
0 commit comments