Actions

MAPREDUCE Elite: Difference between revisions

From NoSQLZoo

No edit summary
No edit summary
Line 14: Line 14:
</pre>
</pre>
==Introducing the elite database **WORK IN PROGRESS==
==Introducing the elite database **WORK IN PROGRESS==
These questions will introduce the "elite" database, which contains data about the video game [https://www.elitedangerous.com/ Elite Dangerous]<br/>
These questions will introduce the "elite" database, which contains data about the video game [https://www.elitedangerous.com/ Elite Dangerous]<br/><br/>
There are two collections, <code>commodities</code> and <code>systems</code>. Inside <code>systems</code> there is are nested documents called <code>stations</code><br/>
There are two collections, <code>commodities</code> and <code>systems</code>. Inside <code>systems</code> there is are nested documents called <code>stations</code><br/>
A <b>system</b> has many <b>stations</b>, and a <b>station</b> imports,exports, and bans many <b>commodities</b>
A <b>system</b> has many <b>stations</b>, and a <b>station</b> imports,exports, and bans many <b>commodities</b>
<br/><br/>
<br/><br/>
Though it could, <code>commodities</code> does not make use of nested documents and the average document looks something like this.
==Document Structure==
Unlike the previous examples, here we'll be using nested documents. A nested document is simply a document that contains other documents, for example:
<pre>
[{"name":"Jim",
  "role":"Dad",
  "age": 42,
  "children":[{"name":"Bob", "age":2},
              {"name":"Alice", "age":3}
            ]
}]       
</pre>
Another change from the previous example is that <code>null</code> and empty values are no longer stored.<br/>
This means that some documents will have fields that others do not. Some systems will be uninhabited and have no stations. Some stations will have no listings.<br/>
To query null <b>or</b> non-existant fields we use <code><field>: null</code><br/><br/>
The average <code>commodities</code> document looks something like this.
<pre>
<pre>
{
{
Line 27: Line 41:
}
}
</pre>
</pre>
<code>systems</code> look like this. For readability this example only has one station.
<code>systems</code> is much bigger, <div class=hint title="click here to show it.">
<pre>
<pre>
{
{
         "_id" : ObjectId("55afa14a369fd51c351f1cb8"),
         "_id" : ObjectId("55b0cef2369fd55b7d4489ed"),
         "stations" : [
         "stations" : [
                {
                        "max_landing_pad_size" : "M",
                        "has_blackmarket" : 0,
                        "has_commodities" : 1,
                        "updated_at" : 1434929486,
                        "has_outfitting" : 0,
                        "government" : "Democracy",
                        "has_shipyard" : 0,
                        "type" : "Unknown Outpost",
                        "faction" : "",
                        "has_rearm" : 0,
                        "allegiance" : "Federation",
                        "has_refuel" : 1,
                        "name" : "Kinsey Ring",
                        "listings" : [
                                {
                                        "commodity" : "Hydrogen Fuel",
                                        "supply" : 129630,
                                        "collected_at" : 1421669319,
                                        "update_count" : "1",
                                        "buy_price" : 93,
                                        "sell_price" : 89,
                                        "demand" : 0
                                },
                                {
                                        "commodity" : "Mineral Oil",
                                        "supply" : 0,
                                        "collected_at" : 1421669320,
                                        "update_count" : "1",
                                        "buy_price" : 0,
                                        "sell_price" : 326,
                                        "demand" : 217674
                                },
                        ],
                        "distance_to_star" : 2359,
                        "economies" : [
                                "Industrial",
                                "Refinery"
                        ],
                        "has_repair" : 1
                },
                 {
                 {
                         "max_landing_pad_size" : "L",
                         "max_landing_pad_size" : "L",
                         "has_blackmarket" : 0,
                         "has_blackmarket" : 1,
                         "has_commodities" : 0,
                         "has_commodities" : 0,
                         "updated_at" : 1430931780,
                         "updated_at" : 1434929486,
                        "id" : 5611,
                         "has_outfitting" : 1,
                         "has_outfitting" : 1,
                         "government" : "Patronage",
                         "government" : "Democracy",
                        "state" : "None",
                        "system_id" : 1,
                         "has_shipyard" : 1,
                         "has_shipyard" : 1,
                         "type" : "Unknown Starport",
                         "type" : "Unknown Starport",
                        "prohibited_commodities" : [
                         "faction" : "",
                                "Narcotics",
                                "Combat Stabilisers",
                                "Slaves",
                                "Personal Weapons",
                                "Battle Weapons",
                                "Toxic Waste"
                        ],
                         "faction" : "Empire League",
                         "has_rearm" : 1,
                         "has_rearm" : 1,
                         "allegiance" : "Empire",
                         "allegiance" : "Federation",
                         "has_refuel" : 1,
                         "has_refuel" : 1,
                         "name" : "Smoot Gateway",
                         "name" : "Wohler Port",
                        "export_commodities" : [
                         "distance_to_star" : 3520,
                                "Water Purifiers",
                                "Bauxite",
                                "Rutile"
                        ],
                        "listings" : [ ],
                         "distance_to_star" : 4761,
                        "import_commodities" : [
                                "Polymers",
                                "Aluminium",
                                "Leather"
                        ],
                         "economies" : [
                         "economies" : [
                                 "Extraction",
                                 "Industrial",
                                 "Industrial"
                                 "Refinery"
                         ],
                         ],
                         "has_repair" : 1
                         "has_repair" : 1
                 }
                 }
         ],
         ],
         "name" : "1 G. Caeli",
         "name" : "1 Kappa Cygni",
         "faction" : "Empire League",
         "faction" : "United 1 Kappa Cygni Future",
         "government" : "Patronage",
         "government" : "Democracy",
         "allegiance" : "Empire",
         "allegiance" : "Federation",
         "updated_at" : 1430931668,
         "updated_at" : 1430938622,
         "state" : "None",
         "state" : "None",
         "needs_permit" : 0,
         "needs_permit" : 0,
         "y" : -83.53125,
         "y" : 37.78125,
         "x" : 80.90625,
         "x" : -117.75,
         "security" : "Medium",
         "security" : "High",
         "z" : -30.8125,
         "z" : 11.1875,
         "primary_economy" : "Industrial",
         "primary_economy" : "Industrial",
        "id" : 1,
         "population" : 24843190
         "population" : 6544826
}
}
</pre>
</pre>
<div class=hint title="a full list of keys used in the elite dangerous database">
Finally, here is a list of all the keys used.
<pre>
<pre>
     Commodities: "_id", "name", "average_price", "category"
     commodities:  
     Systems:
        _id, average_price, category, name
         "_id",
     systems:  
        "allegiance",
         _id, allegiance, faction, government, name, population, primary_economy, security, state, stations, updated_at, x, y, z
        "faction",
 
        "government",
    systems.stations:  
        "id",
         allegiance, distance_to_star, economies, export_commodities,has_blackmarket, has_commodities, has_rearm, has_repair,
        "name",
         has_shipyard, has_outfitting, faction, government, listings, max_landing_pad, name, state, type, updated_at
        "needs_permit",
 
        "population",
    systems.stations.listings:
        "power_control_faction",
         buy_price, collected_at, demand, commodity, sell_price, supply, update_count
        "primary_economy",
       
        "security",
        "state",
        "stations",
        "updated_at",
        "x",
        "y",
        "z"
  Systems.stations:
         "allegiance",
        "government",
        "has_blackmarket",
        "has_commodities",
        "has_outfitting",
        "has_rearm",
        "has_refuel",
        "has_repair",
         "has_shipyard",
        "import_commodities",
        "export_commodities",
        "max_landing_pad",
        "name",
        "state",
         "updated_at",
      quit 
</pre>
</pre>
</div>

Revision as of 12:41, 23 July 2015

#ENCODING
import io
import sys
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-16')
#MONGO
from pymongo import MongoClient
client = MongoClient()
client.progzoo.authenticate('scott','tiger')
db = client['progzoo']
#PRETTY
import pprint
pp = pprint.PrettyPrinter(indent=4)

Introducing the elite database **WORK IN PROGRESS

These questions will introduce the "elite" database, which contains data about the video game Elite Dangerous

There are two collections, commodities and systems. Inside systems there is are nested documents called stations
A system has many stations, and a station imports,exports, and bans many commodities

Document Structure

Unlike the previous examples, here we'll be using nested documents. A nested document is simply a document that contains other documents, for example:

[{"name":"Jim",
  "role":"Dad",
  "age": 42,
  "children":[{"name":"Bob", "age":2},
              {"name":"Alice", "age":3}
             ]
}]        

Another change from the previous example is that null and empty values are no longer stored.
This means that some documents will have fields that others do not. Some systems will be uninhabited and have no stations. Some stations will have no listings.
To query null or non-existant fields we use <field>: null

The average commodities document looks something like this.

{
        "_id" : ObjectId("55af74e7402aa43f1ce7e3a3"),
        "name" : "Explosives",
        "average_price" : 267,
        "category" : "Chemicals"
}

systems is much bigger,

{
        "_id" : ObjectId("55b0cef2369fd55b7d4489ed"),
        "stations" : [
                {
                        "max_landing_pad_size" : "M",
                        "has_blackmarket" : 0,
                        "has_commodities" : 1,
                        "updated_at" : 1434929486,
                        "has_outfitting" : 0,
                        "government" : "Democracy",
                        "has_shipyard" : 0,
                        "type" : "Unknown Outpost",
                        "faction" : "",
                        "has_rearm" : 0,
                        "allegiance" : "Federation",
                        "has_refuel" : 1,
                        "name" : "Kinsey Ring",
                        "listings" : [
                                {
                                        "commodity" : "Hydrogen Fuel",
                                        "supply" : 129630,
                                        "collected_at" : 1421669319,
                                        "update_count" : "1",
                                        "buy_price" : 93,
                                        "sell_price" : 89,
                                        "demand" : 0
                                },
                                {
                                        "commodity" : "Mineral Oil",
                                        "supply" : 0,
                                        "collected_at" : 1421669320,
                                        "update_count" : "1",
                                        "buy_price" : 0,
                                        "sell_price" : 326,
                                        "demand" : 217674
                                },
                        ],
                        "distance_to_star" : 2359,
                        "economies" : [
                                "Industrial",
                                "Refinery"
                        ],
                        "has_repair" : 1
                },
                {
                        "max_landing_pad_size" : "L",
                        "has_blackmarket" : 1,
                        "has_commodities" : 0,
                        "updated_at" : 1434929486,
                        "has_outfitting" : 1,
                        "government" : "Democracy",
                        "has_shipyard" : 1,
                        "type" : "Unknown Starport",
                        "faction" : "",
                        "has_rearm" : 1,
                        "allegiance" : "Federation",
                        "has_refuel" : 1,
                        "name" : "Wohler Port",
                        "distance_to_star" : 3520,
                        "economies" : [
                                "Industrial",
                                "Refinery"
                        ],
                        "has_repair" : 1
                }
        ],
        "name" : "1 Kappa Cygni",
        "faction" : "United 1 Kappa Cygni Future",
        "government" : "Democracy",
        "allegiance" : "Federation",
        "updated_at" : 1430938622,
        "state" : "None",
        "needs_permit" : 0,
        "y" : 37.78125,
        "x" : -117.75,
        "security" : "High",
        "z" : 11.1875,
        "primary_economy" : "Industrial",
        "population" : 24843190
}

Finally, here is a list of all the keys used.

    commodities: 
        _id, average_price, category, name
    systems: 
        _id, allegiance, faction, government, name, population, primary_economy, security, state, stations, updated_at, x, y, z

    systems.stations: 
        allegiance, distance_to_star, economies, export_commodities,has_blackmarket, has_commodities, has_rearm, has_repair,
        has_shipyard, has_outfitting, faction, government, listings, max_landing_pad, name, state, type, updated_at

    systems.stations.listings: 
        buy_price, collected_at, demand, commodity, sell_price, supply, update_count
        
  • You have been served by: dill