Skip to content

Latest commit

 

History

History
55 lines (46 loc) · 3.67 KB

README.md

File metadata and controls

55 lines (46 loc) · 3.67 KB

Ridesharing with your friends from work

Project Status: Active - The project has reached a stable, usable state and is being actively developed.

This repository contains the source code for an interactive app that allows for finding a friend from your work who can give you a lift there and back. Obviosuly the concept can be extended to any environment and adjusted to fit the purpose.

About

The app is built using R and Shiny web framework , utilizing Leaflet maps and Leaflet Routing Machine with custom tile from Mapbox.

Data source

Currently the dummy data are used and stored locally in .rds file.
Refer to this guideline on how to store data with Shiny applications.

The idea behind

In one sentence: show 3 nearest routes from home to work compared to my route.

Location of end point (office, work address) is already fixed on the map - 'Company headquarter'. A user is asked to enter their home location (address) to automatically plot the optimal route. The route should be then adjusted to reflect true way of communiting between home and work. Every adjustment adds new waypoint which is valuable for determining the nearest route.

The nearest route is chosen based on the minimum distance between home location (latitude and longitude) and routes (waypoints) of all other users in the database. The default metric is Euclidean distance, which can be changed to Manhattan, Quadrance or ordinary mathematical difference. The chosen metric is a measure of distance on a flat plane, and provides good approximation for distance calculation on a sphere for relatively small distances (say, up to 100 km). For exact distance one should use Harvesine formula or similar metric.

calculateDistance <- function(latLng, waypoints, method = "euclidean") {
  # calculate difference between two locations (home and all other stored route waypoints)
  waypointsDim <- dim(waypoints)[1]
  difference <- matrix(NA, nrow = waypointsDim, ncol = 2)
  for (i in c(1:waypointsDim) ) {
    difference[i,] <- latLng - waypoints[i,]
  }
  # select method for calculating the distance (default: Euclidean distance)
  if (method == "euclidean") minDistance <- min(sqrt(rowSums(difference^2)))
  else if (method == "manhattan") minDistance <- min(rowSums(abs(difference)))
  else if (method == "quadrance") minDistance <- min(rowSums(difference^2))
  else if (method == "differeces") minDistance <- min(difference) 
  else stop(sprint("Unknown method: %s", method))
  return(minDistance)
}

How to run the app

Online version is now up and running here: http://holek10.shinyapps.io/Ridesharing

To run the app locally you should install required packages: shiny, RJSONIO, and RCurl in R, for example:

if (!require('shiny')) install.packages("shiny")

and use the function runGithub() with specified repository name under my username:

shiny::runGitHub("Ridesharing", "holek10")

Licensing

The app is provided for free under GNU General Public License

TO DO :

The app is under development, and the following items are still on backlog:

  • every time user generates new route the old one should be overwritten/destroyed
  • remove routing control for 3 nearest routes (connected to first issue)
  • research method to combine RStudio Leaflet package with Leaflet Routing Machine (or wait until somebody comes up with R package for LRM :)