diff --git a/Pipfile b/Pipfile new file mode 100644 index 00000000..7130fb71 --- /dev/null +++ b/Pipfile @@ -0,0 +1,12 @@ +[[source]] +name = "pypi" +url = "https://pypi.org/simple" +verify_ssl = true + +[dev-packages] + +[packages] +pandas = "*" + +[requires] +python_version = "3.7" diff --git a/Pipfile.lock b/Pipfile.lock new file mode 100644 index 00000000..44573363 --- /dev/null +++ b/Pipfile.lock @@ -0,0 +1,90 @@ +{ + "_meta": { + "hash": { + "sha256": "fba383031295c98ef4ac605996144102d686f2d38c5a20f33ee0bebae0713200" + }, + "pipfile-spec": 6, + "requires": { + "python_version": "3.7" + }, + "sources": [ + { + "name": "pypi", + "url": "https://pypi.org/simple", + "verify_ssl": true + } + ] + }, + "default": { + "numpy": { + "hashes": [ + "sha256:0172304e7d8d40e9e49553901903dc5f5a49a703363ed756796f5808a06fc233", + "sha256:34e96e9dae65c4839bd80012023aadd6ee2ccb73ce7fdf3074c62f301e63120b", + "sha256:3676abe3d621fc467c4c1469ee11e395c82b2d6b5463a9454e37fe9da07cd0d7", + "sha256:3dd6823d3e04b5f223e3e265b4a1eae15f104f4366edd409e5a5e413a98f911f", + "sha256:4064f53d4cce69e9ac613256dc2162e56f20a4e2d2086b1956dd2fcf77b7fac5", + "sha256:4674f7d27a6c1c52a4d1aa5f0881f1eff840d2206989bae6acb1c7668c02ebfb", + "sha256:7d42ab8cedd175b5ebcb39b5208b25ba104842489ed59fbb29356f671ac93583", + "sha256:965df25449305092b23d5145b9bdaeb0149b6e41a77a7d728b1644b3c99277c1", + "sha256:9c9d6531bc1886454f44aa8f809268bc481295cf9740827254f53c30104f074a", + "sha256:a78e438db8ec26d5d9d0e584b27ef25c7afa5a182d1bf4d05e313d2d6d515271", + "sha256:a7acefddf994af1aeba05bbbafe4ba983a187079f125146dc5859e6d817df824", + "sha256:a87f59508c2b7ceb8631c20630118cc546f1f815e034193dc72390db038a5cb3", + "sha256:ac792b385d81151bae2a5a8adb2b88261ceb4976dbfaaad9ce3a200e036753dc", + "sha256:b03b2c0badeb606d1232e5f78852c102c0a7989d3a534b3129e7856a52f3d161", + "sha256:b39321f1a74d1f9183bf1638a745b4fd6fe80efbb1f6b32b932a588b4bc7695f", + "sha256:cae14a01a159b1ed91a324722d746523ec757357260c6804d11d6147a9e53e3f", + "sha256:cd49930af1d1e49a812d987c2620ee63965b619257bd76eaaa95870ca08837cf", + "sha256:e15b382603c58f24265c9c931c9a45eebf44fe2e6b4eaedbb0d025ab3255228b", + "sha256:e91d31b34fc7c2c8f756b4e902f901f856ae53a93399368d9a0dc7be17ed2ca0", + "sha256:ef627986941b5edd1ed74ba89ca43196ed197f1a206a3f18cc9faf2fb84fd675", + "sha256:f718a7949d1c4f622ff548c572e0c03440b49b9531ff00e4ed5738b459f011e8" + ], + "version": "==1.18.5" + }, + "pandas": { + "hashes": [ + "sha256:034185bb615dc96d08fa13aacba8862949db19d5e7804d6ee242d086f07bcc46", + "sha256:0c9b7f1933e3226cc16129cf2093338d63ace5c85db7c9588e3e1ac5c1937ad5", + "sha256:1f6fcf0404626ca0475715da045a878c7062ed39bc859afc4ccf0ba0a586a0aa", + "sha256:1fc963ba33c299973e92d45466e576d11f28611f3549469aec4a35658ef9f4cc", + "sha256:29b4cfee5df2bc885607b8f016e901e63df7ffc8f00209000471778f46cc6678", + "sha256:2a8b6c28607e3f3c344fe3e9b3cd76d2bf9f59bc8c0f2e582e3728b80e1786dc", + "sha256:2bc2ff52091a6ac481cc75d514f06227dc1b10887df1eb72d535475e7b825e31", + "sha256:415e4d52fcfd68c3d8f1851cef4d947399232741cc994c8f6aa5e6a9f2e4b1d8", + "sha256:519678882fd0587410ece91e3ff7f73ad6ded60f6fcb8aa7bcc85c1dc20ecac6", + "sha256:51e0abe6e9f5096d246232b461649b0aa627f46de8f6344597ca908f2240cbaa", + "sha256:698e26372dba93f3aeb09cd7da2bb6dd6ade248338cfe423792c07116297f8f4", + "sha256:83af85c8e539a7876d23b78433d90f6a0e8aa913e37320785cf3888c946ee874", + "sha256:982cda36d1773076a415ec62766b3c0a21cdbae84525135bdb8f460c489bb5dd", + "sha256:a647e44ba1b3344ebc5991c8aafeb7cca2b930010923657a273b41d86ae225c4", + "sha256:b35d625282baa7b51e82e52622c300a1ca9f786711b2af7cbe64f1e6831f4126", + "sha256:bab51855f8b318ef39c2af2c11095f45a10b74cbab4e3c8199efcc5af314c648" + ], + "index": "pypi", + "version": "==1.0.4" + }, + "python-dateutil": { + "hashes": [ + "sha256:73ebfe9dbf22e832286dafa60473e4cd239f8592f699aa5adaf10050e6e1823c", + "sha256:75bb3f31ea686f1197762692a9ee6a7550b59fc6ca3a1f4b5d7e32fb98e2da2a" + ], + "version": "==2.8.1" + }, + "pytz": { + "hashes": [ + "sha256:a494d53b6d39c3c6e44c3bec237336e14305e4f29bbf800b599253057fbb79ed", + "sha256:c35965d010ce31b23eeb663ed3cc8c906275d6be1a34393a1d73a41febf4a048" + ], + "version": "==2020.1" + }, + "six": { + "hashes": [ + "sha256:30639c035cdb23534cd4aa2dd52c3bf48f06e5f4a941509c8bafd8ce11080259", + "sha256:8b74bedcbbbaca38ff6d7491d76f2b06b3592611af620f8426e82dddb04a5ced" + ], + "version": "==1.15.0" + } + }, + "develop": {} +} diff --git a/Unit-3-Sprint-Challenge-2/.gitkeep b/Unit-3-Sprint-Challenge-2/.gitkeep new file mode 100644 index 00000000..8b137891 --- /dev/null +++ b/Unit-3-Sprint-Challenge-2/.gitkeep @@ -0,0 +1 @@ + diff --git a/Unit-3-Sprint-Challenge-2/challenge.md b/Unit-3-Sprint-Challenge-2/challenge.md new file mode 100644 index 00000000..003aa386 --- /dev/null +++ b/Unit-3-Sprint-Challenge-2/challenge.md @@ -0,0 +1,144 @@ +# Data Science Unit 3 Sprint Challenge 2 + +## Databases and SQL + +A SQL Query walks into a bar. In one corner of the bar are two tables. The Query +walks up to the tables and asks: + +... + +*"Mind if I join you?"* + +--- + +In this sprint challenge you will write code and answer questions related to +databases, with a focus on SQL but an acknowledgment of the broader ecosystem. +You may use any tools and references you wish, but your final code should +reflect *your* work and be saved in `.py` files (*not* notebooks), and (along +with this file including your written answers) turned in directly to your TL. + +For all your code, you may only import/use the following: +- other modules you write +- `sqlite3` (from the standard library) + +As always, make sure to manage your time - get a section/question to "good +enough" and then move on to make sure you do everything. You can always revisit +and polish at the end if time allows. + +This file is Markdown, so it may be helpful to open with VS Code or another tool +that allows you to view it nicely rendered. + +Good luck! + +### Part 1 - Making and populating a Database + +Consider the following data: + +| s | x | y | +|-----|---|---| +| 'g' | 3 | 9 | +| 'v' | 5 | 7 | +| 'f' | 8 | 7 | + +Using the standard `sqlite3` module: + +- Open a connection to a new (blank) database file `demo_data.sqlite3` +- Make a cursor, and execute an appropriate `CREATE TABLE` statement to accept + the above data (name the table `demo`) +- Write and execute appropriate `INSERT INTO` statements to add the data (as + shown above) to the database + +Make sure to `commit()` so your data is saved! The file size should be non-zero. + +Then write the following queries (also with `sqlite3`) to test: + +- Count how many rows you have - it should be 3! +- How many rows are there where both `x` and `y` are at least 5? +- How many unique values of `y` are there (hint - `COUNT()` can accept a keyword + `DISTINCT`)? + +Your code (to reproduce all above steps) should be saved in `demo_data.py` and +added to the repository along with the generated SQLite database. + +### Part 2 - The Northwind Database + +Using `sqlite3`, connect to the given `northwind_small.sqlite3` database. + +![Northwind Entity-Relationship Diagram](./northwind_erd.png) + +Above is an entity-relationship diagram - a picture summarizing the schema and +relationships in the database. Note that it was generated using Microsoft +Access, and some of the specific table/field names are different in the provided +data. You can see all the tables available to SQLite as follows: + +```python +>>> curs.execute("SELECT name FROM sqlite_master WHERE type='table' ORDER BY +name;").fetchall() +[('Category',), ('Customer',), ('CustomerCustomerDemo',), +('CustomerDemographic',), ('Employee',), ('EmployeeTerritory',), ('Order',), +('OrderDetail',), ('Product',), ('Region',), ('Shipper',), ('Supplier',), +('Territory',)] +``` + +*Warning*: unlike the diagram, the tables in SQLite are singular and not plural +(do not end in `s`). And you can see the schema (`CREATE TABLE` statement) +behind any given table with: +```python +>>> curs.execute('SELECT sql FROM sqlite_master WHERE name="Customer";').fetchall() +[('CREATE TABLE "Customer" \n(\n "Id" VARCHAR(8000) PRIMARY KEY, \n +"CompanyName" VARCHAR(8000) NULL, \n "ContactName" VARCHAR(8000) NULL, \n +"ContactTitle" VARCHAR(8000) NULL, \n "Address" VARCHAR(8000) NULL, \n "City" +VARCHAR(8000) NULL, \n "Region" VARCHAR(8000) NULL, \n "PostalCode" +VARCHAR(8000) NULL, \n "Country" VARCHAR(8000) NULL, \n "Phone" VARCHAR(8000) +NULL, \n "Fax" VARCHAR(8000) NULL \n)',)] +``` + +In particular note that the *primary* key is `Id`, and not `CustomerId`. On +other tables (where it is a *foreign* key) it will be `CustomerId`. Also note - +the `Order` table conflicts with the `ORDER` keyword! We'll just avoid that +particular table, but it's a good lesson in the danger of keyword conflicts. + +Answer the following questions (each is from a single table): + +- What are the ten most expensive items (per unit price) in the database? +- What is the average age of an employee at the time of their hiring? (Hint: a + lot of arithmetic works with dates.) +- (*Stretch*) How does the average age of employee at hire vary by city? + +Your code (to load and query the data) should be saved in `northwind.py`, and +added to the repository. Do your best to answer in purely SQL, but if necessary +use Python/other logic to help. + +### Part 3 - Sailing the Northwind Seas + +You've answered some basic questions from the Northwind database, looking at +individual tables - now it's time to put things together, and `JOIN`! + +Using `sqlite3` in `northwind.py`, answer the following: + +- What are the ten most expensive items (per unit price) in the database *and* + their suppliers? +- What is the largest category (by number of unique products in it)? +- (*Stretch*) Who's the employee with the most territories? Use `TerritoryId` + (not name, region, or other fields) as the unique identifier for territories. + +### Part 4 - Questions (and your Answers) + +Answer the following questions, baseline ~3-5 sentences each, as if they were +interview screening questions (a form you fill when applying for a job): + +- In the Northwind database, what is the type of relationship between the + `Employee` and `Territory` tables? +- What is a situation where a document store (like MongoDB) is appropriate, and + what is a situation where it is not appropriate? +- What is "NewSQL", and what is it trying to achieve? + +### Part 5 - Turn it in! +Provide all the files you wrote (`demo_data.py`, `northwind.py`), as well as +this file with your answers to part 4, directly to your TL. You're also +encouraged to include the output from your queries as docstring comments, to +facilitate grading and feedback. Thanks for your hard work! + +If you got this far, check out the [larger Northwind +database](https://github.com/jpwhite3/northwind-SQLite3/blob/master/Northwind_large.sqlite.zip) - +your queries should run on it as well, with richer results. diff --git a/Unit-3-Sprint-Challenge-2/northwind_erd.png b/Unit-3-Sprint-Challenge-2/northwind_erd.png new file mode 100644 index 00000000..7288c24e Binary files /dev/null and b/Unit-3-Sprint-Challenge-2/northwind_erd.png differ diff --git a/buddymove_holidayiq.sqlite3 b/buddymove_holidayiq.sqlite3 new file mode 100644 index 00000000..e69de29b diff --git a/module1-introduction-to-sql/buddymove_holidayiq.py b/module1-introduction-to-sql/buddymove_holidayiq.py new file mode 100644 index 00000000..7c0d393e --- /dev/null +++ b/module1-introduction-to-sql/buddymove_holidayiq.py @@ -0,0 +1,14 @@ +import pandas as pd +import sqlite3 +# df = pd.read_csv("https://archive.ics.uci.edu/ml/machine-learning-databases/00476/buddymove_holidayiq.csv") + +conn = sqlite3.connect('buddymove_holidayiq.sqlite3') +# df.to_sql("review",con=conn) + +# count how many rows you have + +print(conn.execute("SELECT COUNT(*) FROM review;").fetchall()) + +print(conn.execute("SELECT * FROM review WHERE Nature >= 100 LIMIT 10;").fetchall()) + +print(conn.execute("SELECT AVG(Sports),AVG(Religious),AVG(Nature),AVG(Theatre),AVG(Shopping),AVG(Picnic) FROM review;").fetchall()) \ No newline at end of file diff --git a/module1-introduction-to-sql/rpg_queries.py b/module1-introduction-to-sql/rpg_queries.py new file mode 100644 index 00000000..3f53235a --- /dev/null +++ b/module1-introduction-to-sql/rpg_queries.py @@ -0,0 +1,44 @@ +import sqlite3 +conn = sqlite3.connect('/Users/user/Documents/GitHub/Lambda/DS-Unit-3-Sprint-2-SQL-and-Databases/module1-introduction-to-sql/rpg_db.sqlite3') +c = conn.cursor() + + +#How many total Characters there? +c1 = c +print(c1.execute('SELECT COUNT(*) FROM charactercreator_character;').fetchall()) + +#How many of each specific subclass? + +print(len(c1.execute('SELECT * FROM charactercreator_character;').fetchall()[0][2:])) + +#How many total items? + +print(c1.execute('SELECT COUNT(*) FROM armory_item;').fetchall()) + +#How many of the Items are weapons? + +print(c1.execute('SELECT COUNT(*) FROM armory_weapon;').fetchall()) + +# How many are not? + +print(len(c1.execute('SELECT * FROM armory_item;').fetchall()) - len(c1.execute('SELECT * FROM armory_weapon;').fetchall())) + +# How many Items does each character have? (Return first 20 rows) + +print(c1.execute('SELECT character_id, count(*) FROM charactercreator_character_inventory GROUP BY item_id LIMIT 20;').fetchall()) + +# How many Weapons does each character have? (Return first 20 rows) + +print(c1.execute('SELECT cci.character_id,count(*) FROM armory_weapon as aw, charactercreator_character_inventory as cci WHERE cci.item_id = aw.item_ptr_id GROUP BY cci.character_id LIMIT 20;').fetchall()) + +# On average, how many Items does each Character have? + +table = c1.execute('SELECT character_id, count(*) FROM charactercreator_character_inventory GROUP BY item_id;').fetchall()[:] + +print(sum([x[1] for x in table]) / len(table)) + +# On average, how many Weapons does each character have? + +table = c1.execute('SELECT cci.character_id,count(*) FROM armory_weapon as aw, charactercreator_character_inventory as cci WHERE cci.item_id = aw.item_ptr_id GROUP BY cci.character_id;').fetchall() + +print(sum([x[1] for x in table]) / len(table)) \ No newline at end of file diff --git a/module2-sql-for-analysis/Stretch_goal_postgres_and_mongo.txt b/module2-sql-for-analysis/Stretch_goal_postgres_and_mongo.txt new file mode 100644 index 00000000..6104e22e --- /dev/null +++ b/module2-sql-for-analysis/Stretch_goal_postgres_and_mongo.txt @@ -0,0 +1,19 @@ +def increment(x): + return x + 1 + +def double(x): + return x * 2 + +def run_twice(func, arg): + return func(func(arg)) + +def rec_print(n): + print(n) + if n > 0: + rec_print(n-1) + +def add(x,y): + return x + y + +def identity(x): + return x \ No newline at end of file diff --git a/module2-sql-for-analysis/elephant_test.py b/module2-sql-for-analysis/elephant_test.py new file mode 100644 index 00000000..3af8ef4b --- /dev/null +++ b/module2-sql-for-analysis/elephant_test.py @@ -0,0 +1,83 @@ +import sqlite3 +import psycopg2 + +dbname = 'bpecpenu' +user = 'bpecpenu' +password = 'aqJWJbtfkIqQ1oloxEGdC-bEJau3JA4E' +host = 'otto.db.elephantsql.com' + +pg_conn = psycopg2.connect(dbname=dbname, + user=user, + password=password, + host=host) + +pg_curs = pg_conn.cursor() +pg_curs.execute('SELECT * FROM test_table;') +pg_curs.fetchall() + +sl_conn = sqlite3.connect('rpg_db copy.sqlite3') +sl_curs = sl_conn.cursor() +sl_curs.execute('SELECT COUNT(*) FROM charactercreator_character;').fetchall() +sl_curs.execute('SELECT COUNT(DISTINCT name) FROM charactercreator_character;').fetchall() +characters = sl_curs.execute('SELECT * FROM charactercreator_character;').fetchall() +characters[0] +characters[-1] +len(characters) + +sl_curs.execute('PRAGMA table_info(charactercreator_character);').fetchall() + +create_character_table = """ + CREATE TABLE charactercreator_character ( + character_id SERIAL PRIMARY KEY, + name VARCHAR(30), + level INT, + exp INT, + hp INT, + strength INT, + intelligence INT, + dexterity INT, + wisdom INT + ); +""" + +pg_curs.execute(create_character_table) + +show_tables = """ +SELECT * +FROM pg_catalog.pg_tables +WHERE schemaname != 'pg_catalog' +and schemaname != 'information_schema'; +""" + +pg_curs.execute(show_tables) +pg_curs.fetchall() + +example_insert = """ +INSERT INTO charactercreator_character +(name, level, exp, hp, strength, intelligence, dexterity, wisdom) +VALUES """ + str(characters[0][1:]) + ';' + +print(example_insert) + +for character in characters: + insert_chracter = """ + INSERT INTO charactercreator_character + (name, level, exp, hp, strength, intelligence, dexterity, wisdom) + VALUES """ + str(character[1:]) + ';' + # print(insert_chracter)\ + pg_curs.execute(insert_chracter) + +pg_curs.execute('SELECT * FROM charactercreator_character;') +pg_curs.fetchall() + +pg_curs.close() +pg_conn.commit() + +pg_curs = pg_conn.cursor() +pg_characters = pg_curs.execute('SELECT * FROM charactercreator_character;').fetchall() + +characters[0] +pg_characters[0] + +for character, pg_character in zip(characters, pg_characters): + assert characters == pg_character \ No newline at end of file diff --git a/module2-sql-for-analysis/insert_titanic.py b/module2-sql-for-analysis/insert_titanic.py new file mode 100644 index 00000000..d5f999d3 --- /dev/null +++ b/module2-sql-for-analysis/insert_titanic.py @@ -0,0 +1,76 @@ +# import libraries: +import pandas as pd +import psycopg2 +import csv + +# details of postgresql account: +dbname = 'bpecpenu' # same than user +user = 'bpecpenu' # same than dbname +password = 'pm5X5ZXRZjSD9oOEM2t_aLJALLdXNyuN' # Don't commit original pass +host = 'otto.db.elephantsql.com' # from SERVER type + +# stablish connection +pg_conn = psycopg2.connect(dbname=dbname, user=user, password=password, host=host) +pg_conn +# instantiate cursor +pg_curs = pg_conn.cursor() + +# create new empty table and define schema) +create_passengers_table = """ + CREATE TABLE passengers ( + id SERIAL NOT NULL PRIMARY KEY, + survived INT, + pclass INT, + name VARCHAR(200), + sex VARCHAR(20), + age INT, + siblings_spouses INT, + parents_children INT, + fare NUMERIC(30) +); +""" + +pg_curs.execute(create_passengers_table) + +# show table on list of tables +show_tables = """ +SELECT * +FROM pg_catalog.pg_tables +WHERE schemaname != 'pg_catalog' +AND schemaname != 'information_schema'; +""" + +pg_curs.execute(show_tables) +pg_curs.fetchall() + +# read csv file +csv_data = pd.read_csv('titanic.csv') + +# Input each row from the DataFrame into the new table on DataBase +statement = """ + INSERT INTO passengers ( + survived, + pclass, + name, + sex, + age, + siblings_spouses, + parents_children, + fare + ) VALUES + (%s, %s, %s, %s, %s, %s, %s, %s); + """ + +# define data row by row in a for loop where each value is iterated over pandas dataframe using itertuples +data = [row for row in csv_data.itertuples(index=False)] + +# using a for loop to populate the new table passengers +for item in data: + pg_curs.execute( + statement, + item + ) + +# close cursor and commit changes on the DB +pg_curs.close() +pg_conn.commit() \ No newline at end of file diff --git a/module3-nosql-and-document-oriented-databases/MongoDB_with_Pymongo_test.ipynb b/module3-nosql-and-document-oriented-databases/MongoDB_with_Pymongo_test.ipynb new file mode 100644 index 00000000..d18ae26a --- /dev/null +++ b/module3-nosql-and-document-oriented-databases/MongoDB_with_Pymongo_test.ipynb @@ -0,0 +1,1350 @@ +{ + "nbformat": 4, + "nbformat_minor": 0, + "metadata": { + "colab": { + "name": "MongoDB_with_Pymongo_test.ipynb", + "provenance": [] + }, + "kernelspec": { + "name": "python3", + "display_name": "Python 3" + } + }, + "cells": [ + { + "cell_type": "markdown", + "metadata": { + "id": "H1MvisdSz_Ef", + "colab_type": "text" + }, + "source": [ + "# MongoDB with Pymongo\n", + "\n", + "- #### This notebook is to explore/understand MongoDB with Python. Notebooks and REPLs can be great for exploration, but for your assignment you should still turn in .py files.\n", + "\n", + "- #### Some resources:\n", + " - https://docs.atlas.mongodb.com/getting-started/\n", + " - https://api.mongodb.com/python/current/" + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "6L5Y4mOS0jSs", + "colab_type": "code", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 35 + }, + "outputId": "56f80433-f417-4546-ecc8-0ea2d1d42bbb" + }, + "source": [ + "!curl ipecho.net/plain" + ], + "execution_count": 3, + "outputs": [ + { + "output_type": "stream", + "text": [ + "34.83.7.74" + ], + "name": "stdout" + } + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "5NjDXR2g1kKb", + "colab_type": "code", + "colab": {} + }, + "source": [ + " mongo_password = 'MpO22RB2O6kgq7ae' # Do not commit this! Reset this if it is exposed" + ], + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "metadata": { + "id": "RCKlIk8Dzy95", + "colab_type": "code", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 35 + }, + "outputId": "d9ce0486-c3f2-4018-b3d1-60f09ce25a23" + }, + "source": [ + "!python --version" + ], + "execution_count": 6, + "outputs": [ + { + "output_type": "stream", + "text": [ + "Python 3.6.9\n" + ], + "name": "stdout" + } + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "mB-C_JoT2hED", + "colab_type": "code", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 35 + }, + "outputId": "1f007f11-95d7-4f93-cbd4-c29866469bda" + }, + "source": [ + "!pip install pymongo" + ], + "execution_count": 7, + "outputs": [ + { + "output_type": "stream", + "text": [ + "Requirement already satisfied: pymongo in /usr/local/lib/python3.6/dist-packages (3.10.1)\n" + ], + "name": "stdout" + } + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "ZVD1qMso2_iI", + "colab_type": "code", + "colab": {} + }, + "source": [ + "import pymongo" + ], + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "metadata": { + "id": "AzFVEC_8zwil", + "colab_type": "code", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 363 + }, + "outputId": "7f97f4ca-fead-41c2-b2fb-2638f2403f83" + }, + "source": [ + "# Trying 3.6+ connection string\n", + "client = pymongo.MongoClient(\n", + " \"mongodb+srv://ds15userak:MpO22RB2O6kgq7ae@cluster0-pwwam.mongodb.net/?retryWrites=true&w=majority\")\n", + "db = client.test\n", + "\n", + "# Should work if you install dnspython" + ], + "execution_count": 10, + "outputs": [ + { + "output_type": "error", + "ename": "ConfigurationError", + "evalue": "ignored", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mConfigurationError\u001b[0m Traceback (most recent call last)", + "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m()\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[0;31m# Trying 3.6+ connection string\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 2\u001b[0m client = pymongo.MongoClient(\n\u001b[0;32m----> 3\u001b[0;31m \"mongodb+srv://ds15userak:MpO22RB2O6kgq7ae@cluster0-pwwam.mongodb.net/?retryWrites=true&w=majority\")\n\u001b[0m\u001b[1;32m 4\u001b[0m \u001b[0mdb\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mclient\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mtest\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m/usr/local/lib/python3.6/dist-packages/pymongo/mongo_client.py\u001b[0m in \u001b[0;36m__init__\u001b[0;34m(self, host, port, document_class, tz_aware, connect, type_registry, **kwargs)\u001b[0m\n\u001b[1;32m 619\u001b[0m res = uri_parser.parse_uri(\n\u001b[1;32m 620\u001b[0m \u001b[0mentity\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mport\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mvalidate\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;32mTrue\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mwarn\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;32mTrue\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mnormalize\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;32mFalse\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 621\u001b[0;31m connect_timeout=timeout)\n\u001b[0m\u001b[1;32m 622\u001b[0m \u001b[0mseeds\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mupdate\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mres\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m\"nodelist\"\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 623\u001b[0m \u001b[0musername\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mres\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m\"username\"\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;32mor\u001b[0m \u001b[0musername\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m/usr/local/lib/python3.6/dist-packages/pymongo/uri_parser.py\u001b[0m in \u001b[0;36mparse_uri\u001b[0;34m(uri, default_port, validate, warn, normalize, connect_timeout)\u001b[0m\n\u001b[1;32m 388\u001b[0m \u001b[0;32melif\u001b[0m \u001b[0muri\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mstartswith\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mSRV_SCHEME\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 389\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0;32mnot\u001b[0m \u001b[0m_HAVE_DNSPYTHON\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 390\u001b[0;31m raise ConfigurationError('The \"dnspython\" module must be '\n\u001b[0m\u001b[1;32m 391\u001b[0m 'installed to use mongodb+srv:// URIs')\n\u001b[1;32m 392\u001b[0m \u001b[0mis_srv\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;32mTrue\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;31mConfigurationError\u001b[0m: The \"dnspython\" module must be installed to use mongodb+srv:// URIs" + ] + } + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "9UvY_DVd3UD-", + "colab_type": "code", + "colab": {} + }, + "source": [ + "# Using 3.4 connection string still, pymongo still having outstanding issues.\n", + "\n", + "\n", + "client = pymongo.MongoClient(\n", + " \"mongodb://ds15userak:MpO22RB2O6kgq7ae@cluster0-shard-00-00-pwwam.mongodb.net:27017,cluster0-shard-00-01-pwwam.mongodb.net:27017,cluster0-shard-00-02-pwwam.mongodb.net:27017/?ssl=true&replicaSet=Cluster0-shard-0&authSource=admin&retryWrites=true&w=majority\")\n", + "db = client.test" + ], + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "metadata": { + "id": "RTAXp8uV4GGJ", + "colab_type": "code", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 55 + }, + "outputId": "e8850ca2-7747-412b-c872-7d73f9ebca5a" + }, + "source": [ + "db" + ], + "execution_count": 12, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "Database(MongoClient(host=['cluster0-shard-00-01-pwwam.mongodb.net:27017', 'cluster0-shard-00-00-pwwam.mongodb.net:27017', 'cluster0-shard-00-02-pwwam.mongodb.net:27017'], document_class=dict, tz_aware=False, connect=True, ssl=True, replicaset='Cluster0-shard-0', authsource='admin', retrywrites=True, w='majority'), 'test')" + ] + }, + "metadata": { + "tags": [] + }, + "execution_count": 12 + } + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "NhWA7pF44JtQ", + "colab_type": "code", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 1000 + }, + "outputId": "32cc03ee-87b0-4c6d-f621-6a8b88cd2810" + }, + "source": [ + "dir(db)" + ], + "execution_count": 13, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "['_BaseObject__codec_options',\n", + " '_BaseObject__read_concern',\n", + " '_BaseObject__read_preference',\n", + " '_BaseObject__write_concern',\n", + " '_Database__client',\n", + " '_Database__incoming_copying_manipulators',\n", + " '_Database__incoming_manipulators',\n", + " '_Database__name',\n", + " '_Database__outgoing_copying_manipulators',\n", + " '_Database__outgoing_manipulators',\n", + " '__call__',\n", + " '__class__',\n", + " '__delattr__',\n", + " '__dict__',\n", + " '__dir__',\n", + " '__doc__',\n", + " '__eq__',\n", + " '__format__',\n", + " '__ge__',\n", + " '__getattr__',\n", + " '__getattribute__',\n", + " '__getitem__',\n", + " '__gt__',\n", + " '__hash__',\n", + " '__init__',\n", + " '__init_subclass__',\n", + " '__iter__',\n", + " '__le__',\n", + " '__lt__',\n", + " '__module__',\n", + " '__ne__',\n", + " '__new__',\n", + " '__next__',\n", + " '__reduce__',\n", + " '__reduce_ex__',\n", + " '__repr__',\n", + " '__setattr__',\n", + " '__sizeof__',\n", + " '__str__',\n", + " '__subclasshook__',\n", + " '__weakref__',\n", + " '_apply_incoming_copying_manipulators',\n", + " '_apply_incoming_manipulators',\n", + " '_command',\n", + " '_create_or_update_user',\n", + " '_current_op',\n", + " '_default_role',\n", + " '_fix_incoming',\n", + " '_fix_outgoing',\n", + " '_list_collections',\n", + " '_read_preference_for',\n", + " '_retryable_read_command',\n", + " '_write_concern_for',\n", + " 'add_son_manipulator',\n", + " 'add_user',\n", + " 'aggregate',\n", + " 'authenticate',\n", + " 'client',\n", + " 'codec_options',\n", + " 'collection_names',\n", + " 'command',\n", + " 'create_collection',\n", + " 'current_op',\n", + " 'dereference',\n", + " 'drop_collection',\n", + " 'error',\n", + " 'eval',\n", + " 'get_collection',\n", + " 'incoming_copying_manipulators',\n", + " 'incoming_manipulators',\n", + " 'last_status',\n", + " 'list_collection_names',\n", + " 'list_collections',\n", + " 'logout',\n", + " 'name',\n", + " 'next',\n", + " 'outgoing_copying_manipulators',\n", + " 'outgoing_manipulators',\n", + " 'previous_error',\n", + " 'profiling_info',\n", + " 'profiling_level',\n", + " 'read_concern',\n", + " 'read_preference',\n", + " 'remove_user',\n", + " 'reset_error_history',\n", + " 'set_profiling_level',\n", + " 'system_js',\n", + " 'validate_collection',\n", + " 'watch',\n", + " 'with_options',\n", + " 'write_concern']" + ] + }, + "metadata": { + "tags": [] + }, + "execution_count": 13 + } + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "TJMTYl4a502W", + "colab_type": "code", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 55 + }, + "outputId": "53e461ea-f864-43f6-de93-308ef866afec" + }, + "source": [ + "db.test" + ], + "execution_count": 14, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "Collection(Database(MongoClient(host=['cluster0-shard-00-01-pwwam.mongodb.net:27017', 'cluster0-shard-00-00-pwwam.mongodb.net:27017', 'cluster0-shard-00-02-pwwam.mongodb.net:27017'], document_class=dict, tz_aware=False, connect=True, ssl=True, replicaset='Cluster0-shard-0', authsource='admin', retrywrites=True, w='majority'), 'test'), 'test')" + ] + }, + "metadata": { + "tags": [] + }, + "execution_count": 14 + } + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "iuUDzfk-57L0", + "colab_type": "code", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 693 + }, + "outputId": "d53b9b4f-3215-46a5-ac74-406203b36822" + }, + "source": [ + "help(db.test.insert_one)" + ], + "execution_count": 15, + "outputs": [ + { + "output_type": "stream", + "text": [ + "Help on method insert_one in module pymongo.collection:\n", + "\n", + "insert_one(document, bypass_document_validation=False, session=None) method of pymongo.collection.Collection instance\n", + " Insert a single document.\n", + " \n", + " >>> db.test.count_documents({'x': 1})\n", + " 0\n", + " >>> result = db.test.insert_one({'x': 1})\n", + " >>> result.inserted_id\n", + " ObjectId('54f112defba522406c9cc208')\n", + " >>> db.test.find_one({'x': 1})\n", + " {u'x': 1, u'_id': ObjectId('54f112defba522406c9cc208')}\n", + " \n", + " :Parameters:\n", + " - `document`: The document to insert. Must be a mutable mapping\n", + " type. If the document does not have an _id field one will be\n", + " added automatically.\n", + " - `bypass_document_validation`: (optional) If ``True``, allows the\n", + " write to opt-out of document level validation. Default is\n", + " ``False``.\n", + " - `session` (optional): a\n", + " :class:`~pymongo.client_session.ClientSession`.\n", + " \n", + " :Returns:\n", + " - An instance of :class:`~pymongo.results.InsertOneResult`.\n", + " \n", + " .. seealso:: :ref:`writes-and-ids`\n", + " \n", + " .. note:: `bypass_document_validation` requires server version\n", + " **>= 3.2**\n", + " \n", + " .. versionchanged:: 3.6\n", + " Added ``session`` parameter.\n", + " \n", + " .. versionchanged:: 3.2\n", + " Added bypass_document_validation support\n", + " \n", + " .. versionadded:: 3.0\n", + "\n" + ], + "name": "stdout" + } + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "s2qGgf4-6KHb", + "colab_type": "code", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 35 + }, + "outputId": "4597e4ea-27ff-4995-a8fb-b61bcb16179f" + }, + "source": [ + "db.test.count_documents({'x': 1})" + ], + "execution_count": 16, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "0" + ] + }, + "metadata": { + "tags": [] + }, + "execution_count": 16 + } + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "-iZlYcNt6QvV", + "colab_type": "code", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 35 + }, + "outputId": "3a847566-3822-4caf-e826-047e1ba24537" + }, + "source": [ + "db.test.insert_one({'x': 1})" + ], + "execution_count": 17, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "" + ] + }, + "metadata": { + "tags": [] + }, + "execution_count": 17 + } + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "WWOqUIWA6pqo", + "colab_type": "code", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 35 + }, + "outputId": "75da7900-660e-4aaf-8d85-7ecd3c845ac6" + }, + "source": [ + "db.test.count_documents({'x': 1})" + ], + "execution_count": 18, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "1" + ] + }, + "metadata": { + "tags": [] + }, + "execution_count": 18 + } + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "14kfdz436t4p", + "colab_type": "code", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 35 + }, + "outputId": "06e61dba-0c24-41a1-b7a2-ddf2dc839078" + }, + "source": [ + "db.test.insert_one({'x': 1})" + ], + "execution_count": 19, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "" + ] + }, + "metadata": { + "tags": [] + }, + "execution_count": 19 + } + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "vvBBUnDk62-1", + "colab_type": "code", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 35 + }, + "outputId": "3feb8751-5d26-4437-d46e-2dea2edba480" + }, + "source": [ + "db.test.count_documents({'x': 1})" + ], + "execution_count": 20, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "2" + ] + }, + "metadata": { + "tags": [] + }, + "execution_count": 20 + } + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "bFqjTJfb640f", + "colab_type": "code", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 35 + }, + "outputId": "31ad5847-68c0-4293-cd89-b5690b11abe8" + }, + "source": [ + "db.test.find_one({'x': 1})" + ], + "execution_count": 21, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "{'_id': ObjectId('5ee142337c01d74871af049a'), 'x': 1}" + ] + }, + "metadata": { + "tags": [] + }, + "execution_count": 21 + } + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "xThIpSte8s6F", + "colab_type": "code", + "colab": {} + }, + "source": [ + "curs = db.test.find({'x': 1})" + ], + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "metadata": { + "id": "-WrEsIpX89jq", + "colab_type": "code", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 35 + }, + "outputId": "1c72a201-06e0-4803-f572-c0b8a8d69456" + }, + "source": [ + "curs" + ], + "execution_count": 24, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "" + ] + }, + "metadata": { + "tags": [] + }, + "execution_count": 24 + } + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "JFMhTPFu9NAR", + "colab_type": "code", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 1000 + }, + "outputId": "51e24508-ff05-4156-c4a6-ea9ecf7e7707" + }, + "source": [ + "dir(curs)" + ], + "execution_count": 26, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "['_Cursor__address',\n", + " '_Cursor__batch_size',\n", + " '_Cursor__check_okay_to_chain',\n", + " '_Cursor__codec_options',\n", + " '_Cursor__collation',\n", + " '_Cursor__collection',\n", + " '_Cursor__comment',\n", + " '_Cursor__data',\n", + " '_Cursor__die',\n", + " '_Cursor__empty',\n", + " '_Cursor__exhaust',\n", + " '_Cursor__exhaust_mgr',\n", + " '_Cursor__explain',\n", + " '_Cursor__explicit_session',\n", + " '_Cursor__hint',\n", + " '_Cursor__id',\n", + " '_Cursor__killed',\n", + " '_Cursor__limit',\n", + " '_Cursor__manipulate',\n", + " '_Cursor__max',\n", + " '_Cursor__max_await_time_ms',\n", + " '_Cursor__max_scan',\n", + " '_Cursor__max_time_ms',\n", + " '_Cursor__min',\n", + " '_Cursor__modifiers',\n", + " '_Cursor__ordering',\n", + " '_Cursor__projection',\n", + " '_Cursor__query_flags',\n", + " '_Cursor__query_spec',\n", + " '_Cursor__read_concern',\n", + " '_Cursor__read_preference',\n", + " '_Cursor__retrieved',\n", + " '_Cursor__return_key',\n", + " '_Cursor__send_message',\n", + " '_Cursor__session',\n", + " '_Cursor__set_hint',\n", + " '_Cursor__show_record_id',\n", + " '_Cursor__skip',\n", + " '_Cursor__snapshot',\n", + " '_Cursor__spec',\n", + " '__class__',\n", + " '__copy__',\n", + " '__deepcopy__',\n", + " '__del__',\n", + " '__delattr__',\n", + " '__dict__',\n", + " '__dir__',\n", + " '__doc__',\n", + " '__enter__',\n", + " '__eq__',\n", + " '__exit__',\n", + " '__format__',\n", + " '__ge__',\n", + " '__getattribute__',\n", + " '__getitem__',\n", + " '__gt__',\n", + " '__hash__',\n", + " '__init__',\n", + " '__init_subclass__',\n", + " '__iter__',\n", + " '__le__',\n", + " '__lt__',\n", + " '__module__',\n", + " '__ne__',\n", + " '__new__',\n", + " '__next__',\n", + " '__reduce__',\n", + " '__reduce_ex__',\n", + " '__repr__',\n", + " '__setattr__',\n", + " '__sizeof__',\n", + " '__str__',\n", + " '__subclasshook__',\n", + " '__weakref__',\n", + " '_clone',\n", + " '_clone_base',\n", + " '_deepcopy',\n", + " '_getmore_class',\n", + " '_query_class',\n", + " '_read_preference',\n", + " '_refresh',\n", + " '_unpack_response',\n", + " 'add_option',\n", + " 'address',\n", + " 'alive',\n", + " 'batch_size',\n", + " 'clone',\n", + " 'close',\n", + " 'collation',\n", + " 'collection',\n", + " 'comment',\n", + " 'count',\n", + " 'cursor_id',\n", + " 'distinct',\n", + " 'explain',\n", + " 'hint',\n", + " 'limit',\n", + " 'max',\n", + " 'max_await_time_ms',\n", + " 'max_scan',\n", + " 'max_time_ms',\n", + " 'min',\n", + " 'next',\n", + " 'remove_option',\n", + " 'retrieved',\n", + " 'rewind',\n", + " 'session',\n", + " 'skip',\n", + " 'sort',\n", + " 'where']" + ] + }, + "metadata": { + "tags": [] + }, + "execution_count": 26 + } + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "SZtKBznd9OfH", + "colab_type": "code", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 52 + }, + "outputId": "b5ab7937-f88f-46be-d371-d3bac781e94f" + }, + "source": [ + "list(curs)" + ], + "execution_count": 27, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "[{'_id': ObjectId('5ee142337c01d74871af049a'), 'x': 1},\n", + " {'_id': ObjectId('5ee1426a7c01d74871af049b'), 'x': 1}]" + ] + }, + "metadata": { + "tags": [] + }, + "execution_count": 27 + } + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "zZd_fcd19YB4", + "colab_type": "code", + "colab": {} + }, + "source": [ + "aarons_doc ={\n", + " 'name': 'aaron',\n", + " 'favorite_animal': 'dog',\n", + " 'favorite_color': 'green',\n", + " 'favorite_number': 5,\n", + " 'favorite_tv_show': 'riverdale'\n", + "}\n", + "\n", + "juds_doc = {\n", + " 'name': 'jud',\n", + " 'favorite_animal': 'liger',\n", + " 'favorite_color': 'green',\n", + " 'favorite_sport': 'football'\n", + "}\n", + "\n", + "baisali_doc = {\n", + " 'name': 'baisali',\n", + " 'favorite_animal': 'elephant',\n", + " 'favorite_color': 'red',\n", + " 'favorite_number': 2\n", + "}\n", + "\n", + "faraazs_doc ={\n", + " 'name': 'faraaz',\n", + " 'favorite_animal': 'ring-tailed lemur',\n", + " 'favorite_color': 'forest green',\n", + " 'favorite_restaurant': 'in-n-out'\n", + "}\n", + "\n", + "all_docs = [aarons_doc, juds_doc, baisali_doc, faraazs_doc]" + ], + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "metadata": { + "id": "-0jPPNqL_cAz", + "colab_type": "code", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 35 + }, + "outputId": "9ed94755-e9a3-4314-d70c-15ef9f1e6468" + }, + "source": [ + "len(all_docs)" + ], + "execution_count": 48, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "4" + ] + }, + "metadata": { + "tags": [] + }, + "execution_count": 48 + } + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "fLLW7UFt_5UH", + "colab_type": "code", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 35 + }, + "outputId": "004e080c-6360-4384-a5f7-a6257975a99d" + }, + "source": [ + "db.test.insert_many(all_docs)" + ], + "execution_count": 49, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "" + ] + }, + "metadata": { + "tags": [] + }, + "execution_count": 49 + } + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "FyPE1SXSAAw0", + "colab_type": "code", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 711 + }, + "outputId": "bc20bc61-8f20-418c-f90f-e216607f7e2d" + }, + "source": [ + "list(db.test.find())" + ], + "execution_count": 50, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "[{'_id': ObjectId('5ee142337c01d74871af049a'), 'x': 1},\n", + " {'_id': ObjectId('5ee1426a7c01d74871af049b'), 'x': 1},\n", + " {'_id': ObjectId('5ee149217c01d74871af049c'),\n", + " 'favorite_animal': 'dog',\n", + " 'favorite_color': 'green',\n", + " 'favorite_number': 5,\n", + " 'favorite_tv_show': 'riverdale'},\n", + " {'_id': ObjectId('5ee149217c01d74871af049d'),\n", + " 'favorite_animal': 'liger',\n", + " 'favorite_color': 'green',\n", + " 'favorite_sport': 'football'},\n", + " {'_id': ObjectId('5ee149217c01d74871af049e'),\n", + " 'favorite_animal': 'elephant',\n", + " 'favorite_color': 'red',\n", + " 'favorite_number': 2},\n", + " {'_id': ObjectId('5ee149217c01d74871af049f'),\n", + " 'favorite_animal': 'ring-tailed lemur',\n", + " 'favorite_color': 'forest green',\n", + " 'favorite_restaurant': 'in-n-out'},\n", + " {'_id': ObjectId('5ee149bf7c01d74871af04a0'),\n", + " 'favorite_animal': 'dog',\n", + " 'favorite_color': 'green',\n", + " 'favorite_number': 5,\n", + " 'favorite_tv_show': 'riverdale',\n", + " 'name': 'aaron'},\n", + " {'_id': ObjectId('5ee149bf7c01d74871af04a1'),\n", + " 'favorite_animal': 'liger',\n", + " 'favorite_color': 'green',\n", + " 'favorite_sport': 'football',\n", + " 'name': 'jud'},\n", + " {'_id': ObjectId('5ee149bf7c01d74871af04a2'),\n", + " 'favorite_animal': 'elephant',\n", + " 'favorite_color': 'red',\n", + " 'favorite_number': 2,\n", + " 'name': 'baisali'},\n", + " {'_id': ObjectId('5ee149bf7c01d74871af04a3'),\n", + " 'favorite_animal': 'ring-tailed lemur',\n", + " 'favorite_color': 'forest green',\n", + " 'favorite_restaurant': 'in-n-out',\n", + " 'name': 'faraaz'}]" + ] + }, + "metadata": { + "tags": [] + }, + "execution_count": 50 + } + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "W3LVccB6AHGc", + "colab_type": "code", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 191 + }, + "outputId": "caf00c95-543a-401d-e7c6-a764a4f540d9" + }, + "source": [ + "more_docs = []\n", + "for i in range(10):\n", + " doc = {'even': i % 2 == 0}\n", + " doc['value'] = i\n", + " more_docs.append(doc)\n", + "\n", + "more_docs" + ], + "execution_count": 51, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "[{'even': True, 'value': 0},\n", + " {'even': False, 'value': 1},\n", + " {'even': True, 'value': 2},\n", + " {'even': False, 'value': 3},\n", + " {'even': True, 'value': 4},\n", + " {'even': False, 'value': 5},\n", + " {'even': True, 'value': 6},\n", + " {'even': False, 'value': 7},\n", + " {'even': True, 'value': 8},\n", + " {'even': False, 'value': 9}]" + ] + }, + "metadata": { + "tags": [] + }, + "execution_count": 51 + } + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "r5IyJ8ZxCuFX", + "colab_type": "code", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 35 + }, + "outputId": "702d16cd-d84c-4840-e6db-30f950080990" + }, + "source": [ + "db.test.insert_many(more_docs)" + ], + "execution_count": 52, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "" + ] + }, + "metadata": { + "tags": [] + }, + "execution_count": 52 + } + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "wy4R_X8bCyyk", + "colab_type": "code", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 35 + }, + "outputId": "0b04ce7a-f4cc-47c8-9c38-94c6267ddd38" + }, + "source": [ + "list(db.test.find({'even': True, 'value': 0}))" + ], + "execution_count": 53, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "[{'_id': ObjectId('5ee14a8a7c01d74871af04a4'), 'even': True, 'value': 0}]" + ] + }, + "metadata": { + "tags": [] + }, + "execution_count": 53 + } + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "LIKwMwMBDBDh", + "colab_type": "code", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 104 + }, + "outputId": "0bc0f7f4-3758-453c-b61a-0633c6bbec10" + }, + "source": [ + "list(db.test.find({'even': True}))" + ], + "execution_count": 54, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "[{'_id': ObjectId('5ee14a8a7c01d74871af04a4'), 'even': True, 'value': 0},\n", + " {'_id': ObjectId('5ee14a8a7c01d74871af04a6'), 'even': True, 'value': 2},\n", + " {'_id': ObjectId('5ee14a8a7c01d74871af04a8'), 'even': True, 'value': 4},\n", + " {'_id': ObjectId('5ee14a8a7c01d74871af04aa'), 'even': True, 'value': 6},\n", + " {'_id': ObjectId('5ee14a8a7c01d74871af04ac'), 'even': True, 'value': 8}]" + ] + }, + "metadata": { + "tags": [] + }, + "execution_count": 54 + } + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "rkc25vuNDl65", + "colab_type": "code", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 364 + }, + "outputId": "839f8824-a75e-4459-ad2b-e495491b97f8" + }, + "source": [ + "list(db.test.find({'favorite_color': 'green'}))" + ], + "execution_count": 57, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "[{'_id': ObjectId('5ee149217c01d74871af049c'),\n", + " 'favorite_animal': 'dog',\n", + " 'favorite_color': 'green',\n", + " 'favorite_number': 5,\n", + " 'favorite_tv_show': 'riverdale'},\n", + " {'_id': ObjectId('5ee149217c01d74871af049d'),\n", + " 'favorite_animal': 'liger',\n", + " 'favorite_color': 'green',\n", + " 'favorite_sport': 'football'},\n", + " {'_id': ObjectId('5ee149bf7c01d74871af04a0'),\n", + " 'favorite_animal': 'dog',\n", + " 'favorite_color': 'green',\n", + " 'favorite_number': 5,\n", + " 'favorite_tv_show': 'riverdale',\n", + " 'name': 'aaron'},\n", + " {'_id': ObjectId('5ee149bf7c01d74871af04a1'),\n", + " 'favorite_animal': 'liger',\n", + " 'favorite_color': 'green',\n", + " 'favorite_sport': 'football',\n", + " 'name': 'jud'}]" + ] + }, + "metadata": { + "tags": [] + }, + "execution_count": 57 + } + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "11yhBh4yD4I_", + "colab_type": "code", + "colab": {} + }, + "source": [ + "# What is CRUD?\n", + "# C - Create\n", + "# R - Read\n", + "# U - Update\n", + "# D - Delete\n", + "\n", + "# AKA - As Aaron Gallant puts it - most apps" + ], + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "metadata": { + "id": "R8CtxQGFEURL", + "colab_type": "code", + "colab": {} + }, + "source": [ + "rpg_character = (1, \"King Bob\", 10, 3, 0, 0, 0)" + ], + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "metadata": { + "id": "o5izPX5TFAPt", + "colab_type": "code", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 35 + }, + "outputId": "f5c5a87d-bba1-43d9-d9cd-e0b40c892d3d" + }, + "source": [ + "# Lazy and not good for long term goals\n", + "\n", + "db.test.insert_one({'rpg_character': rpg_character})" + ], + "execution_count": 62, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "" + ] + }, + "metadata": { + "tags": [] + }, + "execution_count": 62 + } + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "aXKGzyLvFb47", + "colab_type": "code", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 52 + }, + "outputId": "d18b2475-6d51-4a48-a953-c937d9e4525c" + }, + "source": [ + "db.test.find_one({'rpg_character': rpg_character})" + ], + "execution_count": 63, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "{'_id': ObjectId('5ee14d3e7c01d74871af04ae'),\n", + " 'rpg_character': [1, 'King Bob', 10, 3, 0, 0, 0]}" + ] + }, + "metadata": { + "tags": [] + }, + "execution_count": 63 + } + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "fUtgXELHFjAt", + "colab_type": "code", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 35 + }, + "outputId": "982d8f63-8e04-46bf-bb5b-6b69369747bc" + }, + "source": [ + "# Ideal even though SCHEMA isn't required, we should make informative/useful\n", + "# key names in our docs\n", + "\n", + "rpg_doc = {\n", + " 'sql_key': rpg_character[0],\n", + " 'name': rpg_character[1],\n", + " 'hp': rpg_character[2],\n", + " 'level': rpg_character[3]\n", + "}\n", + "db.test.insert_one(rpg_doc)" + ], + "execution_count": 65, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "" + ] + }, + "metadata": { + "tags": [] + }, + "execution_count": 65 + } + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "IFuPHd5fGRsM", + "colab_type": "code", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 104 + }, + "outputId": "0e29382f-6ca6-4c24-8b41-f42de72402ea" + }, + "source": [ + "list(db.test.find(rpg_doc))" + ], + "execution_count": 66, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "[{'_id': ObjectId('5ee14e647c01d74871af04af'),\n", + " 'hp': 10,\n", + " 'level': 3,\n", + " 'name': 'King Bob',\n", + " 'sql_key': 1}]" + ] + }, + "metadata": { + "tags": [] + }, + "execution_count": 66 + } + ] + } + ] +} \ No newline at end of file diff --git a/module3-nosql-and-document-oriented-databases/RPG_mongoDB.py b/module3-nosql-and-document-oriented-databases/RPG_mongoDB.py new file mode 100644 index 00000000..60ba9186 --- /dev/null +++ b/module3-nosql-and-document-oriented-databases/RPG_mongoDB.py @@ -0,0 +1,40 @@ +""" MongoDB """ + +import pymongo +import sqlite3 + +client = pymongo.MongoClient( + "mongodb+srv://ds15userak:MpO22RB2O6kgq7ae@cluster0-pwwam.mongodb.net/?retryWrites=true&w=majority") +db = client.test + +client.nodes + +sl_conn = sqlite3.connect('rpg_db.sqlite3') +sl_curs = sl_conn.cursor() + +query1 = 'SELECT * FROM charactercreator_character;' +characters = sl_curs.execute(query1).fetchall() + +# my dictionary for charactercreator_character table +docs = [] +for character in characters: + doc1 = {'table1' : 'charactercreator_character'} + doc1['character_id'] = character[0] + doc1['name'] = character[1] + doc1['level'] = character[2] + doc1['exp'] = character[3] + doc1['hp'] = character[4] + doc1['strength'] = character[5] + doc1['intelligence'] = character[6] + doc1['dexterity'] = character[7] + doc1['wisdom'] = character[8] + docs.append(doc1) + +# transfer data to mongoDB +db.test.insert_many(docs) + +# Confirm that table was added in mongoDB +print(db.test.find_one()) + +query2 = 'SELECT * FROM armory_item;' +items = sl_curs.execute(query2).fetchall() \ No newline at end of file diff --git a/module3-nosql-and-document-oriented-databases/mongoDB.py b/module3-nosql-and-document-oriented-databases/mongoDB.py new file mode 100644 index 00000000..b7c3306e --- /dev/null +++ b/module3-nosql-and-document-oriented-databases/mongoDB.py @@ -0,0 +1,187 @@ +import pymongo +import sqlite3 + +client = pymongo.MongoClient( + "mongodb+srv://ds15userak:MpO22RB2O6kgq7ae@cluster0-pwwam.mongodb.net/?retryWrites=true&w=majority") +db = client.test + +client.nodes + +sl_conn = sqlite3.connect('rpg_db.sqlite3') +sl_curs = sl_conn.cursor() + +query1 = 'SELECT * FROM charactercreator_character;' +characters = sl_curs.execute(query1).fetchall() + +# This wil be my dictionary for the charactercreator_character table +charactercreator_character = {} +for character in characters: + cc = { + 'character_id' : character[0], + 'name' : character[1], + 'level' : character[2], + 'exp' : character[3], + 'hp' : character[4], + 'strength' : character[5], + 'intelligence' : character[6], + 'dexterity' : character[7], + 'wisdom' : character[8] + } + charactercreator_character.update({str(character[0]): cc}) + +# This will transfer the data to mongoDB +db.test.insert_one(charactercreator_character) + +# This will confirm that the table was added in mongoDB +print(db.test.find_one()) + +query2 = 'SELECT * FROM armory_item;' +items = sl_curs.execute(query2).fetchall() + +# my dictionary for armory_item table +armory_item = {} +for item in items: + ai = { + 'item_id': item[0], + 'name' : item[1], + 'value' : item[2], + 'weight' : item[3] +} + armory_item.update({str(item[0]): ai}) + +# transfer data to mongoDB +db.test.insert_one(armory_item) + +# Confirm that table was added in mongoDB +print(db.test.find(armory_item)) + +query3 = 'SELECT * FROM armory_weapon;' +weapons = sl_curs.execute(query3).fetchall() + +# my dictionary for armory_weapon table +armory_weapon = {} +for weapon in weapons: + aw = { + 'item__ptr_id': item[0], + 'power' : item[1] +} + armory_weapon.update({str(weapon[0]): aw}) + +# transfer data to mongoDB +db.test.insert_one(armory_weapon) + +# Confirm that table was added in mongoDB +print(db.test.find(armory_weapon)) + +query4 = 'SELECT * FROM charactercreator_character_inventory;' +stocks = sl_curs.execute(query4).fetchall() + +# my dictionary for charactercreator_character_inventory table +charactercreator_character_inventory = {} +for stock in stocks: + cci = { + 'id': stock[0], + 'character_id' : stock[1], + 'item_id' : stock[2] +} + charactercreator_character_inventory.update({str(stock[0]): cci}) + +# transfer data to mongoDB +db.test.insert_one(charactercreator_character_inventory) + +# Confirm that table was added in mongoDB +print(db.test.find(charactercreator_character_inventory)) + +query5 = 'SELECT * FROM charactercreator_mage;' +mages = sl_curs.execute(query5).fetchall() + +# my dictionary for charactercreator_mage table +charactercreator_mage = {} +for mage in mages: + ccm = { + 'character_ptr_id': mage[0], + 'has_pet' : mage[1], + 'mana' : mage[2] +} + charactercreator_mage.update({str(mage[0]): ccm}) + +# transfer data to mongoDB +db.test.insert_one(charactercreator_mage) + +# Confirm that table was added in mongoDB +print(db.test.find(charactercreator_mage)) + +query6 = 'SELECT * FROM charactercreator_thief;' +thieves = sl_curs.execute(query6).fetchall() + +# my dictionary for charactercreator_thief table +charactercreator_thief = {} +for thief in thieves: + cct = { + 'character_ptr_id': thief[0], + 'is_sneaking' : thief[1], + 'energy' : thief[2] +} + charactercreator_thief.update({str(thief[0]): cct}) + +# transfer data to mongoDB +db.test.insert_one(charactercreator_thief) + +# Confirm that table was added in mongoDB +print(db.test.find(charactercreator_thief)) + +query7 = 'SELECT * FROM charactercreator_cleric;' +clerics = sl_curs.execute(query7).fetchall() + +# my dictionary for charactercreator_cleric table +charactercreator_cleric = {} +for cleric in clerics: + ccc = { + 'character_ptr_id': cleric[0], + 'using_shield' : cleric[1], + 'mana' : cleric[2] +} + charactercreator_cleric.update({str(cleric[0]): ccc}) + +# transfer data to mongoDB +db.test.insert_one(charactercreator_cleric) + +# Confirm that table was added in mongoDB +print(db.test.find(charactercreator_cleric)) + +query8 = 'SELECT * FROM charactercreator_fighter;' +fighters = sl_curs.execute(query8).fetchall() + +# my dictionary for charactercreator_cleric table +charactercreator_fighter = {} +for fighter in fighters: + ccf = { + 'character_ptr_id': fighter[0], + 'using_shield' : fighter[1], + 'rage' : fighter[2] +} + charactercreator_fighter.update({str(fighter[0]): ccf}) + +# transfer data to mongoDB +db.test.insert_one(charactercreator_fighter) + +# Confirm that table was added in mongoDB +print(db.test.find(charactercreator_fighter)) + +query9 = 'SELECT * FROM charactercreator_necromancer;' +nmcs = sl_curs.execute(query9).fetchall() + +# my dictionary for charactercreator_necromancer table +charactercreator_necromancer = {} +for nmc in nmcs: + ccn = { + 'mage_ptr_id': nmc[0], + 'talisman_charged' : nmc[1] +} + charactercreator_necromancer.update({str(nmc[0]): ccn}) + +# transfer data to mongoDB +db.test.insert_one(charactercreator_necromancer) + +# Confirm that table was added in mongoDB +print(db.test.find(charactercreator_necromancer)) \ No newline at end of file diff --git a/module3-nosql-and-document-oriented-databases/mongodb_test.py b/module3-nosql-and-document-oriented-databases/mongodb_test.py new file mode 100644 index 00000000..bbe91338 --- /dev/null +++ b/module3-nosql-and-document-oriented-databases/mongodb_test.py @@ -0,0 +1,111 @@ +import pymongo +client = pymongo.MongoClient( + "mongodb://aaron-huizenga@lambdastudents.com:MpO22RB2O6kgq7ae@mycluster0-shard-00-00.mongodb.net:27017,mycluster0-shard-00-01.mongodb.net:27017,mycluster0-shard-00-02.mongodb.net:27017/admin?ssl=true&replicaSet=Mycluster0-shard-0&authSource=admin") +db = client.test + +db + +dir(db) + +db.test + +help(db.test.insert_one) + +db.test.count_documents({'x': 1}) + +db.insert_one({'x': 1}) + +db.test.count_documents({'x': 1}) + +db.insert_one({'x': 1}) + +db.test.count_documents({'x': 1}) + +db.test.find_one({'x': 1}) + +curs = db.test.find({'x': 1}) + +curs + +dir(curs) + +list(curs) + +aarons_doc ={ + 'name': 'aaron', + 'favorite_animal': 'dog', + 'favorite_color': 'green', + 'favorite_number': 5, + 'favorite_tv_show': 'riverdale' +} + +juds_doc = { + 'name': 'jud', + 'favorite_animal': 'liger', + 'favorite_color': 'green', + 'favorite_sport': 'football' +} + +baisali_doc = { + 'name': 'baisali', + 'favorite_animal': 'elephant', + 'favorite_color': 'red', + 'favorite_number': 2 +} + +faraazs_doc ={ + 'name': 'faraaz', + 'favorite_animal': 'ring-tailed lemur', + 'favorite_color': 'forest green', + 'favorite_restaurant': 'in-n-out' +} + +all_docs = [aarons_doc, juds_doc, baisali_doc, faraazs_doc] + +len(all_docs) + +db.test.insert_many(all_docs) + +list(db.test.find()) + +more_docs = [] +for i in range(10): + doc = {'even': i % 2 == 0} + doc['value'] = i + more_docs.append(doc) + +more_docs + +db.test.insert_many(more_docs) + +list(db.test.find({'even': True, 'value': 0})) + +list(db.test.find({'even': True})) + +list(db.test.find({'favorite_color': 'green'})) + +# What is CRUD? +# C - Create +# R - Read +# U - Update +# D - Delete + +# AKA - As Aaron Gallant puts it - most apps +rpg_character = (1, "King Bob", 10, 3, 0, 0, 0) + +# Lazy and not good for long term goals +db.test.insert_one({'rpg_character': rpg_character}) + +db.test.find_one({'rpg_character': rpg_character}) + +# Ideal even though SCHEMA isn't required, we should make informative/useful +# key names in our docs +rpg_doc = { + 'sql_key': rpg_character[0], + 'name': rpg_character[1], + 'hp': rpg_character[2], + 'level': rpg_character[3] +} +db.test.insert_one(rpg_doc) + +list(db.test.find(rpg_doc)) \ No newline at end of file diff --git a/module4-acid-and-database-scalability-tradeoffs/titanic1.csv b/module4-acid-and-database-scalability-tradeoffs/titanic1.csv new file mode 100644 index 00000000..a140d63c --- /dev/null +++ b/module4-acid-and-database-scalability-tradeoffs/titanic1.csv @@ -0,0 +1,157 @@ +PassengerId,Survived,Pclass,Name,Sex,Age,SibSp,Parch,Ticket,Fare,Cabin,Embarked +1,0,3,"Braund, Mr. Owen Harris",male,22,1,0,A/5 21171,7.25,,S +2,1,1,"Cumings, Mrs. John Bradley (Florence Briggs Thayer)",female,38,1,0,PC 17599,71.2833,C85,C +3,1,3,"Heikkinen, Miss. Laina",female,26,0,0,STON/O2. 3101282,7.925,,S +4,1,1,"Futrelle, Mrs. Jacques Heath (Lily May Peel)",female,35,1,0,113803,53.1,C123,S +5,0,3,"Allen, Mr. William Henry",male,35,0,0,373450,8.05,,S +6,0,3,"Moran, Mr. James",male,,0,0,330877,8.4583,,Q +7,0,1,"McCarthy, Mr. Timothy J",male,54,0,0,17463,51.8625,E46,S +8,0,3,"Palsson, Master. Gosta Leonard",male,2,3,1,349909,21.075,,S +9,1,3,"Johnson, Mrs. Oscar W (Elisabeth Vilhelmina Berg)",female,27,0,2,347742,11.1333,,S +10,1,2,"Nasser, Mrs. Nicholas (Adele Achem)",female,14,1,0,237736,30.0708,,C +11,1,3,"Sandstrom, Miss. Marguerite Rut",female,4,1,1,PP 9549,16.7,G6,S +12,1,1,"Bonnell, Miss. Elizabeth",female,58,0,0,113783,26.55,C103,S +13,0,3,"Saundercock, Mr. William Henry",male,20,0,0,A/5. 2151,8.05,,S +14,0,3,"Andersson, Mr. Anders Johan",male,39,1,5,347082,31.275,,S +15,0,3,"Vestrom, Miss. Hulda Amanda Adolfina",female,14,0,0,350406,7.8542,,S +16,1,2,"Hewlett, Mrs. (Mary D Kingcome) ",female,55,0,0,248706,16,,S +17,0,3,"Rice, Master. Eugene",male,2,4,1,382652,29.125,,Q +18,1,2,"Williams, Mr. Charles Eugene",male,,0,0,244373,13,,S +19,0,3,"Vander Planke, Mrs. Julius (Emelia Maria Vandemoortele)",female,31,1,0,345763,18,,S +20,1,3,"Masselmani, Mrs. Fatima",female,,0,0,2649,7.225,,C +21,0,2,"Fynney, Mr. Joseph J",male,35,0,0,239865,26,,S +22,1,2,"Beesley, Mr. Lawrence",male,34,0,0,248698,13,D56,S +23,1,3,"McGowan, Miss. Anna 'Annie'",female,15,0,0,330923,8.0292,,Q +24,1,1,"Sloper, Mr. William Thompson",male,28,0,0,113788,35.5,A6,S +25,0,3,"Palsson, Miss. Torborg Danira",female,8,3,1,349909,21.075,,S +26,1,3,"Asplund, Mrs. Carl Oscar (Selma Augusta Emilia Johansson)",female,38,1,5,347077,31.3875,,S +27,0,3,"Emir, Mr. Farred Chehab",male,,0,0,2631,7.225,,C +28,0,1,"Fortune, Mr. Charles Alexander",male,19,3,2,19950,263,C23 C25 C27,S +29,1,3,"O'Dwyer, Miss. Ellen 'Nellie'",female,,0,0,330959,7.8792,,Q +30,0,3,"Todoroff, Mr. Lalio",male,,0,0,349216,7.8958,,S +31,0,1,"Uruchurtu, Don. Manuel E",male,40,0,0,PC 17601,27.7208,,C +32,1,1,"Spencer, Mrs. William Augustus (Marie Eugenie)",female,,1,0,PC 17569,146.5208,B78,C +33,1,3,"Glynn, Miss. Mary Agatha",female,,0,0,335677,7.75,,Q +34,0,2,"Wheadon, Mr. Edward H",male,66,0,0,C.A. 24579,10.5,,S +35,0,1,"Meyer, Mr. Edgar Joseph",male,28,1,0,PC 17604,82.1708,,C +36,0,1,"Holverson, Mr. Alexander Oskar",male,42,1,0,113789,52,,S +37,1,3,"Mamee, Mr. Hanna",male,,0,0,2677,7.2292,,C +38,0,3,"Cann, Mr. Ernest Charles",male,21,0,0,A./5. 2152,8.05,,S +39,0,3,"Vander Planke, Miss. Augusta Maria",female,18,2,0,345764,18,,S +40,1,3,"Nicola-Yarred, Miss. Jamila",female,14,1,0,2651,11.2417,,C +41,0,3,"Ahlin, Mrs. Johan (Johanna Persdotter Larsson)",female,40,1,0,7546,9.475,,S +42,0,2,"Turpin, Mrs. William John Robert (Dorothy Ann Wonnacott)",female,27,1,0,11668,21,,S +43,0,3,"Kraeff, Mr. Theodor",male,,0,0,349253,7.8958,,C +44,1,2,"Laroche, Miss. Simonne Marie Anne Andree",female,3,1,2,SC/Paris 2123,41.5792,,C +45,1,3,"Devaney, Miss. Margaret Delia",female,19,0,0,330958,7.8792,,Q +46,0,3,"Rogers, Mr. William John",male,,0,0,S.C./A.4. 23567,8.05,,S +47,0,3,"Lennon, Mr. Denis",male,,1,0,370371,15.5,,Q +48,1,3,"O'Driscoll, Miss. Bridget",female,,0,0,14311,7.75,,Q +49,0,3,"Samaan, Mr. Youssef",male,,2,0,2662,21.6792,,C +50,0,3,"Arnold-Franchi, Mrs. Josef (Josefine Franchi)",female,18,1,0,349237,17.8,,S +51,0,3,"Panula, Master. Juha Niilo",male,7,4,1,3101295,39.6875,,S +52,0,3,"Nosworthy, Mr. Richard Cater",male,21,0,0,A/4. 39886,7.8,,S +53,1,1,"Harper, Mrs. Henry Sleeper (Myna Haxtun)",female,49,1,0,PC 17572,76.7292,D33,C +54,1,2,"Faunthorpe, Mrs. Lizzie (Elizabeth Anne Wilkinson)",female,29,1,0,2926,26,,S +55,0,1,"Ostby, Mr. Engelhart Cornelius",male,65,0,1,113509,61.9792,B30,C +56,1,1,"Woolner, Mr. Hugh",male,,0,0,19947,35.5,C52,S +57,1,2,"Rugg, Miss. Emily",female,21,0,0,C.A. 31026,10.5,,S +58,0,3,"Novel, Mr. Mansouer",male,28.5,0,0,2697,7.2292,,C +59,1,2,"West, Miss. Constance Mirium",female,5,1,2,C.A. 34651,27.75,,S +60,0,3,"Goodwin, Master. William Frederick",male,11,5,2,CA 2144,46.9,,S +61,0,3,"Sirayanian, Mr. Orsen",male,22,0,0,2669,7.2292,,C +62,1,1,"Icard, Miss. Amelie",female,38,0,0,113572,80,B28, +63,0,1,"Harris, Mr. Henry Birkhardt",male,45,1,0,36973,83.475,C83,S +64,0,3,"Skoog, Master. Harald",male,4,3,2,347088,27.9,,S +65,0,1,"Stewart, Mr. Albert A",male,,0,0,PC 17605,27.7208,,C +66,1,3,"Moubarek, Master. Gerios",male,,1,1,2661,15.2458,,C +67,1,2,"Nye, Mrs. (Elizabeth Ramell)",female,29,0,0,C.A. 29395,10.5,F33,S +68,0,3,"Crease, Mr. Ernest James",male,19,0,0,S.P. 3464,8.1583,,S +69,1,3,"Andersson, Miss. Erna Alexandra",female,17,4,2,3101281,7.925,,S +70,0,3,"Kink, Mr. Vincenz",male,26,2,0,315151,8.6625,,S +71,0,2,"Jenkin, Mr. Stephen Curnow",male,32,0,0,C.A. 33111,10.5,,S +72,0,3,"Goodwin, Miss. Lillian Amy",female,16,5,2,CA 2144,46.9,,S +73,0,2,"Hood, Mr. Ambrose Jr",male,21,0,0,S.O.C. 14879,73.5,,S +74,0,3,"Chronopoulos, Mr. Apostolos",male,26,1,0,2680,14.4542,,C +75,1,3,"Bing, Mr. Lee",male,32,0,0,1601,56.4958,,S +76,0,3,"Moen, Mr. Sigurd Hansen",male,25,0,0,348123,7.65,F G73,S +77,0,3,"Staneff, Mr. Ivan",male,,0,0,349208,7.8958,,S +78,0,3,"Moutal, Mr. Rahamin Haim",male,,0,0,374746,8.05,,S +79,1,2,"Caldwell, Master. Alden Gates",male,0.83,0,2,248738,29,,S +80,1,3,"Dowdell, Miss. Elizabeth",female,30,0,0,364516,12.475,,S +81,0,3,"Waelens, Mr. Achille",male,22,0,0,345767,9,,S +82,1,3,"Sheerlinck, Mr. Jan Baptist",male,29,0,0,345779,9.5,,S +83,1,3,"McDermott, Miss. Brigdet Delia",female,,0,0,330932,7.7875,,Q +84,0,1,"Carrau, Mr. Francisco M",male,28,0,0,113059,47.1,,S +85,1,2,"Ilett, Miss. Bertha",female,17,0,0,SO/C 14885,10.5,,S +86,1,3,"Backstrom, Mrs. Karl Alfred (Maria Mathilda Gustafsson)",female,33,3,0,3101278,15.85,,S +87,0,3,"Ford, Mr. William Neal",male,16,1,3,W./C. 6608,34.375,,S +88,0,3,"Slocovski, Mr. Selman Francis",male,,0,0,SOTON/OQ 392086,8.05,,S +89,1,1,"Fortune, Miss. Mabel Helen",female,23,3,2,19950,263,C23 C25 C27,S +90,0,3,"Celotti, Mr. Francesco",male,24,0,0,343275,8.05,,S +91,0,3,"Christmann, Mr. Emil",male,29,0,0,343276,8.05,,S +92,0,3,"Andreasson, Mr. Paul Edvin",male,20,0,0,347466,7.8542,,S +93,0,1,"Chaffee, Mr. Herbert Fuller",male,46,1,0,W.E.P. 5734,61.175,E31,S +94,0,3,"Dean, Mr. Bertram Frank",male,26,1,2,C.A. 2315,20.575,,S +95,0,3,"Coxon, Mr. Daniel",male,59,0,0,364500,7.25,,S +96,0,3,"Shorney, Mr. Charles Joseph",male,,0,0,374910,8.05,,S +97,0,1,"Goldschmidt, Mr. George B",male,71,0,0,PC 17754,34.6542,A5,C +98,1,1,"Greenfield, Mr. William Bertram",male,23,0,1,PC 17759,63.3583,D10 D12,C +99,1,2,"Doling, Mrs. John T (Ada Julia Bone)",female,34,0,1,231919,23,,S +100,0,2,"Kantor, Mr. Sinai",male,34,1,0,244367,26,,S +101,0,3,"Petranec, Miss. Matilda",female,28,0,0,349245,7.8958,,S +102,0,3,"Petroff, Mr. Pastcho (""Pentcho"")",male,,0,0,349215,7.8958,,S +103,0,1,"White, Mr. Richard Frasar",male,21,0,1,35281,77.2875,D26,S +104,0,3,"Johansson, Mr. Gustaf Joel",male,33,0,0,7540,8.6542,,S +105,0,3,"Gustafsson, Mr. Anders Vilhelm",male,37,2,0,3101276,7.925,,S +106,0,3,"Mionoff, Mr. Stoytcho",male,28,0,0,349207,7.8958,,S +107,1,3,"Salkjelsvik, Miss. Anna Kristine",female,21,0,0,343120,7.65,,S +108,1,3,"Moss, Mr. Albert Johan",male,,0,0,312991,7.775,,S +109,0,3,"Rekic, Mr. Tido",male,38,0,0,349249,7.8958,,S +110,1,3,"Moran, Miss. Bertha",female,,1,0,371110,24.15,,Q +111,0,1,"Porter, Mr. Walter Chamberlain",male,47,0,0,110465,52,C110,S +112,0,3,"Zabour, Miss. Hileni",female,14.5,1,0,2665,14.4542,,C +113,0,3,"Barton, Mr. David John",male,22,0,0,324669,8.05,,S +114,0,3,"Jussila, Miss. Katriina",female,20,1,0,4136,9.825,,S +115,0,3,"Attalah, Miss. Malake",female,17,0,0,2627,14.4583,,C +116,0,3,"Pekoniemi, Mr. Edvard",male,21,0,0,STON/O 2. 3101294,7.925,,S +117,0,3,"Connors, Mr. Patrick",male,70.5,0,0,370369,7.75,,Q +118,0,2,"Turpin, Mr. William John Robert",male,29,1,0,11668,21,,S +119,0,1,"Baxter, Mr. Quigg Edmond",male,24,0,1,PC 17558,247.5208,B58 B60,C +120,0,3,"Andersson, Miss. Ellis Anna Maria",female,2,4,2,347082,31.275,,S +121,0,2,"Hickman, Mr. Stanley George",male,21,2,0,S.O.C. 14879,73.5,,S +122,0,3,"Moore, Mr. Leonard Charles",male,,0,0,A4. 54510,8.05,,S +123,0,2,"Nasser, Mr. Nicholas",male,32.5,1,0,237736,30.0708,,C +124,1,2,"Webber, Miss. Susan",female,32.5,0,0,27267,13,E101,S +125,0,1,"White, Mr. Percival Wayland",male,54,0,1,35281,77.2875,D26,S +126,1,3,"Nicola-Yarred, Master. Elias",male,12,1,0,2651,11.2417,,C +127,0,3,"McMahon, Mr. Martin",male,,0,0,370372,7.75,,Q +128,1,3,"Madsen, Mr. Fridtjof Arne",male,24,0,0,C 17369,7.1417,,S +129,1,3,"Peter, Miss. Anna",female,,1,1,2668,22.3583,F E69,C +130,0,3,"Ekstrom, Mr. Johan",male,45,0,0,347061,6.975,,S +131,0,3,"Drazenoic, Mr. Jozef",male,33,0,0,349241,7.8958,,C +132,0,3,"Coelho, Mr. Domingos Fernandeo",male,20,0,0,SOTON/O.Q. 3101307,7.05,,S +133,0,3,"Robins, Mrs. Alexander A (Grace Charity Laury)",female,47,1,0,A/5. 3337,14.5,,S +134,1,2,"Weisz, Mrs. Leopold (Mathilde Francoise Pede)",female,29,1,0,228414,26,,S +135,0,2,"Sobey, Mr. Samuel James Hayden",male,25,0,0,C.A. 29178,13,,S +136,0,2,"Richard, Mr. Emile",male,23,0,0,SC/PARIS 2133,15.0458,,C +137,1,1,"Newsom, Miss. Helen Monypeny",female,19,0,2,11752,26.2833,D47,S +138,0,1,"Futrelle, Mr. Jacques Heath",male,37,1,0,113803,53.1,C123,S +139,0,3,"Osen, Mr. Olaf Elon",male,16,0,0,7534,9.2167,,S +140,0,1,"Giglio, Mr. Victor",male,24,0,0,PC 17593,79.2,B86,C +141,0,3,"Boulos, Mrs. Joseph (Sultana)",female,,0,2,2678,15.2458,,C +142,1,3,"Nysten, Miss. Anna Sofia",female,22,0,0,347081,7.75,,S +143,1,3,"Hakkarainen, Mrs. Pekka Pietari (Elin Matilda Dolck)",female,24,1,0,STON/O2. 3101279,15.85,,S +144,0,3,"Burke, Mr. Jeremiah",male,19,0,0,365222,6.75,,Q +145,0,2,"Andrew, Mr. Edgardo Samuel",male,18,0,0,231945,11.5,,S +146,0,2,"Nicholls, Mr. Joseph Charles",male,19,1,1,C.A. 33112,36.75,,S +147,1,3,"Andersson, Mr. August Edvard (""Wennerstrom"")",male,27,0,0,350043,7.7958,,S +148,0,3,"Ford, Miss. Robina Maggie 'Ruby'",female,9,2,2,W./C. 6608,34.375,,S +149,0,2,"Navratil, Mr. Michel (""Louis M Hoffman"")",male,36.5,0,2,230080,26,F2,S +150,0,2,"Byles, Rev. Thomas Roussel Davids",male,42,0,0,244310,13,,S +151,0,2,"Bateman, Rev. Robert James",male,51,0,0,S.O.P. 1166,12.525,,S +152,1,1,"Pears, Mrs. Thomas (Edith Wearne)",female,22,1,0,113776,66.6,C2,S +153,0,3,"Meo, Mr. Alfonzo",male,55.5,0,0,A.5. 11206,8.05,,S +154,0,3,"van Billiard, Mr. Austin Blyler",male,40.5,0,2,A/5. 851,14.5,,S +155,0,3,"Olsen, Mr. Ole Martin",male,,0,0,Fa 265302,7.3125,,S +156,0,1,"Williams, Mr. Charles Duane",male,51,0,1,PC 17597,61.3792,,C diff --git a/rpg_db.sqlite3 b/rpg_db.sqlite3 new file mode 100644 index 00000000..e69de29b