Giter Club home page Giter Club logo

projekt_zaliczenie_nosql's Introduction

Gierszewski Mikołaj

Projekt_zaliczenie_nosql

Ruby Driver

Wykorzystane dane:

Crime in Vancouver

Data of crimes in Vancouver (Canada) from 2003 to 2017 Columns:

  1. TYPE - Type of Crime - string
  2. YEAR - Year when the reported crime activity occurred - numeric
  3. MONTH - Month when the reported crime activity occurred - numeric
  4. DAY - Day when the reported crime activity occurred - numeric
  5. HOUR - Hour when the reported crime activity occurred - numeric
  6. MINUTE - Minute when the reported crime activity occurred - numeric
  7. HUNDRED_BLOCK - Generalized location of the report crime activity - numeric
  8. NEIGHBOURHOOD - Neighbourhood where the reported crime activity occurred - numeric
  9. X - Coordinate values projected in UTM Zone 10 - numeric
  10. Y - Coordinate values projected in UTM Zone 10 - numeric
  11. Latitude - Coordinate values converted to Latitude - numeric
  12. Longitude - Coordinate values converted to Longitude - numeric
TYPE YEAR MONTH DAY HOUR MINUTE HUNDRED_BLOCK NEIGHBOURHOOD X Y Latitude Longitude
Other Theft 2003 5 12 16 15 9XX TERMINAL AVE Strathcona 493906.5 5457452.47 49.26980201 -123.0837633
Other Theft 2003 5 7 15 20 9XX TERMINAL AVE Strathcona 493906.5 5457452.47 49.26980201 -123.0837633

Przygotowanie json z pliku crime.csv

./generowanie_json.sh

Import danych (wygenerowany json) do mongo:

./importowanie.sh

Utworzenie geo-indeksu

./ustaw_baze.rb

Tworzy geo_indeks potrzebny do skryptu punkty_w_okolicy.rb

coll.indexes.create_one( { "location"=> "2dsphere" } )

Pokolorowanie punktów geojson

./pokoloruj.rb

Użytkownik podaje typ przestępstwa i kolor na jaki mają być pokolorowane punkty na mapie oznaczające dane przestępstwo

Przykładowy pokolorowany geojson

Wypisanie przestępstw w podanej okolicy

./punkty_w_okolicy.rb

Pobiera długosc i szerokość geograficzną od użytkownika i liczy ilość zbrodni w okolicy ("$minDistance" : 1000, "$maxDistance" : 5000). Następnie skrypt pyta użytkownika czy zapisac w kolekcji crime_export wyszukane zbrodnie.

matched_crime = coll.find(
  {
    "location"=>
      { "$near"=>
        {
          "$geometry"=> { "type"=> "Point",  "coordinates"=> [ longitude_to_search.to_f, latitude_to_search.to_f ] },
          "$minDistance"=> 1000,
          "$maxDistance"=> 5000
        }
      }
   }
).limit(200).to_a

Wyliczanie centroidy podanego przez użytkownika przestępstwa

./centroid_crime.rb

Pobiera typ zbrodni i liczy centroide danego typu przestępstwa. Następnie wynik zapisuję w kolekcji.

ag = coll.aggregate([
	{"$match"=> {"properties.type_of_crime": type_to_search}},
  {"$replaceRoot"=> { newRoot: "$location" }},
  {"$project"=>	{ "type": 1, szerokosc: { "$arrayElemAt"=> [ "$coordinates", 0 ] },dlugosc: { "$arrayElemAt"=> [ "$coordinates", -1 ] }}},
  {"$group"=> { _id: type_to_search ,srednia_szerokosc: { "$avg" => "$szerokosc"}, srednia_dlugosc: { "$avg"=> "$dlugosc"} } }
] )

Wyświetla liczbę zbrodni każdego typu w wybranym miesiącu

./policz_w_miesiacu.rb

Pobiera rok i miesiąc od użytkownika a następnie wyświetla ilość zarejestrowanych przestępstw w wybranym czasie.

all_chosen_crimes = coll.find({ "properties.year"=> year_to_search.to_i,
"properties.month"=> month_to_search.to_i })

puts all_crimes.group_by{|e| e}.map{|k, v| [k, v.length]}.to_h

policz w miesiacu

Eksportuje dane z kolekcji crime_export do formatu geojson

./export_geojson.sh

Utworzony zostaje plik crime.geojson

Przykladowy GEOJSON

projekt_zaliczenie_nosql's People

Contributors

m111q avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.