<commit_before>import logging

# flask
from flask import Flask, jsonify, request
import flask_cors

# Google
from google.cloud import datastore
from google.cloud.exceptions import ServiceUnavailable
import google.auth.transport.requests
import google.oauth2.id_token

# data
import numpy as np
from sklearn.metrics.pairwise import pairwise_distances

RATING_KIND = 'Rating'
MOVIE_KIND = 'Movie'
HTTP_REQUEST = google.auth.transport.requests.Request()

app = Flask(__name__)
flask_cors.CORS(app)
client = datastore.Client('cf-mr-service')

general_recommendation = []
user_rating = None
user_rating_split_size = 0
user_prediction = None
movie_info = {}

@app.route('/')
def hello():
    return ''

@app.route('/movie/api/v1.0/recommendation', methods=['GET'])
def recommend_movies():
    user_info = get_user_info()
    
    movie_list = []

    if user_info['index'] < 0:
        for m in general_recommendation:
            movie_list.append({
                'movie_id': m[2]
                })        
    elif user_info['index'] < user_rating.shape[0]:
        movies = []
        for i in xrange(user_rating.shape[1]):
            if user_rating[user_info['index']][i] == 0:
                movies.append((user_prediction[user_info['index']][i], i))

        movies.sort(reverse=True)        
        for m in movies:
            movie_list.append({
                'movie_id': m[1]
                })

    return jsonify(movie_list)

@app.route('/movie/api/v1.0/ratings', methods=['GET'])
def get_movie_rating():<commit_msg>Truncate recommendation list to reasonable number<commit_after>import logging

# flask
from flask import Flask, jsonify, request
import flask_cors

# Google
from google.cloud import datastore
from google.cloud.exceptions import ServiceUnavailable
import google.auth.transport.requests
import google.oauth2.id_token

# data
import numpy as np
from sklearn.metrics.pairwise import pairwise_distances

RATING_KIND = 'Rating'
MOVIE_KIND = 'Movie'
HTTP_REQUEST = google.auth.transport.requests.Request()

app = Flask(__name__)
flask_cors.CORS(app)
client = datastore.Client('cf-mr-service')

general_recommendation = []
user_rating = None
user_rating_split_size = 0
user_prediction = None
movie_info = {}

@app.route('/')
def hello():
    return ''

@app.route('/movie/api/v1.0/recommendation', methods=['GET'])
def recommend_movies():
    user_info = get_user_info()
    
    movie_list = []

    if user_info['index'] < 0:
        for m in general_recommendation:
            movie_list.append({
                'movie_id': m[2]
                })        
            if len(movie_list) >= 20:
                break
    elif user_info['index'] < user_rating.shape[0]:
        movies = []
        for i in xrange(user_rating.shape[1]):
            if user_rating[user_info['index']][i] == 0:
                movies.append((user_prediction[user_info['index']][i], i))

        movies.sort(reverse=True)        
        for m in movies:
            movie_list.append({
                'movie_id': m[1]
                })
            if len(movie_list) >= 20:
                break

    return jsonify(movie_list)

@app.route('/movie/api/v1.0/ratings', methods=['GET'])
def get_movie_rating():
{'fraction_non_alphanumeric': 0.12064676616915423, 'fraction_numerical': 0.008706467661691543, 'mean_word_length': 2.904126213592233, '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': '5725906', 'n_tokens_mistral': 1080, 'n_tokens_neox': 1019, 'n_words': 212}