<commit_before>#!/usr/bin/python3.6
import json
import logging
from lib import webutil as webutil
from lib.data import games as game_data

def create(event, context):
    logging.critical(event)
    data = json.loads(event['body'])

def all(event, context):
    logging.critical(event)

    size = event['queryStringParameters'].get('size', 25)
    page = event['queryStringParameters'].get('page', 0)
    player_id = event['queryStringParameters'].get('player_id', None)

    query_criteria = {}
    if player_id is not None:
        query_criteria['player_id'] = player_id

    games = game_data.games_in_range(query_criteria, size, page)

    response = {
        'games': list(games),
        'player_id': player_id,
        'size': size,
        'page': page
    }
    return webutil.respond_success_json(json.dumps(response))

def get(event, context):
    logging.critical(event)

    game_id = event['pathParameters']['id']
    game = game_data.game_by_id(game_id)
    if game is None:
        return webutil.respond_not_found('a game with that id does not exist')
    
    return webutil.respond_success_json(game)

def update(event, context):
    logging.critical(event)
    data = json.loads(event['body'])

def delete(event, context):
    logging.critical(event)

    game_id = event['pathParameters']['id']
    if not game_data.game_by_id(game_id):
        return webutil.respond_not_found('a game with that id does not exist')

    game_data.delete_game(game_id)

    return webutil.respond_success(game_id)<commit_msg>handle case in list_games where there are no query string parameters<commit_after>#!/usr/bin/python3.6
import json
import logging
from lib import webutil as webutil
from lib.data import games as game_data

def create(event, context):
    logging.critical(event)
    data = json.loads(event['body'])

def all(event, context):
    queryStringParameters = event.get('queryStringParameters', {})
    size = queryStringParameters.get('size', 25)
    page = queryStringParameters.get('page', 0)
    player_id = queryStringParameters.get('player_id', None)
    
    query_criteria = {}
    if player_id is not None:
        query_criteria['player_id'] = player_id

    games = game_data.games_in_range(query_criteria, size, page)

    response = {
        'games': list(games),
        'player_id': player_id,
        'size': size,
        'page': page
    }
    return webutil.respond_success_json(json.dumps(response))

def get(event, context):
    game_id = event['pathParameters']['id']
    game = game_data.game_by_id(game_id)
    if game is None:
        return webutil.respond_not_found('a game with that id does not exist')
    
    return webutil.respond_success_json(game)

def update(event, context):
    logging.critical(event)
    data = json.loads(event['body'])

def delete(event, context):
    game_id = event['pathParameters']['id']
    if not game_data.game_by_id(game_id):
        return webutil.respond_not_found('a game with that id does not exist')

    game_data.delete_game(game_id)

    return webutil.respond_success(game_id)
{'fraction_non_alphanumeric': 0.11378413524057217, 'fraction_numerical': 0.003250975292587776, 'mean_word_length': 3.815336463223787, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '4961956', 'n_tokens_mistral': 986, 'n_tokens_neox': 969, 'n_words': 226}