<commit_before>import { filter, find } from 'lodash';
import { computed, observable, action } from 'mobx';
import {
  BaseModel, identifiedBy, field, hasMany, session, belongsTo,
} from '../base';
import { TimeStore } from '../../flux/time';

import TaskResult from './scores/task-result';

@identifiedBy('course/scores/student')
class Student extends BaseModel {
  @session average_score = 0;
  @hasMany({ model: TaskResult, inverseOf: 'student' }) data;
  @session first_name;
  @session last_name;
  @session is_dropped;
  @session name;
  @session role;
  @session student_identifier;
}

@identifiedBy('course/scores/heading')
class Heading extends BaseModel {
  @session average_score = 0;
  @session completion_rate = 0;
  @session({ type: 'date' }) due_at;
  @session plan_id;
  @session title;
  @session type;
  @belongsTo({ model: 'course/scores/period' }) period;
}

@identifiedBy('course/scores/period')
export class CourseScoresPeriod extends BaseModel {

  @hasMany({ model: Heading }) data_headings;
  @session overall_average_score = 0;
  @session period_id;
  @hasMany({ model: Student, inverseOf: 'period' }) students;

  @computed get courseStudents() {
    return this.course.roster.studentsForPeriod(
      find(this.course.periods, { period_id: this.period_id })
    );
  }

  @computed get numAssignments() {
    return this.data_headings.length;
  }

  constructor(attrs, course) {
    super(attrs);
    this.course = course;
  }
}

@identifiedBy('course/scores')
export default class CourseScores extends BaseModel {

  @belongsTo({ model: 'course' }) course;

  @observable periods = observable.map();

  fetch() {
    return { courseId: this.course.id };
  }

  @action onFetchComplete({ data }) {
    data.forEach(s => this.periods.set(s.period_id, new CourseScoresPeriod(s, this.course)));
  }

  getTask(taskId) {
    const id = Number(taskId);
    const periods = this.periods.values();
    for(let p=0; p < periods.length; p+=1) {
      const period = periods[p];
      for(let i=0; i < period.students.length; i +=1 ){
        const task = find(period.students[i].data, { id });
        if (task) return task;
      }
    }<commit_msg>add coursePeriod getter<commit_after>import { filter, find } from 'lodash';
import { computed, observable, action } from 'mobx';
import {
  BaseModel, identifiedBy, field, hasMany, session, belongsTo,
} from '../base';
import { TimeStore } from '../../flux/time';

import TaskResult from './scores/task-result';

@identifiedBy('course/scores/student')
class Student extends BaseModel {
  @session average_score = 0;
  @hasMany({ model: TaskResult, inverseOf: 'student' }) data;
  @session first_name;
  @session last_name;
  @session is_dropped;
  @session name;
  @session role;
  @session student_identifier;
}

@identifiedBy('course/scores/heading')
class Heading extends BaseModel {
  @session average_score = 0;
  @session completion_rate = 0;
  @session({ type: 'date' }) due_at;
  @session plan_id;
  @session title;
  @session type;
  @belongsTo({ model: 'course/scores/period' }) period;
}

@identifiedBy('course/scores/period')
export class CourseScoresPeriod extends BaseModel {

  @hasMany({ model: Heading }) data_headings;
  @session overall_average_score = 0;
  @session period_id;
  @hasMany({ model: Student, inverseOf: 'period' }) students;

  constructor(attrs, course) {
    super(attrs);
    this.course = course;
  }

  @computed get courseStudents() {
    return this.course.roster.studentsForPeriod(this.coursePeriod);
  }

  @computed get numAssignments() {
    return this.data_headings.length;
  }

  @computed get coursePeriod() {
    return find(this.course.periods, { id: this.period_id });
  }

}

@identifiedBy('course/scores')
export default class CourseScores extends BaseModel {

  @belongsTo({ model: 'course' }) course;

  @observable periods = observable.map();

  fetch() {
    return { courseId: this.course.id };
  }

  @action onFetchComplete({ data }) {
    data.forEach(s => this.periods.set(s.period_id, new CourseScoresPeriod(s, this.course)));
  }

  getTask(taskId) {
    const id = Number(taskId);
    const periods = this.periods.values();
    for(let p=0; p < periods.length; p+=1) {
      const period = periods[p];
      for(let i=0; i < period.students.length; i +=1 ){
        const task = find(period.students[i].data, { id });
        if (task) return task;
      }
    }
{'fraction_non_alphanumeric': 0.14035486806187444, 'fraction_numerical': 0.003639672429481347, 'mean_word_length': 3.9460067491563553, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, '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': '7466682', 'n_tokens_mistral': 1471, 'n_tokens_neox': 1406, 'n_words': 352}