Search in sources :

Example 16 with Category

use of model.db.Category in project amos-ss17-alexa by c-i-ber.

the class EditCategoriesService method contains.

private boolean contains(String categoryName) {
    // DynamoDbClient.instance.getItems(Category.TABLE_NAME, Category::new);
    List<Category> items = DynamoDbMapper.getInstance().loadAll(Category.class);
    categoryName = categoryName.toLowerCase();
    for (Category item : items) {
        if (StringUtils.getLevenshteinDistance(item.getName().toLowerCase(), categoryName) < 2) {
            return true;
        }
    }
    return false;
}
Also used : Category(model.db.Category)

Example 17 with Category

use of model.db.Category in project amos-ss17-alexa by c-i-ber.

the class AmosAlexaSimpleTestImpl method categoryStatusInfoIntentTest.

@Test
public void categoryStatusInfoIntentTest() throws IllegalAccessException, NoSuchFieldException, IOException {
    newSession();
    resetTestCategory();
    Category item = new Category(TEST_CATEGORY_NAME);
    DynamoDbMapper.getInstance().save(item);
    List<Category> categories = DynamoDbMapper.getInstance().loadAll(Category.class);
    Category category = null;
    for (Category cat : categories) {
        if (cat.getName().equals(TEST_CATEGORY_NAME)) {
            category = cat;
            break;
        }
    }
    // Set spending to 0 and limit to 100 for test purpose
    category.setLimit(100);
    BudgetManager.instance.createSpending(AccountData.ACCOUNT_DEFAULT, category.getId(), 5);
    DynamoDbMapper.getInstance().save(category);
    // LOGGER.info("getSpending: " + category.getSpending());
    // LOGGER.info("getLimit: " + category.getLimit());
    // Simple status test
    testIntent("CategoryStatusInfoIntent", "Category:" + TEST_CATEGORY_NAME, "Du hast bereits 5% des Limits von 100.0 Euro fuer die Kategorie " + TEST_CATEGORY_NAME + " ausgegeben. Du kannst noch" + " 95.0 Euro für diese Kategorie ausgeben.");
    BudgetManager.instance.createSpending(AccountData.ACCOUNT_DEFAULT, category.getId(), 145);
    // LOGGER.info("getSpending: " + category.getSpending());
    // LOGGER.info("getLimit: " + category.getLimit());
    // Simple status test
    testIntent("CategoryStatusInfoIntent", "Category:" + TEST_CATEGORY_NAME, "Du hast bereits 150% des Limits von 100.0 Euro fuer die Kategorie " + TEST_CATEGORY_NAME + " ausgegeben. Du kannst noch " + "0.0 Euro für diese Kategorie ausgeben.");
    resetTestCategory();
}
Also used : Category(model.db.Category) Test(org.junit.Test)

Example 18 with Category

use of model.db.Category in project amos-ss17-alexa by c-i-ber.

the class AmosAlexaSimpleTestImpl method categorySpendingTestIntent.

@Test
public void categorySpendingTestIntent() throws IllegalAccessException, NoSuchFieldException, IOException {
    newSession();
    resetTestCategory();
    Category item = new Category(TEST_CATEGORY_NAME);
    DynamoDbMapper.getInstance().save(item);
    List<Category> categories = DynamoDbMapper.getInstance().loadAll(Category.class);
    Category category = null;
    for (Category cat : categories) {
        if (cat.getName().equals(TEST_CATEGORY_NAME)) {
            category = cat;
            break;
        }
    }
    // Set limit to 100 for test purpose
    category.setLimit(100);
    DynamoDbMapper.getInstance().save(category);
    // Simple spending test
    testIntent("CategorySpendingIntent", "Category:" + TEST_CATEGORY_NAME, "Amount:5", "Okay. Ich habe 5 Euro fuer " + TEST_CATEGORY_NAME + " notiert.");
    // Spending 89 OK!
    testIntent("CategorySpendingIntent", "Category:" + TEST_CATEGORY_NAME, "Amount:84", "Okay. Ich habe 84 Euro fuer " + TEST_CATEGORY_NAME + " notiert.");
    // Spending 90 Warning!
    testIntent("CategorySpendingIntent", "Category:" + TEST_CATEGORY_NAME, "Amount:1", "Okay. Ich habe 1 Euro fuer " + TEST_CATEGORY_NAME + " notiert. Warnung! Du hast in diesem Monat bereits 90 Euro" + " fuer " + TEST_CATEGORY_NAME + " ausgegeben. Das sind 90% des Limits fuer diese Kategorie.");
    // Limit overrun warning
    testIntent("CategorySpendingIntent", "Category:" + TEST_CATEGORY_NAME, "Amount:20", "Warnung! Durch diese Aktion wirst du das Limit von 100 fuer die Kategorie " + TEST_CATEGORY_NAME + " ueberschreiten." + " Soll ich den Betrag trotzdem notieren?");
    testIntent("AMAZON.YesIntent", "Okay. Ich habe 20 Euro fuer " + TEST_CATEGORY_NAME + " notiert. Warnung! Du hast" + " in diesem Monat bereits 110 Euro fuer " + TEST_CATEGORY_NAME + " ausgegeben. Das sind 110% des Limits fuer diese Kategorie.");
    resetTestCategory();
}
Also used : Category(model.db.Category) Test(org.junit.Test)

Example 19 with Category

use of model.db.Category in project amos-ss17-alexa by c-i-ber.

the class ContactTransferService method transactionCategoryResponse.

private SpeechletResponse transactionCategoryResponse(Intent intent, Session session) {
    String categoryName = intent.getSlot(CATEGORY_SLOT) != null ? intent.getSlot(CATEGORY_SLOT).getValue().toLowerCase() : null;
    // DynamoDbClient.instance.getItems(Category.TABLE_NAME, Category::new);
    List<Category> categories = DynamoDbMapper.getInstance().loadAll(Category.class);
    for (Category category : categories) {
        if (category.getName().equals(categoryName)) {
            String transactionId = (String) session.getAttribute(TRANSACTION_ID_ATTRIBUTE);
            dynamoDbMapper.save(new TransactionDB(transactionId, "" + category.getId(), ACCOUNT_NUMBER));
            return getResponse(CONTACT_TRANSFER_CARD, "Verstanden. Die Transaktion wurde zur Kategorie " + categoryName + " hinzugefügt");
        }
    }
    return getResponse(CONTACT_TRANSFER_CARD, "Ich konnte die Kategorie nicht finden. Tschüss");
}
Also used : Category(model.db.Category) TransactionDB(model.db.TransactionDB)

Aggregations

Category (model.db.Category)19 Test (org.junit.Test)5 Slot (com.amazon.speech.slu.Slot)4 IOException (java.io.IOException)2 StandingOrder (model.banking.StandingOrder)2 Contact (model.db.Contact)2 Spending (model.db.Spending)2 TransactionDB (model.db.TransactionDB)2 Launcher (amosalexa.server.Launcher)1 AccountData (amosalexa.services.AccountData)1 ContactTransferService (amosalexa.services.bankaccount.ContactTransferService)1 BudgetManager (amosalexa.services.budgettracker.BudgetManager)1 AccountBalanceForecastService (amosalexa.services.financing.AccountBalanceForecastService)1 AffordabilityService (amosalexa.services.financing.AffordabilityService)1 TransactionForecastService (amosalexa.services.financing.TransactionForecastService)1 HelpService (amosalexa.services.help.HelpService)1 DynamoDbClient (api.aws.DynamoDbClient)1 DynamoDbMapper (api.aws.DynamoDbMapper)1 AccountAPI (api.banking.AccountAPI)1 TransactionAPI (api.banking.TransactionAPI)1