- Pobranie surowych danych ze strony: Wikipedia - raw data
- Import danych do Google-Refine
- Oczyszczenie danych w licznych krokach (wybranie interesujących nas danych)
- Export danych do postaci JSON
{
"_id" : ObjectId("51837819d9175361bffb10bd"),
"country" : "Czech",
"description" : "",
"latitude_degress" : 48,
"latitude_direction" : "N",
"latitude_minutes" : 49,
"latitude_seconds" : 0,
"longitude_degress" : 14,
"longitude_minutes" : 19,
"longitude_seconds" : 0,
"longtitude_direction" : "E",
"site" : "Historic Centre of Český Krumlov",
"type" : "Cultural",
"year" : "1992"
}
Więcej: Klik.
mongoimport --db test2 --collection unesco --file data/json/unesco_eastern_europe.json
unesco.find.each { |x|
latitude = (x["latitude_seconds"] || 0)/3600.to_f
+ (x["latitude_minutes"] || 0)/60.to_f
+ (x["latitude_degress"] || 0)
longitude = (x["longitude_seconds"] || 0)/3600.to_f
+ (x["longitude_minutes"] || 0)/60.to_f
+ (x["longitude_degress"] || 0)
unesco.update({ "_id" => x["_id"]} ,
{'$set' => {'location' => [latitude, longitude]}}
)
}
Link to skrytu: Klik.
gdansk_location = [54.366667, 18.633333]
unesco.aggregate([
{'$geoNear' => {
near: gdansk_location,
distanceField: 'distance',
limit: 10
}},
{'$sort' => {
distance: 1
}},
{'$project' => {
_id: 0,
site: '$site',
country: '$country',
location: '$location',
distance: '$distance'
}}
])
Wynik zwrócony ze skryptu:
Legenda do mapki:
- Castle of the Teutonic Order in Malbork (51.54 km)
- Medieval Town of Toruń (135.67 km)
- Curonian Spit (249.98 km)
- Historic Centre of Warsaw (317.3 km)
- Centennial Hall in Wrocław (361.22 km)
- Churches of Peace in Jawor and Świdnica (411.27 km)
- Auschwitz Birkenau, German Nazi Concentration and Extermination Camp (1940-1945) (435.93 km)
- Cracow's Historic Centre (449.99 km)
- Wieliczka Salt Mine (461.48 km)
- Kalwaria Zebrzydowska: the Mannerist Architectural and Park Landscape Complex and Pilgrimage Park (461.71 km)
unesco.aggregate([ {'$group' => {_id: '$country', count: {'$sum' => 1}}},
{'$sort' => {count: -1}},
{'$project' => {_id: 0, country: '$_id', count: '$count'}},
{'$limit' => 5}
])
Wynik zwrócony ze skryptu:
car_market.aggregate([ {'$group' => { _id: '$make', avg_price: {'$avg' => '$price'}}} ,
{'$project' => {_id: 0, make: '$_id', avg_price: '$avg_price'}},
{'$sort' => { avg_price: -1 }},
{'$limit' => 10}
])
Wynik zwrócony ze skryptu:
cheapest_model_in_make = []
car_market.aggregate([
{'$group' => { _id: '$make', min_price: {'$min' => '$price'}}},
{'$project' => {_id: 0, make: '$_id', min_price: '$min_price', model: '$model'}},
{'$sort' => { min_price: 1 }}
]).each{|x| cheapest_model_in_make << car_market.find({price: x['min_price'], make: x['make']}).first }
Wynik zwrócony ze skryptu:
Make | Model | Price |
---|---|---|
daewoo | lanos s | 8999 |
hyundai | accent l | 9434 |
suzuki | swift ga | 9499 |
chevrolet | metro | 9585 |
kia | sephia | 10445 |
toyota | echo | 10450 |
saturn | sl | 11125 |
honda | civic cx | 11165 |
nissan | sentra xe | 12169 |
mitsubishi | mirage de | 12182 |
ford | escort zx2 | 12200 |
mazda | protégé dx | 12420 |
dodge | neon highline | 12970 |
plymouth | neon highline | 12970 |
pontiac | sunfire se | 14515 |
volkswagen | golf gl | 15425 |
subaru | impreza l | 16390 |
oldsmobile | alero gx | 16555 |
chrysler | cirrus lx | 16625 |
mercury | mystique gs | 16705 |
acura | integra ls | 19755 |
buick | century custom | 20285 |
infiniti | g20 | 21920 |
volvo | s40 1.9t | 23475 |
audi | a4 1.8t | 24515 |
saab | 9-3 | 26475 |
bmw | 323i | 27560 |
cadillac | catera | 31500 |
lexus | es300 | 31900 |
lincoln | ls v6 | 32275 |
mercedes-benz | c230 kompressor | 32395 |
porsche | boxter | 42195 |
jaguar | s-type 3.0 | 43095 |