Exemple #1
0
    def update(id: int,
               name: str,
               age: int,
               weight: float,
               human: bool,
               hat_id: int = None) -> dict:
        """ Create character """
        result: dict = {}
        try:
            character = CharacterModel.query.get(id)
            character.name = name
            character.age = age
            character.weight = weight
            character.human = human
            character.hat_id = hat_id

            CharacterModel.commit()

            result = {
                'id': character.id,
                'name': character.name,
                'age': character.age,
                'weight': character.weight,
                'human': character.human,
                'hat_id': character.hat_id,
            }
        except IntegrityError:
            CharacterModel.rollback()
            # raise ResourceExists('user already exists')

        return result
Exemple #2
0
def add_item(event, context):
    logger.debug(f'Event received: {json.dumps(event)}')
    char_id = event['pathParameters']['id']

    print(event.get('body'))

    data = json.loads(event.get('body'))

    character = CharacterModel.get(char_id)

    if character is None:
        raise Exception('No character found')

    character.add_item(
        InventoryItemMap(id=data['id'],
                         equipped=False,
                         inv_id=str(uuid4()),
                         slot=data['slot'],
                         slot_name=data['slot_name'],
                         damage=data['damage'],
                         stamina=data['stamina'],
                         crit_chance=data['crit_chance']))

    response = {
        'statusCode': 200,
        'body': json.dumps(character, cls=ModelEncoder),
        'headers': {
            'Access-Control-Allow-Origin': '*'
        }
    }

    logger.debug(f'Response: {json.dumps(event)}')

    return response
Exemple #3
0
    def create(name: str,
               age: int,
               weight: float,
               human: bool,
               hat_id: int = None) -> dict:
        """ Create character """
        result: dict = {}
        try:
            # if hat_id is not None, check if exists, throw exception instead
            if hat_id is not None:
                hat = HatModel.query.get(hat_id)
                if hat is None:
                    raise ResourceDoesNotExist(
                        "Hat {} does not exist".format(hat_id))

            character = CharacterModel(name=name,
                                       age=age,
                                       weight=weight,
                                       human=human,
                                       hat_id=hat_id)
            character.save()

            result = {
                'id': character.id,
                'name': character.name,
                'age': character.age,
                'weight': character.weight,
                'human': character.human,
                'hat_id': character.hat_id,
            }
        except IntegrityError:
            CharacterModel.rollback()
            # raise ResourceExists('Character already exists')

        return result
Exemple #4
0
def create(event, context):
    logger.debug(f'Event received: {json.dumps(event)}')
    data = json.loads(event.get('body'))

    character = CharacterModel(id=str(uuid4()),
                               name=data.get('name'),
                               account=data.get('account', 'None'),
                               player_class=int(data.get('player_class')),
                               created_at=datetime.utcnow())

    character.save()

    response = {
        'statusCode': 200,
        'body': json.dumps(character, cls=ModelEncoder),
        'headers': {
            'Access-Control-Allow-Origin': '*'
        }
    }

    logger.debug(f'Response: {json.dumps(response)}')

    return response
Exemple #5
0
def get(event, context):
    logger.debug(f'Event received: {json.dumps(event)}')
    char_id = event['pathParameters']['id']

    character = CharacterModel.get(char_id)

    response = {
        'statusCode': 200,
        'body': json.dumps(character, cls=ModelEncoder),
        'headers': {
            'Access-Control-Allow-Origin': '*'
        }
    }

    return response
Exemple #6
0
def list(event, context):
    logger.debug(f'Event received: {json.dumps(event)}')

    characters = CharacterModel.scan()

    response = {
        'statusCode':
        200,
        'body':
        json.dumps({"characters": [x for x in characters]}, cls=ModelEncoder),
        'headers': {
            'Access-Control-Allow-Origin': '*'
        }
    }

    return response
Exemple #7
0
def equip_item(event, context):
    logger.debug((f'Event received: {json.dumps(event)}'))
    char_id = event['pathParameters']['id']

    data = json.loads(event.get('body'))

    character = CharacterModel.get(char_id)

    inv_id = data['inv_id']

    character.equip_item(inv_id)

    response = {
        'statusCode': 200,
        'body': json.dumps(character, cls=ModelEncoder),
        'headers': {
            'Access-Control-Allow-Origin': '*'
        }
    }

    logger.debug(f'Response: {json.dumps(response)}')

    return response
Exemple #8
0
def unequip_item(event, context):
    logger.debug(f'Event received: {json.dumps(event)}')
    char_id = event['pathParameters']['id']
    data = json.loads(event.get('body'))

    character = CharacterModel.get(char_id)

    if character is None:
        raise Exception('No character found')

    character.unequip_item(data.get('inv_id'))

    response = {
        'statusCode': 200,
        'body': json.dumps(character, cls=ModelEncoder),
        'headers': {
            'Access-Control-Allow-Origin': '*'
        }
    }

    logger.debug(f'Response: {json.dumps(event)}')

    return response
Exemple #9
0
def handler(event, context):
    logger.debug(f'Event received: {json.dumps(event)}')
    data = json.loads(event.get('body'))

    char_id = event['pathParameters']['id']

    character = CharacterModel.get(char_id)

    for item in character.inventory:
        item.inv_id = str(uuid4())

    character.save()

    response = {
        'statusCode': 200,
        'body': json.dumps(character, cls=ModelEncoder),
        'headers': {
            'Access-Control-Allow-Origin': '*'
        }
    }

    logger.debug(f'Response: {json.dumps(response)}')

    return response
Exemple #10
0
        char_train_dataset = CharacterDataset(train_texts,
                                              train_selected_texts,
                                              train_offsets,
                                              train_start_logits_list,
                                              train_end_logits_list)
        char_val_dataset = CharacterDataset(val_texts, val_selected_texts,
                                            val_offsets_list,
                                            val_start_logits_list,
                                            val_end_logits_list)

        char_train_loader = torch.utils.data.DataLoader(
            dataset=char_train_dataset,
            batch_size=config.batch_size,
            shuffle=False)
        char_val_loader = torch.utils.data.DataLoader(
            dataset=char_val_dataset,
            batch_size=config.batch_size,
            shuffle=False)

        dataloaders_dict = {'train': char_train_loader, 'val': char_val_loader}

        char_model = CharacterModel()
        char_model.to(device)

        optimizer = optim.AdamW(char_model.parameters(),
                                lr=config.character_lr,
                                betas=(0.9, 0.999))
        print('Training Character Model for fold ' + str(fold))
        train_character_model(char_model, device, dataloaders_dict, criterion,
                              optimizer, fold)
#!/bin/python3

# Imports
from models import CharacterModel

if __name__ == "__main__":
    model = CharacterModel()
    model.prepare_model(print_info=True)
    model.create_model()
    model.pattern_length = 100
    #model.train_model(batch_size=1024, epochs=100)

    model.load_weights('./generated_models/character-03-1.9901.hdf5')

    model.print_model_summary()
    print(model.generate_text_of_length(100, True))

Exemple #12
0
from uuid import uuid4

os.environ['ENV'] = '1'
os.environ['REGION'] = 'us-east-2'
os.environ['DYNAMODB_TABLE'] = 'CHARS'

from create import create
from add_item import add_item
from remove_item import remove_item
from get import get
from list import list
from models import CharacterModel, InventoryItemMap

if __name__ == "__main__":

    if not CharacterModel.exists():
        CharacterModel.create_table(read_capacity_units=100,
                                    write_capacity_units=100,
                                    wait=True)

    # request = {
    #     'body': json.dumps({
    #         'name': 'Chico',
    #         'player_class': 3
    #     })
    # }

    # response = create(request, None)

    # print('Created character')
    # print(response)