<commit_before>import React from 'react';
import PropTypes from 'prop-types';
import _ from 'lodash';
import moment from 'moment';
import {merge} from '../helpers/merge';
import Datepicker from '../components/Datepicker';
import {
  toSchoolYear,
  firstDayOfSchool
} from '../helpers/schoolYear';
import {
  toMoment,
  toValue,
  toDate
} from './QuadConverter';
import StudentSectionsRoster from './StudentSectionsRoster';
import { toMomentFromTimestamp } from '../helpers/toMoment';

export default class ProfileDetails extends React.Component {
  constructor(props) {
    super(props);
    const nowMoment = props.nowMoment || moment();
    this.state = {
      filterFromDate: firstDayOfSchool(toSchoolYear(nowMoment)-1),
      filterToDate: nowMoment
    };

    this.checkboxContainerEl = null;
    this.onFilterFromDateChanged = this.onFilterFromDateChanged.bind(this);
    this.onFilterToDateChanged = this.onFilterToDateChanged.bind(this);
    this.onClickGenerateStudentReport = this.onClickGenerateStudentReport.bind(this);
  }

  displayEventDate(event_date){
    // Use UTC to avoid timezone-related display errors. (See GitHub issue #622.)
    // Timezone is irrelevant for this UI. We are not displaying times, only dates.

    return moment(event_date).utc().format("MMMM Do, YYYY:");
  }

  getMessageForServiceType(service_type_id){
    // Given a service_type_id, returns a message suitable for human consumption describing the service.
    const lookup = this.props.serviceTypesIndex;

    return (lookup.hasOwnProperty(service_type_id))
      ? lookup[service_type_id].name
      : "Description not found for code: " + service_type_id;
  }

  getEvents() {
    // Returns a list of {type: ..., date: ..., value: ...} pairs, sorted by date of occurrence.
    const name = this.props.student.first_name;
    const events = [];

    _.each(this.props.attendanceData.tardies, obj => {
      events.push({
        type: 'Tardy',
        id: obj.id,
        message: name + ' was tardy.',
        date: new Date(obj.occurred_at)
      });
    });
    _.each(this.props.attendanceData.absences, obj => {
      events.push({
        type: 'Absence',
        id: obj.id,
        message: name + ' was absent.',
        date: new Date(obj.occurred_at)
      });
    });
    _.each(this.props.attendanceData.discipline_incidents, obj => {
      events.push({
        type: 'Incident',
        id: obj.id,
        message: obj.incident_description + ' in the ' + obj.incident_location,
        date: new Date(obj.occurred_at)
      });
    });
    _.each(this.props.chartData.mcas_series_ela_scaled, quad => {
      // var score = quad[3];
      events.push({
        type: 'MCAS-ELA',
        id: toMoment(quad).format("MM-DD"),
        message: name + ' scored a ' + toValue(quad) +' on the ELA section of the MCAS.',
        date: toDate(quad)
      });
    });
    _.each(this.props.chartData.mcas_series_math_scaled, quad => {
      // var score = quad[3];
      events.push({
        type: 'MCAS-Math',
        id: toMoment(quad).format("MM-DD"),
        message: name + ' scored a ' + toValue(quad) +' on the Math section of the MCAS.',
        date: toDate(quad)
      });
    });
    _.each(this.props.chartData.star_series_reading_percentile, starObject => {
      const dateTaken = toMomentFromTimestamp(starObject.date_taken);

      events.push({
        type: 'STAR-Reading',
        id: dateTaken.format(),
        message: `${name} scored in the ${starObject.percentile_rank}th percentile on the Reading section of STAR at ${dateTaken.local().format('h:mma')}.`,
        date: dateTaken.toDate()
      });
    });
    _.each(this.props.chartData.star_series_math_percentile, starObject => {
      const dateTaken = toMomentFromTimestamp(starObject.date_taken);

      events.push({
        type: 'STAR-Math',
        id: dateTaken.format(),
        message: `${name} scored in the ${starObject.percentile_rank}th percentile on the Math section of STAR at ${dateTaken.local().format('h:mma')}.`,
        date: dateTaken.toDate()
      });
    });
    _.each(this.props.feed.deprecated.interventions, obj => {
      events.push({
        type: 'Note',
        id: obj.id,
        message: obj.name + '(Goal: ' + obj.goal + ')',
        date: moment(obj.start_date_timestamp, "YYYY-MM-DD").toDate()
      });
    });
    _.each(this.props.feed.deprecated.notes, obj => {
      events.push({
        type: 'Note',
        id: obj.id,
        message: obj.content,
        date: moment(obj.created_at_timestamp).toDate()
      });
    });
    _.each(this.props.feed.event_notes, obj => {
      events.push({
        type: 'Note',
        id: obj.id,
        message: obj.text,
        date: moment(obj.recorded_at).toDate()
      });
    });

    const services = this.props.feed.services.active.concat(this.props.feed.services.discontinued);
    _.each(services, obj => {
      events.push({
        type: 'Service',
        id: obj.id,
        message: this.getMessageForServiceType(obj.service_type_id),
        date: moment(obj.date_started).toDate()
      });
    });

    _.each(this.props.dibels, (obj) => {
      const cleanedDate = obj.date_taken.split('T')[0];
      const parsedDate = moment.utc(cleanedDate, 'YYYY-MM-DD').toDate();

      events.push({
        type: 'DIBELS',
        id: obj.id,
        message: name + ' scored ' + obj.benchmark + ' in DIBELS.',
        date: parsedDate
      });
    });
    return _.sortBy(events, 'date').reverse();
  }

  filterFromDateForQuery() {
    const {filterFromDate} = this.state;

    return filterFromDate.format('MM/DD/YYYY');
  }

  filterToDateForQuery() {
    const {filterToDate} = this.state;

    return filterToDate.format('MM/DD/YYYY');
  }

  studentReportURL() {
    const id = this.props.student.id;
    const filterFromDateForQuery = this.filterFromDateForQuery();
    const filterToDateForQuery = this.filterToDateForQuery();
    const checkboxEls = $(this.checkboxContainerEl).find('.ProfileDetails-section').toArray();
    const sections = checkboxEls.filter(el => el.checked).map(el => el.value).join(',');
<commit_msg>Use JS string interpolation<commit_after>import React from 'react';
import PropTypes from 'prop-types';
import _ from 'lodash';
import moment from 'moment';
import {merge} from '../helpers/merge';
import Datepicker from '../components/Datepicker';
import {
  toSchoolYear,
  firstDayOfSchool
} from '../helpers/schoolYear';
import {
  toMoment,
  toValue,
  toDate
} from './QuadConverter';
import StudentSectionsRoster from './StudentSectionsRoster';
import { toMomentFromTimestamp } from '../helpers/toMoment';

export default class ProfileDetails extends React.Component {
  constructor(props) {
    super(props);
    const nowMoment = props.nowMoment || moment();
    this.state = {
      filterFromDate: firstDayOfSchool(toSchoolYear(nowMoment)-1),
      filterToDate: nowMoment
    };

    this.checkboxContainerEl = null;
    this.onFilterFromDateChanged = this.onFilterFromDateChanged.bind(this);
    this.onFilterToDateChanged = this.onFilterToDateChanged.bind(this);
    this.onClickGenerateStudentReport = this.onClickGenerateStudentReport.bind(this);
  }

  displayEventDate(event_date){
    // Use UTC to avoid timezone-related display errors. (See GitHub issue #622.)
    // Timezone is irrelevant for this UI. We are not displaying times, only dates.

    return moment(event_date).utc().format("MMMM Do, YYYY:");
  }

  getMessageForServiceType(service_type_id){
    // Given a service_type_id, returns a message suitable for human consumption describing the service.
    const lookup = this.props.serviceTypesIndex;

    return (lookup.hasOwnProperty(service_type_id))
      ? lookup[service_type_id].name
      : "Description not found for code: " + service_type_id;
  }

  getEvents() {
    // Returns a list of {type: ..., date: ..., value: ...} pairs, sorted by date of occurrence.
    const name = this.props.student.first_name;
    const events = [];

    _.each(this.props.attendanceData.tardies, obj => {
      events.push({
        type: 'Tardy',
        id: obj.id,
        message: name + ' was tardy.',
        date: new Date(obj.occurred_at)
      });
    });
    _.each(this.props.attendanceData.absences, obj => {
      events.push({
        type: 'Absence',
        id: obj.id,
        message: name + ' was absent.',
        date: new Date(obj.occurred_at)
      });
    });
    _.each(this.props.attendanceData.discipline_incidents, obj => {
      events.push({
        type: 'Incident',
        id: obj.id,
        message: obj.incident_description + ' in the ' + obj.incident_location,
        date: new Date(obj.occurred_at)
      });
    });
    _.each(this.props.chartData.mcas_series_ela_scaled, quad => {
      // var score = quad[3];
      events.push({
        type: 'MCAS-ELA',
        id: toMoment(quad).format("MM-DD"),
        message: name + ' scored a ' + toValue(quad) +' on the ELA section of the MCAS.',
        date: toDate(quad)
      });
    });
    _.each(this.props.chartData.mcas_series_math_scaled, quad => {
      // var score = quad[3];
      events.push({
        type: 'MCAS-Math',
        id: toMoment(quad).format("MM-DD"),
        message: name + ' scored a ' + toValue(quad) +' on the Math section of the MCAS.',
        date: toDate(quad)
      });
    });
    _.each(this.props.chartData.star_series_reading_percentile, starObject => {
      const dateTaken = toMomentFromTimestamp(starObject.date_taken);

      events.push({
        type: 'STAR-Reading',
        id: dateTaken.format(),
        message: `${name} scored in the ${starObject.percentile_rank}th percentile on the Reading section of STAR at ${dateTaken.local().format('h:mma')}.`,
        date: dateTaken.toDate()
      });
    });
    _.each(this.props.chartData.star_series_math_percentile, starObject => {
      const dateTaken = toMomentFromTimestamp(starObject.date_taken);

      events.push({
        type: 'STAR-Math',
        id: dateTaken.format(),
        message: `${name} scored in the ${starObject.percentile_rank}th percentile on the Math section of STAR at ${dateTaken.local().format('h:mma')}.`,
        date: dateTaken.toDate()
      });
    });
    _.each(this.props.feed.deprecated.interventions, obj => {
      events.push({
        type: 'Note',
        id: obj.id,
        message: obj.name + '(Goal: ' + obj.goal + ')',
        date: moment(obj.start_date_timestamp, "YYYY-MM-DD").toDate()
      });
    });
    _.each(this.props.feed.deprecated.notes, obj => {
      events.push({
        type: 'Note',
        id: obj.id,
        message: obj.content,
        date: moment(obj.created_at_timestamp).toDate()
      });
    });
    _.each(this.props.feed.event_notes, obj => {
      events.push({
        type: 'Note',
        id: obj.id,
        message: obj.text,
        date: moment(obj.recorded_at).toDate()
      });
    });

    const services = this.props.feed.services.active.concat(this.props.feed.services.discontinued);
    _.each(services, obj => {
      events.push({
        type: 'Service',
        id: obj.id,
        message: this.getMessageForServiceType(obj.service_type_id),
        date: moment(obj.date_started).toDate()
      });
    });

    _.each(this.props.dibels, obj => {
      const cleanedDate = obj.date_taken.split('T')[0];
      const parsedDate = moment.utc(cleanedDate, 'YYYY-MM-DD').toDate();

      events.push({
        type: 'DIBELS',
        id: obj.id,
        message: `${name} scored ${obj.benchmark} in DIBELS.`,
        date: parsedDate
      });
    });
    return _.sortBy(events, 'date').reverse();
  }

  filterFromDateForQuery() {
    const {filterFromDate} = this.state;

    return filterFromDate.format('MM/DD/YYYY');
  }

  filterToDateForQuery() {
    const {filterToDate} = this.state;

    return filterToDate.format('MM/DD/YYYY');
  }

  studentReportURL() {
    const id = this.props.student.id;
    const filterFromDateForQuery = this.filterFromDateForQuery();
    const filterToDateForQuery = this.filterToDateForQuery();
    const checkboxEls = $(this.checkboxContainerEl).find('.ProfileDetails-section').toArray();
    const sections = checkboxEls.filter(el => el.checked).map(el => el.value).join(',');

{'fraction_non_alphanumeric': 0.14278716629928973, 'fraction_numerical': 0.0011429504449342804, 'mean_word_length': 2.8161993769470404, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 31, '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': '370003', 'n_tokens_mistral': 3896, 'n_tokens_neox': 3829, 'n_words': 785}