Financial people normally use calculator devices even for simple calculation to grantee the quality and speed of having the result. You can see this in banks' tilers, stores' cashiers or even with usual people.
This skill will handle mathematics equation whatever its long. Operations that allowed to be used is +, -, *, /, log & square root
Voice User Interface DiagramSample of communication between user & Alexa
user: Alexa, find calculated result for Add five plus six
Alexa: Total = eleven . add more calculation to existing result or say equal to finish.
user: minus ten
Alexa: Total = one . add more calculation to existing result or say equal to finish.
user: multiply by eight
Alexa: Total = eight . add more calculation to existing result or say equal to finish.
user: divide by two
Alexa: Total = four . add more calculation to existing result or say equal to finish.
user: plus log one thousand base ten
Alexa: Total = seven . add more calculation to existing result or say equal to finish.
user: equal
Alexa: Result = seven. Good byeCreating Skill
Amazon avail easy tutorials to create skill & lambda function. To create Skill, Lambda function and trigger lambda using the skill follow steps in trivia skill tutorial
Skill Interaction model
Each operation has 2 intents, one for new equation and the 2nd for old equation.
for example in case of "Add" operation, sample of Utterances. As you can see in New equation two operands are needed while in old equation only one operand is needed as Result from new equation is used as implicit operand in old equation
AddNewEqIntent find calculated result for Add {operand_first} plus {operand_second}
AddNewEqIntent Add {operand_first} plus {operand_second}
AddOldEqIntent Add {operand_first}
AddOldEqIntent plus {operand_first}
Related intent schema will be
{
"slots": [
{
"name": "operand_first",
"type": "AMAZON.NUMBER"
},
{
"name": "operand_second",
"type": "AMAZON.NUMBER"
}
],
"intent": "AddNewEqIntent"
},
{
"slots": [
{
"name": "operand_first",
"type": "AMAZON.NUMBER"
}
],
"intent": "AddOldEqIntent"
}
Some operations will need 2 operands in new equation and some need only one operand (like in "square root" operation).
SqrtNewEqIntent square root {operand_first}
Result of execution of the operation will be saved in "Result" variable.
In case of old equation, most operations need only one operand as the 2nd operand will be the "Result" variable. However operation like "log" will always need 2 operands
LogNewEqIntent log {operand_first} base {operand_second}
LogOldEqIntent {connector} log {operand_first} base {operand_second}
Lambda function
All new equations will be handled the same inside the code
if ("AddNewEqIntent" === intentName) {
handleNewEquationRequest(ADD_OPERATION, event, context, intent, session, callback);
} else if ("SubNewEqIntent" === intentName) {
handleNewEquationRequest(SUB_OPERATION, event, context, intent, session, callback);
} else if ("MultiplyNewEqIntent" === intentName) {
handleNewEquationRequest(MULTIPLY_OPERATION, event, context, intent, session, callback);
} else if ("DivideNewEqIntent" === intentName) {
handleNewEquationRequest(DIVIDE_OPERATION, event, context, intent, session, callback);
} else if ("LogNewEqIntent" === intentName) {
handleNewEquationRequest(LOG_OPERATION, event, context, intent, session, callback);
} else if ("SqrtNewEqIntent" === intentName) {
handleNewEquationRequest(SQRT_OPERATION, event, context, intent, session, callback);
}
"handleNewEquationRequest" function will reset the "Result" value inside the session object and add the net of new calculation to "Result"
session.attributes.Result = 0;
if ((operationType === ADD_OPERATION) && !isNaN(operand_first) && !isNaN(operand_second)) {
session.attributes.Result = operand_first + operand_second;
} else if ((operationType === SUB_OPERATION) && !isNaN(operand_first) && !isNaN(operand_second)) {
session.attributes.Result = operand_first - operand_second;
} else if ((operationType === MULTIPLY_OPERATION) && !isNaN(operand_first) && !isNaN(operand_second)) {
session.attributes.Result = operand_first * operand_second;
} else if ((operationType === DIVIDE_OPERATION) && !isNaN(operand_first) && !isNaN(operand_second)) {
session.attributes.Result = operand_first / operand_second;
} else if ((operationType === LOG_OPERATION) && !isNaN(operand_first) && !isNaN(operand_second)) {
session.attributes.Result = math.log(operand_first, operand_second);
} else if ((operationType === SQRT_OPERATION) && !isNaN(operand_first)) {
session.attributes.Result = math.sqrt(operand_first);
}
Same concept will be applied for adding extra part to the equation. Difference only in using old "Result" value in our calculation as a 2nd operand.
Certification in UKSkill name is "Calculate Result" is certified since 14 June 2017 in English U.K. languages in all countries & regions where Amazon distributes skills.
Future Steps- Adding more functionality to Alexa calculator to support significant operations.
- Support saving result with name and retrieve it in new equations using this name
Comments