Commit f69bba75 authored by Christian Marius Lillelund's avatar Christian Marius Lillelund
Browse files

Merge branch 'master' of https://gitlab.au.dk/cfp/air

parents e8b5e276 ab649567
Pipeline #99980 passed with stage
in 4 minutes and 35 seconds
......@@ -25,7 +25,8 @@ app.use(express.urlencoded({ extended: true }));
};*/
const log = bunyan.createLogger({ name: "AIR_UI_Backend: " });
const predictionURL_training_fall = 'https://air-fastapi.azurewebsites.net/predict_training'
const predictionURL_training = 'https://air-fastapi.azurewebsites.net/predict_training'
const predictionURL_alarm = 'https://air-fastapi.azurewebsites.net/predict_alarm'
async function deleteVariable(variablesMarkedForDeletion) {
variablesMarkedForDeletion.forEach(element => {
......@@ -53,11 +54,20 @@ function dataPreparationForML(age, gender, assistiveAids, loanPeriod) {
}
}
async function getMLPrediction(inputForMLPrediction) {
predictionResult = axios.post(predictionURL_training_fall, inputForMLPrediction).then(result => {
async function getCompleteTrainingPrediction(inputForCompleteTrainingPrediction) {
predictionResult = axios.post(predictionURL_training, inputForCompleteTrainingPrediction).then(result => {
return result.data;
}).catch(error => {
log.error("getMLPrediction() threw an exception: ", error)
log.error("getCompleteTrainingPrediction() threw an exception: ", error)
})
return predictionResult
}
async function getAlarmPrediction(inputForAlarmPrediction) {
predictionResult = axios.post(predictionURL_alarm, inputForAlarmPrediction).then(result => {
return result.data;
}).catch(error => {
log.error("getAlarmPrediction() threw an exception: ", error)
})
return predictionResult
}
......@@ -120,18 +130,40 @@ app.post("/home/:ssn", async (req, res) => {
var sortedAssistiveAids = sortAssistiveAidsByDate(assistiveAidsWithCorrectDateFormat)
//console.log("SORTED AIDS BY DATE: ", sortedAssistiveAids)
//Case Complete Training
//console.log("SORTED AIDS BY DATE LENGTH: ", sortedAssistiveAids.length);
var assistiveAids = appendAssistiveAidsISO(sortedAssistiveAids);
//console.log("APPENDED AIDS: ", assistiveAids);
var assistiveAidsTraining = appendAssistiveAidsISO(sortedAssistiveAids);
//console.log("APPENDED AIDS: ", assistiveAidsTraining);
var loanPeriod = calculateMeanLoanPeriod(sortedAssistiveAids);
var inputDataForMLPrediction = dataPreparationForML(citizenData.age, citizenData.gender, assistiveAids, loanPeriod);
var citizenPrediction = await getMLPrediction(inputDataForMLPrediction);
//Case Alarm
var assistiveAidsWithoutAlarm = removeAlarmFromAssistiveAidsList(sortedAssistiveAids);
//console.log("APPENDED AIDS Without Alarm: ", assistiveAidsWithoutAlarm);
var assistiveAidsAlarm = appendAssistiveAidsISO(assistiveAidsWithoutAlarm);
//console.log("APPENDED AIDS Without Alarm: ", {assistiveAidsAlarm})
var inputForCompleteTrainingPrediction = dataPreparationForML(citizenData.age, citizenData.gender, assistiveAidsTraining, loanPeriod);
var inputForAlarmPrediction = dataPreparationForML(citizenData.age, citizenData.gender, assistiveAidsAlarm, loanPeriod);
var citizenCompleteTrainingPrediction = await getCompleteTrainingPrediction(inputForCompleteTrainingPrediction);
var citizenAlarmPrediction = await getAlarmPrediction(inputForAlarmPrediction);
convertDataSizeToKb("Combined datasize from both the ML Model and Database in Kb: ", { citizenData, citizenPrediction })
res.json({ citizenData, citizenPrediction })
await deleteVariable([citizenData, assistiveAidsWithCorrectDateFormat, sortedAssistiveAids, assistiveAids, loanPeriod, inputDataForMLPrediction, citizenPrediction])
}
//console.log("Alarm Prediction: ", citizenAlarmPrediction)
convertDataSizeToKb("Combined datasize from both the ML Model and Database in Kb: ", { citizenData, citizenCompleteTrainingPrediction, citizenAlarmPrediction })
res.json({ citizenData, citizenCompleteTrainingPrediction, citizenAlarmPrediction })
await deleteVariable([
citizenData,
assistiveAidsWithCorrectDateFormat,
sortedAssistiveAids,
assistiveAidsTraining,
loanPeriod,
inputForCompleteTrainingPrediction,
inputForAlarmPrediction,
citizenCompleteTrainingPrediction,
citizenAlarmPrediction
])
}
});
function changeLendDateFormat(assistiveAids) {
......@@ -160,6 +192,15 @@ function sortAssistiveAidsByDate(assistiveAids){
}
}
function removeAlarmFromAssistiveAidsList(assistiveAids) {
for( var i = 0; i < assistiveAids.length; i++) {
if ( assistiveAids[i].iso === '222718') {
assistiveAids.splice(i, 1);
}
}
return assistiveAids
}
function appendAssistiveAidsISO(assistiveAids) {
var assistiveAidsISOString = "";
for (var i = 0; i < assistiveAids.length; i++) {
......
......@@ -19,11 +19,11 @@ class DataService {
store.dispatch("trainingPlans", citizenInformation.data.citizenData.Training_Plans);
store.dispatch("homeCare", citizenInformation.data.citizenData.Home_Care);
store.dispatch("probabilityComplete", citizenInformation.data.citizenPrediction.CompleteProb);
store.dispatch("probabilityFall", citizenInformation.data.citizenPrediction.FallProb);
store.dispatch("probabilityExplanationComplete", citizenInformation.data.citizenPrediction.CompleteArguments);
store.dispatch("probabilityExplanationFall", citizenInformation.data.citizenPrediction.FallArguments);
store.dispatch("compliance", citizenInformation.data.citizenPrediction.ComplianceProb);
store.dispatch("probabilityComplete", citizenInformation.data.citizenCompleteTrainingPrediction.CompleteProb);
store.dispatch("probabilityFall", citizenInformation.data.citizenCompleteTrainingPrediction.FallProb);
store.dispatch("probabilityExplanationComplete", citizenInformation.data.citizenCompleteTrainingPrediction.CompleteArguments);
store.dispatch("probabilityExplanationFall", citizenInformation.data.citizenCompleteTrainingPrediction.FallArguments);
store.dispatch("compliance", citizenInformation.data.citizenCompleteTrainingPrediction.ComplianceProb);
return true;
}
}
......
......@@ -13,7 +13,7 @@ const trainingPlanStore: Module<any, any> = {
},
mutations: {
SET_TRAINING_PLAN(state, value) {
state.trainingPlans = getDefaultState;
state.trainingPlans = value;
},
RESET_STATE_TRAINING_PLAN(state) {
//state.trainingPlans = [];
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment