MCPcopy Create free account
hub / github.com/codecombat/codecombat / statsForAIProjects

Method statsForAIProjects

app/models/Classroom.js:349–386  ·  view source on GitHub ↗
(sessions, courseId)

Source from the content-addressed store, hash-verified

347 }
348
349 statsForAIProjects (sessions, courseId) {
350 const emptyResults = { levels: { size: 0, left: 0, done: true, numDone: 0, pctDone: '0.0%' }, courseComplete: false }
351 const course = this.get('courses')?.find(c => c._id === courseId)
352 if (!course) {
353 return emptyResults
354 }
355 const scenarios = course.levels
356 if (!scenarios || !scenarios.length) {
357 return emptyResults
358 }
359 const allProjects = sessions.models.map(p => p.toJSON())
360 const projectsByScenario = _.groupBy(allProjects, 'scenario')
361 const levelsTotal = scenarios.length
362 let levelsLeft = levelsTotal
363 for (const scenarioOriginal in projectsByScenario) {
364 const projects = projectsByScenario[scenarioOriginal]
365 const scenario = scenarios.find(s => s.original === scenarioOriginal)
366 if (!scenario) {
367 continue
368 }
369 const isComplete = checkIfProjectComplete(scenario, projects)
370 if (isComplete) {
371 levelsLeft -= 1
372 }
373 }
374 const courseComplete = levelsLeft === 0
375 const stats = {
376 levels: {
377 size: levelsTotal,
378 left: levelsLeft,
379 done: levelsLeft === 0,
380 numDone: levelsTotal - levelsLeft,
381 pctDone: ((100 * (levelsTotal - levelsLeft)) / levelsTotal).toFixed(1) + '%',
382 },
383 courseComplete,
384 }
385 return stats
386 }
387
388 fetchForCourseInstance (courseInstanceID, options) {
389 if (options == null) { options = {} }

Callers 1

calculateAllCompletedMethod · 0.80

Calls 2

checkIfProjectCompleteFunction · 0.85
getMethod · 0.45

Tested by

no test coverage detected