Helsinki City Bike App

This repository contains pre-assignment for Solita Dev Academy Finland 2023.

Live demo of app is available at http://citybike.henkka.one/

API documentation is available at https://hvikman.github.io/helsinki-city-bike-app

Used technologies:

  • React 18.2.0 for frontend
  • Node.js 18.12.1, express 4.16.1 and MySQL 8 for backend
  • Python 3 for data validation

Backend is running in free version of Azure App Service at : https://henkkacitybike.azurewebsites.net/
Database is Azure Database for MySQL.

Table of Contents

Features

Data import

  • Import data from the CSV files to a database or in-memory storage
  • Validate data before importing
  • Don't import journeys that lasted for less than ten seconds
  • Don't import journeys that covered distances shorter than 10 meters

Journey list view

  • List journeys
  • For each journey show departure and return stations, covered distance in kilometers and duration in minutes
  • Pagination
  • Ordering per column
  • Searching
  • Filtering

Station list

  • List all the stations
  • Pagination
  • Ordering per column
  • Searching

Single station view

  • Station name
  • Station address
  • Total number of journeys starting from the station
  • Total number of journeys ending at the station
  • Station location on the map
  • The average distance of a journey starting from the station
  • The average distance of a journey ending at the station
  • Top 5 most popular return stations for journeys starting from the station
  • Top 5 most popular departure stations for journeys ending at the station
  • Ability to filter all the calculations per month

Installation

Backend

  1. Clone the repository:

    git clone https://github.com/HVikman/helsinki-city-bike-app.git
    
  2. Navigate to the backend directory:

    cd helsinki-city-bike-app/backend
    
  3. Install the required dependencies using npm:

    npm install
    
  4. Set up environment variables:

    • Create a .env file in the root of the backend directory.
    • Specify the required environment variables in the .env file. Refer to .env.example for the list of variables.
  5. Create a MySQL database for the backend:

    • Make sure you have a MySQL database server installed and running.

    • Open a terminal or command prompt.

  • Log in to the MySQL server using the command:
    mysql -u your_username -p
  • Create a new database
    CREATE DATABASE your_database_name;
  • Exit mysql
    EXIT;
  1. Import database

    mysql -u your_username -p your_database_name < create_db.sql
  2. Start backend

    npm start
    

    Backend will be running at http://localhost:4000 unless different port is specified in .env file.

Frontend

  1. Navigate to the frontend directory:

    cd helsinki-city-bike-app/frontend
    
  2. Install the required dependencies using npm:

    npm install
    
  3. Edit apiurl constant in /pages/JourneyList.js and /pages/StationList.js to your backend url.

  4. Build the frontend:

    npm run build

    Bundled files will be in build directory

Importing data

  1. Download three datasets of journey data. The data is owned by City Bike Finland.
  1. Download dataset that has information about Helsinki Region Transport’s (HSL) city bicycle stations.
  1. Ensure you have Python 3 installed on your system.

  2. Install the required Python dependencies:

    pip install -r requirements.txt
  3. Modify the script to have your database information and uncomment lines containing database insertion.

  4. Run the script:

    python data_importer.py

    The script will import the data into the Helsinki City Bike App's database.

Tests

Frontend tests

I have created quite a lot of tests for the frontend. You can run tests by:

  1. cd frontend
    
  2. npm test
    
  3. All tests should pass

Backend tests

There is only few backend tests, but you can run them:

  1. cd backend
  2. npx jest
  3. All tests should pass