MCPcopy Create free account
hub / github.com/Devographics/Monorepo / genericComputeFunction

Function genericComputeFunction

api/src/compute/generic.ts:258–688  ·  view source on GitHub ↗
(
    options: GenericComputeOptions
)

Source from the content-addressed store, hash-verified

256 // restrict aggregation to current and past editions, to avoid including results from the future
257 // when regenerating older surveys
258 const pastEditions = getPastNEditions({ survey, edition, editionCount })
259 match.editionId = { $in: pastEditions.map(e => e.id) }
260 }
261 return match
262}
263
264export async function genericComputeFunction(
265 options: GenericComputeOptions
266): Promise<ResponseEditionData[]> {
267 const startAt = new Date()
268 const stageLog: StageLogItem[] = []
269
270 const runStage = async (f: (...args: any[]) => Promise<any>, args: any) => {
271 const startAt = new Date()
272 const result = await f.apply(null, args)
273 const bucketCount = result?.[0]?.buckets?.length
274 const endAt = new Date()
275 const duration = Math.abs(endAt.getTime() - startAt.getTime())
276 const logItem = { name: f.name, startAt, endAt, duration, bucketCount }
277 stageLog.push(logItem)
278 return result
279 }
280
281 const { context, survey, edition, question, questionObjects, computeArguments } = options
282
283 let axis1: ComputeAxisParameters,
284 axis2: ComputeAxisParameters | null = null
285 const { db, isDebug } = context
286
287 // TODO "responsesType" is now called "subField" elsewhere, change it here as well at some point
288 const {
289 responsesType,
290 filters,
291 parameters = {},
292 bucketsFilter,
293 facet,
294 selectedEditionId,
295 editionCount,
296 executionContext = ExecutionContext.REGULAR
297 } = computeArguments
298 const {
299 cutoff = DEFAULT_CUTOFF,
300 cutoffPercent,
301 sort,
302 limit = DEFAULT_LIMIT,
303 facetSort,
304 facetLimit = DEFAULT_LIMIT,
305 facetCutoff = DEFAULT_CUTOFF,
306 facetCutoffPercent,
307 showNoAnswer,
308 mergeOtherBuckets = true,
309 enableBucketGroups = true,
310 enableBucketNesting = true,
311 enableAddOverallBucket = true,
312 enableAddMissingBuckets
313 } = parameters
314
315 const logPath = `last_query/${executionContext}`

Callers 2

combineWithFreeformFunction · 0.90
addOverallBucketFunction · 0.90

Calls 5

logToFileFunction · 0.90
getQuestionSortFunction · 0.85
getDbPathFunction · 0.85
getMatchFunction · 0.85
runStageFunction · 0.85

Tested by

no test coverage detected