Skip to content
This repository has been archived by the owner on Feb 28, 2022. It is now read-only.

Commit

Permalink
DB Fixed & Add Metric page fixed!
Browse files Browse the repository at this point in the history
Issue #1 & #4 fixed.
  • Loading branch information
Ttiki committed Dec 4, 2021
1 parent 88b7f41 commit b23a099
Show file tree
Hide file tree
Showing 9 changed files with 600 additions and 77 deletions.
2 changes: 1 addition & 1 deletion SuiviSante.pro
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ DISTFILES += \
qml/pages/GraphTest.qml \
qml/pages/SecondPage.qml \
qml/pages/About.qml \
qml/pages/AddMetric.qml \
qml/pages/History.qml \
qml/pages/Profile_Settings.qml \
qml/js/util.js \
qml/js/d3.js \
qml/js/utils.js \
qml/pages/Weight.qml \
rpm/SuiviSante.changes.in \
rpm/SuiviSante.changes.run.in \
rpm/SuiviSante.spec \
Expand Down
4 changes: 2 additions & 2 deletions SuiviSante.pro.user
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject>
<!-- Written by QtCreator 4.15.2, 2021-12-01T20:55:57. -->
<!-- Written by QtCreator 4.15.2, 2021-12-04T16:20:58. -->
<qtcreator>
<data>
<variable>EnvironmentId</variable>
Expand Down Expand Up @@ -229,7 +229,7 @@
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.1">
<value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">QtProjectManager.QMakeBuildStep</value>
<value type="bool" key="QtProjectManager.QMakeBuildStep.QMakeForced">false</value>
<value type="bool" key="QtProjectManager.QMakeBuildStep.QMakeForced">true</value>
<valuelist type="QVariantList" key="QtProjectManager.QMakeBuildStep.SelectedAbis"/>
</valuemap>
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.2">
Expand Down
12 changes: 8 additions & 4 deletions qml/js/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,19 @@ function info_user(user_code) {
metric_code = rs.rows.item(0).METRIC;
}

//Récupérer les informations sur le poids de l'utilisateur dans la BD
rs = tx.executeSql('SELECT * FROM METRICS WHERE USER_CODE=? AND CATEGORIE=? AND METRIC_CODE=?',[user_code,"WEIGHT",metric_code]);
if (rs.rows.length > 0) {
user_weight = parseFloat(rs.rows.item(0).VAL);
user_bmi = parseFloat(rs.rows.item(0).VAL2);
}

user_height_m = user_height / 100
height_square = (user_height_m * user_height_m)
if ((user_weight > 0) && (user_height > 0)) {
user_bmi = user_weight / height_square;
//Récupérer les informations sur le poids de l'utilisateur dans la BD
rs = tx.executeSql('SELECT * FROM METRICS WHERE USER_CODE=? AND CATEGORIE=? AND METRIC_CODE=?',[user_code,"SLEEP",metric_code]);
if (rs.rows.length > 0) {
user_sleepTime = parseFloat(rs.rows.item(0).VAL);
user_wakeTime = parseFloat(rs.rows.item(0).VAL2);
user__totalTime = parseFloat(rs.rows.items(0).VAL3);
}

arrayData = {
Expand Down
147 changes: 83 additions & 64 deletions qml/pages/AddMetric.qml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ import QtQuick.LocalStorage 2.0
import "../js/utils.js" as WtUtils

Page {
id: newMetric
id: page
backNavigation: true
allowedOrientations: Orientation.All

property string metric_code;
property string user_code;

property variant wtData;
property string sleepTimeVal;
property string wakeTimeVal;
Expand All @@ -36,13 +37,12 @@ Page {
}

function calculateSleepTotal(sleepTime, wakeTime) {
sleepTotal = sleepTime - wakeTime;
//TODO: Sleep total time calc

}

function addSleepMetric(sleepTime, wakeTime){
//sleepTime = sleepTime.replace(',', '.');
//wakeTime = wakeTime.replace(',', '.');

//load user_code from homepage, if(depth==3)adding from history else from homepage
//if(depth==3) user_code=previousPage().rootPage.user_code;
//else user_code=previousPage().user_code;
Expand Down Expand Up @@ -71,6 +71,7 @@ Page {


function addWeightMetric(value){
print(user_code)
value = value.replace(',', '.');
//load user_code from homepage, if(depth==3)adding from history else from homepage
//if(depth==3) user_code=previousPage().rootPage.user_code;
Expand All @@ -88,7 +89,7 @@ Page {
date = Qt.formatDate(date, "yyyy-MM-dd");

var imc = calculateBMI()
rs = tx.executeSql('INSERT INTO METRICS VALUES (?,?,?,?,?,?)',[user_code,metric_code,date,"WEIGHT",value, imc]);
rs = tx.executeSql('INSERT INTO METRICS VALUES (?,?,?,?,?,?,null)',[user_code,metric_code,date,"WEIGHT",value, imc]);
rs = tx.executeSql('SELECT * FROM METRICS WHERE USER_CODE=?',[user_code]);
}
)
Expand Down Expand Up @@ -116,63 +117,79 @@ Page {

anchors.fill: parent
contentHeight: column.height
}

Column {
id: mainColumn
x: Theme.paddingLarge
width:page.width
spacing: Theme.paddingLarge
Column {
id: mainColumn
x: Theme.paddingLarge
width:page.width
spacing: Theme.paddingLarge

PageHeader{
title: qsTr("Add metric")
}

///////////////////////////////////////////////////////////////
// Page pour rajouter une données de type WEIGHT dans la BD //
///////////////////////////////////////////////////////////////
Component {
id: weightPage

Dialog {
canAccept: weightMetricField.text!=""
acceptDestination: page
acceptDestinationAction: PageStackAction.Pop

Flickable {
width: parent.width
height: parent.height

Column {
id: dialogColumn
x: Theme.paddingLarge
width: page.width
spacing: Theme.paddingLarge

PageHeader { title: 'Add new weight metric' }

TextField {
id: weightMetricField
width: parent.width
inputMethodHints: Qt.ImhFormattedNumbersOnly
label: "kg"
placeholderText: "Weight"
EnterKey.iconSource: "image://theme/icon-m-enter-next"
PageHeader{
title: qsTr("Add a new metric")
}

validator: RegExpValidator { regExp: /^\d+([\.|,]\d{1,2})?$/ }
focus: true
}
Button {
text: 'Add'
anchors.horizontalCenter: parent.horizontalCenter
enabled:weightMetricField.acceptableInput
onClicked: addWeightMetric(weightMetricField.text)
Label {
text: qsTr("You can add your metric here")
width:page.width
color: Theme.secondaryHighlightColor
}
Label {
text: qsTr("At the moment you can add:")
width:page.width
color: Theme.secondaryHighlightColor
}
Label {
text: qsTr("Your weight to get your BMI calculated")
width:page.width
color: Theme.secondaryHighlightColor
}
Label {
text: qsTr("Your sleep shcedule to track your sleep regularity")
width:page.width
color: Theme.secondaryHighlightColor
}
///////////////////////////////////////////////////////////////
// Page pour rajouter une données de type WEIGHT dans la BD //
///////////////////////////////////////////////////////////////
Component {
id: weightPage

Dialog {
canAccept: weightMetricField.text!=""
acceptDestination: page
acceptDestinationAction: PageStackAction.Pop

Flickable {
width: parent.width
height: parent.height

Column {
id: weightDialogColumn
x: Theme.paddingLarge
width: page.width
spacing: Theme.paddingLarge

DialogHeader { title: 'Add new weight metric' }

TextField {
id: weightMetricField
width: parent.width
inputMethodHints: Qt.ImhFormattedNumbersOnly
label: "kg"
placeholderText: "Weight"
EnterKey.iconSource: "image://theme/icon-m-enter-next"

validator: RegExpValidator { regExp: /^\d+([\.|,]\d{1,2})?$/ }
focus: true
}
}
}
onAccepted: {
addWeightMetric(weightMetricField.text)
rootPage.load();
}
}
}
}


///////////////////////////////////////////////////////////////
// Page pour rajouter une données de type SLEEP dans la BD //
Expand All @@ -181,7 +198,7 @@ Page {
id: sleepPage

Dialog {
canAccept: sleepTime.text!="" && wakeTime.text!=""
canAccept: weightMetricField.text!=""
acceptDestination: page
acceptDestinationAction: PageStackAction.Pop

Expand All @@ -190,14 +207,15 @@ Page {
height: parent.height

Column {
id: dialogColumn
id: sleepDialogColumn
x: Theme.paddingLarge
width: page.width
spacing: Theme.paddingLarge

PageHeader { title: 'Add new sleep metric' }

Button {

id: sleepTime
text: "Choose a sleeping time"

Expand All @@ -209,6 +227,7 @@ Page {
})
dialog.accepted.connect(function() {
sleepTimeVal = dialog.timeText
sleepTime.text = "Choose a sleeping time: " + dialog.timeText
})
}
}
Expand All @@ -224,18 +243,18 @@ Page {
})
dialog.accepted.connect(function() {
wakeTimeVal = dialog.timeText
wakeTimeVal.text = "Choose a waking time: " + dialog.timeText
})
}
}
Button {
text: 'Add'
anchors.horizontalCenter: parent.horizontalCenter
enabled:sleepMetricField.acceptableInput, wakeMetricField.acceptableInput
onClicked: addSleepMetric(sleepTimeVal, wakeTimeVal.text)
}
}
}
}
}
}
Component.onCompleted:{
user_code = WtUtils.getLastUser()
print(user_code)
}
}
}
}
Loading

0 comments on commit b23a099

Please sign in to comment.