Skip to content

Commit

Permalink
Sleep data now queries and displays graph - next fix Insights && NaN …
Browse files Browse the repository at this point in the history
…values, Issue #30
  • Loading branch information
cfiguer055 committed Jul 1, 2024
1 parent 77602ee commit 15db9c8
Show file tree
Hide file tree
Showing 2 changed files with 554 additions and 173 deletions.
20 changes: 15 additions & 5 deletions SmartClothingApp/src/actions/userActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -390,14 +390,20 @@ export const deleteAccount = () => {
};
};


export const querySleepData = async (startDate, endDate) => {
try {
//get the user ID
const userId = auth.currentUser.uid;

console.log(`[querySleepData] - Start: ${new Date().toISOString()}`);
console.log('[querySleepData] - userId', userId);

//make a reference to the doc with the user ID
const userRef = doc(database, "Users", userId);

console.log('[querySleepData] - userRef', userRef);

// create a query to filter documents within the date range
const dataQuery = query(
collection(userRef, "SleepData"),
Expand All @@ -406,17 +412,21 @@ export const querySleepData = async (startDate, endDate) => {
orderBy("startDate", "asc")
);

console.log('[querySleepData] - dataQuery', dataQuery);

// Execute the query to get the result
const dataSnapshot = await getDocs(dataQuery);

const fetchedData = [];
dataSnapshot.forEach((doc) => {
const data = doc.data();
if (data.endTime >= startDate && data.endTime <= endDate) {
if (data.endDate >= startDate && data.endDate <= endDate) {
fetchedData.push({ ...data });
}
});

console.log('[querySleepData] - fetchedData', fetchedData);

return fetchedData;
} catch (error) {
console.error("Error fetching data: ", error);
Expand All @@ -430,12 +440,12 @@ export const queryHeartRateData = async (startDate, endDate) => {
const userId = auth.currentUser.uid;

console.log(`[queryHeartRateData] - Start: ${new Date().toISOString()}`);
console.log('queryHeartRateData - userId', userId);
console.log('[queryHeartRateData] - userId', userId);

//make a reference to the doc with the user ID
const userRef = doc(database, "Users", userId);

console.log('queryHeartRateData - userRef', userRef);
console.log('[queryHeartRateData] - userRef', userRef);

// Create a query to filter documents within the date range
const dataQuery = query(
Expand All @@ -444,7 +454,7 @@ export const queryHeartRateData = async (startDate, endDate) => {
where("date", "<=", endDate)
);

console.log('queryHeartRateData - dataQuery', dataQuery);
console.log('[queryHeartRateData] - dataQuery', dataQuery);

// execute the query to get the result
const dataSnapshot = await getDocs(dataQuery);
Expand All @@ -455,7 +465,7 @@ export const queryHeartRateData = async (startDate, endDate) => {
fetchedData.push({ ...doc.data() });
});

console.log('queryHeartRateData - fetchedData', fetchedData);
console.log('[queryHeartRateData] - fetchedData', fetchedData);

return fetchedData;
} catch (error) {
Expand Down
Loading

0 comments on commit 15db9c8

Please sign in to comment.