Skip to content

recreationx/CrAcIn

Repository files navigation


Logo

CRAC(K)IN Crime

Crime Activity Index (CrAcIn) Map

Table of Contents
  1. About The Project
  2. Getting Started
  3. Usage
  4. Methodology
  5. Roadmap
  6. Contact

About The Project

Mockup

(back to top)

Problem statement

Design a solution to seamlessly integrate crime hotspots analysis with patrol route optimization allowing law enforcement agencies to prioritize on higher crime risk areas and shorten emergency response times

Solution

Our team has developed the CRACIN (Crime Activity Index), which incorporates data on the severity, frequency, location, and timing of recent crimes. Using our CRACIN data as the base, our solution optimizes routes for patrolling policemen to be able to respond to emergencies by being as close as possible to various crime hotspots.

Building the solution

Our team opted to develop a website accessible via both computers and mobile devices, providing flexibility for law enforcement personnel on the move. We used HTML/CSS/JS on the front-end, leveraging the Leaflet library to construct the Singapore Map and display optimized routes for the law enforcement personnel. Subsequently, Python was employed at the back-end to sift through and handle data from our crafted sample database, creating the Crime Activity Index (CRACIN). Since real-time crime data is not accessible, we populated the database with sample data representing four regions of Singapore. We then integrated the open-source ORSM API to compute optimal routes. Utilizing CRACIN, we also generated a heatmap depicting crime activity density across localized regions, thereby highlighting areas prone to criminal incidents.

Refer to Methodology.

Built With

Frameworks/libraries used with this project:

Python Tailwind

Getting Started

To get a local copy up and running follow these simple example steps.

Prerequisites

It is recommended to run this within a virtual environment.

  • python
    virtualenv env
    source /bin/env/activate

Installation

  1. Clone the repo
    git clone https://github.com/recreationx/CrAcIn.git
  2. Install Python packages
    pip install -r requirements.txt
  3. Run project
    flask run --app main

Refer to Contributions for node.js related matters.

(back to top)

Usage

The demo application contains the following CRACIN codes for your testing: north, south, east, west and demo.

Mockup

The CRACIN code is a code that is provided to patrolling officers on duty. The CRACIN platform provides a graphical interface via a website for a patrolling officer to effectively visualize their route.

When the buttons Display and Heatmap are pressed, you will be able to see the following:

Mockup

The application assumes that the patrolling officer is driving. On the left, the sequence of the stops needed to be taken on the patrolling route is shown. On the right, the patrolling route is shown in blue, with markers labelling the stops required to be taken, and a heatmap indicating the crime intensity at that particular area.

(back to top)

Methodology

Crime Analysis

We simulate a set of crime data with 10 crimes, and assign them their relative weights, on a scale of 1-5. The weights are determined by the severity of the crime, and is an averaged value collected from a survey of 5 individuals.

        crime_weights = {
            "outrage_of_modesty": 3,
            "theft_in_dwelling": 2,
            "voyeurism": 3,
            "shop_theft": 1,
            "rape": 5,
            "murder": 5,
            "littering": 1,
            "jaywalking": 1,
            "traffic_accident": 2,
            "pickpocketing": 2,
        }

From there, we collect data about crimes in Singapore. As data is not available, we decided to simulate data points ourselves (15 coordinates within 4 different regions, particularly North, East, South and West). We intend to generate an accurate index of the crime intensity of an area, in which the following method is taken.

Mockup

We take a "grid" on the map, that is approximately 1 minute long along the latitude and longitude lines. From there, we collect data about crimes happening in that grid (denoted by X), specifically the type of crime and their frequency. We averaged the values to produce a generalized crime index for that area, which is then approximated to a single point O, which is the center of the grid square.

Example data:

latitude, longitude, outrage_of_modesty, theft_in_dwelling, voyeurism, shop_theft, rape, murder, littering, jaywalking, traffic_accident, pickpocketing
1.2818672, 103.8369766, 1, 1, 0, 2, 0, 0, 2, 2, 0, 0
1.2808705, 103.8444822, 1, 2, 1, 0, 0, 0, 1, 2, 1, 1

From there, the data is recorded using a CSV, with the intensity of each crime on a scale of 1 - 5, and the coordinates being the centre of each grid square. Data should be added to /data/ and loaded into the CRACIN platform (the filename is the code). We then calculate the final weightage and normalize the data to 0-1, to be viewed on a heatmap.

  • Code snippets from preprocess_data.py
        weighted_sum = sum(
            int(self.crime_severity[crime]) * crime_weights[crime]
            for crime in crime_weights
        )
        weighted_sums = [coords.get_weight() for coords in self.data]
        min_sum = min(weighted_sums)
        max_sum = max(weighted_sums)

        normalized_values = [
            (value - min_sum) / (max_sum - min_sum) for value in weighted_sums
        ]

This is then loaded into a visible heatmap, as seen above.

Route Optimization

The problem of planning the patrol route is a generalization of the Travelling Salesman Problem. We proposed to use TSP together with a genetic algorithm to obtain the best model where the values converge effectively. However, due to time constraints, we resort to using Open Source Routing Machine (OSRM) that provides an API to solve TSP for us. We query this API for all routing problems.

Roadmap

We hope to enhance the application further by adding support for different travel modes, such as walking and biking. This would largely increase the versatility of the application. We also hope to include an easy to use GUI that allows patrolling officers to easily drag-and-drop markers and plan the most effective route.

(back to top)

Contact

  • Zheng Nan - @recreationx
  • Damien
  • Glendon

Project Link: https://github.com/recreationx/CrAcIn

(back to top)

Note to contributors

For contributions, a package-lock.json file and package.json file is not provided in this repo.

  1. Install node.js
  2. Install tailwindcss and daisyUI. Refer to the websites for reference.
  • tailwind.config.js
    /** @type {import('tailwindcss').Config} */
    module.exports = {
      content: ["./templates/*.html", "./static/**/*.js"],
      theme: {
        extend: {},
      },
      plugins: [require("@tailwindcss/typography"), require("daisyui")],
      daisyui: {
        themes: ["dracula"],
      },
    };
    
  1. Follow the instructions on tailwind's site.

The project uses black as a Python formatter and Prettier for JS/CSS/HTML files.

About

Crime Activity Index (CrAcIn) Map

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published