<commit_before>import { moment } from 'meteor/momentjs:moment';
import { _ } from 'meteor/erasaur:meteor-lodash';
import { Template } from 'meteor/templating';
import { ReactiveVar } from 'meteor/reactive-var';
import { $ } from 'meteor/jquery';
import { StudentProfiles } from '../../../api/user/StudentProfileCollection';
import { userInteractionFindMethod } from '../../../api/analytic/UserInteractionCollection.methods';
import { Users } from '../../../api/user/UserCollection';

let studentPopulation;

Template.Students_Summary_Widget.onCreated(function studentsSummaryWidgetOnRendered() {
  this.interactions = new ReactiveVar({});
  this.selectedUser = new ReactiveVar({});
  this.behaviors = new ReactiveVar([]);
  this.startDate = new ReactiveVar('');
  this.endDate = new ReactiveVar('');
  studentPopulation = StudentProfiles.find().count();
  /* There is a possible bug with Semantic where the timeline modal is duplicated in the DOM
    upon navigating back to the student summary page from any other page. A suggested fix (temporary)
    is to simply remove the timeline modal every time the template is created again. */
  $('#timeline').remove();
});

Template.Students_Summary_Widget.helpers({
  behaviors() {
    return Template.instance().behaviors.get();
  },
  dateRange() {
    const data = Template.instance();
    if (data.startDate.get() === '') {
      return '';
    }
    const startDate = moment(data.startDate.get()).format('MM-DD-YYYY');
    const endDate = moment(data.endDate.get()).format('MM-DD-YYYY');
    return `${startDate} to ${endDate}`;
  },
  firstIndex(index) {
    return index === 0;
  },
  percent(count) {
    return ((count / studentPopulation) * 100).toFixed(0);
  },
  selectedUser() {
    return !_.isEmpty(Template.instance().selectedUser.get());
  },
  timelineChart() {
    const users = Template.instance().interactions.get();
  },
  user() {
    return Template.instance().selectedUser.get();
  },
});

Template.Students_Summary_Widget.events({
  submit(event, instance) {
    event.preventDefault();
    const startDate = moment(event.target.startDate.value, 'MMMM D, YYYY').toDate();
    const endDate = moment(event.target.endDate.value, 'MMMM D, YYYY').endOf('day').toDate();
    instance.startDate.set(startDate);
    instance.endDate.set(endDate);
    const selector = { timestamp: { $gte: startDate, $lte: endDate } };
    const options = { sort: { username: 1, timestamp: 1 } };
    userInteractionFindMethod.call({ selector, options }, (error, result) => {
      if (error) {
        console.log('Error finding user interactions.', error);
      } else {
        const users = _.groupBy(_.filter(result, (u) => Users.getProfile(u.username).role === 'STUDENT'), 'username');
        const behaviors = [{ type: 'Log In', count: 0, users: [], description: 'Logged into application' },<commit_msg>Fixed eslint error<commit_after>import { moment } from 'meteor/momentjs:moment';
import { _ } from 'meteor/erasaur:meteor-lodash';
import { Template } from 'meteor/templating';
import { ReactiveVar } from 'meteor/reactive-var';
import { $ } from 'meteor/jquery';
import { StudentProfiles } from '../../../api/user/StudentProfileCollection';
import { userInteractionFindMethod } from '../../../api/analytic/UserInteractionCollection.methods';
import { Users } from '../../../api/user/UserCollection';

let studentPopulation;

Template.Students_Summary_Widget.onCreated(function studentsSummaryWidgetOnRendered() {
  this.interactions = new ReactiveVar({});
  this.selectedUser = new ReactiveVar({});
  this.behaviors = new ReactiveVar([]);
  this.startDate = new ReactiveVar('');
  this.endDate = new ReactiveVar('');
  studentPopulation = StudentProfiles.find().count();
  /* There is a possible bug with Semantic where the timeline modal is duplicated in the DOM
    upon navigating back to the student summary page from any other page. A suggested fix (temporary)
    is to simply remove the timeline modal every time the template is created again. */
  $('#timeline').remove();
});

Template.Students_Summary_Widget.helpers({
  behaviors() {
    return Template.instance().behaviors.get();
  },
  dateRange() {
    const data = Template.instance();
    if (data.startDate.get() === '') {
      return '';
    }
    const startDate = moment(data.startDate.get()).format('MM-DD-YYYY');
    const endDate = moment(data.endDate.get()).format('MM-DD-YYYY');
    return `${startDate} to ${endDate}`;
  },
  firstIndex(index) {
    return index === 0;
  },
  percent(count) {
    return ((count / studentPopulation) * 100).toFixed(0);
  },
  selectedUser() {
    return !_.isEmpty(Template.instance().selectedUser.get());
  },
  timelineChart() {
  },
  user() {
    return Template.instance().selectedUser.get();
  },
});

Template.Students_Summary_Widget.events({
  submit(event, instance) {
    event.preventDefault();
    const startDate = moment(event.target.startDate.value, 'MMMM D, YYYY').toDate();
    const endDate = moment(event.target.endDate.value, 'MMMM D, YYYY').endOf('day').toDate();
    instance.startDate.set(startDate);
    instance.endDate.set(endDate);
    const selector = { timestamp: { $gte: startDate, $lte: endDate } };
    const options = { sort: { username: 1, timestamp: 1 } };
    userInteractionFindMethod.call({ selector, options }, (error, result) => {
      if (error) {
        console.log('Error finding user interactions.', error);
      } else {
        const users = _.groupBy(_.filter(result, (u) => Users.getProfile(u.username).role === 'STUDENT'), 'username');
        const behaviors = [{ type: 'Log In', count: 0, users: [], description: 'Logged into application' },
{'fraction_non_alphanumeric': 0.15969648844185635, 'fraction_numerical': 0.0028233633315687314, 'mean_word_length': 3.998236331569665, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6343252', 'n_tokens_mistral': 1702, 'n_tokens_neox': 1673, 'n_words': 403}