mirror of
https://github.com/didyouexpectthat/cs-340.git
synced 2025-08-21 05:33:16 -07:00
Add files via upload
This commit is contained in:
parent
509536bea0
commit
ac3a200a7d
4 changed files with 876 additions and 0 deletions
292
AnimalShelterTest.ipynb
Normal file
292
AnimalShelterTest.ipynb
Normal file
|
@ -0,0 +1,292 @@
|
|||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 1,
|
||||
"id": "f9cc3d73",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# Import the AnimalShelter class\n",
|
||||
"from AnimalShelter import AnimalShelter"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 2,
|
||||
"id": "fe96019a",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# Configure the connection details\n",
|
||||
"username = 'aacuser'\n",
|
||||
"password = '1B@nana4U$'\n",
|
||||
"hostname = 'nv-desktop-services.apporto.com'\n",
|
||||
"port = 30909\n",
|
||||
"database = 'AAC'\n",
|
||||
"collection = 'animals'"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 3,
|
||||
"id": "5685f758",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# Create test data\n",
|
||||
"test_file= {\n",
|
||||
" '':\"10001\",\n",
|
||||
" 'age_upon_outcome':\"2 weeks\", \n",
|
||||
" 'animal_id':\"TEST123\",\n",
|
||||
" 'animal_type': \"Dog\", \n",
|
||||
" 'breed':\"Hawaiian Labrador\", \n",
|
||||
" 'color':\"Black\",\n",
|
||||
" 'date_of_birth':\"2024-03-12\", \n",
|
||||
" 'monthyear': \"2024-03-26 21:18:00\", \n",
|
||||
" 'outcome_subtype':'Transfer',\n",
|
||||
" 'outcome_type':\"GOAT\", \n",
|
||||
" 'sex_upon_outcome':\"Intact Male\", \n",
|
||||
" 'location_long':\"-97.4033754809296\",\n",
|
||||
" 'location_lat':\"30.6664774192579\",\n",
|
||||
" 'age_upon_outcome_in_weeks':\"50 years\", \n",
|
||||
" \"name\": \"Bark Obama\",\n",
|
||||
" \"datetime\": \"2024-03-26 21:18:00\",\n",
|
||||
" \"status\": \"Available\"\n",
|
||||
"}"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 4,
|
||||
"id": "5bd5672a",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# Create a sample query\n",
|
||||
"query = {\"breed\":\"Hawaiian Labrador\"}"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 5,
|
||||
"id": "e43f344a",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# Initiate a failed connection to the MongoDB\n",
|
||||
"shelter = AnimalShelter(\"username\", \"password\", hostname, port, database, collection)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 6,
|
||||
"id": "4d770845",
|
||||
"metadata": {
|
||||
"scrolled": true
|
||||
},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"Could not read animal: Authentication failed., full error: {'ok': 0.0, 'errmsg': 'Authentication failed.', 'code': 18, 'codeName': 'AuthenticationFailed'}\n",
|
||||
"Check existing sample: []\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"# Check to see if the entry exists already \n",
|
||||
"# This assumes this hasn't already been run before.\n",
|
||||
"precheck = shelter.read(query)\n",
|
||||
"print(\"Check existing sample:\", precheck)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 7,
|
||||
"id": "15b3d1bb",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# Initiate the connection to the MongoDB\n",
|
||||
"shelter = AnimalShelter(username, password, hostname, port, database, collection);"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 8,
|
||||
"id": "7f73158c",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"Check existing sample: []\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"# Check to see if the entry exists already \n",
|
||||
"# This assumes this hasn't already been run before.\n",
|
||||
"precheck = shelter.read(query)\n",
|
||||
"print(\"Check existing sample:\", precheck)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 9,
|
||||
"id": "38e43a66",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"Animal added successfully\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"True"
|
||||
]
|
||||
},
|
||||
"execution_count": 9,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"# Add the animal to the database\n",
|
||||
"shelter.create(test_file)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 10,
|
||||
"id": "bb4ebdd0",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"Check post-add sample: [{'': '10001', 'age_upon_outcome': '2 weeks', 'animal_id': 'TEST123', 'animal_type': 'Dog', 'breed': 'Hawaiian Labrador', 'color': 'Black', 'date_of_birth': '2024-03-12', 'monthyear': '2024-03-26 21:18:00', 'outcome_subtype': 'Transfer', 'outcome_type': 'GOAT', 'sex_upon_outcome': 'Intact Male', 'location_long': '-97.4033754809296', 'location_lat': '30.6664774192579', 'age_upon_outcome_in_weeks': '50 years', 'name': 'Bark Obama', 'datetime': '2024-03-26 21:18:00', 'status': 'Available'}]\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"# Confirm the entry was added\n",
|
||||
"postcheck = shelter.read(query)\n",
|
||||
"print(\"Check post-add sample:\", postcheck)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 11,
|
||||
"id": "a822e964",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"Animals updated: 1\n",
|
||||
"Updated items: 1\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"# Update the test animal to an Adopted status\n",
|
||||
"query = {\"animal_id\": \"TEST123\"}\n",
|
||||
"updates = {\"status\": \"Adopted\"}\n",
|
||||
"result = shelter.update(query, updates)\n",
|
||||
"print(f\"Updated items: {result}\")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 12,
|
||||
"id": "5f5300c2",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"Result: [{'': '10001', 'age_upon_outcome': '2 weeks', 'animal_id': 'TEST123', 'animal_type': 'Dog', 'breed': 'Hawaiian Labrador', 'color': 'Black', 'date_of_birth': '2024-03-12', 'monthyear': '2024-03-26 21:18:00', 'outcome_subtype': 'Transfer', 'outcome_type': 'GOAT', 'sex_upon_outcome': 'Intact Male', 'location_long': '-97.4033754809296', 'location_lat': '30.6664774192579', 'age_upon_outcome_in_weeks': '50 years', 'name': 'Bark Obama', 'datetime': '2024-03-26 21:18:00', 'status': 'Adopted'}]\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"# Confirm the update took place\n",
|
||||
"check = shelter.read(query)\n",
|
||||
"print(f\"Result: {check}\")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 13,
|
||||
"id": "974092b3",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"Animals deleted: 1\n",
|
||||
"Deleted result: 1\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"# Delete animals matching the query\n",
|
||||
"result = shelter.delete(query)\n",
|
||||
"print(f\"Deleted result: {result}\")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 14,
|
||||
"id": "aae82505",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"Check for records: []\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"# Check for the deleted animal\n",
|
||||
"check = shelter.read(query)\n",
|
||||
"print(\"Check for records: \", check)\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
"kernelspec": {
|
||||
"display_name": "Python 3 (ipykernel)",
|
||||
"language": "python",
|
||||
"name": "python3"
|
||||
},
|
||||
"language_info": {
|
||||
"codemirror_mode": {
|
||||
"name": "ipython",
|
||||
"version": 3
|
||||
},
|
||||
"file_extension": ".py",
|
||||
"mimetype": "text/x-python",
|
||||
"name": "python",
|
||||
"nbconvert_exporter": "python",
|
||||
"pygments_lexer": "ipython3",
|
||||
"version": "3.9.12"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 5
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue