<commit_before>import { action } from 'mobx';
import Map from './map';
import lazyGetter from '../helpers/lazy-getter';
import Hypothesis from './annotations/hypothesis';
import Annotation from './annotations/annotation';
import AnnotationsUX from './annotations/ux';

export default class Annotations extends Map {

  constructor() {
    super();
    this.api.requestsInProgress.set('fetch', true);
    Hypothesis.fetchUserInfo().then(this.updateAnnotations);
  }

  @lazyGetter ux = new AnnotationsUX();

  @action.bound updateAnnotations(annotations) {
    this.api.requestsInProgress.delete('fetch');
    this.api.requestCounts.read += 1;
    if (annotations) {
      annotations.forEach((an) => {
        const note = this.get(an.id);
        an.listing = this;
        note ? note.update(an) : this.set(an.id, new Annotation(an));
      });
    }<commit_msg>group annotations in nested course/chapter.section maps<commit_after>import { action, computed } from 'mobx';
import { pick, sortBy, map, groupBy, mapValues, extend } from 'lodash';
import Map from './map';
import lazyGetter from '../helpers/lazy-getter';
import { chapterSectionToNumber } from '../helpers/content';
import Hypothesis from './annotations/hypothesis';
import Annotation from './annotations/annotation';
import AnnotationsUX from './annotations/ux';
export default class Annotations extends Map {

  constructor() {
    super();
    this.api.requestsInProgress.set('fetch', true);
    Hypothesis.fetchUserInfo().then(this.updateAnnotations);
  }

  @lazyGetter ux = new AnnotationsUX();


  @computed get byCourseAndPage() {
    return mapValues(
      groupBy(this.array, 'courseId'),
      (cpgs) => groupBy(
        sortBy(cpgs, c=>chapterSectionToNumber(c.chapter_section)),
        a => a.chapter_section.join('.')
      )
    );
  }

  @action.bound updateAnnotations(annotations) {
    this.api.requestsInProgress.delete('fetch');
    this.api.requestCounts.read += 1;
    if (annotations) {
      annotations.forEach((an) => {
        const note = this.get(an.id);
        an.listing = this;
        note ? note.update(an) : this.set(an.id, new Annotation(an));
      });
    }
{'fraction_non_alphanumeric': 0.14279112754158965, 'fraction_numerical': 0.0009242144177449168, 'mean_word_length': 3.596602972399151, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 8, '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': '4531241', 'n_tokens_mistral': 663, 'n_tokens_neox': 642, 'n_words': 146}