Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
foo/
117 changes: 73 additions & 44 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,65 +1,94 @@
# Your Project Name
# Bus When
### [Bus When - Web App Link](https://nikitas-project2.herokuapp.com/)

This is the starter code for WDI projects. Please update this README file with information specific to your project. Replace this paragraph for instance, with a short description of your project. Then update the sections below. Refer to your project specificaion for instructions on how to submit your projects.
Link: nikitas-project2.herokuapp.com
Get bus stops nearby along with real time bus arrival data, on your phone on desktop.

## Getting Started

Provide instructions here about how to get your project running on our local machine. Do we just need to clone and open a certain file or do we need to install anything first.

### Prerequisites

What is needed to install and run the project, how do we install them

```
Code example
```

### How to Use
## Flowchart
<!-- ![Project Flowchart]('./P2-flowchart.jpg') -->

A step by step guide on how to install and use the project, for example if this is a game, how do we play it.
![project-2](readmedocs/flowchart.jpg)


```
Code example
```
## Tech Stack:
Express on Node
Mongoose on MongoDB
Javascript and Jquery
Bootstrap

More steps...
APIs
- LTA Transport Data
- Google Maps
- [Navigator.geolocation webapi](https://developer.mozilla.org/en-US/docs/Web/API/Navigator/geolocation)
- [Web Speech webapi](https://developer.mozilla.org/en-US/docs/Web/API/Web_Speech_API)

```
until finished
```


## Tests

Did you write automated tests? If so, how do we run them.
Packages: Handlebars, Moment, bcrypt, request-promise-native etc

## Getting Started
To run locally, get API keys and add to env
1. [Transport API](https://www.mytransport.sg/content/mytransport/home/dataMall.html)
2. [Google Maps API (optional)](https://developers.google.com/maps/documentation/static-maps/intro)

```
Code example
```
Installation
1. Install yarn/npm
2. Run yarn init
3. Yarn add all – to install all dependencies found in package.json file
4. Restore from collection hosted here: [stops.bson](http://s000.tinyupload.com/?file_id=72779861239136983602)
OR run ‘<host>/load/stops’ which will load bus stops from API

## Live Version

Where is this deployed online (github pages, heroku etc), give us the link and any access details we need.
### User Stories

## Built With
1. As a busy student, I want to check bus timings on stop near my place so I can plan my route on the go.
E.g. Do I take bus 5 to GA from Eunos Link or 8/22 to MRT from bedok Reservoir Road.

What did you use to build it, list the technologies, plugins, gems, packages etc.
2. As a busy commuter, I want to use my voice to check bus timings instead of tapping commands on the phone as I’m gathering my things to save time and leave quickly.

* [jQuery](http://jquery.com/) - jQuery for example is something you likely used

## Workflow

Did you write user stories, draw wireframes, use task tracking, produce ERDs? Did you use source control, with regular commits? Include links to them here.
### ERD
![ERD](readmedocs/BWERD291017.png)

## Authors
### Wireframes
![Authentication](readmedocs/auth-desktop.png)

Did you collaborate with others on this project, list them here

* **John McClain** - *Responsible for keeping vests white* - [GithubUserName](https://github.com/GithubUserName)
![App](readmedocs/dash.png)
### Routes
```
(‘/home’)
GET /
POST /

('/login')
Get /
Post /

('/register')
Get /
Post /

('stop/:code')
GET /

('/load/stops')
GET /
('/load/serviceFromRoutes')
GET / (Phase 2)

('/save/stops/:code')
GET /
('/save/bus/:code’)
GET / (Phase 2)
```

## Acknowledgments

* Hat tip to anyone who's code was used, for example [this was a useful starting point for creating this template](https://gist.github.com/PurpleBooth/109311bb0361f32d87a2).

Many thanks to Alex and Prima for tireless help in the project.

## Phase 2
1. Store location in session, and clear with set my location button. So between toggling pages, the data persists in a session
2. Saved bus stops - show on dashboard(home) even if not nearby (reference for route planning)
3. Saved buses - show on dashboard(home) if its stop is available nearby
4. Show all saved stops and buses, with ability to remove
5. Add search for bus or stop with voice support
6. More voice commands supported
34 changes: 34 additions & 0 deletions config/ppConfig.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
const passport = require('passport');
const LocalStrategy = require('passport-local').Strategy
const User = require('../models/user');

passport.serializeUser(function(user, done) {
done(null, user.id);
});
passport.deserializeUser(function(id, done) {
User.findById(id, function(err, user) {
done(err, user);
});
});
passport.use(new LocalStrategy({
usernameField: 'user[email]',
passwordField: 'user[password]'
}, function(email, password, done) {
User.findOne({
email: email
}, function(err, user) {
if (err) return done(err);

// If no user is found
if (!user) return done(null, false);
user.validPassword(password, (err, isMatch) => {
if (err) return done(null, false)
if (isMatch) return done(null, user)
return done(null, false, {
message: 'passwords dont match'
})
})
});
}));

module.exports = passport;
33 changes: 33 additions & 0 deletions helpers/distance.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
//calculate distance between coords in meters
//Haversine formula example from:
//https://stackoverflow.com/questions/29118745/get-nearest-latitude-and-longitude-from-array/29119331
function toRad(x) {
return x * Math.PI / 180;
}
function distance(position1,position2){
var lat1=position1.latitude;
var lat2=position2.latitude;
var lon1=position1.longitude;
var lon2=position2.longitude;
var R = 6371000; // metres
var φ1 = toRad(lat1);
var φ2 = toRad(lat2)
var Δφ = toRad(lat2-lat1)
var Δλ = toRad(lon2-lon1)
// console.log(Δφ, Δλ);
// var φ2 = lat2.toRad;
// var Δφ = (lat2-lat1).toRad;
// var Δλ = (lon2-lon1).toRad;
//
var a = Math.sin(Δφ/2) * Math.sin(Δφ/2) +
Math.cos(φ1) * Math.cos(φ2) *
Math.sin(Δλ/2) * Math.sin(Δλ/2);
// console.log(a);
var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
// console.log(c);

var d = R * c;
// console.log(d);
return d;
}
module.exports = distance
24 changes: 24 additions & 0 deletions helpers/findNearest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//need to req distance?
const distance = require('./distance.js')
var findNearest = (stops, loc) => {
stops.sort(function compare(a, b) {
if (distance(loc, a) < distance(loc, b)) {
return -1;
}
if (distance(loc, a) > distance(loc, b)) {
return 1;
}
return 0;
})
var stopDistArr = []
for (var i = 0; i < 5; i++) {
stopDistArr.push({
stop: stops[i],
dist: distance(loc, stops[i])
})
}
console.log(stopDistArr);
return stopDistArr
} //end findNearest

module.exports = findNearest
25 changes: 25 additions & 0 deletions helpers/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// if user hasLoggedOut, but try to access routes that's not
//redirect ot home page
// if not let the routes run the actual logic
const isLoggedIn = (req, res, next) => {
if(req.user) {
res.redirect('/')
} else {
next()
}
}

// same as function hasLoggedOut()....
// the opposite of the function above
const hasLoggedOut = (req, res, next) => {
if(req.user) {
next()
} else {
res.redirect('/')
}
}

module.exports = {
hasLoggedOut,
isLoggedIn
}
Loading