Skip to content

Slange-Mhath/reporting-service

Repository files navigation

Report-Service API

FastAPI SQLite Python macOs Linux Docker Swagger-UI

Pytest Black

Table of Contents
  1. About
  2. Getting Started
  3. Usage

About

This small web application helps collecting and analysing data about applications for funding to identify trends and patterns.

This is a dummy project and not intended to be used in production. It exclusively serves the purpose to develop my FastAPI and Python skills further

The system providing the data via an API accepts form submissions from our grants system, each application has a set of fields which describe the research the application is intended for.

  • Written in Python3+

  • Accepts a GET request over HTTP

  • Does not require authentication (it will be deployed internally)

  • Returns a JSON (i.e. application/json) response containing a sumulative report about the grant applications

  • The report that the service returns should contain the following information

  • The total number of submitted, approved and rejected applications per research area

  • For each of the past 12 months, the total submitted, approved, and rejected applications in each month

  • For each of the past 12 months, the sum of funding we approved in each month based on the applications data.

  • The average time in (days) between an application being received (submitted) and an outcome (approved or rejected)

  • A list of application ids which have not been actioned in more than 60 days from their submitted date (i.e. they are still in the submitted state).

Getting Started

Dependencies

This code is developed and tested to be deployed on macOS or Linux. It is not tested on Windows. I recommend using the Installation with Docker for Windows users.

  • Python Version 3.10
  • SQLAlchemy Version 2.0.8
  • FastAPI 0.95.0
  • Python-dateutil 2.8.2

To install all dependencies navigate into the project folder and run:

pip install -r requirements.txt

Installation

  1. Clone the repo

    git clone git@github.com:Slange-Mhath/reporting-service.git
  2. Navigate into the project directory

    cd reporting-service
  3. Set the API_TOKEN as environment variable

    export API_TOKEN=your_api_token
  4. Run uvicorn to start the server

    uvicorn main:app --reload

Using Docker

If you want to run this service in a Docker Container, no problem at all!

  1. Clone the repo
    git clone git@github.com:Slange-Mhath/reporting-service.git
    
  2. Navigate into the project directory
    cd reporting-service
  3. Build the Docker image
     docker build -t reporting-service .
  4. Run the Docker container providing the API_TOKEN as environment variable and
    docker run -e API_TOKEN=YOUR-API-TOKEN -d --name my-reporting-service -p 
    8000:8000 reporting-service
  5. After a couple of minutes you should be able to access your container at http://127.0.0.1:8000/

Usage

Quick Start via Bash Script

To start up the server and get ready to request the report simply run:

./start_service.sh

This might take a couple of minutes if you run the command for the first time, as the DB needs to be filled by the requested data. You will then see the message:

"110000 applications successfully loaded into database."

Now you can access the endpoint in your browser http://127.0.0.1:8000/report/

Manual Start

You can of course also start the server and load the data manually by running the following commands:

uvicorn main:app --reload

and accessing:

Endpoints

[GET] http://127.0.0.1:8000/report/

Again, be aware that, if you access the endpoint for the first time, it might take a couple of minutes until you get a response.

If you want to update the data (e.g. when the data provided by the application changes) you can access the endpoint:

[POST] http://127.0.0.1:8000/load_applications/

If you are curious about the available endpoints have a look at the:

Swagger UI http://127.0.0.1:8000/docs

or

ReDoc UI at http://127.0.0.1:8000/redoc

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages