/* global gettext */ import PropTypes from 'prop-types'; import React from 'react'; import ReactDOM from 'react-dom'; import classNames from 'classnames'; import CircleChart from './CircleChart'; import CircleChartLegend from './CircleChartLegend'; import GradeTable from './GradeTable'; import DueDates from './DueDates'; import Discussions from './Discussions'; function arrayToObject(array) { return array.reduce((accumulator, obj) => { const key = Object.keys(obj)[0]; accumulator[key] = obj[key]; return accumulator; }, {}) } function countByType(type, assignments) { let count = 0; assignments.map(({format}) => { if (format === type) { count += 1; } }) return count; } function getActiveUserString(count) { const users = (count === 1) ? 'User' : 'Users'; return `${users} active in this course right now`; } function getAssignmentCounts(types, assignments) { const countsArray = types.map((type) => { return { [type]: countByType(type, assignments) } }); return arrayToObject(countsArray); } function getStreakIcons(count) { return Array.apply(null, { length: count }).map((e, i) => ( )); } function getStreakEncouragement(count) { const action = (count > 0) ? 'Maintain' : 'Start'; return `${action} your active streak by`; } function getStreakString(count) { const unit = (count ===1) ? 'week' : 'weeks'; return (count > 0) ? `Active ${count} ${unit} in a row` : false; } export function LearnerAnalyticsDashboard(props) { const {grading_policy, grades, schedule, schedule_raw, week_streak, weekly_active_users, discussion_info, profile_images, passing_grade, percent_grade} = props; const gradeBreakdown = grading_policy.GRADER.map(({type, weight}, index) => { return { value: weight, label: type, sliceIndex: index + 1 } }); // Get a list of assignment types minus duplicates const assignments = gradeBreakdown.map(value => value['label']); const assignmentTypes = [...new Set(assignments)]; const assignmentCounts = getAssignmentCounts(assignmentTypes, schedule); console.log(schedule_raw); console.log(grades); return (
{getStreakString(week_streak)}
{getStreakEncouragement(week_streak)}
{getActiveUserString(weekly_active_users)}