<commit_before>/** @jsx React.DOM */

Cosmos.components.Movie = React.createClass({
  /**
   * Expected input:
   * {
   *   component: "Movie",
   *   id: 155
   * }
   * Expected state:
   * {
   *   data: {
   *     id: 155,
   *     title: "The Dark Knight",
   *     release_date: "2008-07-18",
   *     poster_path: "/1hRoyzDtpgMU7Dz4JF22RANzQO7.jpg",
   *     genres: [{id: 28, name: "Action"}, {id: 80, name: "Crime"}],
   *     overview: "Batman raises the stakes in his war on crime...",
   *     credits: {
   *       crew: [...],
   *       cast: [...]
   *     },
   *     genres: [{
   *       id: 28,
   *       name: "Action"
   *     }],
   *     similar_movies: {
   *       results: [{
   *         id: 272,
   *         title: "Batman Begins",
   *         poster_path: "/zfVFOo2XCHbeA0mXbst42TAGhfC.jpg",
   *         vote_average: 7,
   *         vote_count: 2492
   *       }]
   *     },
   *     imdb_id: "tt0468569"
   *   }
   * }
   */
  mixins: [Cosmos.mixins.DataFetch,
           Cosmos.mixins.PersistState],
  initialData: {
    credits: {
      crew: [],
      cast: []
    },
    genres: [],
    similar_movies: {
      results: []
    }
  },
  render: function() {
    return (
      <div>
        <Cosmos component="DemoHeader" />
        <Cosmos component="MovieHeader"
                title={this.state.data.title || ''}
                year={App.getReleaseYear(this.state.data.release_date)}
                posterPath={App.getImagePath(this.state.data.poster_path, 342)}
                credits={App.groupCreditsPerDepartments(this.state.data.credits)} />
        <p className="overview">
          <strong>{App.getGenreNames(this.state.data.genres)}</strong>
          <em>{this.getMovieOverview(this.state.data.overview)}</em>
        </p>
        <div className="related">
          {this.state.data.similar_movies.results.length ?
            <p>If you liked <em>{this.state.data.title}</em>
               you might also like...</p> : ''}
          <Cosmos component="List"
                  state={{data: this.getPropsForSimilarMoviesList(
                                  this.state.data.similar_movies.results)}} />
        </div>
      </div>
    );
  },
  getDataUrl: function(props) {
    return App.getApiPath('movie', props.id, 'credits,similar_movies');
  },
  getMovieOverview: function(overview) {
    return overview ? ' — ' + App.getTextExcerpt(overview, 1000) : '';
  },
  getPropsForSimilarMoviesList: function(movies) {
    var similarMovies = this.filterSimilarMovies(movies);
    return _.map(similarMovies, function(movie) {
      return {
        component: "Thumbnail",
        name: movie.title + ' (' + App.getReleaseYear(movie.release_date) + ')',
        image: App.getImagePath(movie.poster_path, 154),
        linkProps: {
          component: "Movie",
          id: movie.id
        }
      };
    }.bind(this));
  },
  filterSimilarMovies: function(movies) {
    // Can't show thumbnails without images
    movies = _.filter(movies, function(movie) {
      return !!movie.poster_path;
    });
    // Remove unknown or bad movies
    movies = _.filter(movies, function(movie) {
      return movie.vote_count >= 5 && movie.vote_average >= 5;
    });
    // Sort them by vote_average, descending
    movies = _.sortBy(movies, function(movie) {
      return -movie.vote_average;
    });
    return movies;
  }
});<commit_msg>Accept more related movies #24<commit_after>/** @jsx React.DOM */

Cosmos.components.Movie = React.createClass({
  /**
   * Expected input:
   * {
   *   component: "Movie",
   *   id: 155
   * }
   * Expected state:
   * {
   *   data: {
   *     id: 155,
   *     title: "The Dark Knight",
   *     release_date: "2008-07-18",
   *     poster_path: "/1hRoyzDtpgMU7Dz4JF22RANzQO7.jpg",
   *     genres: [{id: 28, name: "Action"}, {id: 80, name: "Crime"}],
   *     overview: "Batman raises the stakes in his war on crime...",
   *     credits: {
   *       crew: [...],
   *       cast: [...]
   *     },
   *     genres: [{
   *       id: 28,
   *       name: "Action"
   *     }],
   *     similar_movies: {
   *       results: [{
   *         id: 272,
   *         title: "<NAME>",
   *         poster_path: "/zfVFOo2XCHbeA0mXbst42TAGhfC.jpg",
   *         vote_average: 7,
   *         vote_count: 2492
   *       }]
   *     },
   *     imdb_id: "tt0468569"
   *   }
   * }
   */
  mixins: [Cosmos.mixins.DataFetch,
           Cosmos.mixins.PersistState],
  initialData: {
    credits: {
      crew: [],
      cast: []
    },
    genres: [],
    similar_movies: {
      results: []
    }
  },
  render: function() {
    return (
      <div>
        <Cosmos component="DemoHeader" />
        <Cosmos component="MovieHeader"
                title={this.state.data.title || ''}
                year={App.getReleaseYear(this.state.data.release_date)}
                posterPath={App.getImagePath(this.state.data.poster_path, 342)}
                credits={App.groupCreditsPerDepartments(this.state.data.credits)} />
        <p className="overview">
          <strong>{App.getGenreNames(this.state.data.genres)}</strong>
          <em>{this.getMovieOverview(this.state.data.overview)}</em>
        </p>
        <div className="related">
          {this.state.data.similar_movies.results.length ?
            <p>If you liked <em>{this.state.data.title}</em>
               you might also like...</p> : ''}
          <Cosmos component="List"
                  state={{data: this.getPropsForSimilarMoviesList(
                                  this.state.data.similar_movies.results)}} />
        </div>
      </div>
    );
  },
  getDataUrl: function(props) {
    return App.getApiPath('movie', props.id, 'credits,similar_movies');
  },
  getMovieOverview: function(overview) {
    return overview ? ' — ' + App.getTextExcerpt(overview, 1000) : '';
  },
  getPropsForSimilarMoviesList: function(movies) {
    var similarMovies = this.filterSimilarMovies(movies);
    return _.map(similarMovies, function(movie) {
      return {
        component: "Thumbnail",
        name: movie.title + ' (' + App.getReleaseYear(movie.release_date) + ')',
        image: App.getImagePath(movie.poster_path, 154),
        linkProps: {
          component: "Movie",
          id: movie.id
        }
      };
    }.bind(this));
  },
  filterSimilarMovies: function(movies) {
    // Can't show thumbnails without images
    movies = _.filter(movies, function(movie) {
      return !!movie.poster_path;
    });
    // Remove unknown or bad movies
    movies = _.filter(movies, function(movie) {
      return movie.vote_count >= 3 && movie.vote_average >= 5;
    });
    // Sort them by vote_average, descending
    movies = _.sortBy(movies, function(movie) {
      return -movie.vote_average;
    });
    return movies;
  }
});
{'fraction_non_alphanumeric': 0.15274919141428991, 'fraction_numerical': 0.017053807703616582, 'mean_word_length': 2.0208703374777977, 'pattern_counts': {'":': 0, '<': 38, '<?xml version=': 0, '>': 42, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4118436', 'n_tokens_mistral': 2433, 'n_tokens_neox': 2254, 'n_words': 373}