<commit_before>/*
 * This file is part of Search NEU and licensed under AGPL3.
 * See the license file in the root folder for details.
 */

import _ from 'lodash';
import moment from 'moment';

import macros from '../commonMacros';

class Meeting {
  constructor(serverData) {
    if (!serverData) {
      return null;
    }

    this.profs = serverData.profs;
    this.profs.sort();
    this.where = serverData.where;

    // if without spaces and case insensitive is tba, make it TBA
    if (this.where.replace(/\s/gi, '').toUpperCase() === 'TBA') {
      this.where = 'TBA';
    }

    //beginning of the day that the class starts/ends
    this.startDate = moment((serverData.startDate + 1) * 24 * 60 * 60 * 1000);
    this.endDate = moment((serverData.endDate + 1) * 24 * 60 * 60 * 1000);

    //grouped by start+end time on each day.
    // eg, if have class that meets tue, wed, thu, at same time each day,
    // each list must be at least 1 long
    // you would have [[{start:end:},{start:end:},{start:end:}]]
    // where each start:end: object is a different day
    this.times = [];

    const timeMoments = [];

    const dayIndexies = Object.keys(serverData.times);

    for (const dayIndex of dayIndexies) {
      serverData.times[dayIndex].forEach((event) => {
        //3 is to set in the second week of 1970
        const day = parseInt(dayIndex, 10) + 3;

        const obj = {
          start: moment.utc(event.start * 1000).add(day, 'day'),
          end: moment.utc(event.end * 1000).add(day, 'day'),
        };

        if (parseInt(obj.start.format('YYYY'), 10) !== 1970) {
          macros.error();
        }

        timeMoments.push(obj);
      });
    }

    // returns objects like this: {3540000041400000: Array[3]}
    // if has three meetings per week that meet at the same times
    let groupedByTimeOfDay = _.groupBy(timeMoments, (event) => {
      const zero = moment(event.start).startOf('day');
      return `${event.start.diff(zero)}${event.end.diff(zero)}`;
    });

    // Get the values of the object returned above
    groupedByTimeOfDay = _.values(groupedByTimeOfDay);

    // And sort by start time
    groupedByTimeOfDay.sort((meetingsInAday) => {
      const zero = moment(meetingsInAday[0].start).startOf('day');
      return meetingsInAday[0].start.diff(zero);
    });

    this.times = groupedByTimeOfDay;
  }

  getBuilding() {
    // regex off the room number
    return this.where.replace(/\d+\s*$/i, '').trim();<commit_msg>Fixed a bug in Meeting.js<commit_after>/*
 * This file is part of Search NEU and licensed under AGPL3.
 * See the license file in the root folder for details.
 */

import _ from 'lodash';
import moment from 'moment';

import macros from '../commonMacros';

class Meeting {
  constructor(serverData) {
    if (!serverData) {
      return null;
    }

    this.profs = serverData.profs;
    this.profs.sort();
    this.where = serverData.where;

    // if without spaces and case insensitive is tba, make it TBA
    if (this.where.replace(/\s/gi, '').toUpperCase() === 'TBA') {
      this.where = 'TBA';
    }

    //beginning of the day that the class starts/ends
    this.startDate = moment((serverData.startDate + 1) * 24 * 60 * 60 * 1000);
    this.endDate = moment((serverData.endDate + 1) * 24 * 60 * 60 * 1000);

    //grouped by start+end time on each day.
    // eg, if have class that meets tue, wed, thu, at same time each day,
    // each list must be at least 1 long
    // you would have [[{start:end:},{start:end:},{start:end:}]]
    // where each start:end: object is a different day
    this.times = [];

    const timeMoments = [];

    if (serverData.times) {
      const dayIndexies = Object.keys(serverData.times);

      for (const dayIndex of dayIndexies) {
        serverData.times[dayIndex].forEach((event) => {
          //3 is to set in the second week of 1970
          const day = parseInt(dayIndex, 10) + 3;

          const obj = {
            start: moment.utc(event.start * 1000).add(day, 'day'),
            end: moment.utc(event.end * 1000).add(day, 'day'),
          };

          if (parseInt(obj.start.format('YYYY'), 10) !== 1970) {
            macros.error();
          }

          timeMoments.push(obj);
        });
      }
    }


    // returns objects like this: {3540000041400000: Array[3]}
    // if has three meetings per week that meet at the same times
    let groupedByTimeOfDay = _.groupBy(timeMoments, (event) => {
      const zero = moment(event.start).startOf('day');
      return `${event.start.diff(zero)}${event.end.diff(zero)}`;
    });

    // Get the values of the object returned above
    groupedByTimeOfDay = _.values(groupedByTimeOfDay);

    // And sort by start time
    groupedByTimeOfDay.sort((meetingsInAday) => {
      const zero = moment(meetingsInAday[0].start).startOf('day');
      return meetingsInAday[0].start.diff(zero);
    });

    this.times = groupedByTimeOfDay;
  }

  getBuilding() {
    // regex off the room number
    return this.where.replace(/\d+\s*$/i, '').trim();
{'fraction_non_alphanumeric': 0.1403857625770531, 'fraction_numerical': 0.02585006959634122, 'mean_word_length': 2.5877318116975747, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, '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': '7531152', 'n_tokens_mistral': 1729, 'n_tokens_neox': 1571, 'n_words': 459}