From bb4ee470d946d199aa6955467d381a8df3016957 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Nils=20Norman=20Hauk=C3=A5s?=
- Din anbefalte dose: {{ recommendedDose }} -
+Blodsukkermål: {{ bloodsugarGoal }}
+ +Din anbefalte dose: {{ roundToNearestHalf(recommendedDose) }}
+Bakgrunnstall: {{ recommendedDose }}
@@ -23,17 +27,42 @@ name: 'DosageCalculator', data() { return { - bloodsugar: null, - carbohydrates: null + measuredBloodsugar: null, + plannedCarbohydratesIntake: null, + isTrainingMode: false } }, computed: { recommendedDose: function () { - const result = this.bloodsugar + this.carbohydrates + const { IKValue, IFValue } = this.$store.state + const {measuredBloodsugar, plannedCarbohydratesIntake, bloodsugarGoal} = this + const result = plannedCarbohydratesIntake / IKValue + (measuredBloodsugar - bloodsugarGoal) / IFValue return result ? result : 0 }, + bloodsugarGoal: function () { + const defaultBloodSugarGoal = 5 + const trainingBloodsugarGoal = 8 + return this.isTrainingMode ? trainingBloodsugarGoal : defaultBloodSugarGoal + }, disableInputFields: function () { return !(this.$store.state.IKValue && this.$store.state.IFValue) + }, + shouldShowCalculation: function () { + return this.measuredBloodsugar !== null || this.plannedCarbohydratesIntake !== null + } + }, + methods: { + roundToNearestHalf: function (num) { + const decimals = num % 1 + let adjustment = 0.0 + if (decimals >= 0.3 && decimals <= 0.7) { + adjustment = 0.5 + } else if (decimals > 0.7) { + adjustment = 1.0 + } else if (decimals < 0.3) { + adjustment = 0.0 + } + return (num - decimals) + adjustment } } } diff --git a/src/components/UserSettings.vue b/src/components/UserSettings.vue index d569b02..6ded9f8 100644 --- a/src/components/UserSettings.vue +++ b/src/components/UserSettings.vue @@ -1,16 +1,15 @@