<commit_before>import _ from 'lodash';

Template.homeReport.onCreated(function () {
  // get a reference to template instance
  const templateInstance = this;

  // Get Home ID from template instance
  templateInstance.homeId = Router.current().params.homeId;

  // Get home data for page elements
  templateInstance.subscribe('singleHome', templateInstance.homeId);

  // set reactive variable to hold chart data (attached to template instance)
  templateInstance.activityData = new ReactiveVar();

  // call method to retrieve aggregated activity data
  Meteor.call('getDailyAggregatedHomeResidentActivities', templateInstance.homeId, function (error, activities) {
    // set activity data in the reactive variable
    templateInstance.activityData.set(activities);
  })
});

Template.homeReport.onRendered(function () {
  const templateInstance = this;

  templateInstance.autorun(function () {
    //TODO: add reactive data source to toggle between
    //  - 'activity_minutes'
    //  - 'activity_count'
    const activityData = templateInstance.activityData.get();

    // Make sure we have some activity data
    if (activityData) {
      // Chart data consists of multiple traces
      const data = _.map(activityData, function (activityCategoryData) {
        // Create a trace for each activity type
        const trace = {
          type: 'scatter',
          mode: 'lines',
          name: activityCategoryData.key,
          // X values are activity dates
          x: _.map(activityCategoryData.values, function(activityCategoryDay) {
            return new Date(activityCategoryDay.key);
          }),
          // Y values are (currently) activity minutes
          // TODO: add page element to toggle between activity counts and minutes
          y: _.map(activityCategoryData.values, function(activityCategoryDay) {
            return activityCategoryDay.value.activity_minutes;
          }),
        }<commit_msg>Switch to bar chart showing activity count<commit_after>import _ from 'lodash';

Template.homeReport.onCreated(function () {
  // get a reference to template instance
  const templateInstance = this;

  // Get Home ID from template instance
  templateInstance.homeId = Router.current().params.homeId;

  // Get home data for page elements
  templateInstance.subscribe('singleHome', templateInstance.homeId);

  // set reactive variable to hold chart data (attached to template instance)
  templateInstance.activityData = new ReactiveVar();

  // call method to retrieve aggregated activity data
  Meteor.call('getMonthlyAggregatedHomeResidentActivities', templateInstance.homeId, function (error, activities) {
    // set activity data in the reactive variable
    templateInstance.activityData.set(activities);
  })
});

Template.homeReport.onRendered(function () {
  const templateInstance = this;

  templateInstance.autorun(function () {
    //TODO: add reactive data source to toggle between
    //  - 'activity_minutes'
    //  - 'activity_count'
    const activityData = templateInstance.activityData.get();

    // Make sure we have some activity data
    if (activityData) {
      // Chart data consists of multiple traces
      const data = _.map(activityData, function (activityCategoryData) {
        // Create a trace for each activity type
        const trace = {
          type: 'bar',
          mode: 'lines',
          name: activityCategoryData.key,
          // X values are activity dates
          x: _.map(activityCategoryData.values, function(activityCategoryDay) {
            return new Date(activityCategoryDay.key);
          }),
          // Y values are (currently) activity minutes
          // TODO: add page element to toggle between activity counts and minutes
          y: _.map(activityCategoryData.values, function(activityCategoryDay) {
            return activityCategoryDay.value.activity_count;
          }),
        }
{'fraction_non_alphanumeric': 0.08738113595476742, 'fraction_numerical': 0.0, 'mean_word_length': 3.0583941605839415, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '2256389', 'n_tokens_mistral': 975, 'n_tokens_neox': 947, 'n_words': 304}