Skip to content

Commit

Permalink
basic tracking features added
Browse files Browse the repository at this point in the history
  • Loading branch information
claire livingstone committed Aug 20, 2020
1 parent 873c355 commit 851d929
Show file tree
Hide file tree
Showing 43,802 changed files with 3,737,007 additions and 1 deletion.
The diff you're trying to view is too large. We only load the first 3000 changed files.
Binary file added .DS_Store
Binary file not shown.
69 changes: 68 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,68 @@
# habit-tracker
This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).

## Available Scripts

In the project directory, you can run:

### `npm start`

Runs the app in the development mode.<br />
Open [http://localhost:3000](http://localhost:3000) to view it in the browser.

The page will reload if you make edits.<br />
You will also see any lint errors in the console.

### `npm test`

Launches the test runner in the interactive watch mode.<br />
See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.

### `npm run build`

Builds the app for production to the `build` folder.<br />
It correctly bundles React in production mode and optimizes the build for the best performance.

The build is minified and the filenames include the hashes.<br />
Your app is ready to be deployed!

See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.

### `npm run eject`

**Note: this is a one-way operation. Once you `eject`, you can’t go back!**

If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project.

Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own.

You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it.

## Learn More

You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).

To learn React, check out the [React documentation](https://reactjs.org/).

### Code Splitting

This section has moved here: https://facebook.github.io/create-react-app/docs/code-splitting

### Analyzing the Bundle Size

This section has moved here: https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size

### Making a Progressive Web App

This section has moved here: https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app

### Advanced Configuration

This section has moved here: https://facebook.github.io/create-react-app/docs/advanced-configuration

### Deployment

This section has moved here: https://facebook.github.io/create-react-app/docs/deployment

### `npm run build` fails to minify

This section has moved here: https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify
1 change: 1 addition & 0 deletions backend/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ATLAS_URI = mongodb+srv://clivi0:Azuki4569@cluster0.lay9k.mongodb.net/<dbname>?retryWrites=true&w=majority
54 changes: 54 additions & 0 deletions backend/helpers/datesLogic.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
const onConsecutiveDays = (date1, date2) => {
const timeDiffHours =
(Date.parse(date1) - Date.parse(date2)) / (1000 * 60 * 60);
return timeDiffHours < 24;
};

const getStreak = (dates) => {
let currStreak = 0;
let i = dates.length - 1;
while (i >= 0) {
if (dates[i].completed) {
currStreak++;
i--;
} else {
break;
}
}
return currStreak;
};

const getLongestStreak = (dates) => {
let longestStreak = 0;
let currLongestStreak = 0;
console.log(dates.length);

for (let i = 0; i < dates.length; i++) {
if (dates[i].completed) {
//increase longest streak length
currLongestStreak++;
}
if (currLongestStreak >= longestStreak) {
longestStreak = currLongestStreak;
} else {
currLongestStreak = 0;
}
}
console.log("Longest streak: " + longestStreak);
return longestStreak;
};

const getPercentCompliance = (dates) => {
if (dates.length == 0) {
return 0;
}
let successfulDays = dates.filter((date) => date.completed);
return Math.round((100 * successfulDays.length) / dates.length);
};

module.exports = {
getStreak,
onConsecutiveDays,
getLongestStreak,
getPercentCompliance,
};
22 changes: 22 additions & 0 deletions backend/models/habit.model.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
const mongoose = require("mongoose");
const Schema = mongoose.Schema;

const habitSchema = new Schema({
username: { type: String, required: true },
name: { type: String, required: true },
startDate: { type: Date, required: true },
datesCompleted: [
{
date: { type: Date, required: true },
completed: { type: Boolean, required: true },
},
],
duration: { type: [Number], required: true },
streak: Number,
longestStreak: Number,
percentCompliance: Number,
});

var Habit = mongoose.model("Habit", habitSchema);

module.exports = Habit;
28 changes: 28 additions & 0 deletions backend/models/user.model.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
const mongoose = require("mongoose");
const Schema = mongoose.Schema;

const userSchema = new Schema(
{
username: {
type: String,
required: true,
trim: true,
minlength: 3,
},
password: {
type: String,
required: true,
},
email: {
type: String,
required: true,
},
},
{
timestamps: true,
}
);

var User = mongoose.model("User", userSchema);

module.exports = User;
1 change: 1 addition & 0 deletions backend/node_modules/.bin/mime

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions backend/node_modules/.bin/semver

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 851d929

Please sign in to comment.