<commit_before>import axios from 'axios';
import {observable} from 'mobx';
import {Face} from './face.jsx';

export class Video {
  @observable loadedMeta = false;
  @observable loadedFaces = false;
  @observable loadedFrames = false;

  faces = {};
  ids = {};
  frames = {}

  constructor(props) {
    if (typeof props != "object") {
      this.id = props;
      axios
        .get('/api/videos', {params: {'id': this.id}})
        .then(((response) => {
          let video = response.data.videos[0];
          this._setProps(video);
        }).bind(this));
    } else {
      this._setProps(props);
    }
  }

  _setProps(props) {
    this.id = props.id;
    for (var k in props) {
      this[k] = props[k];
    }
    this.loadedMeta = true;
  }

  loadFrames() {
    if (!this.loadedFrames) {
      return axios
        .get('/api/frames', {params: {
          'video_id': this.id, 'handlabeled': true}})
        .then(((response) => {
          response.data.frames.forEach(((frame) => {
            this.frames[frame.number] = frame;
          }).bind(this));
          this.loadedFrames = true;
          return true;
        }).bind(this));
    } else {
      return new Promise((resolve, _) => resolve(false));
    }
  }

  loadFaces() {
    if (!this.loadedFaces) {
      return axios
        .get('/api/faces', {params: {'video_id': this.id}})
        .then(((response) => {
          this.faces = _.mapValues(response.data.faces, (frames) =>
            _.mapValues(frames, (frame) =>
              frame.map((face) => new Face(face))));
          this.loadedFaces = true;
          return true;
        }).bind(this));
    } else {
      return new Promise((resolve, _) => resolve(false));
    }
  }
};<commit_msg>fixed loading the same data multiple times<commit_after>import axios from 'axios';
import {observable} from 'mobx';
import {Face} from './face.jsx';

export class Video {
  @observable loadedMeta = false;
  @observable loadedFaces = false;
  @observable loadedFrames = false;
  loadingFaces = false;
  loadingFrames = false;

  faces = {};
  ids = {};
  frames = {}

  constructor(props) {
    if (typeof props != "object") {
      this.id = props;
      axios
        .get('/api/videos', {params: {'id': this.id}})
        .then(((response) => {
          let video = response.data.videos[0];
          this._setProps(video);
        }).bind(this));
    } else {
      this._setProps(props);
    }
  }

  _setProps(props) {
    this.id = props.id;
    for (var k in props) {
      this[k] = props[k];
    }
    this.loadedMeta = true;
  }

  loadFrames() {
    if (!this.loadedFrames && !this.loadingFrames) {
      this.loadingFrames = true;
      return axios
        .get('/api/frames', {params: {
          'video_id': this.id, 'handlabeled': true}})
        .then(((response) => {
          response.data.frames.forEach(((frame) => {
            this.frames[frame.number] = frame;
          }).bind(this));
          this.loadedFrames = true;
          return true;
        }).bind(this));
    } else {
      return new Promise((resolve, _) => resolve(false));
    }
  }

  loadFaces() {
    if (!this.loadedFaces && !this.loadingFaces) {
      this.loadingFaces = true;
      return axios
        .get('/api/faces', {params: {'video_id': this.id}})
        .then(((response) => {
          this.faces = _.mapValues(response.data.faces, (frames) =>
            _.mapValues(frames, (frame) =>
              frame.map((face) => new Face(face))));
          this.loadedFaces = true;
          return true;
        }).bind(this));
    } else {
      return new Promise((resolve, _) => resolve(false));
    }
  }
};
{'fraction_non_alphanumeric': 0.1690450054884742, 'fraction_numerical': 0.0005488474204171241, 'mean_word_length': 2.1341358555460017, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 21, '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': '7369068', 'n_tokens_mistral': 1173, 'n_tokens_neox': 1145, 'n_words': 242}