From a0f38492fcdb1d1cb160b1ab79ee084956fde08c Mon Sep 17 00:00:00 2001 From: faithngetich Date: Sun, 19 Mar 2017 22:33:23 +0300 Subject: [PATCH 01/52] Initial commit --- .gitignore | 2 +- FETCH_HEAD | 0 __init__.py | 0 app.py | 0 classes/__init__.py | 0 models/__init__.py | 0 tests/__init__.py | 0 tests/test_amity.py | 61 +++++++++++++++++++++++++++++++++++++++++++++ views.py | 38 ++++++++++++++++++++++++++++ 9 files changed, 100 insertions(+), 1 deletion(-) create mode 100644 FETCH_HEAD create mode 100644 __init__.py create mode 100644 app.py create mode 100644 classes/__init__.py create mode 100644 models/__init__.py create mode 100644 tests/__init__.py create mode 100644 tests/test_amity.py create mode 100644 views.py diff --git a/.gitignore b/.gitignore index 72364f9..5c9b562 100644 --- a/.gitignore +++ b/.gitignore @@ -2,7 +2,7 @@ __pycache__/ *.py[cod] *$py.class - +,pyc # C extensions *.so diff --git a/FETCH_HEAD b/FETCH_HEAD new file mode 100644 index 0000000..e69de29 diff --git a/__init__.py b/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/app.py b/app.py new file mode 100644 index 0000000..e69de29 diff --git a/classes/__init__.py b/classes/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/models/__init__.py b/models/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/test_amity.py b/tests/test_amity.py new file mode 100644 index 0000000..371d5ae --- /dev/null +++ b/tests/test_amity.py @@ -0,0 +1,61 @@ +import unittest +from ..views import Amity +class Amitytest(unittest.TestCase): + + def setUp(self): + self.amity = Amity() + # self.fellow = fellow + # self.staff = staff + # self.livingspace = create_rooms + # self.office = create_rooms + + def test_create_office(self): + # amity = Amity() + self.amity.create_rooms('office', 'Krypton') + all_rooms = len(self.amity.All_rooms)+1 + self.assertEqual(len(self.amity.All_rooms), all_rooms, "office added succesfully") + + def test_add_person(self): + self.amity.add_person('dede','fellow') + all_people = len(self.amity.All_people)+1 + self.assertEqual(len(self.amity.All_people), all_people, "person added succesfully") + + def test_person_added_is_fellow(self): + self.amity.add_person('dede', 'fellow') + self.assertIn('dede', self.amity.All_fellows, "dede added as fellow") + self.assertFalse('dede', Staff) + self.assertNotIn('dede', self.amity.All_staff, "dede is not staff") + + def test_fellow_wants_accomodation(self): + self.amity.add_person('dede', 'fellow', 'wants_accomodation = Y') + self.assertTrue('dede' in self.amity.Accomodation_list) + self.assertFalse('dede' in self.amity.No_accomodation_list) + # self.amity.add_person('dede', 'fellow', 'wants_accomodation = Y') + # self.assertRaises("Fellow already exists") + + def test_fellow_does_not_want_accomodation(self): + self.amity.add_person('awesome', 'fellow', 'wants_accomodation') + self.assertTrue('awesome' in self.amity.No_accomodation_list) + self.assertFalse('awesome' in self.amity.Accomodation_list) + + def test_person_added_is_staff(self): + self.amity.add_person('brian', 'staff') + self.assertIn('brian', self.amity.All_staff, "brian added as staff" ) + self.assertFalse('brian', Fellow) + self.assertNotIn('brian', self.amity.All_fellows, "brian is not staff") + + def test_Staff_gets_no_accomodation(self): + self.amity.add_person('luke', 'staff', 'wants_accomodation') + self.assertTrue('dede' in self.amity.No_accomodation_list) + + def test_if_room_is_livingspace(self): + self.amity.create_rooms('livingspace', 'ruby') + all_rooms = len(self.amity.All_rooms)+1 + self.assertEqual(len(self.amity.All_rooms), all_rooms, "livingroom added succesfully") + + def test_reallocate_person(self): + pass + +if __name__ == '__main__': + unittest.main() + diff --git a/views.py b/views.py new file mode 100644 index 0000000..7d93c28 --- /dev/null +++ b/views.py @@ -0,0 +1,38 @@ + +class Amity(): + All_people = [] + All_staff = [] + All_fellows = [] + All_rooms = [] + Accomodation_list = [] + No_accomodation_list = [] + Allocated_rooms = [] + Unallocated_rooms = [] + + def create_rooms(self, rtype, rname): + # self.rtype = rtype + # self.rname = rname + pass + + + def add_person(self, name, occupation, wants_accomodation = 'N'): + pass + # self.name = name + # self.occupation = occupation + + + def reallocate_person(self, name, newroom): + + pass + + def load_people(): + pass + + def print_allocations(self, name, ): + pass + + def print_unallocated(): + pass + + def print_rooms(): + pass \ No newline at end of file From c2e774edb4a3d22410ebcfe3f741a2690c1c2785 Mon Sep 17 00:00:00 2001 From: faithngetich Date: Fri, 24 Mar 2017 23:31:30 +0300 Subject: [PATCH 02/52] add gitignore content --- .gitignore | 101 ++++++++++++++++++++++++++++++++++++++++++++ tests/test_amity.py | 16 +++---- 2 files changed, 109 insertions(+), 8 deletions(-) diff --git a/.gitignore b/.gitignore index 5c9b562..63178c3 100644 --- a/.gitignore +++ b/.gitignore @@ -87,3 +87,104 @@ ENV/ # Rope project settings .ropeproject + + +# Created by https://www.gitignore.io/api/python + +### Python ### +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +env/ +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +*.egg-info/ +.installed.cfg +*.egg + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*,cover +.hypothesis/ + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# pyenv +.python-version + +# celery beat schedule file +celerybeat-schedule + +# SageMath parsed files +*.sage.py + +# dotenv +.env + +# virtualenv +.venv +venv/ +ENV/ + +# Spyder project settings +.spyderproject + +# Rope project settings +.ropeproject + +# End of https://www.gitignore.io/api/python \ No newline at end of file diff --git a/tests/test_amity.py b/tests/test_amity.py index 371d5ae..0e90bac 100644 --- a/tests/test_amity.py +++ b/tests/test_amity.py @@ -13,18 +13,18 @@ def test_create_office(self): # amity = Amity() self.amity.create_rooms('office', 'Krypton') all_rooms = len(self.amity.All_rooms)+1 - self.assertEqual(len(self.amity.All_rooms), all_rooms, "office added succesfully") + self.assertEqual(len(self.amity.All_rooms), all_rooms, msg = "office added succesfully") def test_add_person(self): self.amity.add_person('dede','fellow') all_people = len(self.amity.All_people)+1 - self.assertEqual(len(self.amity.All_people), all_people, "person added succesfully") + self.assertEqual(len(self.amity.All_people), all_people, msg = "person added succesfully") def test_person_added_is_fellow(self): self.amity.add_person('dede', 'fellow') - self.assertIn('dede', self.amity.All_fellows, "dede added as fellow") + self.assertIn('dede', self.amity.All_fellows, msg = "dede added as fellow") self.assertFalse('dede', Staff) - self.assertNotIn('dede', self.amity.All_staff, "dede is not staff") + self.assertNotIn('dede', self.amity.All_staff, msg = "dede is not staff") def test_fellow_wants_accomodation(self): self.amity.add_person('dede', 'fellow', 'wants_accomodation = Y') @@ -40,18 +40,18 @@ def test_fellow_does_not_want_accomodation(self): def test_person_added_is_staff(self): self.amity.add_person('brian', 'staff') - self.assertIn('brian', self.amity.All_staff, "brian added as staff" ) + self.assertIn('brian', self.amity.All_staff, msg = "brian added as staff" ) self.assertFalse('brian', Fellow) - self.assertNotIn('brian', self.amity.All_fellows, "brian is not staff") + self.assertNotIn('brian', self.amity.All_fellows, msg = "brian is not staff") def test_Staff_gets_no_accomodation(self): - self.amity.add_person('luke', 'staff', 'wants_accomodation') + self.amity.add_person('luke', 'staff', msg = 'wants_accomodation') self.assertTrue('dede' in self.amity.No_accomodation_list) def test_if_room_is_livingspace(self): self.amity.create_rooms('livingspace', 'ruby') all_rooms = len(self.amity.All_rooms)+1 - self.assertEqual(len(self.amity.All_rooms), all_rooms, "livingroom added succesfully") + self.assertEqual(len(self.amity.All_rooms), all_rooms, msg = "livingroom added succesfully") def test_reallocate_person(self): pass From d448eb38cc659a1293072fe41274429853fb8e8d Mon Sep 17 00:00:00 2001 From: faithngetich Date: Thu, 30 Mar 2017 10:19:54 +0300 Subject: [PATCH 03/52] add test cases --- tests/test_amity.py | 73 ++++++++++++++++++++++++++++++++------------- views.py | 27 ++++++++++------- 2 files changed, 68 insertions(+), 32 deletions(-) diff --git a/tests/test_amity.py b/tests/test_amity.py index 0e90bac..49cfae4 100644 --- a/tests/test_amity.py +++ b/tests/test_amity.py @@ -9,52 +9,83 @@ def setUp(self): # self.livingspace = create_rooms # self.office = create_rooms - def test_create_office(self): + def test_create_room_function_works(self): # amity = Amity() self.amity.create_rooms('office', 'Krypton') - all_rooms = len(self.amity.All_rooms)+1 - self.assertEqual(len(self.amity.All_rooms), all_rooms, msg = "office added succesfully") + all_rooms = len(self.amity.allocated_rooms)+1 + self.assertEqual(len(self.amity.allocated_rooms), all_rooms, msg = "office(s) not added successfully ") - def test_add_person(self): + + + def test_add_person_adds_fellow_to_list(self): self.amity.add_person('dede','fellow') - all_people = len(self.amity.All_people)+1 - self.assertEqual(len(self.amity.All_people), all_people, msg = "person added succesfully") + all_fellow1 = len(self.amity.all_fellows) + 1 + self.assertEqual(len(self.amity.all_fellows), all_fellow1, msg = "fellow added succesfully") + + def test_add_person_adds_staff_to_list(self): + self.amity.add_person('luke','staff') + all_staff1 = len(self.amity.all_staff) + 1 + self.assertEqual(len(self.amity.all_staff), all_staff1, msg = "staff added succesfully") def test_person_added_is_fellow(self): self.amity.add_person('dede', 'fellow') - self.assertIn('dede', self.amity.All_fellows, msg = "dede added as fellow") - self.assertFalse('dede', Staff) - self.assertNotIn('dede', self.amity.All_staff, msg = "dede is not staff") + self.assertIn('dede', self.amity.all_fellows, msg = "dede added as fellow") + self.assertFalse('dede', 'Staff') + self.assertNotIn('dede', self.amity.all_staff, msg = "dede is not staff") def test_fellow_wants_accomodation(self): self.amity.add_person('dede', 'fellow', 'wants_accomodation = Y') - self.assertTrue('dede' in self.amity.Accomodation_list) + self.assertTrue('dede' in self.amity.accomodation_list) self.assertFalse('dede' in self.amity.No_accomodation_list) # self.amity.add_person('dede', 'fellow', 'wants_accomodation = Y') # self.assertRaises("Fellow already exists") def test_fellow_does_not_want_accomodation(self): - self.amity.add_person('awesome', 'fellow', 'wants_accomodation') - self.assertTrue('awesome' in self.amity.No_accomodation_list) - self.assertFalse('awesome' in self.amity.Accomodation_list) + self.amity.add_person('dede', 'fellow', 'wants_accomodation = N') + # self.assertTrue('dede' in self.amity.No_accomodation_list) + self.assertFalse('awesome' in self.amity.accomodation_list) def test_person_added_is_staff(self): self.amity.add_person('brian', 'staff') - self.assertIn('brian', self.amity.All_staff, msg = "brian added as staff" ) - self.assertFalse('brian', Fellow) - self.assertNotIn('brian', self.amity.All_fellows, msg = "brian is not staff") + self.assertIn('brian', self.amity.all_staff, msg = "brian added as staff" ) + self.assertFalse('brian', 'fellow') + self.assertNotIn('brian', self.amity.all_fellows, msg = "brian is not staff") def test_Staff_gets_no_accomodation(self): - self.amity.add_person('luke', 'staff', msg = 'wants_accomodation') - self.assertTrue('dede' in self.amity.No_accomodation_list) + self.amity.add_person('luke', 'staff', 'wants_accomodation') + self.assertFalse('luke' in self.amity.accomodation_list) def test_if_room_is_livingspace(self): self.amity.create_rooms('livingspace', 'ruby') - all_rooms = len(self.amity.All_rooms)+1 - self.assertEqual(len(self.amity.All_rooms), all_rooms, msg = "livingroom added succesfully") + living_space1 = len(self.amity.living_spaces) + 1 + #self.assertEqual(ruby.room_capacity, 4) + self.assertEqual(len(self.amity.living_spaces), living_space1, msg = "livingroom is not added succesfully") + + def test_if_room_is_office(self): + self.amity.create_rooms('office', 'hogwarts') + #self.assertEqual(hogwarts.room_capacity, 6) + offices1 = len(self.amity.offices) + 1 + self.assertEqual(len(self.amity.offices), offices1, msg = "livingroom is not added succesfully") + def test_reallocate_person(self): - pass + self.amity.create_rooms('office', 'oculus') + self.amity.add_person('dede', 'staff', 'N') + self.amity.create_rooms('office', 'valhalla') + self.amity.reallocate_person('dede', 'valhalla') + self.assertIn('dede', self.amity.allocated_rooms['valhalla']) + + def test_print_allocations_returns_all_allocated_names(self): + self.amity.add_person('dede', 'fellow') + allocated_names = len(self.amity.allocated_rooms) + 1 + self.assertEqual(len(self.amity.allocated_rooms), allocated_names, msg = "allocated person is missing") + + def test_print_unallocated_returns_all_not_in_accomodation_list(self): + self.amity.print_unallocated('dede') + self.assertFalse('dede' in self.amity.accomodation_list, msg = "person not in accomodation list") + + #def test_print_rooms + if __name__ == '__main__': unittest.main() diff --git a/views.py b/views.py index 7d93c28..e9f43d6 100644 --- a/views.py +++ b/views.py @@ -1,13 +1,16 @@ class Amity(): - All_people = [] - All_staff = [] - All_fellows = [] - All_rooms = [] - Accomodation_list = [] - No_accomodation_list = [] - Allocated_rooms = [] - Unallocated_rooms = [] + + def __init__(self): + self.all_staff = [] + self.all_fellows = [] + self.living_spaces = [] + self.offices = [] + self.accomodation_list = [] + self.allocated_rooms = {} + + + def create_rooms(self, rtype, rname): # self.rtype = rtype @@ -15,6 +18,8 @@ def create_rooms(self, rtype, rname): pass + + def add_person(self, name, occupation, wants_accomodation = 'N'): pass # self.name = name @@ -28,11 +33,11 @@ def reallocate_person(self, name, newroom): def load_people(): pass - def print_allocations(self, name, ): + def print_allocations(self): pass - def print_unallocated(): + def print_unallocated(self, name): pass - def print_rooms(): + def print_rooms(self, rname): pass \ No newline at end of file From 09768e65e4c1d5f9215f592d939febb2fdc1c49c Mon Sep 17 00:00:00 2001 From: faithngetich Date: Thu, 6 Apr 2017 09:12:10 +0300 Subject: [PATCH 04/52] create models --- amity.db | Bin 0 -> 12288 bytes models/base.py | 3 +++ models/migrate.py | 9 +++++++ models/person.py | 14 ++++++++++ models/room.py | 17 ++++++++++++ tests/test_amity.py | 64 +++++++++++++++++++++++--------------------- views.py | 31 ++++++++++++--------- 7 files changed, 94 insertions(+), 44 deletions(-) create mode 100644 amity.db create mode 100644 models/base.py create mode 100644 models/migrate.py create mode 100644 models/person.py create mode 100644 models/room.py diff --git a/amity.db b/amity.db new file mode 100644 index 0000000000000000000000000000000000000000..e55dee0ac976b4f0aa312b2642acf8e3d5ba2ea0 GIT binary patch literal 12288 zcmeI$O-jQ+6bJB0s+L4*bRi+ThpPlc6fa;b!Is9f#wc_l5}OGGnvOIn#brH^NAU>W zK)iyJN}(0Sg&UFoBlGcQ63F}QW-c%MtmKr6aUPd+%(j`LuoEK2*oJI1*%qP7$=V{3 zqp~#rZo0t^G`k^p)vYIHjAe&_00bZa0SG_<0uX=z1Rwwb2>d88bJesppjJBYk9FQlLwQE=t^`=o25IOlZjhRv26R(bhw zzmiYmQCZx^gMr9J5|^16(P_8qdu~v@-3#02ZrG=e*C#tmoNBGv@|qp8zxc2nkbSsM zM~Togqar>UXJ+|m-B@RSdSVrs}6fR%-JhgN;n literal 0 HcmV?d00001 diff --git a/models/base.py b/models/base.py new file mode 100644 index 0000000..7c2377a --- /dev/null +++ b/models/base.py @@ -0,0 +1,3 @@ +from sqlalchemy.ext.declarative import declarative_base + +Base = declarative_base() \ No newline at end of file diff --git a/models/migrate.py b/models/migrate.py new file mode 100644 index 0000000..b260a95 --- /dev/null +++ b/models/migrate.py @@ -0,0 +1,9 @@ +from base import Base +from sqlalchemy import create_engine +from person import Person +from room import Room + +eng = create_engine('sqlite:///amity.db') + +Base.metadata.bind = eng +Base.metadata.create_all() \ No newline at end of file diff --git a/models/person.py b/models/person.py new file mode 100644 index 0000000..cd56509 --- /dev/null +++ b/models/person.py @@ -0,0 +1,14 @@ +from sqlalchemy import Column, Integer, String, Boolean +from base import Base + + +class Person(Base): + __tablename__ = "People" + + id = Column(Integer, primary_key=True, autoincrement=True) + name = Column(String) + type = Column(String) + wants_accomodation = Column(Boolean) + + def __repr__(self): + return 'name{}'.format(self.name) diff --git a/models/room.py b/models/room.py new file mode 100644 index 0000000..7662adf --- /dev/null +++ b/models/room.py @@ -0,0 +1,17 @@ +from sqlalchemy import Column, Integer, String, Boolean +from base import Base + + +class Room(Base): + __tablename__ = "Rooms" + + id = Column(Integer, primary_key=True, autoincrement=True) + name = Column(String) + type = Column(String) + members = Column(String) + + + + + def __repr__(self): + return 'name{}'.format(self.name) \ No newline at end of file diff --git a/tests/test_amity.py b/tests/test_amity.py index 49cfae4..f2ec3b1 100644 --- a/tests/test_amity.py +++ b/tests/test_amity.py @@ -4,46 +4,49 @@ class Amitytest(unittest.TestCase): def setUp(self): self.amity = Amity() - # self.fellow = fellow - # self.staff = staff - # self.livingspace = create_rooms - # self.office = create_rooms def test_create_room_function_works(self): - # amity = Amity() - self.amity.create_rooms('office', 'Krypton') + self.amity.create_room('office', 'Krypton') all_rooms = len(self.amity.allocated_rooms)+1 self.assertEqual(len(self.amity.allocated_rooms), all_rooms, msg = "office(s) not added successfully ") - - def test_add_person_adds_fellow_to_list(self): self.amity.add_person('dede','fellow') - all_fellow1 = len(self.amity.all_fellows) + 1 - self.assertEqual(len(self.amity.all_fellows), all_fellow1, msg = "fellow added succesfully") + all_fellows = len(self.amity.all_fellows) + 1 + self.assertEqual(len(self.amity.all_fellows), all_fellows, msg = "fellow not added") def test_add_person_adds_staff_to_list(self): self.amity.add_person('luke','staff') - all_staff1 = len(self.amity.all_staff) + 1 - self.assertEqual(len(self.amity.all_staff), all_staff1, msg = "staff added succesfully") + all_staff(s) = len(self.amity.all_staff) + 1 + self.assertEqual(len(self.amity.all_staff), all_staff(s), msg = "staff not added") def test_person_added_is_fellow(self): self.amity.add_person('dede', 'fellow') - self.assertIn('dede', self.amity.all_fellows, msg = "dede added as fellow") + self.assertIn('dede', self.amity.all_fellows, msg = "person not added as fellow") + self.assertFalse('dede', 'Staff') + self.assertNotIn('dede', self.amity.all_staff, msg = "dede is not staff") + + def test_person_added_is_staff(self): + self.amity.add_person('dede', 'staff') + self.assertIn('dede', self.amity.all_fellows, msg = "person not added as fellow") self.assertFalse('dede', 'Staff') self.assertNotIn('dede', self.amity.all_staff, msg = "dede is not staff") def test_fellow_wants_accomodation(self): self.amity.add_person('dede', 'fellow', 'wants_accomodation = Y') - self.assertTrue('dede' in self.amity.accomodation_list) - self.assertFalse('dede' in self.amity.No_accomodation_list) - # self.amity.add_person('dede', 'fellow', 'wants_accomodation = Y') - # self.assertRaises("Fellow already exists") + self.assertTrue('dede' in self.amity.accomodation_list, msg = 'fellow not in accomodation list') + self.assertFalse('dede' not in self.amity.accomodation_list, msg = 'fellow should be in the accomodation list') + self.amity.add_person('dede', 'fellow', 'wants_accomodation = Y') + self.assertRaises("Fellow already exists") def test_fellow_does_not_want_accomodation(self): self.amity.add_person('dede', 'fellow', 'wants_accomodation = N') - # self.assertTrue('dede' in self.amity.No_accomodation_list) - self.assertFalse('awesome' in self.amity.accomodation_list) + self.assertTrue('dede' in self.amity.accomodation_list) + self.assertFalse('awesome' in self.amity.accomodation_list, msg = 'fellow does not want accomodation') + + def test_Staff_gets_no_accomodation(self): + self.amity.add_person('luke', 'staff', 'wants_accomodation') + self.assertFalse('luke' in self.amity.accomodation_list) def test_person_added_is_staff(self): self.amity.add_person('brian', 'staff') @@ -51,27 +54,22 @@ def test_person_added_is_staff(self): self.assertFalse('brian', 'fellow') self.assertNotIn('brian', self.amity.all_fellows, msg = "brian is not staff") - def test_Staff_gets_no_accomodation(self): - self.amity.add_person('luke', 'staff', 'wants_accomodation') - self.assertFalse('luke' in self.amity.accomodation_list) - def test_if_room_is_livingspace(self): - self.amity.create_rooms('livingspace', 'ruby') - living_space1 = len(self.amity.living_spaces) + 1 + self.amity.create_room('livingspace', 'ruby') + living_spaces = len(self.amity.living_spaces) + 1 #self.assertEqual(ruby.room_capacity, 4) - self.assertEqual(len(self.amity.living_spaces), living_space1, msg = "livingroom is not added succesfully") + self.assertEqual(len(self.amity.living_spaces), living_spaces, msg = "livingroom is not added succesfully") def test_if_room_is_office(self): - self.amity.create_rooms('office', 'hogwarts') + self.amity.create_room('office', 'hogwarts') #self.assertEqual(hogwarts.room_capacity, 6) offices1 = len(self.amity.offices) + 1 self.assertEqual(len(self.amity.offices), offices1, msg = "livingroom is not added succesfully") - def test_reallocate_person(self): - self.amity.create_rooms('office', 'oculus') + self.amity.create_room('office', 'oculus') self.amity.add_person('dede', 'staff', 'N') - self.amity.create_rooms('office', 'valhalla') + self.amity.create_room('office', 'valhalla') self.amity.reallocate_person('dede', 'valhalla') self.assertIn('dede', self.amity.allocated_rooms['valhalla']) @@ -84,7 +82,11 @@ def test_print_unallocated_returns_all_not_in_accomodation_list(self): self.amity.print_unallocated('dede') self.assertFalse('dede' in self.amity.accomodation_list, msg = "person not in accomodation list") - #def test_print_rooms + def test_print_rooms_returns_names(self): + self.amity.create_room('office', 'kikwete') + self.amity.add_person('collins', 'staff', 'N') + self.amity.reallocate_person('collins','kikwete') + self.assertIn('collins', self.amity.print_room('kikwete')) if __name__ == '__main__': diff --git a/views.py b/views.py index e9f43d6..fa9fea9 100644 --- a/views.py +++ b/views.py @@ -1,7 +1,12 @@ - +from models.migrate import eng +from sqlalchemy.orm import sessionmaker +from models.room import Room +from models.person import Person class Amity(): def __init__(self): + Session = sessionmaker(bind=eng) + self.session = Session() self.all_staff = [] self.all_fellows = [] self.living_spaces = [] @@ -9,25 +14,25 @@ def __init__(self): self.accomodation_list = [] self.allocated_rooms = {} - - + def create_room(self, rtype, rname): + self.session.add(Room(name=rname, type=rtype, members='')) + self.session.commit() + + def list_rooms(self): + rs = ses.query(room).all() + for room in rs: + print room.Name - def create_rooms(self, rtype, rname): - # self.rtype = rtype - # self.rname = rname - pass - - def add_person(self, name, occupation, wants_accomodation = 'N'): - pass + self.session.add(Person(name=name, type=occupation, wants_accomodation='N')) + self.session.commit() + # self.name = name # self.occupation = occupation - def reallocate_person(self, name, newroom): - pass def load_people(): @@ -39,5 +44,5 @@ def print_allocations(self): def print_unallocated(self, name): pass - def print_rooms(self, rname): + def print_room(self, rname): pass \ No newline at end of file From 6e25acf1b3f0a2f6b312e2c7f38c48e914ab208a Mon Sep 17 00:00:00 2001 From: faithngetich Date: Wed, 12 Apr 2017 23:12:48 +0300 Subject: [PATCH 05/52] add logic --- amity.db | Bin 12288 -> 12288 bytes models/amity.db | Bin 0 -> 12288 bytes models/model.py | 29 +++++++++ models/person.py | 14 ----- models/persons.py | 27 +++++++++ models/room.py | 17 ------ models/rooms.py | 19 ++++++ tests/test_amity.py | 5 -- views.py | 139 ++++++++++++++++++++++++++++++-------------- 9 files changed, 171 insertions(+), 79 deletions(-) create mode 100644 models/amity.db create mode 100644 models/model.py delete mode 100644 models/person.py create mode 100644 models/persons.py delete mode 100644 models/room.py create mode 100644 models/rooms.py diff --git a/amity.db b/amity.db index e55dee0ac976b4f0aa312b2642acf8e3d5ba2ea0..636ea97259ecb188100ae8b770f61965cc9a35bb 100644 GIT binary patch delta 176 zcmZojXh@hK&B!xR#+i|4W5N=CE@u8?4E%5TZ}K18EGV#pUtN%yl|fRHH$N>cGda~S zu_!MyQHTjBBn=fROU%hg%t@U5R$g3)oxg*D|2_Xb{&W0$_*e7K;_m>OQN-^iz|P7b xF3IVYn44OhmYS23U(U}46cLAr6qh8XrSY?(2?(%&_4p;GWF|uNOg^V?1OSpnGSUD5 delta 59 zcmZojXh@hK&B!)U#+i|AW5N=CHb(xp4E%353kq!IpV*)``K`P-7c>7k2LAW__xR62 Mgaf!IpVK!205vERvH$=8 diff --git a/models/amity.db b/models/amity.db new file mode 100644 index 0000000000000000000000000000000000000000..166f892c43b8f65637b144a1b052edf262461328 GIT binary patch literal 12288 zcmeI#%}T>S5C`y0DwIb2xP{(^o)Rdc_yTUjVnbt6*C_NLlC}{7rdyJTc#IF^GnzyL zttcM6mH)y{c6K+A`Q*IrV@^r*5lD(IXYGfiU`M2s=Lnw@I4qt5r*q))0- zJLy>m)v12?&W^GwU_bx@5P$##AOHafKmY;|fB*#k6ezjgHT!+-?Y@ZSPw_NX>o#^A zDR?L-&d)hGg_sQ5w@7m(G~WIxk+=Tlq`0D)NVD zu~4a6Mn$4lGztPwaKFAimF^XnGn$AQS;^9__nfhCCS?8aqU)1&I;1n(Htcd=>zbyi zmCsELQmHg=g1%irv-h6@(m0*RS-x50_pdhWx;L+yehdge00Izz00bZa0SG_<0uX=z j1a?>e{r?XCT$Ba@2tWV=5P$##AOHafKmY;|_!9U4egS4N literal 0 HcmV?d00001 diff --git a/models/model.py b/models/model.py new file mode 100644 index 0000000..7b419c5 --- /dev/null +++ b/models/model.py @@ -0,0 +1,29 @@ +from sqlalchemy import Column, Integer, String +from base import Base + + +class Person(Base): + __tablename__ = "People" + + id = Column(Integer, primary_key=True, autoincrement=True) + name = Column(String) + type = Column(String) + wants_accomodation = Column(Boolean) + + def __repr__(self): + return 'name{}'.format(self.name) + + +class Room(Base): + __tablename__ = "Rooms" + + id = Column(Integer, primary_key=True, autoincrement=True) + name = Column(String) + type = Column(String) + members = Column(String) + + + def __repr__(self): + return 'name{}'.format(self.name) + + diff --git a/models/person.py b/models/person.py deleted file mode 100644 index cd56509..0000000 --- a/models/person.py +++ /dev/null @@ -1,14 +0,0 @@ -from sqlalchemy import Column, Integer, String, Boolean -from base import Base - - -class Person(Base): - __tablename__ = "People" - - id = Column(Integer, primary_key=True, autoincrement=True) - name = Column(String) - type = Column(String) - wants_accomodation = Column(Boolean) - - def __repr__(self): - return 'name{}'.format(self.name) diff --git a/models/persons.py b/models/persons.py new file mode 100644 index 0000000..569bd55 --- /dev/null +++ b/models/persons.py @@ -0,0 +1,27 @@ +class Person(object): + def __init__(self,name): + self.name = name + self.assigned_office = "" + + def __repr__(self): + return self.__class__.__name__ + +class Staff(Person): + def __init__(self, person): + super(Staff, self).__init__(person) + self.accomodation = "None" + self.assigned_liningSpace = "None" + +class Fellow(Person): + def __init__(self, person): + super(Fellow, self).__init__(person) + self.accomodation = "" + self.assigned_liningSpace = "" + + + + + + + + \ No newline at end of file diff --git a/models/room.py b/models/room.py deleted file mode 100644 index 7662adf..0000000 --- a/models/room.py +++ /dev/null @@ -1,17 +0,0 @@ -from sqlalchemy import Column, Integer, String, Boolean -from base import Base - - -class Room(Base): - __tablename__ = "Rooms" - - id = Column(Integer, primary_key=True, autoincrement=True) - name = Column(String) - type = Column(String) - members = Column(String) - - - - - def __repr__(self): - return 'name{}'.format(self.name) \ No newline at end of file diff --git a/models/rooms.py b/models/rooms.py new file mode 100644 index 0000000..31369c1 --- /dev/null +++ b/models/rooms.py @@ -0,0 +1,19 @@ +class Room(object): + + def __init__(self, room_name): + self.room_name = room_name + self.occupants = [] + + def __repr__(self): + return "%s" % (self.room_name) + + @property + def room_type(self): + return self.__class__.__name__ + +class OfficeSpace(Room): + capacity = 6 + +class LivingSpace(Room): + capacity = 4 + diff --git a/tests/test_amity.py b/tests/test_amity.py index f2ec3b1..0d49ba5 100644 --- a/tests/test_amity.py +++ b/tests/test_amity.py @@ -15,11 +15,6 @@ def test_add_person_adds_fellow_to_list(self): all_fellows = len(self.amity.all_fellows) + 1 self.assertEqual(len(self.amity.all_fellows), all_fellows, msg = "fellow not added") - def test_add_person_adds_staff_to_list(self): - self.amity.add_person('luke','staff') - all_staff(s) = len(self.amity.all_staff) + 1 - self.assertEqual(len(self.amity.all_staff), all_staff(s), msg = "staff not added") - def test_person_added_is_fellow(self): self.amity.add_person('dede', 'fellow') self.assertIn('dede', self.amity.all_fellows, msg = "person not added as fellow") diff --git a/views.py b/views.py index fa9fea9..2689631 100644 --- a/views.py +++ b/views.py @@ -1,48 +1,101 @@ -from models.migrate import eng -from sqlalchemy.orm import sessionmaker -from models.room import Room -from models.person import Person -class Amity(): - +# from models.migrate import eng +# from sqlalchemy.orm import sessionmaker +from models.persons import Fellow +from models.persons import Staff +from models.rooms import LivingSpace +from models.rooms import OfficeSpace +from models.rooms import Room + + +class Amity(object): def __init__(self): - Session = sessionmaker(bind=eng) - self.session = Session() self.all_staff = [] - self.all_fellows = [] - self.living_spaces = [] + self.all_fellows = [{"person_type" : "fellow", "person_name" : "Tetio"}] + self.living_spaces = [{"room_type" : "living_space", "room_name" : "Vazlhala"}] self.offices = [] self.accomodation_list = [] self.allocated_rooms = {} - - def create_room(self, rtype, rname): - self.session.add(Room(name=rname, type=rtype, members='')) - self.session.commit() - - def list_rooms(self): - rs = ses.query(room).all() - for room in rs: - print room.Name - - - - def add_person(self, name, occupation, wants_accomodation = 'N'): - self.session.add(Person(name=name, type=occupation, wants_accomodation='N')) - self.session.commit() - - # self.name = name - # self.occupation = occupation - - def reallocate_person(self, name, newroom): - pass - - def load_people(): - pass - - def print_allocations(self): - pass - - def print_unallocated(self, name): - pass - - def print_room(self, rname): - pass \ No newline at end of file + + def create_room(self, room): + if room["room_type"] == "office": + for rooms in self.offices: + if room["room_name"] == rooms["room_name"]: + print( "\n" + rooms.room_name.upper()+"already exists. \n") + return + else: + new_office = OfficeSpace(room["room_name"]) + self.offices.append(new_office) + text = ("\n You have successfully added " + new_office.room_name.upper() + " to offices in amity") + print(text) + else: + if self.living_spaces: + for rooms in self.living_spaces: + if room["room_name"] == rooms["room_name"]: + print( "\n" + rooms["room_name"].upper()+"already exists. \n") + return + else: + new_livingSpace = room["room_name"] + self.living_spaces.append(new_livingSpace) + text = ("\n You have successfully added" + new_livingSpace.upper() + "to living space in amity") + print(text) + return +# amity = Amity() +# amity.create_room({"room_type" : "living_space", "room_name" : "Valhala"}) + + def add_person(self, person): + if person["person_type"] == "fellow": + for people in self.all_fellows: + if person["person_name"] == people["person_name"]: + print("\n"+person["person_name"].upper()+"already exists.\n") + return + else: + new_person = person["person_name"] + # new_person.accomodation = person["wants_accomodation"] + self.all_fellows.append(new_person) + print("you have added"+new_person.upper()+"as a staff to the list") + return + else: + if self.staff: + for people in self.all_staff: + if person["person_name"] == people["person_name"]: + print("\n"+person["person_name"].upper()+"already exists.\n") + return + else: + new_person = person["staff_name"] + new_person.accomodation = person["wants_accomodation"] + self.all_fellows.append(new_person) + print("you have added"+new_person.person.upper()+"as a fellow to the list") + return + +# amity = Amity() +# amity.add_person({"person_type" : "fellow", "person_name" : "Ebrahim"}) + + # def reallocate_person(self, name, newroom): + # pass + + # def load_people(): + # pass + + # def print_allocations(self): + # session.query(Person).all() + + # def print_unallocated(self, name): + # pass + + # def print_room(self, rname): + # rs = ses.query(room).all() + # for room in rs: + # print(room.Name) + + # def get_list_of_fellows(self): + # return self.all_fellows + + # def get_list_of_offices(self): + # return self.offices + + # def get_list_of_living_spaces(self): + # return self.living_spaces + + # def get_list_of_staff(self): + # return self.all_staff + From ae804a30461c805cccd2789776345320eb047f5f Mon Sep 17 00:00:00 2001 From: faithngetich Date: Thu, 13 Apr 2017 16:18:44 +0300 Subject: [PATCH 06/52] [Chore] create class person --- models/persons.py | 31 +++++-------------------------- requirements.txt | 4 ++++ views.py | 2 +- 3 files changed, 10 insertions(+), 27 deletions(-) create mode 100644 requirements.txt diff --git a/models/persons.py b/models/persons.py index 569bd55..1ae7baa 100644 --- a/models/persons.py +++ b/models/persons.py @@ -1,27 +1,6 @@ class Person(object): - def __init__(self,name): - self.name = name - self.assigned_office = "" - - def __repr__(self): - return self.__class__.__name__ - -class Staff(Person): - def __init__(self, person): - super(Staff, self).__init__(person) - self.accomodation = "None" - self.assigned_liningSpace = "None" - -class Fellow(Person): - def __init__(self, person): - super(Fellow, self).__init__(person) - self.accomodation = "" - self.assigned_liningSpace = "" - - - - - - - - \ No newline at end of file + def __init__(self, first_name, last_name): + self.person_id = id(self) + self.first_name = first_name + self.last_name = last_name + self.wants_accomodation = 'N' \ No newline at end of file diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..6c9b145 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,4 @@ +appdirs==1.4.3 +packaging==16.8 +pyparsing==2.2.0 +six==1.10.0 diff --git a/views.py b/views.py index 2689631..7c643aa 100644 --- a/views.py +++ b/views.py @@ -16,7 +16,7 @@ def __init__(self): self.accomodation_list = [] self.allocated_rooms = {} - def create_room(self, room): + def create_room(self, list_of_rooms, room_type): if room["room_type"] == "office": for rooms in self.offices: if room["room_name"] == rooms["room_name"]: From 14595cc9618173f45a7275a12d15867689ab3f19 Mon Sep 17 00:00:00 2001 From: faithngetich Date: Thu, 13 Apr 2017 16:20:38 +0300 Subject: [PATCH 07/52] [Chore] add sub class staff --- models/persons.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/models/persons.py b/models/persons.py index 1ae7baa..90774aa 100644 --- a/models/persons.py +++ b/models/persons.py @@ -3,4 +3,17 @@ def __init__(self, first_name, last_name): self.person_id = id(self) self.first_name = first_name self.last_name = last_name - self.wants_accomodation = 'N' \ No newline at end of file + self.wants_accomodation = 'N' + +class Staff(Person): + + wants_accomodation = "N" + category = "staff" + + def __init__(self, first_name, last_name): + """Override the init method of Person superclass.""" + super(Staff, self).__init__(first_name, last_name) + + def __str__(self): + """To make Staff class human readable.""" + return "{} {}".format(self.first_name, self.last_name) \ No newline at end of file From 1fca9853c921d1b47d8f99b88faaa75c0f6682d8 Mon Sep 17 00:00:00 2001 From: faithngetich Date: Thu, 13 Apr 2017 16:24:56 +0300 Subject: [PATCH 08/52] [Chore] create sub class Staff --- models/persons.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/models/persons.py b/models/persons.py index 90774aa..107c5ad 100644 --- a/models/persons.py +++ b/models/persons.py @@ -16,4 +16,20 @@ def __init__(self, first_name, last_name): def __str__(self): """To make Staff class human readable.""" - return "{} {}".format(self.first_name, self.last_name) \ No newline at end of file + return "{} {}".format(self.first_name, self.last_name) + +class Fellow(Person): + + wants_accomodation = "N" + category = "fellow" + + def __init__(self, first_name, last_name): + """Override the init method of Person superclass.""" + super(Fellow, self).__init__(first_name, last_name) + + def __str__(self): + """To make Staff class human readable.""" + return "{} {}".format(self.first_name, self.last_name) + +staff = Fellow("Daniel", "Maina") +print(staff) \ No newline at end of file From dd77b8221e7b91de6a65884ebc795f04ac738869 Mon Sep 17 00:00:00 2001 From: faithngetich Date: Thu, 13 Apr 2017 16:57:59 +0300 Subject: [PATCH 09/52] [Chore] create super class Room --- models/persons.py | 2 -- models/rooms.py | 19 ++----------------- views.py | 2 +- 3 files changed, 3 insertions(+), 20 deletions(-) diff --git a/models/persons.py b/models/persons.py index 107c5ad..35b02d8 100644 --- a/models/persons.py +++ b/models/persons.py @@ -31,5 +31,3 @@ def __str__(self): """To make Staff class human readable.""" return "{} {}".format(self.first_name, self.last_name) -staff = Fellow("Daniel", "Maina") -print(staff) \ No newline at end of file diff --git a/models/rooms.py b/models/rooms.py index 31369c1..ea48d58 100644 --- a/models/rooms.py +++ b/models/rooms.py @@ -1,19 +1,4 @@ class Room(object): - def __init__(self, room_name): - self.room_name = room_name - self.occupants = [] - - def __repr__(self): - return "%s" % (self.room_name) - - @property - def room_type(self): - return self.__class__.__name__ - -class OfficeSpace(Room): - capacity = 6 - -class LivingSpace(Room): - capacity = 4 - + self.room_id = id(self) + self.room_name = room_name \ No newline at end of file diff --git a/views.py b/views.py index 7c643aa..d452756 100644 --- a/views.py +++ b/views.py @@ -20,7 +20,7 @@ def create_room(self, list_of_rooms, room_type): if room["room_type"] == "office": for rooms in self.offices: if room["room_name"] == rooms["room_name"]: - print( "\n" + rooms.room_name.upper()+"already exists. \n") + print( "\n" + rooms.room_name.upper() + "already exists. \n") return else: new_office = OfficeSpace(room["room_name"]) From a5d7e8857381cea685cf78b5567c8cc2d6429651 Mon Sep 17 00:00:00 2001 From: faithngetich Date: Thu, 13 Apr 2017 16:59:35 +0300 Subject: [PATCH 10/52] [Chore] create sub class Office --- models/rooms.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/models/rooms.py b/models/rooms.py index ea48d58..5b9740c 100644 --- a/models/rooms.py +++ b/models/rooms.py @@ -1,4 +1,16 @@ class Room(object): def __init__(self, room_name): self.room_id = id(self) - self.room_name = room_name \ No newline at end of file + self.room_name = room_name + +class Office(Room): + + room_type = "office" + + def __init__(self, room_name): + """Override the init method of Person superclass.""" + super(Office, self).__init__(room_name) + + def __str__(self): + """To make Staff class human readable.""" + return "{}".format(self.room_name) \ No newline at end of file From 09f8ec83c632a817ef714e4132f229a748fc4a73 Mon Sep 17 00:00:00 2001 From: faithngetich Date: Thu, 13 Apr 2017 17:13:45 +0300 Subject: [PATCH 11/52] [Chore] create sub class living space --- models/persons.py | 2 +- models/rooms.py | 19 +++++++++++++++++-- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/models/persons.py b/models/persons.py index 35b02d8..f9c16c1 100644 --- a/models/persons.py +++ b/models/persons.py @@ -28,6 +28,6 @@ def __init__(self, first_name, last_name): super(Fellow, self).__init__(first_name, last_name) def __str__(self): - """To make Staff class human readable.""" + """To make fellow class human readable.""" return "{} {}".format(self.first_name, self.last_name) diff --git a/models/rooms.py b/models/rooms.py index 5b9740c..6a179a8 100644 --- a/models/rooms.py +++ b/models/rooms.py @@ -12,5 +12,20 @@ def __init__(self, room_name): super(Office, self).__init__(room_name) def __str__(self): - """To make Staff class human readable.""" - return "{}".format(self.room_name) \ No newline at end of file + """To make office class human readable.""" + return "{}".format(self.room_name) + +class Living_space(Room): + + room_type = "living_space" + + def __init__(self, room_name): + """Override the init method of Person superclass.""" + super(Living_space, self).__init__(room_name) + + def __str__(self): + """To make living space class human readable.""" + return "{}".format(self.room_name) + +space = Living_space("Ruby") +print(space.room_id, space.room_name, space.room_type) \ No newline at end of file From 193e906d41d1d47b7d415c9cbe7bcf8cdbe25a8e Mon Sep 17 00:00:00 2001 From: faithngetich Date: Thu, 13 Apr 2017 17:40:48 +0300 Subject: [PATCH 12/52] [Chore] Add attribute room capacity --- models/rooms.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/models/rooms.py b/models/rooms.py index 6a179a8..1f38d2b 100644 --- a/models/rooms.py +++ b/models/rooms.py @@ -5,7 +5,8 @@ def __init__(self, room_name): class Office(Room): - room_type = "office" + room_type = "office" + room_capacity = 6 def __init__(self, room_name): """Override the init method of Person superclass.""" @@ -15,9 +16,10 @@ def __str__(self): """To make office class human readable.""" return "{}".format(self.room_name) -class Living_space(Room): +class LivingSpace(Room): room_type = "living_space" + room_capacity = 4 def __init__(self, room_name): """Override the init method of Person superclass.""" @@ -27,5 +29,3 @@ def __str__(self): """To make living space class human readable.""" return "{}".format(self.room_name) -space = Living_space("Ruby") -print(space.room_id, space.room_name, space.room_type) \ No newline at end of file From 08c0046f38d68755f1f4a24a3aab08f73588fc2d Mon Sep 17 00:00:00 2001 From: faithngetich Date: Thu, 13 Apr 2017 17:48:46 +0300 Subject: [PATCH 13/52] [Chore] Remove existing functionality --- views.py | 115 ++++++++++++++----------------------------------------- 1 file changed, 29 insertions(+), 86 deletions(-) diff --git a/views.py b/views.py index d452756..040f20e 100644 --- a/views.py +++ b/views.py @@ -8,94 +8,37 @@ class Amity(object): - def __init__(self): - self.all_staff = [] - self.all_fellows = [{"person_type" : "fellow", "person_name" : "Tetio"}] - self.living_spaces = [{"room_type" : "living_space", "room_name" : "Vazlhala"}] - self.offices = [] - self.accomodation_list = [] - self.allocated_rooms = {} + all_staff = [] + all_fellows = [{"person_type" : "fellow", "person_name" : "Tetio"}] + living_spaces = [{"room_type" : "living_space", "room_name" : "Vazlhala"}] + offices = [] + accomodation_list = [] + allocated_rooms = {} def create_room(self, list_of_rooms, room_type): - if room["room_type"] == "office": - for rooms in self.offices: - if room["room_name"] == rooms["room_name"]: - print( "\n" + rooms.room_name.upper() + "already exists. \n") - return - else: - new_office = OfficeSpace(room["room_name"]) - self.offices.append(new_office) - text = ("\n You have successfully added " + new_office.room_name.upper() + " to offices in amity") - print(text) - else: - if self.living_spaces: - for rooms in self.living_spaces: - if room["room_name"] == rooms["room_name"]: - print( "\n" + rooms["room_name"].upper()+"already exists. \n") - return - else: - new_livingSpace = room["room_name"] - self.living_spaces.append(new_livingSpace) - text = ("\n You have successfully added" + new_livingSpace.upper() + "to living space in amity") - print(text) - return -# amity = Amity() -# amity.create_room({"room_type" : "living_space", "room_name" : "Valhala"}) + pass def add_person(self, person): - if person["person_type"] == "fellow": - for people in self.all_fellows: - if person["person_name"] == people["person_name"]: - print("\n"+person["person_name"].upper()+"already exists.\n") - return - else: - new_person = person["person_name"] - # new_person.accomodation = person["wants_accomodation"] - self.all_fellows.append(new_person) - print("you have added"+new_person.upper()+"as a staff to the list") - return - else: - if self.staff: - for people in self.all_staff: - if person["person_name"] == people["person_name"]: - print("\n"+person["person_name"].upper()+"already exists.\n") - return - else: - new_person = person["staff_name"] - new_person.accomodation = person["wants_accomodation"] - self.all_fellows.append(new_person) - print("you have added"+new_person.person.upper()+"as a fellow to the list") - return - -# amity = Amity() -# amity.add_person({"person_type" : "fellow", "person_name" : "Ebrahim"}) - - # def reallocate_person(self, name, newroom): - # pass - - # def load_people(): - # pass - - # def print_allocations(self): - # session.query(Person).all() - - # def print_unallocated(self, name): - # pass - - # def print_room(self, rname): - # rs = ses.query(room).all() - # for room in rs: - # print(room.Name) - - # def get_list_of_fellows(self): - # return self.all_fellows - - # def get_list_of_offices(self): - # return self.offices - - # def get_list_of_living_spaces(self): - # return self.living_spaces - - # def get_list_of_staff(self): - # return self.all_staff + pass + + def reallocate_person(self, person_id, new_room_name): + pass + + def print_allocations(self): + pass + + def print_unallocated(self): + pass + + def print_room(self, room_name): + pass + + def save_state(self): + pass + + def load_state(self): + pass + + def load_people(self, filename): + pass From b3116334d8117040411d365808ac34be98b56b96 Mon Sep 17 00:00:00 2001 From: faithngetich Date: Sun, 16 Apr 2017 21:14:48 +0300 Subject: [PATCH 14/52] [chore] Add create room function --- models/persons.py | 3 ++ models/rooms.py | 2 +- tests/test_amity.py | 125 ++++++++++++++++++++++---------------------- views.py | 72 +++++++++++++++---------- 4 files changed, 110 insertions(+), 92 deletions(-) diff --git a/models/persons.py b/models/persons.py index f9c16c1..ab53868 100644 --- a/models/persons.py +++ b/models/persons.py @@ -31,3 +31,6 @@ def __str__(self): """To make fellow class human readable.""" return "{} {}".format(self.first_name, self.last_name) + +space = Living_space("Ruby") +print(space.room_id, space.room_name, space.room_type, space.room_capacity) \ No newline at end of file diff --git a/models/rooms.py b/models/rooms.py index 1f38d2b..9e849d5 100644 --- a/models/rooms.py +++ b/models/rooms.py @@ -23,7 +23,7 @@ class LivingSpace(Room): def __init__(self, room_name): """Override the init method of Person superclass.""" - super(Living_space, self).__init__(room_name) + super(LivingSpace, self).__init__(room_name) def __str__(self): """To make living space class human readable.""" diff --git a/tests/test_amity.py b/tests/test_amity.py index 0d49ba5..1171aef 100644 --- a/tests/test_amity.py +++ b/tests/test_amity.py @@ -5,83 +5,82 @@ class Amitytest(unittest.TestCase): def setUp(self): self.amity = Amity() - def test_create_room_function_works(self): + def test_create_room_adds_room_succesfully(self): self.amity.create_room('office', 'Krypton') - all_rooms = len(self.amity.allocated_rooms)+1 - self.assertEqual(len(self.amity.allocated_rooms), all_rooms, msg = "office(s) not added successfully ") + self.assertIn('Krypton', self.amity.offices) - def test_add_person_adds_fellow_to_list(self): - self.amity.add_person('dede','fellow') - all_fellows = len(self.amity.all_fellows) + 1 - self.assertEqual(len(self.amity.all_fellows), all_fellows, msg = "fellow not added") + # def test_add_person_adds_fellow_to_list(self): + # self.amity.add_person('dede','fellow') + # all_fellows = len(self.amity.all_fellows) + 1 + # self.assertEqual(len(self.amity.all_fellows), all_fellows, msg = "fellow not added") - def test_person_added_is_fellow(self): - self.amity.add_person('dede', 'fellow') - self.assertIn('dede', self.amity.all_fellows, msg = "person not added as fellow") - self.assertFalse('dede', 'Staff') - self.assertNotIn('dede', self.amity.all_staff, msg = "dede is not staff") + # def test_person_added_is_fellow(self): + # self.amity.add_person('dede', 'fellow') + # self.assertIn('dede', self.amity.all_fellows, msg = "person not added as fellow") + # self.assertFalse('dede', 'Staff') + # self.assertNotIn('dede', self.amity.all_staff, msg = "dede is not staff") - def test_person_added_is_staff(self): - self.amity.add_person('dede', 'staff') - self.assertIn('dede', self.amity.all_fellows, msg = "person not added as fellow") - self.assertFalse('dede', 'Staff') - self.assertNotIn('dede', self.amity.all_staff, msg = "dede is not staff") + # def test_person_added_is_staff(self): + # self.amity.add_person('dede', 'staff') + # self.assertIn('dede', self.amity.all_fellows, msg = "person not added as fellow") + # self.assertFalse('dede', 'Staff') + # self.assertNotIn('dede', self.amity.all_staff, msg = "dede is not staff") - def test_fellow_wants_accomodation(self): - self.amity.add_person('dede', 'fellow', 'wants_accomodation = Y') - self.assertTrue('dede' in self.amity.accomodation_list, msg = 'fellow not in accomodation list') - self.assertFalse('dede' not in self.amity.accomodation_list, msg = 'fellow should be in the accomodation list') - self.amity.add_person('dede', 'fellow', 'wants_accomodation = Y') - self.assertRaises("Fellow already exists") + # def test_fellow_wants_accomodation(self): + # self.amity.add_person('dede', 'fellow', 'wants_accomodation = Y') + # self.assertTrue('dede' in self.amity.accomodation_list, msg = 'fellow not in accomodation list') + # self.assertFalse('dede' not in self.amity.accomodation_list, msg = 'fellow should be in the accomodation list') + # self.amity.add_person('dede', 'fellow', 'wants_accomodation = Y') + # self.assertRaises("Fellow already exists") - def test_fellow_does_not_want_accomodation(self): - self.amity.add_person('dede', 'fellow', 'wants_accomodation = N') - self.assertTrue('dede' in self.amity.accomodation_list) - self.assertFalse('awesome' in self.amity.accomodation_list, msg = 'fellow does not want accomodation') + # def test_fellow_does_not_want_accomodation(self): + # self.amity.add_person('dede', 'fellow', 'wants_accomodation = N') + # self.assertTrue('dede' in self.amity.accomodation_list) + # self.assertFalse('awesome' in self.amity.accomodation_list, msg = 'fellow does not want accomodation') - def test_Staff_gets_no_accomodation(self): - self.amity.add_person('luke', 'staff', 'wants_accomodation') - self.assertFalse('luke' in self.amity.accomodation_list) + # def test_Staff_gets_no_accomodation(self): + # self.amity.add_person('luke', 'staff', 'wants_accomodation') + # self.assertFalse('luke' in self.amity.accomodation_list) - def test_person_added_is_staff(self): - self.amity.add_person('brian', 'staff') - self.assertIn('brian', self.amity.all_staff, msg = "brian added as staff" ) - self.assertFalse('brian', 'fellow') - self.assertNotIn('brian', self.amity.all_fellows, msg = "brian is not staff") + # def test_person_added_is_staff(self): + # self.amity.add_person('brian', 'staff') + # self.assertIn('brian', self.amity.all_staff, msg = "brian added as staff" ) + # self.assertFalse('brian', 'fellow') + # self.assertNotIn('brian', self.amity.all_fellows, msg = "brian is not staff") - def test_if_room_is_livingspace(self): - self.amity.create_room('livingspace', 'ruby') - living_spaces = len(self.amity.living_spaces) + 1 - #self.assertEqual(ruby.room_capacity, 4) - self.assertEqual(len(self.amity.living_spaces), living_spaces, msg = "livingroom is not added succesfully") + # def test_if_room_is_livingspace(self): + # self.amity.create_room('livingspace', 'ruby') + # living_spaces = len(self.amity.living_spaces) + 1 + # #self.assertEqual(ruby.room_capacity, 4) + # self.assertEqual(len(self.amity.living_spaces), living_spaces, msg = "livingroom is not added succesfully") - def test_if_room_is_office(self): - self.amity.create_room('office', 'hogwarts') - #self.assertEqual(hogwarts.room_capacity, 6) - offices1 = len(self.amity.offices) + 1 - self.assertEqual(len(self.amity.offices), offices1, msg = "livingroom is not added succesfully") + # def test_if_room_is_office(self): + # self.amity.create_room('office', 'hogwarts') + # #self.assertEqual(hogwarts.room_capacity, 6) + # offices1 = len(self.amity.offices) + 1 + # self.assertEqual(len(self.amity.offices), offices1, msg = "livingroom is not added succesfully") - def test_reallocate_person(self): - self.amity.create_room('office', 'oculus') - self.amity.add_person('dede', 'staff', 'N') - self.amity.create_room('office', 'valhalla') - self.amity.reallocate_person('dede', 'valhalla') - self.assertIn('dede', self.amity.allocated_rooms['valhalla']) + # def test_reallocate_person(self): + # self.amity.create_room('office', 'oculus') + # self.amity.add_person('dede', 'staff', 'N') + # self.amity.create_room('office', 'valhalla') + # self.amity.reallocate_person('dede', 'valhalla') + # self.assertIn('dede', self.amity.allocated_rooms['valhalla']) - def test_print_allocations_returns_all_allocated_names(self): - self.amity.add_person('dede', 'fellow') - allocated_names = len(self.amity.allocated_rooms) + 1 - self.assertEqual(len(self.amity.allocated_rooms), allocated_names, msg = "allocated person is missing") + # def test_print_allocations_returns_all_allocated_names(self): + # self.amity.add_person('dede', 'fellow') + # allocated_names = len(self.amity.allocated_rooms) + 1 + # self.assertEqual(len(self.amity.allocated_rooms), allocated_names, msg = "allocated person is missing") - def test_print_unallocated_returns_all_not_in_accomodation_list(self): - self.amity.print_unallocated('dede') - self.assertFalse('dede' in self.amity.accomodation_list, msg = "person not in accomodation list") + # def test_print_unallocated_returns_all_not_in_accomodation_list(self): + # self.amity.print_unallocated('dede') + # self.assertFalse('dede' in self.amity.accomodation_list, msg = "person not in accomodation list") - def test_print_rooms_returns_names(self): - self.amity.create_room('office', 'kikwete') - self.amity.add_person('collins', 'staff', 'N') - self.amity.reallocate_person('collins','kikwete') - self.assertIn('collins', self.amity.print_room('kikwete')) + # def test_print_rooms_returns_names(self): + # self.amity.create_room('office', 'kikwete') + # self.amity.add_person('collins', 'staff', 'N') + # self.amity.reallocate_person('collins','kikwete') + # self.assertIn('collins', self.amity.print_room('kikwete')) if __name__ == '__main__': diff --git a/views.py b/views.py index 040f20e..1f3217a 100644 --- a/views.py +++ b/views.py @@ -1,44 +1,60 @@ # from models.migrate import eng # from sqlalchemy.orm import sessionmaker -from models.persons import Fellow -from models.persons import Staff +from models.rooms import Office from models.rooms import LivingSpace -from models.rooms import OfficeSpace -from models.rooms import Room - - class Amity(object): all_staff = [] - all_fellows = [{"person_type" : "fellow", "person_name" : "Tetio"}] - living_spaces = [{"room_type" : "living_space", "room_name" : "Vazlhala"}] - offices = [] + all_fellows = [] + all_rooms = [] + living_spaces = {'None' : []} + office_spaces = {'None' : []} accomodation_list = [] allocated_rooms = {} - def create_room(self, list_of_rooms, room_type): - pass - - def add_person(self, person): - pass + def create_room(self, room_type, room_name): + """creates a specified room""" + if room_name.upper() in [room.name for room in Amity.all_rooms]: + print("sorry, Room already exist.") + else: + mapping = {'O': Office, 'L': LivingSpace} + new_room = mapping[room_type.upper()], (room_name.upper()) + Amity.all_rooms.append(new_room) + if room_type.upper() == 'O': + Amity.office_spaces[room_name.upper()] = [] + elif room_type.upper() == 'L': + Amity.living_spaces[room_name.upper()] = [] + print(room_name.upper() + "created successfully") + +space = Amity() +space.create_room('O', 'valahala') +print(Amity.all_rooms) + +# create = Amity() +# amity = create.create_room("office", "tet") +# print(amity.room_type,amity.room_name) + + + # def add_person(self, person): + # pass - def reallocate_person(self, person_id, new_room_name): - pass + # def reallocate_person(self, person_id, new_room_name): + # pass - def print_allocations(self): - pass + # def print_allocations(self): + # pass - def print_unallocated(self): - pass + # def print_unallocated(self): + # pass - def print_room(self, room_name): - pass + # def print_room(self, room_name): + # pass - def save_state(self): - pass + # def save_state(self): + # pass - def load_state(self): - pass + # def load_state(self): + # pass - def load_people(self, filename): - pass + # def load_people(self, filename): + # pass From fa0aaed7a517b1afd70019aa75c4b219cfb0e95c Mon Sep 17 00:00:00 2001 From: faithngetich Date: Mon, 17 Apr 2017 00:02:18 +0300 Subject: [PATCH 15/52] [chore] test create room method works --- .gitignore | 2 +- __init__.py | 0 tests/test_amity.py | 8 +++++--- views.py | 43 ++++++++++++++++++++++++------------------- 4 files changed, 30 insertions(+), 23 deletions(-) delete mode 100644 __init__.py diff --git a/.gitignore b/.gitignore index 63178c3..c99a8d8 100644 --- a/.gitignore +++ b/.gitignore @@ -2,7 +2,7 @@ __pycache__/ *.py[cod] *$py.class -,pyc +*.pyc # C extensions *.so diff --git a/__init__.py b/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/tests/test_amity.py b/tests/test_amity.py index 1171aef..75c31b5 100644 --- a/tests/test_amity.py +++ b/tests/test_amity.py @@ -1,13 +1,15 @@ import unittest -from ..views import Amity +from views import Amity +from models.rooms import Office +from models.rooms import LivingSpace class Amitytest(unittest.TestCase): def setUp(self): self.amity = Amity() def test_create_room_adds_room_succesfully(self): - self.amity.create_room('office', 'Krypton') - self.assertIn('Krypton', self.amity.offices) + self.amity.create_room('O', 'Krypton') + self.assertIn('KRYPTON', self.amity.office_spaces) # def test_add_person_adds_fellow_to_list(self): # self.amity.add_person('dede','fellow') diff --git a/views.py b/views.py index 1f3217a..cf6d6d9 100644 --- a/views.py +++ b/views.py @@ -25,36 +25,41 @@ def create_room(self, room_type, room_name): Amity.living_spaces[room_name.upper()] = [] print(room_name.upper() + "created successfully") -space = Amity() -space.create_room('O', 'valahala') -print(Amity.all_rooms) + # def add_person(self, first_name, last_name, category, wants_accomodation='N'): + # """Adds person to Amity and randomly allocates the person""" + # allocated_office = self.generate_room() + # mapping = {'F': Fellow, 'S':Staff} + # new_person = mapping[category.upper()], (person_id, first_name.upper(), last_name.upper(),) + + + # create = Amity() # amity = create.create_room("office", "tet") # print(amity.room_type,amity.room_name) - # def add_person(self, person): - # pass + def add_person(self, person): + pass - # def reallocate_person(self, person_id, new_room_name): - # pass + def reallocate_person(self, person_id, new_room_name): + pass - # def print_allocations(self): - # pass + def print_allocations(self): + pass - # def print_unallocated(self): - # pass + def print_unallocated(self): + pass - # def print_room(self, room_name): - # pass + def print_room(self, room_name): + pass - # def save_state(self): - # pass + def save_state(self): + pass - # def load_state(self): - # pass + def load_state(self): + pass - # def load_people(self, filename): - # pass + def load_people(self, filename): + pass From 9ccf89f262252c5d3ad035122d9d230cc2acfb70 Mon Sep 17 00:00:00 2001 From: faithngetich Date: Mon, 17 Apr 2017 03:50:56 +0300 Subject: [PATCH 16/52] [chore] Add an add person method --- models/persons.py | 3 -- models/rooms.py | 6 +++- tests/test_amity.py | 8 ++--- views.py | 86 ++++++++++++++++++++++++++++----------------- 4 files changed, 63 insertions(+), 40 deletions(-) diff --git a/models/persons.py b/models/persons.py index ab53868..f9c16c1 100644 --- a/models/persons.py +++ b/models/persons.py @@ -31,6 +31,3 @@ def __str__(self): """To make fellow class human readable.""" return "{} {}".format(self.first_name, self.last_name) - -space = Living_space("Ruby") -print(space.room_id, space.room_name, space.room_type, space.room_capacity) \ No newline at end of file diff --git a/models/rooms.py b/models/rooms.py index 9e849d5..33b2dae 100644 --- a/models/rooms.py +++ b/models/rooms.py @@ -6,11 +6,13 @@ def __init__(self, room_name): class Office(Room): room_type = "office" - room_capacity = 6 + room_capacity = 6 def __init__(self, room_name): """Override the init method of Person superclass.""" super(Office, self).__init__(room_name) + + self.members = [] def __str__(self): """To make office class human readable.""" @@ -25,6 +27,8 @@ def __init__(self, room_name): """Override the init method of Person superclass.""" super(LivingSpace, self).__init__(room_name) + self.members = [] + def __str__(self): """To make living space class human readable.""" return "{}".format(self.room_name) diff --git a/tests/test_amity.py b/tests/test_amity.py index 75c31b5..aa8eb95 100644 --- a/tests/test_amity.py +++ b/tests/test_amity.py @@ -11,10 +11,10 @@ def test_create_room_adds_room_succesfully(self): self.amity.create_room('O', 'Krypton') self.assertIn('KRYPTON', self.amity.office_spaces) - # def test_add_person_adds_fellow_to_list(self): - # self.amity.add_person('dede','fellow') - # all_fellows = len(self.amity.all_fellows) + 1 - # self.assertEqual(len(self.amity.all_fellows), all_fellows, msg = "fellow not added") + def test_add_person_adds_fellow_to_list(self): + self.amity.add_person('dede','faith','F') + all_fellows = len(self.amity.all_fellows) + 1 + self.assertEqual(len(self.amity.all_fellows), all_fellows, msg = "fellow not added") # def test_person_added_is_fellow(self): # self.amity.add_person('dede', 'fellow') diff --git a/views.py b/views.py index cf6d6d9..1f2b492 100644 --- a/views.py +++ b/views.py @@ -2,10 +2,16 @@ # from sqlalchemy.orm import sessionmaker from models.rooms import Office from models.rooms import LivingSpace +from models.persons import Fellow +from models.persons import Staff + +import random + class Amity(object): all_staff = [] all_fellows = [] all_rooms = [] + all_people = [] living_spaces = {'None' : []} office_spaces = {'None' : []} accomodation_list = [] @@ -17,7 +23,7 @@ def create_room(self, room_type, room_name): print("sorry, Room already exist.") else: mapping = {'O': Office, 'L': LivingSpace} - new_room = mapping[room_type.upper()], (room_name.upper()) + new_room = mapping[room_type.upper()](room_name.upper()) Amity.all_rooms.append(new_room) if room_type.upper() == 'O': Amity.office_spaces[room_name.upper()] = [] @@ -25,41 +31,57 @@ def create_room(self, room_type, room_name): Amity.living_spaces[room_name.upper()] = [] print(room_name.upper() + "created successfully") - # def add_person(self, first_name, last_name, category, wants_accomodation='N'): - # """Adds person to Amity and randomly allocates the person""" - # allocated_office = self.generate_room() - # mapping = {'F': Fellow, 'S':Staff} - # new_person = mapping[category.upper()], (person_id, first_name.upper(), last_name.upper(),) + def generate_random_office_spaces(self): + """Generates random office""" + offices = [room for room in Amity.all_rooms if room.room_type == "OFFICE"] + available_offices = [] + for office in offices: + if office.room_capacity > len(Amity.office_spaces[office.room_name]): + available_offices.append(office.room_name) + # selected_room = 'None' + if len(available_offices): + selected_room = random.choice(available_offices) + else: + selected_room = None + return selected_room + def generate_random_living_spaces(self): + """Generates random living spaces""" + # self.create_room('L', "MyRoom") + livingSpaces = [room for room in Amity.all_rooms if room.room_type == "living_space"] + available_living_space = [] + for living_space in livingSpaces: + if living_space.room_capacity > len(Amity.living_spaces[living_space.room_name]): + available_living_space.append(living_space.room_name) -# create = Amity() -# amity = create.create_room("office", "tet") -# print(amity.room_type,amity.room_name) - - - def add_person(self, person): - pass + if len(available_living_space): + selected_room = random.choice(available_living_space) + else: + selected_room = None + return selected_room - def reallocate_person(self, person_id, new_room_name): - pass - - def print_allocations(self): - pass - - def print_unallocated(self): - pass + def add_person(self, first_name, last_name, category, wants_accomodation='N'): + """Adds person to Amity and randomly allocates the person""" + amity = Amity() + allocated_office = self.generate_random_office_spaces() + if allocated_office: + mapping = {"F": Fellow, "S":Staff} + person_id = len (Amity.all_people) + 1 + new_person = mapping[category.upper()](person_id, first_name.upper(),last_name.upper(), category) + Amity.all_people.append(new_person) + Amity.office_spaces[allocated_office].append(first_name.upper() + " " + last_name.upper()) + else: + print("No office space available") + if wants_accomodation.upper() == 'Y' and category == 'F': + + allocated_living_space = self.generate_random_living_spaces() + amity.living_spaces[allocated_living_space].append(first_name.upper() + "" + last_name.upper()) + print("Adding process completed succesfully") - def print_room(self, room_name): - pass - - def save_state(self): - pass +# create = Amity() +# amity = create.add_person("faith", "tet", "F", "Y") +# print(amity) - def load_state(self): - pass - - def load_people(self, filename): - pass - + From d24108c58d97e432cfc84cb2a20990994f32a1ed Mon Sep 17 00:00:00 2001 From: faithngetich Date: Mon, 17 Apr 2017 14:52:51 +0300 Subject: [PATCH 17/52] [chore] Add reallocate function --- tests/test_amity.py | 40 +++++++++++++++----------- views.py | 70 ++++++++++++++++++++++++++++++++++++++------- 2 files changed, 84 insertions(+), 26 deletions(-) diff --git a/tests/test_amity.py b/tests/test_amity.py index aa8eb95..566e0f9 100644 --- a/tests/test_amity.py +++ b/tests/test_amity.py @@ -10,20 +10,34 @@ def setUp(self): def test_create_room_adds_room_succesfully(self): self.amity.create_room('O', 'Krypton') self.assertIn('KRYPTON', self.amity.office_spaces) + - def test_add_person_adds_fellow_to_list(self): - self.amity.add_person('dede','faith','F') - all_fellows = len(self.amity.all_fellows) + 1 - self.assertEqual(len(self.amity.all_fellows), all_fellows, msg = "fellow not added") + # def test_add_person_adds_fellow_to_list(self): + # self.amity.add_person('dede','faith','F','N') + # all_fellows = len(self.amity.all_fellows) + 1 + # self.assertEqual(len(self.amity.all_fellows), all_fellows, msg = "fellow not added") # def test_person_added_is_fellow(self): - # self.amity.add_person('dede', 'fellow') - # self.assertIn('dede', self.amity.all_fellows, msg = "person not added as fellow") - # self.assertFalse('dede', 'Staff') - # self.assertNotIn('dede', self.amity.all_staff, msg = "dede is not staff") + # length = len(self.amity.all_fellows) + # self.amity.add_person('dede', 'F', 'y') + # new_length = len(self.amity.all_fellows) + # self.assertEqual((length + 1), new_length) + + + def test_reallocate_person(self): + length = len(self.amity.all_fellows) + self.amity.add_person('dede', 'F', 'y') + new_length = len(self.amity.all_fellows) + self.assertEqual((length + 1), new_length) + + self.amity.create_room('O', 'valhalla') + self.amity.reallocate_person('dede', 'fat', 'O', 'valhalla') + self.assertIn('DEDE', 'FAT', self.amity.allocated_rooms['VALHALLA']) + + # def test_person_added_is_staff(self): - # self.amity.add_person('dede', 'staff') + # self.amity.add_person('dede', 'S') # self.assertIn('dede', self.amity.all_fellows, msg = "person not added as fellow") # self.assertFalse('dede', 'Staff') # self.assertNotIn('dede', self.amity.all_staff, msg = "dede is not staff") @@ -62,13 +76,7 @@ def test_add_person_adds_fellow_to_list(self): # offices1 = len(self.amity.offices) + 1 # self.assertEqual(len(self.amity.offices), offices1, msg = "livingroom is not added succesfully") - # def test_reallocate_person(self): - # self.amity.create_room('office', 'oculus') - # self.amity.add_person('dede', 'staff', 'N') - # self.amity.create_room('office', 'valhalla') - # self.amity.reallocate_person('dede', 'valhalla') - # self.assertIn('dede', self.amity.allocated_rooms['valhalla']) - + # def test_print_allocations_returns_all_allocated_names(self): # self.amity.add_person('dede', 'fellow') # allocated_names = len(self.amity.allocated_rooms) + 1 diff --git a/views.py b/views.py index 1f2b492..7fd02b3 100644 --- a/views.py +++ b/views.py @@ -8,6 +8,7 @@ import random class Amity(object): + """""" all_staff = [] all_fellows = [] all_rooms = [] @@ -18,7 +19,7 @@ class Amity(object): allocated_rooms = {} def create_room(self, room_type, room_name): - """creates a specified room""" + """creates a specified room""" if room_name.upper() in [room.name for room in Amity.all_rooms]: print("sorry, Room already exist.") else: @@ -68,20 +69,69 @@ def add_person(self, first_name, last_name, category, wants_accomodation='N'): allocated_office = self.generate_random_office_spaces() if allocated_office: mapping = {"F": Fellow, "S":Staff} - person_id = len (Amity.all_people) + 1 - new_person = mapping[category.upper()](person_id, first_name.upper(),last_name.upper(), category) + person_id = len(Amity.all_people) + 1 + new_person = mapping[category.upper()](person_id, first_name.upper(), last_name.upper(), category) Amity.all_people.append(new_person) Amity.office_spaces[allocated_office].append(first_name.upper() + " " + last_name.upper()) else: print("No office space available") if wants_accomodation.upper() == 'Y' and category == 'F': - allocated_living_space = self.generate_random_living_spaces() amity.living_spaces[allocated_living_space].append(first_name.upper() + "" + last_name.upper()) print("Adding process completed succesfully") - -# create = Amity() -# amity = create.add_person("faith", "tet", "F", "Y") -# print(amity) - - + + def reallocate_person(self, first_name, last_name, room_type, new_room): + """ moves person from one room to another room""" + full_name = first_name.upper() + " " + last_name.upper() + fellows = [person.name for person in Amity.all_people if person.category == "FELLOW"] + staff = [person.name for person in Amity.all_people if person.category == "STAFF"] + available_lspaces = [room.room_name for room in Amity.all_rooms + if room.room_type == "LIVING SPACE" + and len(Amity.living_spaces[room.room_name]) < 4] + available_offices = [room.room_name for room in Amity.all_rooms + if room.room_type == "OFFICE" + and len(Amity.office_spaces[room.room_name]) < 6] + if full_name not in fellows and full_name not in staff: + print("Sorry, the person doesn't exist.") + + elif new_room.upper() not in available_lspaces and new_room.upper() not in available_offices: + print("The room requested does not exist or is not available") + print("Available office \n" + available_offices) + print("Available living space \n" + available_lspaces) + else: + if room_type.upper() == "L": + if new_room in available_offices and new_room not in available_lspaces: + print("The room selected is not a living space") + elif full_name not in fellows: + return "The person has to exist and be a fellow!" + else: + for room in Amity.living_spaces.keys(): + if full_name in Amity.living_spaces[room]: + lspace = Amity.living_spaces[room] + lspace.remove(full_name) + Amity.office_spaces[new_room.upper()].append(full_name) + print("successfully reallocated") + + +space = Amity() +space.create_room('O', "MyRoom") +space.add_person('faith', 'dede', 'F', 'Y') +space.reallocate_person('faith', 'dede', 'O', 'valahala') +print(Amity.living_spaces) +print(space.reallocate_person('faith', 'dede', 'O', 'valahala')) +print(Amity.living_spaces) +print(Amity.all_rooms) + +# def load_people(filename): +# """loads people from a txt file to the app""" +# with open (filename, 'r') as people_file: +# for person_details in people_file: +# details = person_details.rstrip().split() +# accomodate = details[3] if len(details) == 4 else "N" +# Amity.add_person(details[0], details[1], details[2], accomodate) +# print("Successfully loaded people") + +# space = Amity() +# space.add_person('faith', 'dede', 'F', 'Y') +# space.load_people('faith') +# print(Amity.living_spaces) From 34fe90c18eea5c150cd58bfb64b73277f8c1331f Mon Sep 17 00:00:00 2001 From: faithngetich Date: Tue, 18 Apr 2017 09:15:55 +0300 Subject: [PATCH 18/52] [chore] refactor the reallocation method --- app.py | 5 +++++ check | 10 ++++++++++ models/persons.py | 8 +++++--- models/rooms.py | 4 ++-- views.py | 47 ++++++++++++++++++++++++++--------------------- 5 files changed, 48 insertions(+), 26 deletions(-) create mode 100644 check diff --git a/app.py b/app.py index e69de29..f84565e 100644 --- a/app.py +++ b/app.py @@ -0,0 +1,5 @@ +import cmd, os +from docopt import docopt, DocoptExit +from pyfiglet import figlet_format +from termcolor import cprint +from views import Amity \ No newline at end of file diff --git a/check b/check new file mode 100644 index 0000000..6e88872 --- /dev/null +++ b/check @@ -0,0 +1,10 @@ +1. Check if person is in all_people + 1.a if not, return + 1b. if is, continue + +2. Check roomtype + 2a. If roomtype is living, fetch fellows and living spaces + 2b. If roomtype is office, fetch fellows and staff and offices. + + +3. \ No newline at end of file diff --git a/models/persons.py b/models/persons.py index f9c16c1..08f77f2 100644 --- a/models/persons.py +++ b/models/persons.py @@ -4,11 +4,13 @@ def __init__(self, first_name, last_name): self.first_name = first_name self.last_name = last_name self.wants_accomodation = 'N' - + @property + def full_name(self): + return self.first_name + " " + self.last_name class Staff(Person): wants_accomodation = "N" - category = "staff" + category = "STAFF" def __init__(self, first_name, last_name): """Override the init method of Person superclass.""" @@ -21,7 +23,7 @@ def __str__(self): class Fellow(Person): wants_accomodation = "N" - category = "fellow" + category = "FELLOW" def __init__(self, first_name, last_name): """Override the init method of Person superclass.""" diff --git a/models/rooms.py b/models/rooms.py index 33b2dae..e44a0a0 100644 --- a/models/rooms.py +++ b/models/rooms.py @@ -5,7 +5,7 @@ def __init__(self, room_name): class Office(Room): - room_type = "office" + room_type = "OFFICE" room_capacity = 6 def __init__(self, room_name): @@ -20,7 +20,7 @@ def __str__(self): class LivingSpace(Room): - room_type = "living_space" + room_type = "LIVING_SPACE" room_capacity = 4 def __init__(self, room_name): diff --git a/views.py b/views.py index 7fd02b3..be40f06 100644 --- a/views.py +++ b/views.py @@ -8,7 +8,6 @@ import random class Amity(object): - """""" all_staff = [] all_fellows = [] all_rooms = [] @@ -20,7 +19,7 @@ class Amity(object): def create_room(self, room_type, room_name): """creates a specified room""" - if room_name.upper() in [room.name for room in Amity.all_rooms]: + if room_name.upper() in [room.room_name for room in Amity.all_rooms]: print("sorry, Room already exist.") else: mapping = {'O': Office, 'L': LivingSpace} @@ -30,7 +29,7 @@ def create_room(self, room_type, room_name): Amity.office_spaces[room_name.upper()] = [] elif room_type.upper() == 'L': Amity.living_spaces[room_name.upper()] = [] - print(room_name.upper() + "created successfully") + print(room_name.upper() + " " + "created successfully") def generate_random_office_spaces(self): """Generates random office""" @@ -51,7 +50,7 @@ def generate_random_office_spaces(self): def generate_random_living_spaces(self): """Generates random living spaces""" # self.create_room('L', "MyRoom") - livingSpaces = [room for room in Amity.all_rooms if room.room_type == "living_space"] + livingSpaces = [room for room in Amity.all_rooms if room.room_type == "LIVING_SPACE"] available_living_space = [] for living_space in livingSpaces: if living_space.room_capacity > len(Amity.living_spaces[living_space.room_name]): @@ -65,39 +64,42 @@ def generate_random_living_spaces(self): def add_person(self, first_name, last_name, category, wants_accomodation='N'): """Adds person to Amity and randomly allocates the person""" - amity = Amity() + mapping = {"F": Fellow, "S":Staff} + new_person = mapping[category.upper()](first_name.upper(), last_name.upper()) + Amity.all_people.append(new_person) allocated_office = self.generate_random_office_spaces() if allocated_office: - mapping = {"F": Fellow, "S":Staff} - person_id = len(Amity.all_people) + 1 - new_person = mapping[category.upper()](person_id, first_name.upper(), last_name.upper(), category) - Amity.all_people.append(new_person) - Amity.office_spaces[allocated_office].append(first_name.upper() + " " + last_name.upper()) + Amity.office_spaces[allocated_office].append(new_person.full_name) + print(new_person.full_name + " added successfully to " + allocated_office) else: print("No office space available") if wants_accomodation.upper() == 'Y' and category == 'F': allocated_living_space = self.generate_random_living_spaces() - amity.living_spaces[allocated_living_space].append(first_name.upper() + "" + last_name.upper()) + if allocated_living_space is None: + print("No available living spaces") + else: + Amity.living_spaces[allocated_living_space].append(new_person.full_name) + print(new_person.full_name + " added successfully to " + allocated_living_space) print("Adding process completed succesfully") def reallocate_person(self, first_name, last_name, room_type, new_room): """ moves person from one room to another room""" full_name = first_name.upper() + " " + last_name.upper() - fellows = [person.name for person in Amity.all_people if person.category == "FELLOW"] - staff = [person.name for person in Amity.all_people if person.category == "STAFF"] + fellows = [person.full_name for person in Amity.all_people if person.category == "FELLOW"] + staff = [person.full_name for person in Amity.all_people if person.category == "STAFF"] available_lspaces = [room.room_name for room in Amity.all_rooms - if room.room_type == "LIVING SPACE" - and len(Amity.living_spaces[room.room_name]) < 4] + if room.room_type == "LIVING_SPACE" + and len(Amity.living_spaces[room.room_name]) < LivingSpace.room_capacity] available_offices = [room.room_name for room in Amity.all_rooms if room.room_type == "OFFICE" - and len(Amity.office_spaces[room.room_name]) < 6] + and len(Amity.office_spaces[room.room_name]) < Office.room_capacity] if full_name not in fellows and full_name not in staff: print("Sorry, the person doesn't exist.") elif new_room.upper() not in available_lspaces and new_room.upper() not in available_offices: print("The room requested does not exist or is not available") - print("Available office \n" + available_offices) - print("Available living space \n" + available_lspaces) + print("Available office \n", available_offices) + print("Available living space \n", available_lspaces) else: if room_type.upper() == "L": if new_room in available_offices and new_room not in available_lspaces: @@ -114,11 +116,14 @@ def reallocate_person(self, first_name, last_name, room_type, new_room): space = Amity() -space.create_room('O', "MyRoom") +space.create_room('L', "MyRoom") +space.create_room('O', 'valhala') space.add_person('faith', 'dede', 'F', 'Y') -space.reallocate_person('faith', 'dede', 'O', 'valahala') + +space.reallocate_person('faith', 'dede', 'L', 'valhala') print(Amity.living_spaces) -print(space.reallocate_person('faith', 'dede', 'O', 'valahala')) +print(Amity.office_spaces) +print(space.reallocate_person('faith', 'dede', 'L', 'valhala')) print(Amity.living_spaces) print(Amity.all_rooms) From 42d7496a5c4c32d63dfb2ba20156cf757a1d7a87 Mon Sep 17 00:00:00 2001 From: faithngetich Date: Tue, 18 Apr 2017 11:07:51 +0300 Subject: [PATCH 19/52] [chore] Add load people method --- people.txt | 4 ++++ views.py | 33 ++++++++------------------------- 2 files changed, 12 insertions(+), 25 deletions(-) create mode 100644 people.txt diff --git a/people.txt b/people.txt new file mode 100644 index 0000000..616e608 --- /dev/null +++ b/people.txt @@ -0,0 +1,4 @@ +JONATHAN NGONDI S +AHMED YUSUB F +EPRAHIM KIMANI F +FAITH DEDE S \ No newline at end of file diff --git a/views.py b/views.py index be40f06..f8a7bab 100644 --- a/views.py +++ b/views.py @@ -114,29 +114,12 @@ def reallocate_person(self, first_name, last_name, room_type, new_room): Amity.office_spaces[new_room.upper()].append(full_name) print("successfully reallocated") + def load_people(self, filename): + """loads people from a txt file to the app""" + with open (filename, 'r') as people_file: + for person_details in people_file: + details = person_details.rstrip().split() + accomodate = details[3] if len(details) == 4 else "N" + self.add_person(details[0], details[1], details[2], accomodate) + print("Successfully loaded people") -space = Amity() -space.create_room('L', "MyRoom") -space.create_room('O', 'valhala') -space.add_person('faith', 'dede', 'F', 'Y') - -space.reallocate_person('faith', 'dede', 'L', 'valhala') -print(Amity.living_spaces) -print(Amity.office_spaces) -print(space.reallocate_person('faith', 'dede', 'L', 'valhala')) -print(Amity.living_spaces) -print(Amity.all_rooms) - -# def load_people(filename): -# """loads people from a txt file to the app""" -# with open (filename, 'r') as people_file: -# for person_details in people_file: -# details = person_details.rstrip().split() -# accomodate = details[3] if len(details) == 4 else "N" -# Amity.add_person(details[0], details[1], details[2], accomodate) -# print("Successfully loaded people") - -# space = Amity() -# space.add_person('faith', 'dede', 'F', 'Y') -# space.load_people('faith') -# print(Amity.living_spaces) From eb37b18d79f9be09089c3c7dad0e7cf2562e3f9e Mon Sep 17 00:00:00 2001 From: faithngetich Date: Tue, 18 Apr 2017 23:28:07 +0300 Subject: [PATCH 20/52] [chore] Refactor the create room method --- models/persons.py | 3 ++ people.txt | 7 ++++- views.py | 79 +++++++++++++++++++++++++---------------------- 3 files changed, 51 insertions(+), 38 deletions(-) diff --git a/models/persons.py b/models/persons.py index 08f77f2..093904a 100644 --- a/models/persons.py +++ b/models/persons.py @@ -20,6 +20,9 @@ def __str__(self): """To make Staff class human readable.""" return "{} {}".format(self.first_name, self.last_name) + def __repr__(self): + return 'first_name:{}, last_name:{}'.format(self.first_name,self.last_name) + class Fellow(Person): wants_accomodation = "N" diff --git a/people.txt b/people.txt index 616e608..af7e8b8 100644 --- a/people.txt +++ b/people.txt @@ -1,4 +1,9 @@ JONATHAN NGONDI S AHMED YUSUB F EPRAHIM KIMANI F -FAITH DEDE S \ No newline at end of file +FAITH DEDE S + +# mapping = {'O': Office, 'L': LivingSpace} + # new_room = mapping[room_type.upper()](room_name.upper()) + +#print(room_name.upper() + " " + "created successfully") \ No newline at end of file diff --git a/views.py b/views.py index f8a7bab..9220dd4 100644 --- a/views.py +++ b/views.py @@ -11,36 +11,40 @@ class Amity(object): all_staff = [] all_fellows = [] all_rooms = [] + office_allocations = {} + living_space_allocations = {} all_people = [] - living_spaces = {'None' : []} + living_spaces = {'' : []} office_spaces = {'None' : []} accomodation_list = [] allocated_rooms = {} - def create_room(self, room_type, room_name): + def create_room(self, room_type, list_of_rooms): """creates a specified room""" - if room_name.upper() in [room.room_name for room in Amity.all_rooms]: - print("sorry, Room already exist.") - else: - mapping = {'O': Office, 'L': LivingSpace} - new_room = mapping[room_type.upper()](room_name.upper()) - Amity.all_rooms.append(new_room) - if room_type.upper() == 'O': - Amity.office_spaces[room_name.upper()] = [] - elif room_type.upper() == 'L': - Amity.living_spaces[room_name.upper()] = [] - print(room_name.upper() + " " + "created successfully") + for room_name in list_of_rooms: + if room_name.upper() in [room.room_name for room in self.all_rooms]: + print("sorry, Room already exist.") + else: + if room_type.upper() == 'O': + office = Office(room_name) + self.all_rooms.append(office) + self.office_allocations[office] = [] + self.office_spaces[room_name.upper()] = [] + print("Office {} successfully created.".format(office.room_name)) + elif room_type.upper() == 'L': + self.living_spaces[room_name.upper()] = [] + living_space = LivingSpace(room_name) + self.all_rooms.append(living_space) + self.living_space_allocations[living_space] = [] + print("Living space {} successfully created.".format(living_space.room_name)) def generate_random_office_spaces(self): """Generates random office""" - offices = [room for room in Amity.all_rooms if room.room_type == "OFFICE"] + offices = [room for room in self.all_rooms if room.room_type == "OFFICE"] available_offices = [] for office in offices: - if office.room_capacity > len(Amity.office_spaces[office.room_name]): + if office.room_capacity > len(self.office_spaces[office.room_name.upper()]): available_offices.append(office.room_name) - - # selected_room = 'None' - if len(available_offices): selected_room = random.choice(available_offices) else: @@ -49,13 +53,11 @@ def generate_random_office_spaces(self): def generate_random_living_spaces(self): """Generates random living spaces""" - # self.create_room('L', "MyRoom") - livingSpaces = [room for room in Amity.all_rooms if room.room_type == "LIVING_SPACE"] + livingSpaces = [room for room in self.all_rooms if room.room_type == "LIVING_SPACE"] available_living_space = [] for living_space in livingSpaces: - if living_space.room_capacity > len(Amity.living_spaces[living_space.room_name]): + if living_space.room_capacity > len(self.living_spaces[living_space.room_name]): available_living_space.append(living_space.room_name) - if len(available_living_space): selected_room = random.choice(available_living_space) else: @@ -63,13 +65,15 @@ def generate_random_living_spaces(self): return selected_room def add_person(self, first_name, last_name, category, wants_accomodation='N'): - """Adds person to Amity and randomly allocates the person""" + """Adds person to self and randomly allocates the person""" mapping = {"F": Fellow, "S":Staff} new_person = mapping[category.upper()](first_name.upper(), last_name.upper()) - Amity.all_people.append(new_person) + print("NEW {}".format(new_person)) + self.all_people.append(new_person) + print(self.all_people) allocated_office = self.generate_random_office_spaces() if allocated_office: - Amity.office_spaces[allocated_office].append(new_person.full_name) + self.office_spaces[allocated_office.upper()].append(new_person.full_name) print(new_person.full_name + " added successfully to " + allocated_office) else: print("No office space available") @@ -78,21 +82,21 @@ def add_person(self, first_name, last_name, category, wants_accomodation='N'): if allocated_living_space is None: print("No available living spaces") else: - Amity.living_spaces[allocated_living_space].append(new_person.full_name) + self.living_spaces[allocated_living_space].append(new_person.full_name) print(new_person.full_name + " added successfully to " + allocated_living_space) print("Adding process completed succesfully") def reallocate_person(self, first_name, last_name, room_type, new_room): """ moves person from one room to another room""" full_name = first_name.upper() + " " + last_name.upper() - fellows = [person.full_name for person in Amity.all_people if person.category == "FELLOW"] - staff = [person.full_name for person in Amity.all_people if person.category == "STAFF"] - available_lspaces = [room.room_name for room in Amity.all_rooms + fellows = [person.full_name for person in self.all_people if person.category == "FELLOW"] + staff = [person.full_name for person in self.all_people if person.category == "STAFF"] + available_lspaces = [room.room_name for room in self.all_rooms if room.room_type == "LIVING_SPACE" - and len(Amity.living_spaces[room.room_name]) < LivingSpace.room_capacity] - available_offices = [room.room_name for room in Amity.all_rooms + and len(self.living_spaces[room.room_name]) < LivingSpace.room_capacity] + available_offices = [room.room_name for room in self.all_rooms if room.room_type == "OFFICE" - and len(Amity.office_spaces[room.room_name]) < Office.room_capacity] + and len(self.office_spaces[room.room_name]) < Office.room_capacity] if full_name not in fellows and full_name not in staff: print("Sorry, the person doesn't exist.") @@ -107,11 +111,11 @@ def reallocate_person(self, first_name, last_name, room_type, new_room): elif full_name not in fellows: return "The person has to exist and be a fellow!" else: - for room in Amity.living_spaces.keys(): - if full_name in Amity.living_spaces[room]: - lspace = Amity.living_spaces[room] + for room in self.living_spaces.keys(): + if full_name in self.living_spaces[room]: + lspace = self.living_spaces[room] lspace.remove(full_name) - Amity.office_spaces[new_room.upper()].append(full_name) + self.office_spaces[new_room.upper()].append(full_name) print("successfully reallocated") def load_people(self, filename): @@ -122,4 +126,5 @@ def load_people(self, filename): accomodate = details[3] if len(details) == 4 else "N" self.add_person(details[0], details[1], details[2], accomodate) print("Successfully loaded people") - + + From 2deaae947f16ee5c83fbee445daad463fa7eecac Mon Sep 17 00:00:00 2001 From: faithngetich Date: Wed, 19 Apr 2017 11:08:41 +0300 Subject: [PATCH 21/52] [chore] Add print allocation method --- people.txt | 13 ++++--------- views.py | 32 +++++++++++++++++++++++++++++++- 2 files changed, 35 insertions(+), 10 deletions(-) diff --git a/people.txt b/people.txt index af7e8b8..da60040 100644 --- a/people.txt +++ b/people.txt @@ -1,9 +1,4 @@ -JONATHAN NGONDI S -AHMED YUSUB F -EPRAHIM KIMANI F -FAITH DEDE S - -# mapping = {'O': Office, 'L': LivingSpace} - # new_room = mapping[room_type.upper()](room_name.upper()) - -#print(room_name.upper() + " " + "created successfully") \ No newline at end of file +JONATHAN NGONDI S O +AHMED YUSUB F O +EPRAHIM KIMANI F L +FAITH DEDE S O diff --git a/views.py b/views.py index 9220dd4..45dd7df 100644 --- a/views.py +++ b/views.py @@ -126,5 +126,35 @@ def load_people(self, filename): accomodate = details[3] if len(details) == 4 else "N" self.add_person(details[0], details[1], details[2], accomodate) print("Successfully loaded people") + + @staticmethod + def print_allocations(file_name=None): + print("=" * 30 + "\n" + "Office Allocations\n" + "=" *30) + for room in Amity.office_spaces.keys(): + if room != "None": + print (room + "\n" + "+" * 30) + for person in Amity.office_spaces[room]: + print(person) + print("=" * 30 + "\n" + "Living spaces Allocations\n" + "=" *30) + for room in Amity.living_spaces.keys(): + if room != "None": + print (room + "\n" + "+" * 30) + for person in Amity.living_spaces[room]: + print(person) + if file_name: + nfile = open(file_name + ".txt", "a") + nfile.write("=" * 30 + "\n" + "Office Allocations\n" + "=" *30) + for room in Amity.office_spaces[room]: + if room != "None": + nfile.write(room + "\n" + "+" * 30) + for person in Amity.office_spaces[room]: + nfile.write(person) + nfile.write("=" *30 + "\n" + "Living space Allocations\n" + "=" * 30 ) + for room in Amity.living_spaces[room]: + if room != "None": + nfile.write(room + "\n" + "+" * 30) + for person in Amity.living_spaces[room]: + nfile.write(person) + print("%s.txt written" % file) - + \ No newline at end of file From 47f641c7f38814448826544e87614d2aff233286 Mon Sep 17 00:00:00 2001 From: faithngetich Date: Wed, 19 Apr 2017 12:28:23 +0300 Subject: [PATCH 22/52] [chore] Add print room method --- views.py | 49 +++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 45 insertions(+), 4 deletions(-) diff --git a/views.py b/views.py index 45dd7df..69dab78 100644 --- a/views.py +++ b/views.py @@ -14,7 +14,7 @@ class Amity(object): office_allocations = {} living_space_allocations = {} all_people = [] - living_spaces = {'' : []} + living_spaces = {'None' : []} office_spaces = {'None' : []} accomodation_list = [] allocated_rooms = {} @@ -56,7 +56,7 @@ def generate_random_living_spaces(self): livingSpaces = [room for room in self.all_rooms if room.room_type == "LIVING_SPACE"] available_living_space = [] for living_space in livingSpaces: - if living_space.room_capacity > len(self.living_spaces[living_space.room_name]): + if living_space.room_capacity > len(self.living_spaces[living_space.room_name.upper()]): available_living_space.append(living_space.room_name) if len(available_living_space): selected_room = random.choice(available_living_space) @@ -82,7 +82,7 @@ def add_person(self, first_name, last_name, category, wants_accomodation='N'): if allocated_living_space is None: print("No available living spaces") else: - self.living_spaces[allocated_living_space].append(new_person.full_name) + self.living_spaces[allocated_living_space.upper()].append(new_person.full_name) print(new_person.full_name + " added successfully to " + allocated_living_space) print("Adding process completed succesfully") @@ -129,6 +129,7 @@ def load_people(self, filename): @staticmethod def print_allocations(file_name=None): + """Prints a list of allocations onto the screen""" print("=" * 30 + "\n" + "Office Allocations\n" + "=" *30) for room in Amity.office_spaces.keys(): if room != "None": @@ -157,4 +158,44 @@ def print_allocations(file_name=None): nfile.write(person) print("%s.txt written" % file) - \ No newline at end of file + @staticmethod + def print_unallocated(file_name=None): + """Prints all people not allocated""" + unallocated_offices = Amity.office_spaces["None"] + unallocated_living_spaces = Amity.living_spaces["None"] + print("=" * 30 + "\n" + "No offices\n" + "=" * 30) + for person in unallocated_offices: + print(person or "None") + print("=" * 30 + "\n" + "Living Spaces\n" + "=" * 30) + for person in unallocated_living_spaces: + print(person or "None") + + if file_name: + file = open(file_name + ".txt", "a") + file.write("=" * 30 + "\n" + "No offices\n" + "=" * 30) + for person in unallocated_offices: + file.write("\n" + person or "None") + file.write("=" * 30 + "\n" + "No living spaces\n" + "=" * 30) + for person in unallocated_living_spaces: + file.write("\n" + person or "None") + print("%s.txt written succesfully", file_name) + + @staticmethod + def print_room(room_name): + """ Prints the names of all the people in room_name on the + screen.""" + offices = [room for room in Amity.office_spaces if room != "None"] + living_spaces = [room for room in Amity.living_spaces if room != "None"] + if room_name.upper() not in offices and room_name.upper() not in living_spaces: + print("sorry! the room does not exist") + else: + print("=" * 30 + "\n Members \n" + "=" * 30) + if room_name.upper() in offices: + for person in Amity.office_spaces[room_name.upper()]: + print(person) + elif room_name.upper() in living_spaces: + for person in Amity.living_spaces[room_name.upper()]: + print(person) + + + \ No newline at end of file From 658095ab11efd1f1334301e4acb95f3414fead34 Mon Sep 17 00:00:00 2001 From: faithngetich Date: Wed, 19 Apr 2017 18:34:20 +0300 Subject: [PATCH 23/52] [chore] Refactor add person method --- views.py | 228 +++++++++++++++++++------------------------------------ 1 file changed, 79 insertions(+), 149 deletions(-) diff --git a/views.py b/views.py index 69dab78..066705f 100644 --- a/views.py +++ b/views.py @@ -1,11 +1,11 @@ -# from models.migrate import eng -# from sqlalchemy.orm import sessionmaker -from models.rooms import Office -from models.rooms import LivingSpace -from models.persons import Fellow -from models.persons import Staff - import random +from sqlalchemy import create_engine +from sqlalchemy.orm import mapper, sessionmaker +from models.rooms import Office, LivingSpace +from models.persons import Fellow, Staff +from models.model import (Base, Room, Person, OfficeSpaces, LivingSpaces, DatabaseCreator) + + class Amity(object): all_staff = [] @@ -14,11 +14,9 @@ class Amity(object): office_allocations = {} living_space_allocations = {} all_people = [] - living_spaces = {'None' : []} - office_spaces = {'None' : []} - accomodation_list = [] - allocated_rooms = {} - + living_spaces_waiting_list = [] + office_spaces_waiting_list = [] + def create_room(self, room_type, list_of_rooms): """creates a specified room""" for room_name in list_of_rooms: @@ -29,10 +27,8 @@ def create_room(self, room_type, list_of_rooms): office = Office(room_name) self.all_rooms.append(office) self.office_allocations[office] = [] - self.office_spaces[room_name.upper()] = [] print("Office {} successfully created.".format(office.room_name)) elif room_type.upper() == 'L': - self.living_spaces[room_name.upper()] = [] living_space = LivingSpace(room_name) self.all_rooms.append(living_space) self.living_space_allocations[living_space] = [] @@ -43,9 +39,9 @@ def generate_random_office_spaces(self): offices = [room for room in self.all_rooms if room.room_type == "OFFICE"] available_offices = [] for office in offices: - if office.room_capacity > len(self.office_spaces[office.room_name.upper()]): - available_offices.append(office.room_name) - if len(available_offices): + if office.room_capacity < 6: + available_offices.append(office) + if available_offices: selected_room = random.choice(available_offices) else: selected_room = None @@ -53,12 +49,12 @@ def generate_random_office_spaces(self): def generate_random_living_spaces(self): """Generates random living spaces""" - livingSpaces = [room for room in self.all_rooms if room.room_type == "LIVING_SPACE"] + living_spaces = [room for room in self.all_rooms if room.room_type == "LIVING_SPACE"] available_living_space = [] - for living_space in livingSpaces: - if living_space.room_capacity > len(self.living_spaces[living_space.room_name.upper()]): - available_living_space.append(living_space.room_name) - if len(available_living_space): + for living_space in living_spaces: + if living_space.room_capacity < 4: + available_living_space.append(living_space) + if available_living_space: selected_room = random.choice(available_living_space) else: selected_room = None @@ -66,136 +62,70 @@ def generate_random_living_spaces(self): def add_person(self, first_name, last_name, category, wants_accomodation='N'): """Adds person to self and randomly allocates the person""" - mapping = {"F": Fellow, "S":Staff} - new_person = mapping[category.upper()](first_name.upper(), last_name.upper()) - print("NEW {}".format(new_person)) - self.all_people.append(new_person) - print(self.all_people) - allocated_office = self.generate_random_office_spaces() - if allocated_office: - self.office_spaces[allocated_office.upper()].append(new_person.full_name) - print(new_person.full_name + " added successfully to " + allocated_office) - else: - print("No office space available") - if wants_accomodation.upper() == 'Y' and category == 'F': - allocated_living_space = self.generate_random_living_spaces() - if allocated_living_space is None: - print("No available living spaces") + # check if category is FELLOW + if wants_accomodation == "N": + if category is "FELLOW": + # create fellow object + fellow = Fellow(first_name, last_name) + Amity.all_fellows.append(fellow) + allocated_office = self.generate_random_office_spaces() + if allocated_office: + # if random room selected + Amity.office_allocations[allocated_office].append(fellow) + print("You have allocated {} successfully ".format(fellow.first_name)) + else: + Amity.office_spaces_waiting_list.append(fellow) + print("Sorry, no space available {} has been added to the waiting list".format(fellow.first_name)) else: - self.living_spaces[allocated_living_space.upper()].append(new_person.full_name) - print(new_person.full_name + " added successfully to " + allocated_living_space) - print("Adding process completed succesfully") - - def reallocate_person(self, first_name, last_name, room_type, new_room): - """ moves person from one room to another room""" - full_name = first_name.upper() + " " + last_name.upper() - fellows = [person.full_name for person in self.all_people if person.category == "FELLOW"] - staff = [person.full_name for person in self.all_people if person.category == "STAFF"] - available_lspaces = [room.room_name for room in self.all_rooms - if room.room_type == "LIVING_SPACE" - and len(self.living_spaces[room.room_name]) < LivingSpace.room_capacity] - available_offices = [room.room_name for room in self.all_rooms - if room.room_type == "OFFICE" - and len(self.office_spaces[room.room_name]) < Office.room_capacity] - if full_name not in fellows and full_name not in staff: - print("Sorry, the person doesn't exist.") - - elif new_room.upper() not in available_lspaces and new_room.upper() not in available_offices: - print("The room requested does not exist or is not available") - print("Available office \n", available_offices) - print("Available living space \n", available_lspaces) + # create fellow object + staff = Staff(first_name, last_name) + Amity.all_staff.append(staff) + allocated_office = self.generate_random_office_spaces() + if allocated_office: + # if random room selected + Amity.office_allocations[allocated_office].append(staff) + print("You have allocated {} successfully ".format(staff.first_name)) + else: + Amity.office_spaces_waiting_list.append(staff) + print("Sorry, no space available {} has been added to the waiting list".format(staff.first_name)) else: - if room_type.upper() == "L": - if new_room in available_offices and new_room not in available_lspaces: - print("The room selected is not a living space") - elif full_name not in fellows: - return "The person has to exist and be a fellow!" + # if wants accomodation + if category is "FELLOW": + # create fellow object + fellow = Fellow(first_name, last_name) + Amity.all_fellows.append(fellow) + allocated_office = self.generate_random_office_spaces() + if allocated_office: + # if random room selected + Amity.office_allocations[allocated_office].append(fellow) + print("You have allocated {} successfully ".format(fellow.first_name)) else: - for room in self.living_spaces.keys(): - if full_name in self.living_spaces[room]: - lspace = self.living_spaces[room] - lspace.remove(full_name) - self.office_spaces[new_room.upper()].append(full_name) - print("successfully reallocated") - - def load_people(self, filename): - """loads people from a txt file to the app""" - with open (filename, 'r') as people_file: - for person_details in people_file: - details = person_details.rstrip().split() - accomodate = details[3] if len(details) == 4 else "N" - self.add_person(details[0], details[1], details[2], accomodate) - print("Successfully loaded people") + Amity.office_spaces_waiting_list.append(fellow) + print("Sorry, no space available {} has been added to the waiting list".format(fellow.first_name)) + + # add living space + allocated_living_space = self.generate_random_living_spaces() + if allocated_living_space: + Amity.living_space_allocations[allocated_living_space].append(fellow) + print("You have allocated {} successfully to living space {} ".format(fellow.first_name, allocated_living_space.room_name)) + else: + Amity.living_spaces_waiting_list.append(fellow) + print("Sorry, no space available {} has been added to the waiting list".format(fellow.first_name)) + else: + staff = Staff(first_name, last_name) + Amity.all_staff.append(staff) + allocated_office = self.generate_random_office_spaces() + if allocated_office: + # if random room selected + Amity.office_allocations[allocated_office].append(staff) + print("You have allocated {} successfully ".format(staff.first_name)) + # reject adding staff to living space + else: + Amity.office_spaces_waiting_list.append(staff) + print("Sorry, no space available {} has been added to the waiting list".format(staff.first_name)) - @staticmethod - def print_allocations(file_name=None): - """Prints a list of allocations onto the screen""" - print("=" * 30 + "\n" + "Office Allocations\n" + "=" *30) - for room in Amity.office_spaces.keys(): - if room != "None": - print (room + "\n" + "+" * 30) - for person in Amity.office_spaces[room]: - print(person) - print("=" * 30 + "\n" + "Living spaces Allocations\n" + "=" *30) - for room in Amity.living_spaces.keys(): - if room != "None": - print (room + "\n" + "+" * 30) - for person in Amity.living_spaces[room]: - print(person) - if file_name: - nfile = open(file_name + ".txt", "a") - nfile.write("=" * 30 + "\n" + "Office Allocations\n" + "=" *30) - for room in Amity.office_spaces[room]: - if room != "None": - nfile.write(room + "\n" + "+" * 30) - for person in Amity.office_spaces[room]: - nfile.write(person) - nfile.write("=" *30 + "\n" + "Living space Allocations\n" + "=" * 30 ) - for room in Amity.living_spaces[room]: - if room != "None": - nfile.write(room + "\n" + "+" * 30) - for person in Amity.living_spaces[room]: - nfile.write(person) - print("%s.txt written" % file) - - @staticmethod - def print_unallocated(file_name=None): - """Prints all people not allocated""" - unallocated_offices = Amity.office_spaces["None"] - unallocated_living_spaces = Amity.living_spaces["None"] - print("=" * 30 + "\n" + "No offices\n" + "=" * 30) - for person in unallocated_offices: - print(person or "None") - print("=" * 30 + "\n" + "Living Spaces\n" + "=" * 30) - for person in unallocated_living_spaces: - print(person or "None") + + print("Staff not entitled to living space") - if file_name: - file = open(file_name + ".txt", "a") - file.write("=" * 30 + "\n" + "No offices\n" + "=" * 30) - for person in unallocated_offices: - file.write("\n" + person or "None") - file.write("=" * 30 + "\n" + "No living spaces\n" + "=" * 30) - for person in unallocated_living_spaces: - file.write("\n" + person or "None") - print("%s.txt written succesfully", file_name) - @staticmethod - def print_room(room_name): - """ Prints the names of all the people in room_name on the - screen.""" - offices = [room for room in Amity.office_spaces if room != "None"] - living_spaces = [room for room in Amity.living_spaces if room != "None"] - if room_name.upper() not in offices and room_name.upper() not in living_spaces: - print("sorry! the room does not exist") - else: - print("=" * 30 + "\n Members \n" + "=" * 30) - if room_name.upper() in offices: - for person in Amity.office_spaces[room_name.upper()]: - print(person) - elif room_name.upper() in living_spaces: - for person in Amity.living_spaces[room_name.upper()]: - print(person) - - - \ No newline at end of file + \ No newline at end of file From 6c8ae3dd700c8ac475f3f9742b42a957c9c9bd8b Mon Sep 17 00:00:00 2001 From: faithngetich Date: Thu, 20 Apr 2017 12:25:56 +0300 Subject: [PATCH 24/52] [chore] Add a docopt app file --- app.py | 166 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 164 insertions(+), 2 deletions(-) diff --git a/app.py b/app.py index f84565e..713e619 100644 --- a/app.py +++ b/app.py @@ -1,5 +1,167 @@ -import cmd, os + +""" +Usage: + amity create_room ( )... + amity add_person (Fellow | Staff) [--wants_accomodation=(Y | N)] + amity print_allocations [-output=] + amity reallocate_person + amity print_room + amity print_unallocated [-output=] + amity load_people + amity save_state [--database=] + amity load_state + amity (-i | --interactive) + amity (-h | --help | --version) +Options: + -i, --interactive Interactive Mode + -h, --help Show this screen and exit. + -a, --wants_accomodation= Person wants accomodation [default: N] + -d, --database= Save state to specified database [default: amity_db] +""" +import cmd, os, sys from docopt import docopt, DocoptExit from pyfiglet import figlet_format from termcolor import cprint -from views import Amity \ No newline at end of file +from views import Amity + +amity = Amity() + +def docopt_cmd(func): + """ + This decorator is used to simplify the try/except block and pass the result + of the docopt parsing to the called action. + """ + def fn(self, arg): + try: + opt = docopt(fn.__doc__,arg) + except DocoptExit as e: + # The DocoptExit is thrown when the args do not match. + # We print a message to the user and the usage block. + + print('Invalid command!') + print(e) + return + except SystemExit: + # The SystemExit exception prints the usage for --help + # We do not need to do the print here. + return + return func(self, opt) + + fn.__name__ = func.__name__ + fn.__doc__ = func.__doc__ + fn.__dict__.update(func.__dict__) + return fn + +def intro(): + cprint(figlet_format('Space Allocator', font='slant'), + 'blue', attrs=['bold']) + print("Welcome to Amity! Here is a list of commands to get you started." + + " Type 'help' anytime to access documented commands") + cprint(__doc__, 'magenta') + +class AmitySystem(cmd.Cmd): + prompt = '(Amity) ' + file = None + + @docopt_cmd + def do_create_room(self, args): + """Usage: create_room ( )...""" + + rooms = args[""] + types = args[""] + for room in rooms: + r_type = types[rooms.index(room)] + amity.create_room(room, r_type) + + @docopt_cmd + def do_add_person(self, args): + """ + Usage: + add_person (fellow | staff) [--wants_accomodation=] + Options: + -a, --wants_accomodation= Wants accomodation [default: N] + """ + first_name = args[""] + last_name = args[""] + if args["fellow"]: + role = "FELLOW" + else: + role = "STAFF" + accomodate = args["--wants_accomodation"].upper() + if accomodate == 'Y' or accomodate == 'N': + amity.add_person(first_name, last_name, role, accomodate) + else: + cprint("Invalid accomodation option. Please enter Y/N", 'red') + + + @docopt_cmd + def do_reallocate_person(self, args): + """Usage: reallocate_person """ + + first_name = args[""] + last_name = args[""] + room_name = args[""] + person_name = first_name + " " + last_name + + amity.reallocate_person(person_name, room_name) + + @docopt_cmd + def do_print_allocations(self, args): + """ + Usage: print_allocations [--output=] + Options: + -o, --output= Save allocations to file + """ + + filename = args["--output"] + amity.print_allocations(filename) + + @docopt_cmd + def do_print_room(self, args): + """Usage: print_room """ + + room_name = args[""] + amity.print_room(room_name) + + def do_clear(self, arg): + """Clears screen""" + + os.system('clear') + + def do_quit(self, arg): + """Quits out of Interactive Mode.""" + + print('Thank you for using Amity. Adios!') + exit() + + @docopt_cmd + def do_save_state(self, args): + """ + Usage: save_state [--database=] + Options: + -d, --database= Save state to specified database [default: amity_db] + """ + + db_name = args["--database"] + amity.save_state(db_name) + + @docopt_cmd + def do_load_state(self, args): + """ + Usage: load_state [--load=] + Options: + -l, --load= Load data from specified database [default: amity_db] + """ + amity.load_state(args["--load"]) + + +opt = docopt(__doc__, sys.argv[1:]) + +if opt['--interactive']: + os.system('clear') + intro() + AmitySystem().cmdloop() + +print(opt) + + From c57049b3d04e09293b7cd7d7e6344191e5144b99 Mon Sep 17 00:00:00 2001 From: faithngetich Date: Thu, 20 Apr 2017 22:22:17 +0300 Subject: [PATCH 25/52] [chore] Add a save state method --- Olex.db | Bin 0 -> 12288 bytes classes/__init__.py => __init__.py | 0 amon.db | Bin 0 -> 12288 bytes amon.db.db | Bin 0 -> 12288 bytes amos.db | Bin 0 -> 12288 bytes app.py | 38 ++-- dbname.sqlite | 0 fa.db | Bin 0 -> 12288 bytes fadedbfdb.db | Bin 0 -> 12288 bytes fadede.db | Bin 0 -> 12288 bytes faha.db | Bin 0 -> 12288 bytes faith.db | Bin 0 -> 12288 bytes lazy.db | Bin 0 -> 12288 bytes models/base.py | 3 - models/migrate.py | 9 - models/model.py | 48 +++-- views.py | 279 +++++++++++++++++++++++++++-- 17 files changed, 310 insertions(+), 67 deletions(-) create mode 100644 Olex.db rename classes/__init__.py => __init__.py (100%) create mode 100644 amon.db create mode 100644 amon.db.db create mode 100644 amos.db create mode 100644 dbname.sqlite create mode 100644 fa.db create mode 100644 fadedbfdb.db create mode 100644 fadede.db create mode 100644 faha.db create mode 100644 faith.db create mode 100644 lazy.db delete mode 100644 models/base.py delete mode 100644 models/migrate.py diff --git a/Olex.db b/Olex.db new file mode 100644 index 0000000000000000000000000000000000000000..5185ff2a38d374761dc98265394b5673853e70df GIT binary patch literal 12288 zcmeI#&ubGw6bJCxq-;qbZUtpoygUlZ28t;D18$c|vvl3WZH)9FVY*p$G1&>}v?buB z`VSQRFZ?^alpgDki{Q<_!`UR22BHVSOZX1#%<$gs+j*bc>^%)LmC{Q&9tuT|*akBU z_Lztv$?d`$}IR#y(B`VujF`gb(95xlj4v)ktA{``$AX??WbTB-G6h1*4I5P$##AOHafKmY;|fB*y_0D=D}aP#cq^81F# zZaYRzCQ7y%jlkz-5&lfGa4yFAweXMjEPN~mVjgzRE1f3 literal 0 HcmV?d00001 diff --git a/classes/__init__.py b/__init__.py similarity index 100% rename from classes/__init__.py rename to __init__.py diff --git a/amon.db b/amon.db new file mode 100644 index 0000000000000000000000000000000000000000..b81b43833fa0e8927f916876d8acfe4da5fbd9f7 GIT binary patch literal 12288 zcmeI#&r8EF6bJCM6GjLAxRu==J4gpZ6#oIc65UwsX06H&GGbSyxGrUj$d1#0+;p?x zV0!R4zJa943w_P|^px8hKUE1m%ULEAowFlm80>QqYemxbyuM)vT$=61sOouj6iR%yi0;TI7H1#v&JS zsuo)l%Q$|^#Z=A9?8VmxVfWe%ht%Uka?)|L)?7XqRl8m{KCM+DgGA<&WIdXjrL2Sh zswEaGd6Bb4d6W%-_u`Nv5yvuQqYemxbyuM)vT$=61sOouj6iR%yi0;TI7H1#v&JS zsuo)l%Q$|^#Z=A9?8VmxVfWe%ht%Uka?)|L)?7XqRl8m{KCM+DgGA<&WIdXjrL2Sh zswEaGd6Bb4d6W%-_u`Nv5yvuoU54>^S|$O*aQl zrU#Gn8%Ubuk?`{A>D}E1nNI0h6}i-O!A_WEu}dPxm~DE+^i3<*2b+cYT3_ZrO>K7O zc!wrx9~JEQ)C_14fB*y_009U<00Izz00bcLPXv~2yXv~G^~SY)nxv6Z`Fu50{7CRv zP|Q1lpvG#iL0-+t#?%dCaU~)O`!R+0LC~U_GnIKt4?Oa(`F5Z%SB~^z_DeL8Gnr(1 zvGd|V)V<-+ka}WBUN&yln#)J4>elPlyR*u9kgC}vU61y5*6YnbrJYEfzNlic^G&aE zs^=q_Bq~>9sWUaDPQM=r9+ni}GcNc1YvK3E+i|cPl6T&scGJA9tj$f)j|Kqr{@>%Di>E;V0uX=z1Rwwb2tWV=5P$##J_SAi^b~h} literal 0 HcmV?d00001 diff --git a/app.py b/app.py index 713e619..57b9e07 100644 --- a/app.py +++ b/app.py @@ -65,13 +65,18 @@ class AmitySystem(cmd.Cmd): @docopt_cmd def do_create_room(self, args): - """Usage: create_room ( )...""" + """Usage: create_room (O|L) ...""" + + # rooms = args[""] + # types = args[""] + # for room in rooms: + # r_type = types[rooms.index(room)] + if args["O"]: + room_type = "O" + else: + room_type = "L" - rooms = args[""] - types = args[""] - for room in rooms: - r_type = types[rooms.index(room)] - amity.create_room(room, r_type) + amity.create_room(room_type, args[""]) @docopt_cmd def do_add_person(self, args): @@ -134,26 +139,7 @@ def do_quit(self, arg): print('Thank you for using Amity. Adios!') exit() - @docopt_cmd - def do_save_state(self, args): - """ - Usage: save_state [--database=] - Options: - -d, --database= Save state to specified database [default: amity_db] - """ - - db_name = args["--database"] - amity.save_state(db_name) - - @docopt_cmd - def do_load_state(self, args): - """ - Usage: load_state [--load=] - Options: - -l, --load= Load data from specified database [default: amity_db] - """ - amity.load_state(args["--load"]) - + opt = docopt(__doc__, sys.argv[1:]) diff --git a/dbname.sqlite b/dbname.sqlite new file mode 100644 index 0000000..e69de29 diff --git a/fa.db b/fa.db new file mode 100644 index 0000000000000000000000000000000000000000..7d752ad3ea8258a70784284204ffb8a049f1ffdb GIT binary patch literal 12288 zcmeI&F-yZh6bJB2E7cZi6p_;H;UFo9C@zkk;aZC^(O4@EB4-*UXnUnbq@y}H`Z)xh z{T6-;zk#!t)`ErV;AZ(BJ=quH{>V>rJ3tkgcBoQo1Rwwb2tWV=5P$##AOHafKwyjolKX$!d}ZdF z`D(t8aieGr0uX=z1Rwwb2tWV=5P$##An+drW*;9uo@X*_zG&pVO1a{d%T-%slJwJ5 ZKkf4RAU&tkFY6hm|6$12xx*`i!Y7s7li&aV literal 0 HcmV?d00001 diff --git a/fadedbfdb.db b/fadedbfdb.db new file mode 100644 index 0000000000000000000000000000000000000000..f4d4811dfb4f44ee364d73a14f9c56a0a3d46ae1 GIT binary patch literal 12288 zcmeI&J!{)Q7zgl^T@-9^)mMb+@{l3O5JF17KrZ6!n5a^!s45vsxX4N(8vBH!Qaq-G z&KXLfQ$I(?e1npqdxz4cAEGC}Kn!k&WDEZT-JPBXJ$Lup4z&Bi%Zii^)vzxMddBWC z!(bakjIrwU(Zje^bbn_$F9+kw{9n^5TdO$@ovqw`&8!vOp+Nuw5P$##AOHafKmY;| zfWYk&IBQpyY}+>8zbWLwNg68EKOJ{fHxxV)6!A?@(DFF8OisO)^{DGdq9a1`gNXc> zp0`T%+CcVGih1a6@%hA1m)tK#`G2yB%w>`lqlJZ4lDy63pg5gXFIU?MyU%&JN84hL zoUGTXx6WP}OLntqe5j2NvXiR(B%Sn?`J+sN*E&lgi}XkhN3*TW3A`&exi6DM^;J(6 znHtb$5O{+7i*{Vb+%4g5le6H%u20VTDm`uKla+UKed$Mo00bZa0SG_<0uX=z1Rwwb z2teQ#3zYYN(;6`AoAulJZhf@A>K8N!KmY;|fB*y_009U<00Izz00eFz@ZkL7$CnM0 z*-fJnxKSX2cDw5e^P!G^B9rM~3>rQU{WzW`9_hsA++%6p_;1!-b?EqIdzvFs-FA(O4@kM8`Br&~{3VNSEpbyo`(9 zLD01q@ET593l^#icb0!3Z-)2CWZt(M$ico7#UWj&ZcE0r$>y11uq`6SSo-VH(_o}@ zocUTOlksi+(=yH0vQ}PKQ*$TGT+smo0uX=z1Rwwb2tWV=5P$##rcdC$oSH2Z3dX}# zEYGh)U#Zs3Af#Te$PtPxJXBoCsH1b}hT=B}~sx2}}`h9(v Yc6nozUexJVmSOrIhJ1rNyfP|$0>RIelmGw# literal 0 HcmV?d00001 diff --git a/faha.db b/faha.db new file mode 100644 index 0000000000000000000000000000000000000000..dd0d6ea9b6a6e79cfbdabbd69b60d336e150013b GIT binary patch literal 12288 zcmeI%K}y3w6b9f)D@qGmHxjyg6qFQ16ffX3j2et-jaBJF%9ut8+D>RA(q$D~dj(J7 z1w4XVS9%a9QNcoW;Y#FxkT=6TGMV@7hV1XTQ4-Rr>UU*A>ujDG2HPNFjO9NbJ!Fy7 zdFo@H4#t=HchfvuDOj_*nwvXjr6rvZ5P$##AOHafKmY;|fB*y_@c#rxo4Fa&G>z-? zM4nuPzEa&mmh!eQcvDc5*IYrBY^_38u@H60@tR^w_~g}_6N_F_s+tqG3>p zs4tA>@t{r2f0`!QdRos$tBIvkmRpS)3IY&-00bZa0SG_<0uX=z1m;hmUrj6)3I*-q zDwOBfzN1v@X3&y`Be*Nb;2%a%_^+%b0f z^g=h<@+|Ciep&ToM|wfno4K*_yxWd!hd1Nh<9};7wLR{fP+gpm9yH6Da{pLcEEJ2{ zV|s9rhOau;{;(&euQCk(bQe#C{-x^n#z&bFxQh>YCOuEJR8xk5YE#9wO~I{MCyp~? zR~U8DXM9+*NZ(ka&2n_J_-!6N`cV*o00bZa0SG_<0uX=z1Rwwb2+XlS{Qgho-dXN5 z_Z1B&2tWV=5P$##AOHafKmY;|fB*#km%#Gt$J@(&imep2tZlfqU9Hv(k&5G|{4ln- QV@<@*jbVJmO+Jdh0s7LDWB>pF literal 0 HcmV?d00001 diff --git a/lazy.db b/lazy.db new file mode 100644 index 0000000000000000000000000000000000000000..57a17871579d2ed118852ce36974905973f254f7 GIT binary patch literal 12288 zcmeI#!Aj#m7zgl4l}Za5_pp@SK0HVYvM77mSzQl{%%<5TtnHMVReDsx zo8Vr20-wQ)H$e{`6nqQMzJQaKfThL59z2x)KqkXK$(Q+lw^?6v;v}M9s?(GSePpxD zFxY1z#@M93CiIn!oL;0^HjHfX%6*c3C|J|_h1|>!X3pyg0|F3$00bZa0SG_<0uX=z z1jbL`pqiU1l}g6ppG5xLiF~D+yS-_`_5}|F1$@~NG}p`K$SM}%2G!g^d=WmmUO?_Q z$626ap(UFUZE)XS;e!u4y5x4!ZNKs~lx-QtNq1yn6^4J?vX$&+)ziP#{n}UVZ_%pQ zA}elGij{*+W2#gx8%Kp+BlSqNccT8B8*HT?{#P%dOrqba)6KRrAh4fqa$AO>YO01z zV%4H$&vOKKN9{Px>=j|Jk~QMPnoHK=0xeZ^XX)8oANnyM009U<00Izz00bZa0SG_< z0uUHuf%N>JH}{x%VxF6O=7afYUXF3QXbl1ofB*y_009U<00Izz00bcLh63+SFP?6` z=h^$RG40ub=T)mUTjbOD%Ie21_uUuq^ Date: Thu, 20 Apr 2017 22:50:36 +0300 Subject: [PATCH 26/52] [chore] Remove commented code --- views.py | 101 ++++++++++++++----------------------------------------- 1 file changed, 26 insertions(+), 75 deletions(-) diff --git a/views.py b/views.py index 4119497..0440df8 100644 --- a/views.py +++ b/views.py @@ -177,54 +177,33 @@ def get_person_room(self, person_id, room_type): return "Person not allocated to room" def reallocate_person(self, person_id, new_room_name): - """ moves person from one room to another room""" - person_object = self.get_person(person_id) - if person_object == "Invalid person id": - # prints id does not exist - print(person_object) - return person_object - elif person_object == "There are no people in the system.": - print("There are no people in the system. Add person(s) first, then reallocate") - return person_object - else: - new_room_object = self.get_room(new_room_name) - if new_room_object == "Room name does not exist": - return "Room name does not exist" - elif new_room_object == "There are no rooms available": - return "There are no rooms available" - # else: - # if new_room_object.room_type == "LIVING_SPACE": - - # current_room = - + full_name = first_name.upper() + " " + last_name.upper() + fellows = [person.full_name for person in self.all_people if person.category == "FELLOW"] + staff = [person.full_name for person in self.all_people if person.category == "STAFF"] + available_living_spaces = ([room.room_name for room in self.all_rooms if room.room_type == "LIVING_SPACE" and len(self.living_space_allocations[room.room_name]) < LivingSpace.room_capacity]) + available_offices = [room.room_name for room in self.all_rooms + if room.room_type == "OFFICE" + and len(self.office_allocations[room.room_name]) < Office.room_capacity] + if full_name not in fellows and full_name not in staff: + print("Sorry, the person doesn't exist.") - # full_name = first_name.upper() + " " + last_name.upper() - # fellows = [person.full_name for person in self.all_people if person.category == "FELLOW"] - # staff = [person.full_name for person in self.all_people if person.category == "STAFF"] - # available_living_spaces = ([room.room_name for room in self.all_rooms if room.room_type == "LIVING_SPACE" and len(self.living_space_allocations[room.room_name]) < LivingSpace.room_capacity]) - # available_offices = [room.room_name for room in self.all_rooms - # if room.room_type == "OFFICE" - # and len(self.office_allocations[room.room_name]) < Office.room_capacity] - # if full_name not in fellows and full_name not in staff: - # print("Sorry, the person doesn't exist.") - - # elif new_room.upper() not in available_living_spaces and new_room.upper() not in available_offices: - # print("The room requested does not exist or is not available") - # print("Available office \n", available_offices) - # print("Available living space \n", available_living_spaces) - # else: - # if room_type.upper() == "L": - # if new_room in available_offices and new_room not in available_living_spaces: - # print("The room selected is not a living space") - # elif full_name not in fellows: - # return "The person has to exist and be a fellow!" - # else: - # for room in self.living_space_allocations.keys(): - # if full_name in self.living_space_allocations[room]: - # lspace = self.living_space_allocations[room] - # lspace.remove(full_name) - # self.office_allocations[new_room.upper()].append(full_name) - # print("successfully reallocated") + elif new_room.upper() not in available_living_spaces and new_room.upper() not in available_offices: + print("The room requested does not exist or is not available") + print("Available office \n", available_offices) + print("Available living space \n", available_living_spaces) + else: + if room_type.upper() == "L": + if new_room in available_offices and new_room not in available_living_spaces: + print("The room selected is not a living space") + elif full_name not in fellows: + return "The person has to exist and be a fellow!" + else: + for room in self.living_space_allocations.keys(): + if full_name in self.living_space_allocations[room]: + lspace = self.living_space_allocations[room] + lspace.remove(full_name) + self.office_allocations[new_room.upper()].append(full_name) + print("successfully reallocated") def load_people(self, filename): """loads people from a txt file to the app""" @@ -344,33 +323,5 @@ def save_state(self, db_name): self.session.add_all(people) self.session.commit() -space = Amity() -# # space.create_room('O', ["MyRoom"]) -# space.create_room('O', ['VaLhAla']) -# space.create_room('O', ['valhala']) -# space.create_room('L', ['Ruby','Narnia']) - -# space.add_person('faith', 'dede', 'F', 'Y') - - -# space.reallocate_person('faith', 'dede', 'L', 'valhala') -# print(Amity.living_spaces) -# print(Amity.office_spaces) -# print(space.reallocate_person('faith', 'dede', 'L', 'valhala')) -# print(Amity.living_spaces) -# print(Amity.all_rooms) -# space = Amity() -# space.add_person('faith', 'dede', 'F', 'Y') - -# ******************* - -# space.load_people("people.txt") -space.save_state("faha") -# space.print_allocations() -# space.print_unallocated() -# space.print_room('elda') - -# ******************* -# print(Amity.living_spaces) From 5088d4f06f5bd3a684fd7a9118a2615a156823a5 Mon Sep 17 00:00:00 2001 From: faithngetich Date: Thu, 20 Apr 2017 22:59:33 +0300 Subject: [PATCH 27/52] [chore] Ignore and delete all db files --- .gitignore | 1 + Olex.db | Bin 12288 -> 0 bytes amity.db | Bin 12288 -> 0 bytes amon.db | Bin 12288 -> 0 bytes amon.db.db | Bin 12288 -> 0 bytes amos.db | Bin 12288 -> 0 bytes dbname.sqlite | 0 fa.db | Bin 12288 -> 0 bytes fadedbfdb.db | Bin 12288 -> 0 bytes fadede.db | Bin 12288 -> 0 bytes faha.db | Bin 12288 -> 0 bytes faith.db | Bin 12288 -> 0 bytes lazy.db | Bin 12288 -> 0 bytes models/amity.db | Bin 12288 -> 0 bytes 14 files changed, 1 insertion(+) delete mode 100644 Olex.db delete mode 100644 amity.db delete mode 100644 amon.db delete mode 100644 amon.db.db delete mode 100644 amos.db delete mode 100644 dbname.sqlite delete mode 100644 fa.db delete mode 100644 fadedbfdb.db delete mode 100644 fadede.db delete mode 100644 faha.db delete mode 100644 faith.db delete mode 100644 lazy.db delete mode 100644 models/amity.db diff --git a/.gitignore b/.gitignore index c99a8d8..82f8525 100644 --- a/.gitignore +++ b/.gitignore @@ -99,6 +99,7 @@ __pycache__/ # C extensions *.so +*.db # Distribution / packaging .Python diff --git a/Olex.db b/Olex.db deleted file mode 100644 index 5185ff2a38d374761dc98265394b5673853e70df..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 12288 zcmeI#&ubGw6bJCxq-;qbZUtpoygUlZ28t;D18$c|vvl3WZH)9FVY*p$G1&>}v?buB z`VSQRFZ?^alpgDki{Q<_!`UR22BHVSOZX1#%<$gs+j*bc>^%)LmC{Q&9tuT|*akBU z_Lztv$?d`$}IR#y(B`VujF`gb(95xlj4v)ktA{``$AX??WbTB-G6h1*4I5P$##AOHafKmY;|fB*y_0D=D}aP#cq^81F# zZaYRzCQ7y%jlkz-5&lfGa4yFAweXMjEPN~mVjgzRE1f3 diff --git a/amity.db b/amity.db deleted file mode 100644 index 636ea97259ecb188100ae8b770f61965cc9a35bb..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 12288 zcmeI&&uY{_90%}8w(F9$?QDe-f|nmXB~V211x%M<*QVJTSD^=y>1Kj~WT$Mh7LV(x z&(K#8d;-rs_U^?uD87P|O&7XF@gRbS@4)=|{bnX)KDP{c^)k#VNvWC^qN1m)#|(o# zBVvrL>)O(FSxh}xTL!u}ZjFC8TxX9gcSFybn_n28>IMY@5P$##AOHafKmY;|fB*y_ z@JE5UZ+2|QF+RPm#7QoXq&i);t$rN%qku;KUKr3$Gqpo**UAzaM5Ew&5K}Z9QS>?t zcd2VlL?P*oANTkDxQ?rjrz`Q9m{jFEF&?WzC8EmIg!YERFz};#^-(-H^y6bX2#(3k z60gqn_k;ccxxd&rh{%1sOHVwn>&@>Q9ox2z`D}59SgE31H0J6F7P-GUKp~40IW2FW z@$Or9z53g{#V;AZ=HGOO0s#m>00Izz00bZa0SG_<0uX?}e=D%nYBR^#P-&WtWhADP zOgu1k>fuf5gUH{DTx=Q5vhggRmCfS%`@h4_8UMk*^DF+9f94lDM1cSVAOHafKmY;| zfB*y_009U<;2#L|I&Ee<)(ibpLYc}uS7-d5&e%<+tVEjf_MJp;ZLud3NhX>-oBAGL a+qV2dmCY7?39#*0iA?0pL-h^7O5!Kqc%J6~ diff --git a/amon.db b/amon.db deleted file mode 100644 index b81b43833fa0e8927f916876d8acfe4da5fbd9f7..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 12288 zcmeI#&r8EF6bJCM6GjLAxRu==J4gpZ6#oIc65UwsX06H&GGbSyxGrUj$d1#0+;p?x zV0!R4zJa943w_P|^px8hKUE1m%ULEAowFlm80>QqYemxbyuM)vT$=61sOouj6iR%yi0;TI7H1#v&JS zsuo)l%Q$|^#Z=A9?8VmxVfWe%ht%Uka?)|L)?7XqRl8m{KCM+DgGA<&WIdXjrL2Sh zswEaGd6Bb4d6W%-_u`Nv5yvuQqYemxbyuM)vT$=61sOouj6iR%yi0;TI7H1#v&JS zsuo)l%Q$|^#Z=A9?8VmxVfWe%ht%Uka?)|L)?7XqRl8m{KCM+DgGA<&WIdXjrL2Sh zswEaGd6Bb4d6W%-_u`Nv5yvuoU54>^S|$O*aQl zrU#Gn8%Ubuk?`{A>D}E1nNI0h6}i-O!A_WEu}dPxm~DE+^i3<*2b+cYT3_ZrO>K7O zc!wrx9~JEQ)C_14fB*y_009U<00Izz00bcLPXv~2yXv~G^~SY)nxv6Z`Fu50{7CRv zP|Q1lpvG#iL0-+t#?%dCaU~)O`!R+0LC~U_GnIKt4?Oa(`F5Z%SB~^z_DeL8Gnr(1 zvGd|V)V<-+ka}WBUN&yln#)J4>elPlyR*u9kgC}vU61y5*6YnbrJYEfzNlic^G&aE zs^=q_Bq~>9sWUaDPQM=r9+ni}GcNc1YvK3E+i|cPl6T&scGJA9tj$f)j|Kqr{@>%Di>E;V0uX=z1Rwwb2tWV=5P$##J_SAi^b~h} diff --git a/dbname.sqlite b/dbname.sqlite deleted file mode 100644 index e69de29..0000000 diff --git a/fa.db b/fa.db deleted file mode 100644 index 7d752ad3ea8258a70784284204ffb8a049f1ffdb..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 12288 zcmeI&F-yZh6bJB2E7cZi6p_;H;UFo9C@zkk;aZC^(O4@EB4-*UXnUnbq@y}H`Z)xh z{T6-;zk#!t)`ErV;AZ(BJ=quH{>V>rJ3tkgcBoQo1Rwwb2tWV=5P$##AOHafKwyjolKX$!d}ZdF z`D(t8aieGr0uX=z1Rwwb2tWV=5P$##An+drW*;9uo@X*_zG&pVO1a{d%T-%slJwJ5 ZKkf4RAU&tkFY6hm|6$12xx*`i!Y7s7li&aV diff --git a/fadedbfdb.db b/fadedbfdb.db deleted file mode 100644 index f4d4811dfb4f44ee364d73a14f9c56a0a3d46ae1..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 12288 zcmeI&J!{)Q7zgl^T@-9^)mMb+@{l3O5JF17KrZ6!n5a^!s45vsxX4N(8vBH!Qaq-G z&KXLfQ$I(?e1npqdxz4cAEGC}Kn!k&WDEZT-JPBXJ$Lup4z&Bi%Zii^)vzxMddBWC z!(bakjIrwU(Zje^bbn_$F9+kw{9n^5TdO$@ovqw`&8!vOp+Nuw5P$##AOHafKmY;| zfWYk&IBQpyY}+>8zbWLwNg68EKOJ{fHxxV)6!A?@(DFF8OisO)^{DGdq9a1`gNXc> zp0`T%+CcVGih1a6@%hA1m)tK#`G2yB%w>`lqlJZ4lDy63pg5gXFIU?MyU%&JN84hL zoUGTXx6WP}OLntqe5j2NvXiR(B%Sn?`J+sN*E&lgi}XkhN3*TW3A`&exi6DM^;J(6 znHtb$5O{+7i*{Vb+%4g5le6H%u20VTDm`uKla+UKed$Mo00bZa0SG_<0uX=z1Rwwb z2teQ#3zYYN(;6`AoAulJZhf@A>K8N!KmY;|fB*y_009U<00Izz00eFz@ZkL7$CnM0 z*-fJnxKSX2cDw5e^P!G^B9rM~3>rQU{WzW`9_hsA++%6p_;1!-b?EqIdzvFs-FA(O4@kM8`Br&~{3VNSEpbyo`(9 zLD01q@ET593l^#icb0!3Z-)2CWZt(M$ico7#UWj&ZcE0r$>y11uq`6SSo-VH(_o}@ zocUTOlksi+(=yH0vQ}PKQ*$TGT+smo0uX=z1Rwwb2tWV=5P$##rcdC$oSH2Z3dX}# zEYGh)U#Zs3Af#Te$PtPxJXBoCsH1b}hT=B}~sx2}}`h9(v Yc6nozUexJVmSOrIhJ1rNyfP|$0>RIelmGw# diff --git a/faha.db b/faha.db deleted file mode 100644 index dd0d6ea9b6a6e79cfbdabbd69b60d336e150013b..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 12288 zcmeI%K}y3w6b9f)D@qGmHxjyg6qFQ16ffX3j2et-jaBJF%9ut8+D>RA(q$D~dj(J7 z1w4XVS9%a9QNcoW;Y#FxkT=6TGMV@7hV1XTQ4-Rr>UU*A>ujDG2HPNFjO9NbJ!Fy7 zdFo@H4#t=HchfvuDOj_*nwvXjr6rvZ5P$##AOHafKmY;|fB*y_@c#rxo4Fa&G>z-? zM4nuPzEa&mmh!eQcvDc5*IYrBY^_38u@H60@tR^w_~g}_6N_F_s+tqG3>p zs4tA>@t{r2f0`!QdRos$tBIvkmRpS)3IY&-00bZa0SG_<0uX=z1m;hmUrj6)3I*-q zDwOBfzN1v@X3&y`Be*Nb;2%a%_^+%b0f z^g=h<@+|Ciep&ToM|wfno4K*_yxWd!hd1Nh<9};7wLR{fP+gpm9yH6Da{pLcEEJ2{ zV|s9rhOau;{;(&euQCk(bQe#C{-x^n#z&bFxQh>YCOuEJR8xk5YE#9wO~I{MCyp~? zR~U8DXM9+*NZ(ka&2n_J_-!6N`cV*o00bZa0SG_<0uX=z1Rwwb2+XlS{Qgho-dXN5 z_Z1B&2tWV=5P$##AOHafKmY;|fB*#km%#Gt$J@(&imep2tZlfqU9Hv(k&5G|{4ln- QV@<@*jbVJmO+Jdh0s7LDWB>pF diff --git a/lazy.db b/lazy.db deleted file mode 100644 index 57a17871579d2ed118852ce36974905973f254f7..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 12288 zcmeI#!Aj#m7zgl4l}Za5_pp@SK0HVYvM77mSzQl{%%<5TtnHMVReDsx zo8Vr20-wQ)H$e{`6nqQMzJQaKfThL59z2x)KqkXK$(Q+lw^?6v;v}M9s?(GSePpxD zFxY1z#@M93CiIn!oL;0^HjHfX%6*c3C|J|_h1|>!X3pyg0|F3$00bZa0SG_<0uX=z z1jbL`pqiU1l}g6ppG5xLiF~D+yS-_`_5}|F1$@~NG}p`K$SM}%2G!g^d=WmmUO?_Q z$626ap(UFUZE)XS;e!u4y5x4!ZNKs~lx-QtNq1yn6^4J?vX$&+)ziP#{n}UVZ_%pQ zA}elGij{*+W2#gx8%Kp+BlSqNccT8B8*HT?{#P%dOrqba)6KRrAh4fqa$AO>YO01z zV%4H$&vOKKN9{Px>=j|Jk~QMPnoHK=0xeZ^XX)8oANnyM009U<00Izz00bZa0SG_< z0uUHuf%N>JH}{x%VxF6O=7afYUXF3QXbl1ofB*y_009U<00Izz00bcLh63+SFP?6` z=h^$RG40ub=T)mUTjbOD%Ie21_uUuq^S5C`y0DwIb2xP{(^o)Rdc_yTUjVnbt6*C_NLlC}{7rdyJTc#IF^GnzyL zttcM6mH)y{c6K+A`Q*IrV@^r*5lD(IXYGfiU`M2s=Lnw@I4qt5r*q))0- zJLy>m)v12?&W^GwU_bx@5P$##AOHafKmY;|fB*#k6ezjgHT!+-?Y@ZSPw_NX>o#^A zDR?L-&d)hGg_sQ5w@7m(G~WIxk+=Tlq`0D)NVD zu~4a6Mn$4lGztPwaKFAimF^XnGn$AQS;^9__nfhCCS?8aqU)1&I;1n(Htcd=>zbyi zmCsELQmHg=g1%irv-h6@(m0*RS-x50_pdhWx;L+yehdge00Izz00bZa0SG_<0uX=z j1a?>e{r?XCT$Ba@2tWV=5P$##AOHafKmY;|_!9U4egS4N From 47488ea8252c74f7a14963562c0c2f2e0afff776 Mon Sep 17 00:00:00 2001 From: faithngetich Date: Fri, 21 Apr 2017 10:03:24 +0300 Subject: [PATCH 28/52] [chore] Refactor docopt file --- app.py | 46 ++++++++-------- views.py | 156 +++++++++++++++++++++++++++++++++++++++---------------- 2 files changed, 132 insertions(+), 70 deletions(-) diff --git a/app.py b/app.py index 57b9e07..06b0d3f 100644 --- a/app.py +++ b/app.py @@ -2,7 +2,7 @@ """ Usage: amity create_room ( )... - amity add_person (Fellow | Staff) [--wants_accomodation=(Y | N)] + amity add_person (F | S) [--wants_accomodation=value] amity print_allocations [-output=] amity reallocate_person amity print_room @@ -81,34 +81,26 @@ def do_create_room(self, args): @docopt_cmd def do_add_person(self, args): """ - Usage: - add_person (fellow | staff) [--wants_accomodation=] - Options: - -a, --wants_accomodation= Wants accomodation [default: N] + Usage: add_person (F | S) [--wants_accomodation=value] """ + if args["F"]: + category = "F" + else: + category = "S" first_name = args[""] last_name = args[""] - if args["fellow"]: - role = "FELLOW" - else: - role = "STAFF" - accomodate = args["--wants_accomodation"].upper() - if accomodate == 'Y' or accomodate == 'N': - amity.add_person(first_name, last_name, role, accomodate) - else: - cprint("Invalid accomodation option. Please enter Y/N", 'red') - - + amity.add_person(first_name, last_name, category, args["--wants_accomodation"]) + @docopt_cmd def do_reallocate_person(self, args): - """Usage: reallocate_person """ - - first_name = args[""] - last_name = args[""] - room_name = args[""] - person_name = first_name + " " + last_name + """Usage: reallocate_person """ + if args[""].isalpha(): + print("person id cannot be string") + return + else: + (amity.reallocate_person(int(args['']), + args[''])) - amity.reallocate_person(person_name, room_name) @docopt_cmd def do_print_allocations(self, args): @@ -117,10 +109,16 @@ def do_print_allocations(self, args): Options: -o, --output= Save allocations to file """ - filename = args["--output"] amity.print_allocations(filename) + def do_load_state(self, arg): + """ + Loads data from the specified db into the app. + Usage: load_state + """ + self.amity.load_state(arg[""]) + @docopt_cmd def do_print_room(self, args): """Usage: print_room """ diff --git a/views.py b/views.py index 0440df8..ecfd114 100644 --- a/views.py +++ b/views.py @@ -6,13 +6,18 @@ from models.persons import Fellow, Staff from models.model import (Base, Room, Person, DatabaseCreator) from models.model import Base +from colorama import init +init(autoreset=True) +from termcolor import colored +from colorama import Fore, Back, Style + class Amity(object): all_staff = [] all_fellows = [] all_rooms = [] - office_allocations = {'None':[]} - living_space_allocations = {'None':[]} + office_allocations = {} + living_space_allocations = {} all_people = [] living_spaces_waiting_list = [] office_spaces_waiting_list = [] @@ -27,12 +32,12 @@ def create_room(self, room_type, list_of_rooms): office = Office(name) self.all_rooms.append(office) self.office_allocations[office] = [] - print("Office {} successfully created.".format(office.room_name)) + print(Fore.GREEN + "Office {} successfully created.".format(office.room_name.upper())) elif room_type.upper() == 'L': living_space = LivingSpace(name) self.all_rooms.append(living_space) self.living_space_allocations[living_space] = [] - print("Living space {} successfully created.".format(living_space.room_name)) + print(Fore.GREEN + "Living space {} successfully created.".format(living_space.room_name.upper())) def generate_random_office_spaces(self): """Generates random office""" @@ -67,12 +72,15 @@ def add_person(self, first_name, last_name, category, wants_accomodation='N'): if category is "F": # create fellow object and adds them to fellow list fellow = Fellow(first_name, last_name) - Amity.all_fellows.append(fellow) + self.all_people.append(fellow) + self.all_fellows.append(fellow) allocated_office = self.generate_random_office_spaces() + print(fellow.person_id) if allocated_office: # if random room selected Amity.office_allocations[allocated_office].append(fellow) - print("You have allocated {} successfully ".format(fellow.first_name)) + + print(Fore.GREEN +"You have allocated {} successfully to {}".format(fellow.first_name,allocated_office.room_name)) else: Amity.office_spaces_waiting_list.append(fellow) print("Sorry, no space available {} has been added to the waiting list".format(fellow.first_name)) @@ -80,6 +88,7 @@ def add_person(self, first_name, last_name, category, wants_accomodation='N'): # create staff object and adds them to list staff = Staff(first_name, last_name) Amity.all_staff.append(staff) + Amity.all_people.append(staff) allocated_office = self.generate_random_office_spaces() if allocated_office: # if random room selected @@ -87,21 +96,22 @@ def add_person(self, first_name, last_name, category, wants_accomodation='N'): print("You have allocated {} successfully ".format(staff.first_name)) else: Amity.office_spaces_waiting_list.append(staff) - print("Sorry, no space available {} has been added to the waiting list".format(staff.first_name)) + print(Fore.RED+"Sorry, no space available {} has been added to the waiting list".format(staff.first_name)) else: # if wants accomodation if category is "F": # create fellow object fellow = Fellow(first_name, last_name) + Amity.all_people.append(fellow) Amity.all_fellows.append(fellow) allocated_office = self.generate_random_office_spaces() if allocated_office: # if random room selected Amity.office_allocations[allocated_office].append(fellow) - print("You have allocated {} successfully ".format(fellow.first_name)) + print("You have allocated {} successfully to {}".format(fellow.first_name,office_allocations.room_name)) else: Amity.office_spaces_waiting_list.append(fellow) - print("Sorry, no space available {} has been added to the waiting list".format(fellow.first_name)) + print(Fore.RED+"Sorry, no space available {} has been added to the waiting list".format(fellow.first_name)) # add living space allocated_living_space = self.generate_random_living_spaces() @@ -110,9 +120,10 @@ def add_person(self, first_name, last_name, category, wants_accomodation='N'): print("You have allocated {} successfully to living space {} ".format(fellow.first_name, allocated_living_space.room_name)) else: Amity.living_spaces_waiting_list.append(fellow) - print("Sorry, no space available {} has been added to the waiting list".format(fellow.first_name)) + print(Fore.RED+"Sorry, no space available {} has been added to the waiting list".format(fellow.first_name)) else: staff = Staff(first_name, last_name) + Amity.all_people.append(staff) Amity.all_staff.append(staff) allocated_office = self.generate_random_office_spaces() if allocated_office: @@ -122,10 +133,10 @@ def add_person(self, first_name, last_name, category, wants_accomodation='N'): # reject adding staff to living space else: Amity.office_spaces_waiting_list.append(staff) - print("Sorry, no space available {} has been added to the waiting list".format(staff.first_name)) + print(Fore.RED+"Sorry, no space available {} has been added to the waiting list".format(staff.first_name)) - print("Staff not entitled to living space") + print(Fore.RED+ "Staff not entitled to living space") def get_person(self, person_id): """To return person object given person id.""" @@ -159,7 +170,7 @@ def get_room(self, room_name): return "There are no rooms available" def get_person_room(self, person_id, room_type): - """To return currently allocated room.""" + """To return currently allocated room given a valid person id""" result = None if room_type is "O": for room in list(self.office_allocations.keys()): @@ -175,36 +186,46 @@ def get_person_room(self, person_id, room_type): return result else: return "Person not allocated to room" + def reallocate_person(self, person_id, new_room_name): - full_name = first_name.upper() + " " + last_name.upper() - fellows = [person.full_name for person in self.all_people if person.category == "FELLOW"] - staff = [person.full_name for person in self.all_people if person.category == "STAFF"] - available_living_spaces = ([room.room_name for room in self.all_rooms if room.room_type == "LIVING_SPACE" and len(self.living_space_allocations[room.room_name]) < LivingSpace.room_capacity]) - available_offices = [room.room_name for room in self.all_rooms - if room.room_type == "OFFICE" - and len(self.office_allocations[room.room_name]) < Office.room_capacity] - if full_name not in fellows and full_name not in staff: - print("Sorry, the person doesn't exist.") - - elif new_room.upper() not in available_living_spaces and new_room.upper() not in available_offices: - print("The room requested does not exist or is not available") - print("Available office \n", available_offices) - print("Available living space \n", available_living_spaces) + """ moves person from one room to another room""" + # gets person object from person id + person_object = self.get_person(person_id) + if person_object == "Invalid person id": + # prints id does not exist + print(person_object) + return person_object + elif person_object == "There are no people in the system.": + print("There are no people in the system. Add person(s) first, then reallocate") + return person_object else: - if room_type.upper() == "L": - if new_room in available_offices and new_room not in available_living_spaces: - print("The room selected is not a living space") - elif full_name not in fellows: - return "The person has to exist and be a fellow!" - else: - for room in self.living_space_allocations.keys(): - if full_name in self.living_space_allocations[room]: - lspace = self.living_space_allocations[room] - lspace.remove(full_name) - self.office_allocations[new_room.upper()].append(full_name) - print("successfully reallocated") - + new_room_object = self.get_room(new_room_name) + if new_room_object == "Room name does not exist": + return "Room name does not exist" + elif new_room_object == "There are no rooms available": + return "There are no rooms available" + else: + if type(person_object) == Staff and type(new_room_object) == LivingSpace: + cprint("Cannot reallocate staff to living space.", "red") + return "Cannot reallocate staff to living space." + elif type(new_room_object) == Office: + current_room = self.get_person_room(person_id, "O") + if current_room == "Person not allocated to room": + # if person has no office + cprint("{} has no current office space,hence cannot reallocate".format(person_object.first_name)) + return "person has no current office space, hence canot reallocate" + elif current_room == new_room_object: + print("Cannot reallocate a person to the same room.") + return "Cannot reallocate to same room." + else: + # remove from current office + (self.office_allocations[current_room].remove(person_object)) + # append to new room + (self.office_allocations[new_room_object].append(person_object)) + print("{} {} has been reallocated from office {} to {}".format(person_object.first_name,person_object.last_name, current_room.room_name,new_room_object.room_name)) + return "Has been reallocated from office" + def load_people(self, filename): """loads people from a txt file to the app""" with open (filename, 'r') as people_file: @@ -283,12 +304,22 @@ def print_room(room_name): elif room_name.upper() in living_spaces: for person in Amity.living_space_allocations[room_name.upper()]: print(person) - @staticmethod - def load_state(dbname=None): + + def load_state(self, dbname): # connect to the db provided + self.save_state() # query all rooms and people - # save them to the current Amity instance. - pass + self.session = SessionMaker() + people = session.query(Person).all() + rooms = session.query(Room).all() + # save them to the current Amity instance + for room in Amity.all_rooms: + Amity.all_rooms.append(room) + for person in Amity.all_people: + Amity.all_people.append(people) + print(Fore.GREEN + "Data from {} loaded to the app.".format(dbname)) + + def save_state(self, db_name): # create a db called db_name @@ -306,8 +337,6 @@ def save_state(self, db_name): rooms = [] for room in self.all_rooms: current_occupants = '' - print('There are {}'.format(room.members)) - for member in room.members: current_occupants += member.full_name new_room = Room(id=room.room_id, name=room.room_name.upper(), room_type=room.room_type, room_capacity=room.room_capacity, occupants=current_occupants) @@ -323,5 +352,40 @@ def save_state(self, db_name): self.session.add_all(people) self.session.commit() +space = Amity() +# # space.create_room('O', ["MyRoom"]) +# space.create_room('O', ['VaLhAla']) +# space.create_room('O', ['valhala']) +space.create_room('L', ['Ruby','Narnia', 'valhala']) + + +space.add_person('faith', 'dede', 'F', 'Y') +space.add_person('fai', 'den', 'S', 'Y') +space.add_person('fauz', 'mini', 'F', 'N') +space.add_person('fAm', 'de', 'F', 'Y') + + +space.reallocate_person('faith dede','valhala') +space.reallocate_person('faith dede', 'valhala') +space.reallocate_person('fauz mini', 'Ruby') +space.reallocate_person('fAm dede','valhala') +# print(Amity.living_spaces) +# print(Amity.office_spaces) +# print(space.reallocate_person('faith', 'dede', 'L', 'valhala')) +# print(Amity.living_spaces) +# print(Amity.all_rooms) +# space = Amity() +# space.add_person('faith', 'dede', 'F', 'Y') + +# ******************* + +# space.load_people("people.txt") +# space.save_state("faa") +# space.print_allocations() +# space.print_unallocated() +# space.print_room('elda') + +# ******************* +# print(Amity.living_spaces) From df0a0a2eba8e81534b2d09fdcc78bb83f9fc180b Mon Sep 17 00:00:00 2001 From: faithngetich Date: Fri, 21 Apr 2017 10:07:31 +0300 Subject: [PATCH 29/52] [chore] Remove unused code --- app.py | 4 ---- views.py | 36 ------------------------------------ 2 files changed, 40 deletions(-) diff --git a/app.py b/app.py index 06b0d3f..10469fb 100644 --- a/app.py +++ b/app.py @@ -67,10 +67,6 @@ class AmitySystem(cmd.Cmd): def do_create_room(self, args): """Usage: create_room (O|L) ...""" - # rooms = args[""] - # types = args[""] - # for room in rooms: - # r_type = types[rooms.index(room)] if args["O"]: room_type = "O" else: diff --git a/views.py b/views.py index ecfd114..23b77b1 100644 --- a/views.py +++ b/views.py @@ -352,40 +352,4 @@ def save_state(self, db_name): self.session.add_all(people) self.session.commit() -space = Amity() -# # space.create_room('O', ["MyRoom"]) -# space.create_room('O', ['VaLhAla']) -# space.create_room('O', ['valhala']) -space.create_room('L', ['Ruby','Narnia', 'valhala']) - - -space.add_person('faith', 'dede', 'F', 'Y') -space.add_person('fai', 'den', 'S', 'Y') -space.add_person('fauz', 'mini', 'F', 'N') -space.add_person('fAm', 'de', 'F', 'Y') - - -space.reallocate_person('faith dede','valhala') -space.reallocate_person('faith dede', 'valhala') -space.reallocate_person('fauz mini', 'Ruby') -space.reallocate_person('fAm dede','valhala') -# print(Amity.living_spaces) -# print(Amity.office_spaces) -# print(space.reallocate_person('faith', 'dede', 'L', 'valhala')) -# print(Amity.living_spaces) -# print(Amity.all_rooms) -# space = Amity() -# space.add_person('faith', 'dede', 'F', 'Y') - -# ******************* - -# space.load_people("people.txt") -# space.save_state("faa") -# space.print_allocations() -# space.print_unallocated() -# space.print_room('elda') - -# ******************* - -# print(Amity.living_spaces) From 337deb5424444becfd8fc71fcd8368881a0e7e56 Mon Sep 17 00:00:00 2001 From: faithngetich Date: Sat, 22 Apr 2017 01:21:36 +0300 Subject: [PATCH 30/52] [chore] make all the functionality work --- .coveragerc | 4 ++ app.py | 26 +++---- check | 10 --- ingine.txt | 0 models/persons.py | 34 ++++----- models/rooms.py | 13 ++-- non-sense.txt | 24 +++++++ people.txt | 7 ++ tests/context.py | 5 ++ tests/test_amity.py | 28 ++++---- views.py | 170 +++++++++++++++++++++++++++----------------- 11 files changed, 195 insertions(+), 126 deletions(-) create mode 100644 .coveragerc delete mode 100644 check create mode 100644 ingine.txt create mode 100644 non-sense.txt create mode 100644 tests/context.py diff --git a/.coveragerc b/.coveragerc new file mode 100644 index 0000000..cf0f4e0 --- /dev/null +++ b/.coveragerc @@ -0,0 +1,4 @@ +[report] +omit= + *tests/* + */python?.?/* \ No newline at end of file diff --git a/app.py b/app.py index 10469fb..bf80258 100644 --- a/app.py +++ b/app.py @@ -41,6 +41,7 @@ def fn(self, arg): print('Invalid command!') print(e) return + except SystemExit: # The SystemExit exception prints the usage for --help # We do not need to do the print here. @@ -65,15 +66,11 @@ class AmitySystem(cmd.Cmd): @docopt_cmd def do_create_room(self, args): - """Usage: create_room (O|L) ...""" - - if args["O"]: - room_type = "O" - else: - room_type = "L" - - amity.create_room(room_type, args[""]) - + """Usage: create_room ...""" + room_name = args[""] + room_type = args[""] + amity.create_room(args[""],args[""]) + @docopt_cmd def do_add_person(self, args): """ @@ -107,21 +104,26 @@ def do_print_allocations(self, args): """ filename = args["--output"] amity.print_allocations(filename) - + @docopt_cmd def do_load_state(self, arg): """ Loads data from the specified db into the app. Usage: load_state """ self.amity.load_state(arg[""]) - + @docopt_cmd + def do_load_people(self, args): + """Usage: load_state """ + amity.load_people(args[""]) + + @docopt_cmd def do_print_room(self, args): """Usage: print_room """ room_name = args[""] amity.print_room(room_name) - + @docopt_cmd def do_clear(self, arg): """Clears screen""" diff --git a/check b/check deleted file mode 100644 index 6e88872..0000000 --- a/check +++ /dev/null @@ -1,10 +0,0 @@ -1. Check if person is in all_people - 1.a if not, return - 1b. if is, continue - -2. Check roomtype - 2a. If roomtype is living, fetch fellows and living spaces - 2b. If roomtype is office, fetch fellows and staff and offices. - - -3. \ No newline at end of file diff --git a/ingine.txt b/ingine.txt new file mode 100644 index 0000000..e69de29 diff --git a/models/persons.py b/models/persons.py index 093904a..09142ca 100644 --- a/models/persons.py +++ b/models/persons.py @@ -1,38 +1,34 @@ class Person(object): - def __init__(self, first_name, last_name): + def __init__(self, first_name, last_name, wants_accomodation): self.person_id = id(self) self.first_name = first_name self.last_name = last_name - self.wants_accomodation = 'N' + self.wants_accomodation = wants_accomodation + @property def full_name(self): return self.first_name + " " + self.last_name + + def __str__(self): + """To make Staff human readable.""" + return "{} {}".format(self.first_name.upper(), self.last_name.upper()) + + def __repr__(self): + return 'first_name:{}, last_name:{}'.format(self.first_name.upper(),self.last_name.upper()) class Staff(Person): - wants_accomodation = "N" category = "STAFF" - def __init__(self, first_name, last_name): + def __init__(self, first_name, last_name, wants_accomodation): """Override the init method of Person superclass.""" - super(Staff, self).__init__(first_name, last_name) - - def __str__(self): - """To make Staff class human readable.""" - return "{} {}".format(self.first_name, self.last_name) - - def __repr__(self): - return 'first_name:{}, last_name:{}'.format(self.first_name,self.last_name) + super(Staff, self).__init__(first_name, last_name, wants_accomodation) + class Fellow(Person): - wants_accomodation = "N" category = "FELLOW" - def __init__(self, first_name, last_name): + def __init__(self, first_name, last_name, wants_accomodation): """Override the init method of Person superclass.""" - super(Fellow, self).__init__(first_name, last_name) - - def __str__(self): - """To make fellow class human readable.""" - return "{} {}".format(self.first_name, self.last_name) + super(Fellow, self).__init__(first_name, last_name, wants_accomodation) diff --git a/models/rooms.py b/models/rooms.py index e44a0a0..2b2451c 100644 --- a/models/rooms.py +++ b/models/rooms.py @@ -3,6 +3,10 @@ def __init__(self, room_name): self.room_id = id(self) self.room_name = room_name + def __str__(self): + """To make the class human readable.""" + return "{}".format(self.room_name.upper()) + class Office(Room): room_type = "OFFICE" @@ -14,10 +18,6 @@ def __init__(self, room_name): self.members = [] - def __str__(self): - """To make office class human readable.""" - return "{}".format(self.room_name) - class LivingSpace(Room): room_type = "LIVING_SPACE" @@ -29,7 +29,4 @@ def __init__(self, room_name): self.members = [] - def __str__(self): - """To make living space class human readable.""" - return "{}".format(self.room_name) - + diff --git a/non-sense.txt b/non-sense.txt new file mode 100644 index 0000000..ec2ff42 --- /dev/null +++ b/non-sense.txt @@ -0,0 +1,24 @@ + +VALHALA +------------------------------ +NDVKGUNGU KEVGBIN +FSSWNJH DEME +FKFFJH DHHVME + +VALHALMKA +------------------------------ +FAITH DEDE +FATH DEE +FAAADA DEMBGE +FKJNSSJH DEEME + +RUBY +------------------------------ +FAITH DEDE +FSSWNJH DEME +FKFFJH DHHVME +FKJNSSJH DEEME + +NARNIA +------------------------------ +FAAADA DEMBGE diff --git a/people.txt b/people.txt index da60040..6b519a0 100644 --- a/people.txt +++ b/people.txt @@ -2,3 +2,10 @@ JONATHAN NGONDI S O AHMED YUSUB F O EPRAHIM KIMANI F L FAITH DEDE S O +OLUWAFEMI SULE F Y +DOMINIC WALTERS S +SIMON PATTERSON F Y +MARI LAWRENCE F Y +LEIGH RILEY S +TANA LOPEZ F Y +KELLY McGUIRE S diff --git a/tests/context.py b/tests/context.py new file mode 100644 index 0000000..6e0c72b --- /dev/null +++ b/tests/context.py @@ -0,0 +1,5 @@ +import os +import sys +sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))) + +from views import Amity \ No newline at end of file diff --git a/tests/test_amity.py b/tests/test_amity.py index 566e0f9..5b25009 100644 --- a/tests/test_amity.py +++ b/tests/test_amity.py @@ -1,15 +1,17 @@ import unittest -from views import Amity -from models.rooms import Office -from models.rooms import LivingSpace +from .context import Amity +from ..views import Amity +from ..models.rooms import Office +from ..models.rooms import LivingSpace + class Amitytest(unittest.TestCase): def setUp(self): self.amity = Amity() def test_create_room_adds_room_succesfully(self): - self.amity.create_room('O', 'Krypton') - self.assertIn('KRYPTON', self.amity.office_spaces) + self.amity.create_room('O', ['Krypton']) + self.assertIn('KRYPTON', [room.room_name.upper() for room in self.amity.all_rooms]) # def test_add_person_adds_fellow_to_list(self): @@ -24,15 +26,15 @@ def test_create_room_adds_room_succesfully(self): # self.assertEqual((length + 1), new_length) - def test_reallocate_person(self): - length = len(self.amity.all_fellows) - self.amity.add_person('dede', 'F', 'y') - new_length = len(self.amity.all_fellows) - self.assertEqual((length + 1), new_length) + # def test_reallocate_person(self): + # length = len(self.amity.all_fellows) + # self.amity.add_person('dede', 'F', 'y') + # new_length = len(self.amity.all_fellows) + # self.assertEqual((length + 1), new_length) - self.amity.create_room('O', 'valhalla') - self.amity.reallocate_person('dede', 'fat', 'O', 'valhalla') - self.assertIn('DEDE', 'FAT', self.amity.allocated_rooms['VALHALLA']) + # self.amity.create_room('O', 'valhalla') + # self.amity.reallocate_person('dede', 'fat', 'O', 'valhalla') + # self.assertIn('DEDE', 'FAT', self.amity.allocated_rooms['VALHALLA']) diff --git a/views.py b/views.py index 23b77b1..f8778f1 100644 --- a/views.py +++ b/views.py @@ -23,6 +23,7 @@ class Amity(object): office_spaces_waiting_list = [] def create_room(self, room_type, list_of_rooms): + """creates a specified room""" for name in list_of_rooms: if name.upper() in [room.room_name.upper() for room in self.all_rooms]: @@ -31,20 +32,22 @@ def create_room(self, room_type, list_of_rooms): if room_type.upper() == 'O': office = Office(name) self.all_rooms.append(office) - self.office_allocations[office] = [] + self.office_allocations[office.room_name] = [] print(Fore.GREEN + "Office {} successfully created.".format(office.room_name.upper())) elif room_type.upper() == 'L': living_space = LivingSpace(name) self.all_rooms.append(living_space) - self.living_space_allocations[living_space] = [] + self.living_space_allocations[living_space.room_name] = [] print(Fore.GREEN + "Living space {} successfully created.".format(living_space.room_name.upper())) + else: + print("please specify the room_type") def generate_random_office_spaces(self): """Generates random office""" offices = [room for room in self.all_rooms if room.room_type == "OFFICE"] available_offices = [] for office in offices: - if len(self.office_allocations[office]) < 6: + if len(self.office_allocations[office.room_name]) < 6: available_offices.append(office) if available_offices: selected_room = random.choice(available_offices) @@ -57,7 +60,7 @@ def generate_random_living_spaces(self): living_spaces = [room for room in self.all_rooms if room.room_type == "LIVING_SPACE"] available_living_space = [] for living_space in living_spaces: - if len(self.living_space_allocations[living_space]) < 6: + if len(self.living_space_allocations[living_space.room_name]) < 6: available_living_space.append(living_space) if available_living_space: selected_room = random.choice(available_living_space) @@ -68,32 +71,39 @@ def generate_random_living_spaces(self): def add_person(self, first_name, last_name, category, wants_accomodation='N'): """Adds person to self and randomly allocates the person""" # check if category is FELLOW - if wants_accomodation == "N": + # if category is "S" and wants_accomodation is "Y" + + if wants_accomodation == "N" or (category is "S" and wants_accomodation is "Y"): if category is "F": # create fellow object and adds them to fellow list - fellow = Fellow(first_name, last_name) + fellow = Fellow(first_name, last_name, wants_accomodation) self.all_people.append(fellow) self.all_fellows.append(fellow) allocated_office = self.generate_random_office_spaces() print(fellow.person_id) if allocated_office: + allocated_office.members.append(fellow) # if random room selected - Amity.office_allocations[allocated_office].append(fellow) - + Amity.office_allocations[allocated_office.room_name] = allocated_office.members + + # Amity.office_allocations[allocated_office.room_name] = allocated_office.members + print(Fore.GREEN +"You have allocated {} successfully to {}".format(fellow.first_name,allocated_office.room_name)) else: Amity.office_spaces_waiting_list.append(fellow) print("Sorry, no space available {} has been added to the waiting list".format(fellow.first_name)) else: # create staff object and adds them to list - staff = Staff(first_name, last_name) + staff = Staff(first_name, last_name, wants_accomodation) Amity.all_staff.append(staff) Amity.all_people.append(staff) allocated_office = self.generate_random_office_spaces() + print(staff.person_id) if allocated_office: + allocated_office.members.append(staff) # if random room selected - Amity.office_allocations[allocated_office].append(staff) - print("You have allocated {} successfully ".format(staff.first_name)) + Amity.office_allocations[allocated_office.room_name] = allocated_office.members + print(Fore.GREEN+"You have allocated {} successfully ".format(staff.first_name)) else: Amity.office_spaces_waiting_list.append(staff) print(Fore.RED+"Sorry, no space available {} has been added to the waiting list".format(staff.first_name)) @@ -101,14 +111,15 @@ def add_person(self, first_name, last_name, category, wants_accomodation='N'): # if wants accomodation if category is "F": # create fellow object - fellow = Fellow(first_name, last_name) + fellow = Fellow(first_name, last_name, wants_accomodation) Amity.all_people.append(fellow) Amity.all_fellows.append(fellow) allocated_office = self.generate_random_office_spaces() if allocated_office: # if random room selected - Amity.office_allocations[allocated_office].append(fellow) - print("You have allocated {} successfully to {}".format(fellow.first_name,office_allocations.room_name)) + allocated_office.members.append(fellow) + Amity.office_allocations[allocated_office.room_name] = allocated_office.members + print(Fore.GREEN+"You have allocated {} successfully to {}".format(fellow.first_name,allocated_office.room_name)) else: Amity.office_spaces_waiting_list.append(fellow) print(Fore.RED+"Sorry, no space available {} has been added to the waiting list".format(fellow.first_name)) @@ -116,27 +127,13 @@ def add_person(self, first_name, last_name, category, wants_accomodation='N'): # add living space allocated_living_space = self.generate_random_living_spaces() if allocated_living_space: - Amity.living_space_allocations[allocated_living_space].append(fellow) - print("You have allocated {} successfully to living space {} ".format(fellow.first_name, allocated_living_space.room_name)) + allocated_living_space.members.append(fellow) + Amity.living_space_allocations[allocated_living_space.room_name] = allocated_living_space.members + print(Fore.GREEN+"You have allocated {} successfully to living space {} ".format(fellow.first_name, allocated_living_space.room_name)) else: Amity.living_spaces_waiting_list.append(fellow) print(Fore.RED+"Sorry, no space available {} has been added to the waiting list".format(fellow.first_name)) - else: - staff = Staff(first_name, last_name) - Amity.all_people.append(staff) - Amity.all_staff.append(staff) - allocated_office = self.generate_random_office_spaces() - if allocated_office: - # if random room selected - Amity.office_allocations[allocated_office].append(staff) - print("You have allocated {} successfully ".format(staff.first_name)) - # reject adding staff to living space - else: - Amity.office_spaces_waiting_list.append(staff) - print(Fore.RED+"Sorry, no space available {} has been added to the waiting list".format(staff.first_name)) - - - print(Fore.RED+ "Staff not entitled to living space") + def get_person(self, person_id): """To return person object given person id.""" @@ -238,40 +235,37 @@ def load_people(self, filename): @staticmethod def print_allocations(file_name=None): """Prints a list of allocations onto the screen""" - print("=" * 30 + "\n" + "Office Allocations\n" + "=" *30) + print(Fore.MAGENTA + "=" * 30 + "\n" + "Office Allocations\n" + "=" *30) for room in Amity.office_allocations.keys(): if room != "None": - print ("room" + "\n" + "+" * 30) + print (Fore.BLUE + room.upper() + "\n") for person in Amity.office_allocations[room]: print(person) - print("=" * 30 + "\n" + "Living spaces Allocations\n" + "=" *30) + print(Fore.MAGENTA + "=" * 30 + "\n" + "Living spaces Allocations\n" + "=" *30) for room in Amity.living_space_allocations.keys(): if room != "None": - print ("room" + "\n" + "+" * 30) + print (Fore.BLUE +room.upper() + "\n" + "+" * 30) for person in Amity.living_space_allocations[room]: print(person) if file_name: nfile = open(file_name + ".txt", "a") - nfile.write("=" * 30 + "\n" + "Office Allocations\n" + "=" *30) - for room in Amity.office_allocations[room]: + for room in Amity.office_allocations.keys(): if room != "None": - nfile.write(room + "\n" + "+" * 30) + nfile.write("\n"+ room.upper() + "\n"+ "-" *30+ "\n") for person in Amity.office_allocations[room]: - nfile.write(person) - nfile.write("=" *30 + "\n" + "Living space Allocations\n" + "=" * 30 ) - for room in Amity.living_space_allocations[room]: + nfile.write(person.full_name.upper()+"\n") + for room in Amity.living_space_allocations.keys(): if room != "None": - nfile.write(room + "\n" + "+" * 30) + nfile.write("\n" + room.upper() + "\n" + "-" * 30+ "\n") for person in Amity.living_space_allocations[room]: - nfile.write(person) - print("%s.txt written" % file) + nfile.write(person.full_name.upper()+"\n") + print("%s.txt written" % file_name) @staticmethod def print_unallocated(file_name=None): """Prints all people not allocated""" - unallocated_offices = Amity.office_allocations["None"] - unallocated_living_spaces = Amity.living_space_allocations["None"] - print("=" * 30 + "\n" + "No offices\n" + "=" * 30) + unallocated_offices = Amity.office_spaces_waiting_list + unallocated_living_spaces = Amity.living_spaces_waiting_list for person in unallocated_offices: print(person or "None") print("=" * 30 + "\n" + "Living Spaces\n" + "=" * 30) @@ -280,12 +274,11 @@ def print_unallocated(file_name=None): if file_name: file = open(file_name + ".txt", "a") - file.write("=" * 30 + "\n" + "No offices\n" + "=" * 30) + file.write("=" * 30 + "\n" + "Unallocated people\n" + "=" * 30) for person in unallocated_offices: - file.write("\n" + person or "None") - file.write("=" * 30 + "\n" + "No living spaces\n" + "=" * 30) + file.write("\n" + person.full_name or "None") for person in unallocated_living_spaces: - file.write("\n" + person or "None") + file.write("\n" + person.full_name or "None") print("{}.txt written succesfully".format(file_name)) @staticmethod @@ -294,30 +287,34 @@ def print_room(room_name): screen.""" offices = [room for room in Amity.office_allocations if room != "None"] living_spaces = [room for room in Amity.living_space_allocations if room != "None"] - if room_name.upper() not in offices and room_name.upper() not in living_spaces: + if room_name not in offices and room_name not in living_spaces: print("sorry! the room does not exist") else: print("=" * 30 + "\n Members \n" + "=" * 30) - if room_name.upper() in offices: - for person in Amity.office_allocations[room_name.upper()]: + if room_name in offices: + for person in Amity.office_allocations[room_name]: print(person) - elif room_name.upper() in living_spaces: - for person in Amity.living_space_allocations[room_name.upper()]: + elif room_name in living_spaces: + for person in Amity.living_space_allocations[room_name]: print(person) - def load_state(self, dbname): + def load_state(self, db_name): # connect to the db provided - self.save_state() # query all rooms and people - self.session = SessionMaker() + self.db_name = db_name + '.db' + self.engine = create_engine('sqlite:///' + self.db_name) + Base.metadata.bind = self.engine + + SessionMaker = sessionmaker(bind=self.engine) + session = SessionMaker() people = session.query(Person).all() rooms = session.query(Room).all() # save them to the current Amity instance - for room in Amity.all_rooms: + for room in rooms: Amity.all_rooms.append(room) - for person in Amity.all_people: + for person in people: Amity.all_people.append(people) - print(Fore.GREEN + "Data from {} loaded to the app.".format(dbname)) + print(Fore.GREEN + "Data from {} loaded to the app.".format(db_name)) @@ -346,10 +343,55 @@ def save_state(self, db_name): # save people's data people = [] for person in self.all_people: - new_person = Person(id=person.person_id, name=person.full_name, category=person.category, wants_accomodation=person.wants_accomodation) + wants_accomodation = True if person.wants_accomodation == "Y" else False + print(person, person.wants_accomodation) + new_person = Person(id=person.person_id, name=person.full_name, category=person.category, wants_accomodation=wants_accomodation) people.append(new_person) # self.session.update(new_person) self.session.add_all(people) self.session.commit() +space = Amity() +# space.create_room('O', ["MyRoom"]) +space.create_room('O', ['VaLhAla']) +# space.create_room('O', ['valhalmka']) +space.create_room('L', ['Ruby']) + +space.add_person('faith', 'dede', 'F', 'Y') +space.add_person('fath', 'dee', 'S', 'Y') +space.add_person('ndVKGungu', 'kevGBin', 'S', 'Y') +space.add_person('fSSWnjh', 'deme', 'F', 'Y') +space.add_person('fkFFjh', 'dHHVme', 'F', 'N') +space.add_person('fAAADA', 'demBGe', 'F', 'Y') +space.add_person('fkjnSSjh', 'deEme', 'F', 'Y') + + + + + + + + + +# space.reallocate_person('faith', 'dede', 'L', 'valhala') +# print(Amity.living_spaces) +# print(Amity.office_spaces) +# print(space.reallocate_person('faith', 'dede', 'L', 'valhala')) +# print(Amity.living_spaces) +# print(Amity.all_rooms) +# space = Amity() +# space.add_person('faith', 'dede', 'F', 'Y') + +# ******************* + +# space.load_people("people.txt") +# space.save_state("faha") +# space.print_allocations('non-sense') +# space.print_unallocated('ingine') +# space.print_room('VaLhAla') +space.load_state("faha") + +# ******************* + +# print(Amity.living_spaces) \ No newline at end of file From 9793ebce30b746dd9850d89ad03215cc4a36cec2 Mon Sep 17 00:00:00 2001 From: faithngetich Date: Sun, 23 Apr 2017 12:42:31 +0300 Subject: [PATCH 31/52] [chore] deny staff accomodation --- views.py | 105 ++++++++++++++++--------------------------------------- 1 file changed, 31 insertions(+), 74 deletions(-) diff --git a/views.py b/views.py index f8778f1..521aa10 100644 --- a/views.py +++ b/views.py @@ -72,8 +72,8 @@ def add_person(self, first_name, last_name, category, wants_accomodation='N'): """Adds person to self and randomly allocates the person""" # check if category is FELLOW # if category is "S" and wants_accomodation is "Y" - - if wants_accomodation == "N" or (category is "S" and wants_accomodation is "Y"): + # if wants_accomodation == "N" or (category is "S" and wants_accomodation is "Y"): + if wants_accomodation == "N" : if category is "F": # create fellow object and adds them to fellow list fellow = Fellow(first_name, last_name, wants_accomodation) @@ -107,33 +107,35 @@ def add_person(self, first_name, last_name, category, wants_accomodation='N'): else: Amity.office_spaces_waiting_list.append(staff) print(Fore.RED+"Sorry, no space available {} has been added to the waiting list".format(staff.first_name)) - else: - # if wants accomodation - if category is "F": - # create fellow object - fellow = Fellow(first_name, last_name, wants_accomodation) - Amity.all_people.append(fellow) - Amity.all_fellows.append(fellow) - allocated_office = self.generate_random_office_spaces() - if allocated_office: - # if random room selected - allocated_office.members.append(fellow) - Amity.office_allocations[allocated_office.room_name] = allocated_office.members - print(Fore.GREEN+"You have allocated {} successfully to {}".format(fellow.first_name,allocated_office.room_name)) - else: - Amity.office_spaces_waiting_list.append(fellow) - print(Fore.RED+"Sorry, no space available {} has been added to the waiting list".format(fellow.first_name)) - - # add living space - allocated_living_space = self.generate_random_living_spaces() - if allocated_living_space: - allocated_living_space.members.append(fellow) - Amity.living_space_allocations[allocated_living_space.room_name] = allocated_living_space.members - print(Fore.GREEN+"You have allocated {} successfully to living space {} ".format(fellow.first_name, allocated_living_space.room_name)) - else: - Amity.living_spaces_waiting_list.append(fellow) - print(Fore.RED+"Sorry, no space available {} has been added to the waiting list".format(fellow.first_name)) + + # if wants accomodation + elif category is "F": + # create fellow object + fellow = Fellow(first_name, last_name, wants_accomodation) + Amity.all_people.append(fellow) + Amity.all_fellows.append(fellow) + allocated_office = self.generate_random_office_spaces() + if allocated_office: + # if random room selected + allocated_office.members.append(fellow) + Amity.office_allocations[allocated_office.room_name] = allocated_office.members + print(Fore.GREEN+"You have allocated {} successfully to {}".format(fellow.first_name,allocated_office.room_name)) + else: + Amity.office_spaces_waiting_list.append(fellow) + print(Fore.RED+"Sorry, no space available {} has been added to the waiting list".format(fellow.first_name)) + # add living space + allocated_living_space = self.generate_random_living_spaces() + if allocated_living_space: + allocated_living_space.members.append(fellow) + Amity.living_space_allocations[allocated_living_space.room_name] = allocated_living_space.members + print(Fore.GREEN+"You have allocated {} successfully to living space {} ".format(fellow.first_name, allocated_living_space.room_name)) + else: + Amity.living_spaces_waiting_list.append(fellow) + print(Fore.RED+"Sorry, no space available {} has been added to the waiting list".format(fellow.first_name)) + else: + if category == "S": + print("staff cannot be allocated to living space") def get_person(self, person_id): """To return person object given person id.""" @@ -300,11 +302,10 @@ def print_room(room_name): def load_state(self, db_name): # connect to the db provided - # query all rooms and people self.db_name = db_name + '.db' self.engine = create_engine('sqlite:///' + self.db_name) Base.metadata.bind = self.engine - + # query all rooms and people SessionMaker = sessionmaker(bind=self.engine) session = SessionMaker() people = session.query(Person).all() @@ -351,47 +352,3 @@ def save_state(self, db_name): self.session.add_all(people) self.session.commit() - -space = Amity() -# space.create_room('O', ["MyRoom"]) -space.create_room('O', ['VaLhAla']) -# space.create_room('O', ['valhalmka']) -space.create_room('L', ['Ruby']) - -space.add_person('faith', 'dede', 'F', 'Y') -space.add_person('fath', 'dee', 'S', 'Y') -space.add_person('ndVKGungu', 'kevGBin', 'S', 'Y') -space.add_person('fSSWnjh', 'deme', 'F', 'Y') -space.add_person('fkFFjh', 'dHHVme', 'F', 'N') -space.add_person('fAAADA', 'demBGe', 'F', 'Y') -space.add_person('fkjnSSjh', 'deEme', 'F', 'Y') - - - - - - - - - -# space.reallocate_person('faith', 'dede', 'L', 'valhala') -# print(Amity.living_spaces) -# print(Amity.office_spaces) -# print(space.reallocate_person('faith', 'dede', 'L', 'valhala')) -# print(Amity.living_spaces) -# print(Amity.all_rooms) -# space = Amity() -# space.add_person('faith', 'dede', 'F', 'Y') - -# ******************* - -# space.load_people("people.txt") -# space.save_state("faha") -# space.print_allocations('non-sense') -# space.print_unallocated('ingine') -# space.print_room('VaLhAla') -space.load_state("faha") - -# ******************* - -# print(Amity.living_spaces) \ No newline at end of file From 1b8ecb42ed1ea79972c93ce85f63821b3086fffe Mon Sep 17 00:00:00 2001 From: faithngetich Date: Mon, 24 Apr 2017 17:37:53 +0300 Subject: [PATCH 32/52] [chore] Test reallocate function works --- tests/test_amity.py | 96 ++++++++++----------------------------------- 1 file changed, 20 insertions(+), 76 deletions(-) diff --git a/tests/test_amity.py b/tests/test_amity.py index 5b25009..4123c13 100644 --- a/tests/test_amity.py +++ b/tests/test_amity.py @@ -14,86 +14,30 @@ def test_create_room_adds_room_succesfully(self): self.assertIn('KRYPTON', [room.room_name.upper() for room in self.amity.all_rooms]) - # def test_add_person_adds_fellow_to_list(self): - # self.amity.add_person('dede','faith','F','N') - # all_fellows = len(self.amity.all_fellows) + 1 - # self.assertEqual(len(self.amity.all_fellows), all_fellows, msg = "fellow not added") - - # def test_person_added_is_fellow(self): - # length = len(self.amity.all_fellows) - # self.amity.add_person('dede', 'F', 'y') - # new_length = len(self.amity.all_fellows) - # self.assertEqual((length + 1), new_length) - - - # def test_reallocate_person(self): - # length = len(self.amity.all_fellows) - # self.amity.add_person('dede', 'F', 'y') - # new_length = len(self.amity.all_fellows) - # self.assertEqual((length + 1), new_length) - - # self.amity.create_room('O', 'valhalla') - # self.amity.reallocate_person('dede', 'fat', 'O', 'valhalla') - # self.assertIn('DEDE', 'FAT', self.amity.allocated_rooms['VALHALLA']) - - - - # def test_person_added_is_staff(self): - # self.amity.add_person('dede', 'S') - # self.assertIn('dede', self.amity.all_fellows, msg = "person not added as fellow") - # self.assertFalse('dede', 'Staff') - # self.assertNotIn('dede', self.amity.all_staff, msg = "dede is not staff") - - # def test_fellow_wants_accomodation(self): - # self.amity.add_person('dede', 'fellow', 'wants_accomodation = Y') - # self.assertTrue('dede' in self.amity.accomodation_list, msg = 'fellow not in accomodation list') - # self.assertFalse('dede' not in self.amity.accomodation_list, msg = 'fellow should be in the accomodation list') - # self.amity.add_person('dede', 'fellow', 'wants_accomodation = Y') - # self.assertRaises("Fellow already exists") - - # def test_fellow_does_not_want_accomodation(self): - # self.amity.add_person('dede', 'fellow', 'wants_accomodation = N') - # self.assertTrue('dede' in self.amity.accomodation_list) - # self.assertFalse('awesome' in self.amity.accomodation_list, msg = 'fellow does not want accomodation') - - # def test_Staff_gets_no_accomodation(self): - # self.amity.add_person('luke', 'staff', 'wants_accomodation') - # self.assertFalse('luke' in self.amity.accomodation_list) - - # def test_person_added_is_staff(self): - # self.amity.add_person('brian', 'staff') - # self.assertIn('brian', self.amity.all_staff, msg = "brian added as staff" ) - # self.assertFalse('brian', 'fellow') - # self.assertNotIn('brian', self.amity.all_fellows, msg = "brian is not staff") + def test_add_person_adds_fellow_to_list(self): + all_fellows = len(self.amity.all_fellows) + 1 + self.amity.add_person('dede','faith','F','N') + self.assertEqual(len(self.amity.all_fellows), all_fellows, msg = "fellow not added") + + def test_office_is_created_successfully(self): + """Tests offices are created""" + self.amity.create_room('O', ['Krypto']) + self.assertTrue('Krypto' in self.amity.office_allocations.keys()) + + def test_living_space_is_created_successfully(self): + """Tests living space are created""" + self.amity.create_room('L', ['Krpto']) + self.assertTrue('Krpto' in self.amity.living_space_allocations.keys()) - # def test_if_room_is_livingspace(self): - # self.amity.create_room('livingspace', 'ruby') - # living_spaces = len(self.amity.living_spaces) + 1 - # #self.assertEqual(ruby.room_capacity, 4) - # self.assertEqual(len(self.amity.living_spaces), living_spaces, msg = "livingroom is not added succesfully") + def test_reallocate_person(self): + self.amity.create_room('O', ['oculus']) + self.amity.create_room('O', ['Krypto']) + self.amity.add_person('dede','gathu','F', 'Y') + self.amity.reallocate_person('','krypto') + self.assertFalse('dede' in self.amity.office_allocations['oculus']) - # def test_if_room_is_office(self): - # self.amity.create_room('office', 'hogwarts') - # #self.assertEqual(hogwarts.room_capacity, 6) - # offices1 = len(self.amity.offices) + 1 - # self.assertEqual(len(self.amity.offices), offices1, msg = "livingroom is not added succesfully") - # def test_print_allocations_returns_all_allocated_names(self): - # self.amity.add_person('dede', 'fellow') - # allocated_names = len(self.amity.allocated_rooms) + 1 - # self.assertEqual(len(self.amity.allocated_rooms), allocated_names, msg = "allocated person is missing") - - # def test_print_unallocated_returns_all_not_in_accomodation_list(self): - # self.amity.print_unallocated('dede') - # self.assertFalse('dede' in self.amity.accomodation_list, msg = "person not in accomodation list") - - # def test_print_rooms_returns_names(self): - # self.amity.create_room('office', 'kikwete') - # self.amity.add_person('collins', 'staff', 'N') - # self.amity.reallocate_person('collins','kikwete') - # self.assertIn('collins', self.amity.print_room('kikwete')) - if __name__ == '__main__': unittest.main() From 9c332126b6731e133b449878efad2e4d7d45f496 Mon Sep 17 00:00:00 2001 From: faithngetich Date: Mon, 24 Apr 2017 17:43:34 +0300 Subject: [PATCH 33/52] [chore] Test staff is added to all staff list --- tests/test_amity.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tests/test_amity.py b/tests/test_amity.py index 4123c13..0c4a369 100644 --- a/tests/test_amity.py +++ b/tests/test_amity.py @@ -19,6 +19,11 @@ def test_add_person_adds_fellow_to_list(self): self.amity.add_person('dede','faith','F','N') self.assertEqual(len(self.amity.all_fellows), all_fellows, msg = "fellow not added") + def test_add_person_adds_staff_to_list(self): + all_staff = len(self.amity.all_staff) + 1 + self.amity.add_person('ded','fai','S','N') + self.assertEqual(len(self.amity.all_staff), all_staff, msg = "staff not added") + def test_office_is_created_successfully(self): """Tests offices are created""" self.amity.create_room('O', ['Krypto']) @@ -28,6 +33,7 @@ def test_living_space_is_created_successfully(self): """Tests living space are created""" self.amity.create_room('L', ['Krpto']) self.assertTrue('Krpto' in self.amity.living_space_allocations.keys()) + def test_reallocate_person(self): self.amity.create_room('O', ['oculus']) @@ -38,7 +44,6 @@ def test_reallocate_person(self): - if __name__ == '__main__': unittest.main() From 456f7e481b6d9e242685a6abbadd88ef74cc3707 Mon Sep 17 00:00:00 2001 From: faithngetich Date: Mon, 24 Apr 2017 20:17:40 +0300 Subject: [PATCH 34/52] [chore] Test office is created successfully --- tests/test_amity.py | 16 +--------------- 1 file changed, 1 insertion(+), 15 deletions(-) diff --git a/tests/test_amity.py b/tests/test_amity.py index 0c4a369..6253b3e 100644 --- a/tests/test_amity.py +++ b/tests/test_amity.py @@ -27,23 +27,9 @@ def test_add_person_adds_staff_to_list(self): def test_office_is_created_successfully(self): """Tests offices are created""" self.amity.create_room('O', ['Krypto']) - self.assertTrue('Krypto' in self.amity.office_allocations.keys()) + self.assertTrue('Krypto' in self.amity.office_allocations.key - def test_living_space_is_created_successfully(self): - """Tests living space are created""" - self.amity.create_room('L', ['Krpto']) - self.assertTrue('Krpto' in self.amity.living_space_allocations.keys()) - - - def test_reallocate_person(self): - self.amity.create_room('O', ['oculus']) - self.amity.create_room('O', ['Krypto']) - self.amity.add_person('dede','gathu','F', 'Y') - self.amity.reallocate_person('','krypto') - self.assertFalse('dede' in self.amity.office_allocations['oculus']) - - if __name__ == '__main__': unittest.main() From 68aa22d2a0bc5b6e342817af775b81bfb1ccd893 Mon Sep 17 00:00:00 2001 From: faithngetich Date: Tue, 25 Apr 2017 16:17:07 +0300 Subject: [PATCH 35/52] [chore] Add more test methods --- app.py | 46 ++++++++-- ingine.txt | 56 ++++++++++++ models/rooms.py | 4 +- non-sense.txt | 202 +++++++++++++++++++++++++++++++++++++++++--- tests/test_amity.py | 131 +++++++++++++++++++++++++++- views.py | 90 +++++++++++++++++--- 6 files changed, 492 insertions(+), 37 deletions(-) diff --git a/app.py b/app.py index bf80258..bdca1a4 100644 --- a/app.py +++ b/app.py @@ -1,10 +1,10 @@ """ Usage: - amity create_room ( )... + amity create_room (O|L) ... amity add_person (F | S) [--wants_accomodation=value] amity print_allocations [-output=] - amity reallocate_person + amity reallocate_person amity print_room amity print_unallocated [-output=] amity load_people @@ -58,6 +58,9 @@ def intro(): 'blue', attrs=['bold']) print("Welcome to Amity! Here is a list of commands to get you started." + " Type 'help' anytime to access documented commands") + print("\n\n\n\n\n") + print(amity) + print(amity.__dict__) cprint(__doc__, 'magenta') class AmitySystem(cmd.Cmd): @@ -66,10 +69,20 @@ class AmitySystem(cmd.Cmd): @docopt_cmd def do_create_room(self, args): - """Usage: create_room ...""" - room_name = args[""] - room_type = args[""] - amity.create_room(args[""],args[""]) + """Usage: create_room (O|L) ...""" + # rooms = args[""] + # types = args["(O|L)"] + # for room in rooms: + # r_type = types[rooms.index(room)] + # amity.create_room(r_type) + + room_type = None + if args["O"]: + room_type = "O" + else: + room_type = "L" + amity.create_room(room_type, args[""]) + # print(args[""]) @docopt_cmd def do_add_person(self, args): @@ -94,6 +107,17 @@ def do_reallocate_person(self, args): (amity.reallocate_person(int(args['']), args[''])) + @docopt_cmd + def do_save_state(self, args): + """Usage: save_state [--db=sqlite_database]""" + # print(args['--db']) + amity.save_state(args['--db']) + + @docopt_cmd + def do_print_unallocated(self, args): + """Usage: print_unallocated [--file=text_file]""" + amity.print_unallocated(args['--file']) + @docopt_cmd def do_print_allocations(self, args): @@ -129,14 +153,20 @@ def do_clear(self, arg): os.system('clear') + @docopt_cmd + def do_load_people(self, args): + """Usage: load_state """ + amity.load_people(args[""]) + + + def do_quit(self, arg): """Quits out of Interactive Mode.""" print('Thank you for using Amity. Adios!') exit() - - + opt = docopt(__doc__, sys.argv[1:]) if opt['--interactive']: diff --git a/ingine.txt b/ingine.txt index e69de29..48b4c67 100644 --- a/ingine.txt +++ b/ingine.txt @@ -0,0 +1,56 @@ +============================== +Unallocated people +============================== +LEIGH RILEY +TANA LOPEZ +KELLY McGUIRE============================== +Unallocated people +============================== +LEIGH RILEY +TANA LOPEZ +KELLY McGUIRE============================== +Unallocated people +============================== +LEIGH RILEY +TANA LOPEZ +KELLY McGUIRE============================== +Unallocated people +============================== +LEIGH RILEY +TANA LOPEZ +KELLY McGUIRE============================== +Unallocated people +============================== +LEIGH RILEY +TANA LOPEZ +KELLY McGUIRE============================== +Unallocated people +============================== +LEIGH RILEY +TANA LOPEZ +KELLY McGUIRE============================== +Unallocated people +============================== +LEIGH RILEY +TANA LOPEZ +KELLY McGUIRE============================== +Unallocated people +============================== +LEIGH RILEY +TANA LOPEZ +KELLY McGUIRE============================== +Unallocated people +============================== +LEIGH RILEY +TANA LOPEZ +KELLY McGUIRE============================== +Unallocated people +============================== +LEIGH RILEY +TANA LOPEZ +KELLY McGUIRE============================== +Unallocated people +============================== +LEIGH RILEY +TANA LOPEZ +KELLY McGUIRE \ No newline at end of file diff --git a/models/rooms.py b/models/rooms.py index 2b2451c..fe0b11c 100644 --- a/models/rooms.py +++ b/models/rooms.py @@ -2,6 +2,7 @@ class Room(object): def __init__(self, room_name): self.room_id = id(self) self.room_name = room_name + self.members = [] def __str__(self): """To make the class human readable.""" @@ -16,7 +17,6 @@ def __init__(self, room_name): """Override the init method of Person superclass.""" super(Office, self).__init__(room_name) - self.members = [] class LivingSpace(Room): @@ -27,6 +27,6 @@ def __init__(self, room_name): """Override the init method of Person superclass.""" super(LivingSpace, self).__init__(room_name) - self.members = [] + diff --git a/non-sense.txt b/non-sense.txt index ec2ff42..b213c8b 100644 --- a/non-sense.txt +++ b/non-sense.txt @@ -1,24 +1,198 @@ VALHALA ------------------------------ -NDVKGUNGU KEVGBIN -FSSWNJH DEME -FKFFJH DHHVME +AHMED YUSUB +EPRAHIM KIMANI +OLUWAFEMI SULE +DOMINIC WALTERS +SIMON PATTERSON +MARI LAWRENCE -VALHALMKA +RUBY +------------------------------ +AHMED YUSUB +EPRAHIM KIMANI +OLUWAFEMI SULE +SIMON PATTERSON +MARI LAWRENCE +TANA LOPEZ + +VALHALA +------------------------------ +AHMED YUSUB +EPRAHIM KIMANI +OLUWAFEMI SULE +DOMINIC WALTERS +SIMON PATTERSON +MARI LAWRENCE + +RUBY +------------------------------ +AHMED YUSUB +EPRAHIM KIMANI +OLUWAFEMI SULE +SIMON PATTERSON +MARI LAWRENCE +TANA LOPEZ + +VALHALA +------------------------------ +AHMED YUSUB +EPRAHIM KIMANI +OLUWAFEMI SULE +DOMINIC WALTERS +SIMON PATTERSON +MARI LAWRENCE + +RUBY +------------------------------ +AHMED YUSUB +EPRAHIM KIMANI +OLUWAFEMI SULE +SIMON PATTERSON +MARI LAWRENCE +TANA LOPEZ + +VALHALA +------------------------------ +AHMED YUSUB +EPRAHIM KIMANI +OLUWAFEMI SULE +DOMINIC WALTERS +SIMON PATTERSON +MARI LAWRENCE + +RUBY +------------------------------ +AHMED YUSUB +EPRAHIM KIMANI +OLUWAFEMI SULE +SIMON PATTERSON +MARI LAWRENCE +TANA LOPEZ + +VALHALA +------------------------------ +AHMED YUSUB +EPRAHIM KIMANI +OLUWAFEMI SULE +DOMINIC WALTERS +SIMON PATTERSON +MARI LAWRENCE + +RUBY +------------------------------ +AHMED YUSUB +EPRAHIM KIMANI +OLUWAFEMI SULE +SIMON PATTERSON +MARI LAWRENCE +TANA LOPEZ + +VALHALA ------------------------------ -FAITH DEDE -FATH DEE -FAAADA DEMBGE -FKJNSSJH DEEME +AHMED YUSUB +EPRAHIM KIMANI +OLUWAFEMI SULE +DOMINIC WALTERS +SIMON PATTERSON +MARI LAWRENCE RUBY ------------------------------ -FAITH DEDE -FSSWNJH DEME -FKFFJH DHHVME -FKJNSSJH DEEME +AHMED YUSUB +EPRAHIM KIMANI +OLUWAFEMI SULE +SIMON PATTERSON +MARI LAWRENCE +TANA LOPEZ -NARNIA +VALHALA +------------------------------ +AHMED YUSUB +EPRAHIM KIMANI +OLUWAFEMI SULE +DOMINIC WALTERS +SIMON PATTERSON +MARI LAWRENCE + +RUBY +------------------------------ +AHMED YUSUB +EPRAHIM KIMANI +OLUWAFEMI SULE +SIMON PATTERSON +MARI LAWRENCE +TANA LOPEZ + +VALHALA +------------------------------ +AHMED YUSUB +EPRAHIM KIMANI +OLUWAFEMI SULE +DOMINIC WALTERS +SIMON PATTERSON +MARI LAWRENCE + +RUBY +------------------------------ +AHMED YUSUB +EPRAHIM KIMANI +OLUWAFEMI SULE +SIMON PATTERSON +MARI LAWRENCE +TANA LOPEZ + +VALHALA +------------------------------ +AHMED YUSUB +EPRAHIM KIMANI +OLUWAFEMI SULE +DOMINIC WALTERS +SIMON PATTERSON +MARI LAWRENCE + +RUBY +------------------------------ +AHMED YUSUB +EPRAHIM KIMANI +OLUWAFEMI SULE +SIMON PATTERSON +MARI LAWRENCE +TANA LOPEZ + +VALHALA +------------------------------ +AHMED YUSUB +EPRAHIM KIMANI +OLUWAFEMI SULE +DOMINIC WALTERS +SIMON PATTERSON +MARI LAWRENCE + +RUBY +------------------------------ +AHMED YUSUB +EPRAHIM KIMANI +OLUWAFEMI SULE +SIMON PATTERSON +MARI LAWRENCE +TANA LOPEZ + +VALHALA +------------------------------ +AHMED YUSUB +EPRAHIM KIMANI +OLUWAFEMI SULE +DOMINIC WALTERS +SIMON PATTERSON +MARI LAWRENCE + +RUBY ------------------------------ -FAAADA DEMBGE +AHMED YUSUB +EPRAHIM KIMANI +OLUWAFEMI SULE +SIMON PATTERSON +MARI LAWRENCE +TANA LOPEZ diff --git a/tests/test_amity.py b/tests/test_amity.py index 6253b3e..f4a65d4 100644 --- a/tests/test_amity.py +++ b/tests/test_amity.py @@ -8,6 +8,17 @@ class Amitytest(unittest.TestCase): def setUp(self): self.amity = Amity() + + def tearDown(self): + del self.amity + # self.amity.all_fellows = [] + # self.all_fellows = [] + # self.all_rooms = [] + # self.office_allocations = {} + # self.living_space_allocations = {} + # self.all_people = [] + # self.living_spaces_waiting_list = [] + # self.office_spaces_waiting_list = [] def test_create_room_adds_room_succesfully(self): self.amity.create_room('O', ['Krypton']) @@ -24,12 +35,130 @@ def test_add_person_adds_staff_to_list(self): self.amity.add_person('ded','fai','S','N') self.assertEqual(len(self.amity.all_staff), all_staff, msg = "staff not added") + def test_staff_not_in_accomodation_list(self): + """test that fellow is not entitled to living space""" + self.amity.create_room('L', ['bonivile']) + new_staff = len(self.amity.living_space_allocations['bonivile']) + 1 + self.amity.add_person('ded','fai','S','Y') + self.assertNotEqual(len(self.amity.living_space_allocations['bonivile']), new_staff, msg = "staff cannot be allocated to living space") + + def test_office_is_created_successfully(self): """Tests offices are created""" self.amity.create_room('O', ['Krypto']) - self.assertTrue('Krypto' in self.amity.office_allocations.key + self.assertTrue('Krypto' in self.amity.office_allocations.keys()) + + def test_living_space_is_created_successfully(self): + """Tests living space are created""" + self.amity.create_room('L', ['Krpto']) + self.assertTrue('Krpto' in self.amity.living_space_allocations.keys()) + def test_reallocate_person_to_office(self): + """Test if person reallocated succesfully to office""" + self.amity.create_room('O', ['oculus']) + self.amity.create_room('O', ['Krypto']) + self.amity.reallocate_person('','krypto') + self.assertFalse('dede' in self.amity.office_allocations['oculus'], msg = "person not reallocated succesfully to office") + + + def test_if_person_is_added_to_livingspace(self): + """ Test if person has been added to a living space""" + living_spaces = len(self.amity.living_space_allocations) + 1 + self.amity.create_room('L', ['ruby']) + self.amity.add_person('dedS','gath','F', 'Y') + self.assertEqual(len(self.amity.living_space_allocations), living_spaces, msg = "livingroom is not added succesfully") + + def test_if_person_is_added_to_livingspace(self): + """ Test if person has been added to a living space""" + living_spaces = len(self.amity.living_space_allocations) + 1 + self.amity.create_room('L', ['ruby']) + self.amity.add_person('dedS','gath','F', 'Y') + self.assertEqual(len(self.amity.living_space_allocations), living_spaces, msg = "livingroom is not added succesfully") + + + def test_fellow_does_not_want_accomodation(self): + self.amity.add_person('dedeh', 'fagh', 'F', 'N') + self.assertFalse('dedeh' in self.amity.living_space_allocations, msg = 'fellow does not want accomodation') + + def test_add_person_adds_people_to_waiting_list_if_office_is_full(self): + """To test if add_person caters for excess people. + Adds fellow/staff to office waiting list when offices are full. + """ + self.amity.add_person("Daniel", "Maina","F", "N") + self.amity.add_person("Dan", "Wachira", "F") + self.amity.add_person("Larry", "W", "F", "N") + self.amity.add_person("David", "White", "S", "N") + self.amity.add_person("Xie", "Yuen", "S", "N") + self.amity.add_person("Stella", "Storl", "S", "N") + self.assertFalse('stella' in self.amity.office_allocations, msg = "person not reallocated succesfully to office") + + + def test_add_person_adds_fellows_to_living_space_waiting_list(self): + """To test if add_person caters for excess people. + Adds fellow to living space waiting list when offices are full. + """ + self.amity.add_person("Daniel", "Maina","F", "Y") + self.amity.add_person("Dan", "Wachira", "F","Y") + self.amity.add_person("Larry", "W", "F", "Y") + self.amity.add_person("David", "White", "Y", "Y") + self.amity.add_person("Xie", "Yuen", "S", "Y") + # self.amity.add_person("Stella", "Storl", "S", "Y") + self.assertFalse('stella' in self.amity.living_space_allocations, msg = "person not reallocated succesfully to living space") + + def test_print_room_does_not_print_inexistent_room(self): + """To test if method prints rooms and occupants successfully.""" + room_name = "I don't exist!!!" + self.assertEqual(self.amity.print_room(room_name),"sorry! the room does not exist") + + def test_print_unallocated_returns_all_not_in_accomodation_list(self): + self.amity.print_unallocated('') + self.assertFalse('Dan' in self.amity.office_allocations, msg = "person not in accomodation list") + + def test_print_rooms_returns_names(self): + self.amity.add_person('collins', 'star', 'S' 'N') + self.amity.print_room('Krypton') + self.assertFalse('dede'in self.amity.print_room('krypton')) + + def test_print_allocations_prints_successfully_to_screen(self): + """To test if method prints allocations to screen.""" + self.amity.create_room("O", ["Narnia"]) + self.amity.create_room("living_space", ["Python"]) + # create people + self.amity.add_person("Fell", "Dl", "S", "Y") + self.amity.add_person("Fell", "Dl", "S", "Y") + self.amity.add_person("Fello", "Dl", "S", "Y") + + self.assertEqual(self.amity.print_allocations(),"office allocations printed successfully") + # + + + # def test_fellow_wants_accomodation(self): + # self.amity.create_room('L', ['narnia']) + # self.amity.add_person('dede', 'fauz', 'F', 'Y') + # print(self.amity.living_space_allocations['narnia'][0]) + # print("DEDE" in self.amity.living_space_allocations['narnia']) + # self.assertTrue('DEDE' in self.amity.living_space_allocations['narnia'], msg = 'fellow not in accomodation list') + + # self.assertFalse('dede' not in self.amity.accomodation_list, msg = 'fellow should be in the accomodation list') + # self.amity.add_person('dede', 'fellow', 'wants_accomodation = Y') + # self.assertRaises("Fellow already exists") + + # self.amity.create_room('O', 'valhalla') + # self.amity.reallocate_person('dede', 'fat', 'O', 'valhalla') + # self.assertIn('DEDE', 'FAT', self.amity.allocated_rooms['VALHALLA']) + + # def test_if_room_is_office(self): + # self.amity.create_room('office', 'hogwarts') + # #self.assertEqual(hogwarts.room_capacity, 6) + # offices1 = len(self.amity.offices) + 1 + # self.assertEqual(len(self.amity.offices), offices1, msg = "livingroom is not added succesfully") + + + + + + if __name__ == '__main__': unittest.main() diff --git a/views.py b/views.py index 521aa10..3b29b47 100644 --- a/views.py +++ b/views.py @@ -26,8 +26,8 @@ def create_room(self, room_type, list_of_rooms): """creates a specified room""" for name in list_of_rooms: - if name.upper() in [room.room_name.upper() for room in self.all_rooms]: - print("sorry,{} Room already exist.".format(name.upper())) + if name in [room.room_name.upper() for room in self.all_rooms]: + print("sorry,{} room already exist.".format(name.upper())) else: if room_type.upper() == 'O': office = Office(name) @@ -115,6 +115,7 @@ def add_person(self, first_name, last_name, category, wants_accomodation='N'): Amity.all_people.append(fellow) Amity.all_fellows.append(fellow) allocated_office = self.generate_random_office_spaces() + print(fellow.person_id) if allocated_office: # if random room selected allocated_office.members.append(fellow) @@ -128,6 +129,7 @@ def add_person(self, first_name, last_name, category, wants_accomodation='N'): allocated_living_space = self.generate_random_living_spaces() if allocated_living_space: allocated_living_space.members.append(fellow) + print(allocated_living_space) Amity.living_space_allocations[allocated_living_space.room_name] = allocated_living_space.members print(Fore.GREEN+"You have allocated {} successfully to living space {} ".format(fellow.first_name, allocated_living_space.room_name)) else: @@ -136,7 +138,8 @@ def add_person(self, first_name, last_name, category, wants_accomodation='N'): else: if category == "S": print("staff cannot be allocated to living space") - + return "staff cannot be allocated to living space" + def get_person(self, person_id): """To return person object given person id.""" person_object = None @@ -233,6 +236,7 @@ def load_people(self, filename): accomodate = details[3] if len(details) == 4 else "N" self.add_person(details[0], details[1], details[2], accomodate) print("Successfully loaded people") + return "Successfully loaded people" @staticmethod def print_allocations(file_name=None): @@ -243,12 +247,14 @@ def print_allocations(file_name=None): print (Fore.BLUE + room.upper() + "\n") for person in Amity.office_allocations[room]: print(person) + return "office allocations printed successfully" print(Fore.MAGENTA + "=" * 30 + "\n" + "Living spaces Allocations\n" + "=" *30) for room in Amity.living_space_allocations.keys(): if room != "None": print (Fore.BLUE +room.upper() + "\n" + "+" * 30) for person in Amity.living_space_allocations[room]: print(person) + return "Living space allocations printed successfully" if file_name: nfile = open(file_name + ".txt", "a") for room in Amity.office_allocations.keys(): @@ -262,6 +268,7 @@ def print_allocations(file_name=None): for person in Amity.living_space_allocations[room]: nfile.write(person.full_name.upper()+"\n") print("%s.txt written" % file_name) + return "Successfully written the file" @staticmethod def print_unallocated(file_name=None): @@ -273,6 +280,7 @@ def print_unallocated(file_name=None): print("=" * 30 + "\n" + "Living Spaces\n" + "=" * 30) for person in unallocated_living_spaces: print(person or "None") + return person or "None" if file_name: file = open(file_name + ".txt", "a") @@ -289,16 +297,20 @@ def print_room(room_name): screen.""" offices = [room for room in Amity.office_allocations if room != "None"] living_spaces = [room for room in Amity.living_space_allocations if room != "None"] - if room_name not in offices and room_name not in living_spaces: - print("sorry! the room does not exist") + if not offices or not living_spaces: + print("There are no rooms in the system.") else: - print("=" * 30 + "\n Members \n" + "=" * 30) - if room_name in offices: - for person in Amity.office_allocations[room_name]: - print(person) - elif room_name in living_spaces: - for person in Amity.living_space_allocations[room_name]: - print(person) + if room_name not in offices and room_name not in living_spaces: + print("sorry! the room does not exist") + return "sorry! the room does not exist" + else: + print("=" * 30 + "\n Members \n" + "=" * 30) + if room_name in offices: + for person in Amity.office_allocations[room_name]: + print(person) + elif room_name in living_spaces: + for person in Amity.living_space_allocations[room_name]: + print(person) def load_state(self, db_name): # connect to the db provided @@ -316,6 +328,7 @@ def load_state(self, db_name): for person in people: Amity.all_people.append(people) print(Fore.GREEN + "Data from {} loaded to the app.".format(db_name)) + return "Successfully loaded people to the app" @@ -352,3 +365,56 @@ def save_state(self, db_name): self.session.add_all(people) self.session.commit() + +# space = Amity() +# # # # space.create_room('O', ["MyRoom"]) +# space.create_room('O', ['VaLhAla']) +# space.create_room('L', ['valhala_']) +# space.create_room('L', ['Ruby']) + +# # space.add_person('faith', 'dede', 'F', 'Y') +# # space.add_person('faith', 'dede', 'F', 'Y') +# # space.add_person('faith', 'dede', 'F', 'Y') +# # space.add_person('faith', 'dede', 'F', 'Y') +# # space.add_person('faith', 'dede', 'F', 'Y') +# # space.add_person('faith', 'dede', 'F', 'Y') +# # space.add_person('faith', 'dede', 'F', 'Y') +# # space.add_person('faith', 'dede', 'F', 'Y') +# space.add_person('faith', 'dede', 'S', 'N') +# space.add_person('faith', 'dede', 'F', 'Y') +# # space.add_person('fath', 'dee', 'F') +# space.add_person('ndVKGungu', 'kevGBin', 'S', 'Y') +# # space.add_person('fSSWnjh', 'deme', 'F', 'Y') +# space.add_person('fkFFjh', 'dHHVme', 'F', 'N') +# # space.add_person('fAAADA', 'demBGe', 'F', 'Y') +# # space.add_person('fkjnSSjh', 'deEme', 'F', 'Y') + + + + + + + + + +# # space.reallocate_person('faith', 'dede', 'L', 'valhala') +# # print(Amity.living_spaces) +# # print(Amity.office_spaces) +# # print(space.reallocate_person('faith', 'dede', 'L', 'valhala')) +# # print(Amity.living_spaces) +# # print(Amity.all_rooms) +# # space = Amity() +# # space.add_person('faith', 'dede', 'F', 'Y') + +# # ******************* + +# # space.load_people("people.txt") +# # space.save_state("faha") +# # space.print_allocations('non-sense') +# # space.print_unallocated() +# # space.print_room('valhala_') +# space.load_state("faha") + +# # ******************* + +# # print(Amity.living_spaces) \ No newline at end of file From 00da78ca7809b9671a13b722fa1b436d0e6cef67 Mon Sep 17 00:00:00 2001 From: faithngetich Date: Tue, 25 Apr 2017 16:50:56 +0300 Subject: [PATCH 36/52] [chore] Update requirements --- ingine.txt | 56 ------------- non-sense.txt | 198 -------------------------------------------- requirements.txt | 20 +++++ tests/test_amity.py | 7 +- 4 files changed, 24 insertions(+), 257 deletions(-) diff --git a/ingine.txt b/ingine.txt index 48b4c67..e69de29 100644 --- a/ingine.txt +++ b/ingine.txt @@ -1,56 +0,0 @@ -============================== -Unallocated people -============================== -LEIGH RILEY -TANA LOPEZ -KELLY McGUIRE============================== -Unallocated people -============================== -LEIGH RILEY -TANA LOPEZ -KELLY McGUIRE============================== -Unallocated people -============================== -LEIGH RILEY -TANA LOPEZ -KELLY McGUIRE============================== -Unallocated people -============================== -LEIGH RILEY -TANA LOPEZ -KELLY McGUIRE============================== -Unallocated people -============================== -LEIGH RILEY -TANA LOPEZ -KELLY McGUIRE============================== -Unallocated people -============================== -LEIGH RILEY -TANA LOPEZ -KELLY McGUIRE============================== -Unallocated people -============================== -LEIGH RILEY -TANA LOPEZ -KELLY McGUIRE============================== -Unallocated people -============================== -LEIGH RILEY -TANA LOPEZ -KELLY McGUIRE============================== -Unallocated people -============================== -LEIGH RILEY -TANA LOPEZ -KELLY McGUIRE============================== -Unallocated people -============================== -LEIGH RILEY -TANA LOPEZ -KELLY McGUIRE============================== -Unallocated people -============================== -LEIGH RILEY -TANA LOPEZ -KELLY McGUIRE \ No newline at end of file diff --git a/non-sense.txt b/non-sense.txt index b213c8b..e69de29 100644 --- a/non-sense.txt +++ b/non-sense.txt @@ -1,198 +0,0 @@ - -VALHALA ------------------------------- -AHMED YUSUB -EPRAHIM KIMANI -OLUWAFEMI SULE -DOMINIC WALTERS -SIMON PATTERSON -MARI LAWRENCE - -RUBY ------------------------------- -AHMED YUSUB -EPRAHIM KIMANI -OLUWAFEMI SULE -SIMON PATTERSON -MARI LAWRENCE -TANA LOPEZ - -VALHALA ------------------------------- -AHMED YUSUB -EPRAHIM KIMANI -OLUWAFEMI SULE -DOMINIC WALTERS -SIMON PATTERSON -MARI LAWRENCE - -RUBY ------------------------------- -AHMED YUSUB -EPRAHIM KIMANI -OLUWAFEMI SULE -SIMON PATTERSON -MARI LAWRENCE -TANA LOPEZ - -VALHALA ------------------------------- -AHMED YUSUB -EPRAHIM KIMANI -OLUWAFEMI SULE -DOMINIC WALTERS -SIMON PATTERSON -MARI LAWRENCE - -RUBY ------------------------------- -AHMED YUSUB -EPRAHIM KIMANI -OLUWAFEMI SULE -SIMON PATTERSON -MARI LAWRENCE -TANA LOPEZ - -VALHALA ------------------------------- -AHMED YUSUB -EPRAHIM KIMANI -OLUWAFEMI SULE -DOMINIC WALTERS -SIMON PATTERSON -MARI LAWRENCE - -RUBY ------------------------------- -AHMED YUSUB -EPRAHIM KIMANI -OLUWAFEMI SULE -SIMON PATTERSON -MARI LAWRENCE -TANA LOPEZ - -VALHALA ------------------------------- -AHMED YUSUB -EPRAHIM KIMANI -OLUWAFEMI SULE -DOMINIC WALTERS -SIMON PATTERSON -MARI LAWRENCE - -RUBY ------------------------------- -AHMED YUSUB -EPRAHIM KIMANI -OLUWAFEMI SULE -SIMON PATTERSON -MARI LAWRENCE -TANA LOPEZ - -VALHALA ------------------------------- -AHMED YUSUB -EPRAHIM KIMANI -OLUWAFEMI SULE -DOMINIC WALTERS -SIMON PATTERSON -MARI LAWRENCE - -RUBY ------------------------------- -AHMED YUSUB -EPRAHIM KIMANI -OLUWAFEMI SULE -SIMON PATTERSON -MARI LAWRENCE -TANA LOPEZ - -VALHALA ------------------------------- -AHMED YUSUB -EPRAHIM KIMANI -OLUWAFEMI SULE -DOMINIC WALTERS -SIMON PATTERSON -MARI LAWRENCE - -RUBY ------------------------------- -AHMED YUSUB -EPRAHIM KIMANI -OLUWAFEMI SULE -SIMON PATTERSON -MARI LAWRENCE -TANA LOPEZ - -VALHALA ------------------------------- -AHMED YUSUB -EPRAHIM KIMANI -OLUWAFEMI SULE -DOMINIC WALTERS -SIMON PATTERSON -MARI LAWRENCE - -RUBY ------------------------------- -AHMED YUSUB -EPRAHIM KIMANI -OLUWAFEMI SULE -SIMON PATTERSON -MARI LAWRENCE -TANA LOPEZ - -VALHALA ------------------------------- -AHMED YUSUB -EPRAHIM KIMANI -OLUWAFEMI SULE -DOMINIC WALTERS -SIMON PATTERSON -MARI LAWRENCE - -RUBY ------------------------------- -AHMED YUSUB -EPRAHIM KIMANI -OLUWAFEMI SULE -SIMON PATTERSON -MARI LAWRENCE -TANA LOPEZ - -VALHALA ------------------------------- -AHMED YUSUB -EPRAHIM KIMANI -OLUWAFEMI SULE -DOMINIC WALTERS -SIMON PATTERSON -MARI LAWRENCE - -RUBY ------------------------------- -AHMED YUSUB -EPRAHIM KIMANI -OLUWAFEMI SULE -SIMON PATTERSON -MARI LAWRENCE -TANA LOPEZ - -VALHALA ------------------------------- -AHMED YUSUB -EPRAHIM KIMANI -OLUWAFEMI SULE -DOMINIC WALTERS -SIMON PATTERSON -MARI LAWRENCE - -RUBY ------------------------------- -AHMED YUSUB -EPRAHIM KIMANI -OLUWAFEMI SULE -SIMON PATTERSON -MARI LAWRENCE -TANA LOPEZ diff --git a/requirements.txt b/requirements.txt index 6c9b145..c8da736 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,24 @@ appdirs==1.4.3 +appnope==0.1.0 +colorama==0.3.7 +coverage==4.3.4 +decorator==4.0.11 +docopt==0.6.2 +ipdb==0.10.2 +ipython==5.3.0 +ipython-genutils==0.2.0 +nose==1.3.7 packaging==16.8 +pexpect==4.2.1 +pickleshare==0.7.4 +prompt-toolkit==1.0.14 +ptyprocess==0.5.1 +pyfiglet==0.7.5 +Pygments==2.2.0 pyparsing==2.2.0 +simplegeneric==0.8.1 six==1.10.0 +SQLAlchemy==1.1.9 +termcolor==1.1.0 +traitlets==4.3.2 +wcwidth==0.1.7 diff --git a/tests/test_amity.py b/tests/test_amity.py index f4a65d4..6fb4876 100644 --- a/tests/test_amity.py +++ b/tests/test_amity.py @@ -134,11 +134,12 @@ def test_print_allocations_prints_successfully_to_screen(self): # def test_fellow_wants_accomodation(self): + # self.amity.create_room('O', ['bur']) # self.amity.create_room('L', ['narnia']) # self.amity.add_person('dede', 'fauz', 'F', 'Y') - # print(self.amity.living_space_allocations['narnia'][0]) - # print("DEDE" in self.amity.living_space_allocations['narnia']) - # self.assertTrue('DEDE' in self.amity.living_space_allocations['narnia'], msg = 'fellow not in accomodation list') + # # print(self.amity.living_space_allocations['narnia'][0]) + # # print("DEDE" in self.amity.living_space_allocations['narnia']) + # self.assertTrue('dede' in self.amity.living_space_allocations, msg = 'fellow not in accomodation list') # self.assertFalse('dede' not in self.amity.accomodation_list, msg = 'fellow should be in the accomodation list') # self.amity.add_person('dede', 'fellow', 'wants_accomodation = Y') From 2f810553429a24c3d192adff2baa2823e66a8c4b Mon Sep 17 00:00:00 2001 From: faithngetich Date: Tue, 25 Apr 2017 20:42:08 +0300 Subject: [PATCH 37/52] [chore] Refactor docopt file --- app.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/app.py b/app.py index bdca1a4..430a927 100644 --- a/app.py +++ b/app.py @@ -24,6 +24,7 @@ from termcolor import cprint from views import Amity + amity = Amity() def docopt_cmd(func): @@ -59,10 +60,11 @@ def intro(): print("Welcome to Amity! Here is a list of commands to get you started." + " Type 'help' anytime to access documented commands") print("\n\n\n\n\n") - print(amity) - print(amity.__dict__) + # print(amity) + # print(amity.__dict__) cprint(__doc__, 'magenta') + class AmitySystem(cmd.Cmd): prompt = '(Amity) ' file = None @@ -77,7 +79,7 @@ def do_create_room(self, args): # amity.create_room(r_type) room_type = None - if args["O"]: + if args["O"].upper() == 'O': room_type = "O" else: room_type = "L" @@ -89,7 +91,7 @@ def do_add_person(self, args): """ Usage: add_person (F | S) [--wants_accomodation=value] """ - if args["F"]: + if args["F"].upper() == 'F': category = "F" else: category = "S" @@ -153,7 +155,7 @@ def do_clear(self, arg): os.system('clear') - @docopt_cmd + @docopt_cmd def do_load_people(self, args): """Usage: load_state """ amity.load_people(args[""]) From 0b40614675ef08c5dce95de79a417144032be914 Mon Sep 17 00:00:00 2001 From: faithngetich Date: Tue, 25 Apr 2017 23:25:54 +0300 Subject: [PATCH 38/52] [chore] Add load state test --- tests/test_amity.py | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/tests/test_amity.py b/tests/test_amity.py index 6fb4876..841b166 100644 --- a/tests/test_amity.py +++ b/tests/test_amity.py @@ -1,3 +1,4 @@ +import os import unittest from .context import Amity from ..views import Amity @@ -8,9 +9,13 @@ class Amitytest(unittest.TestCase): def setUp(self): self.amity = Amity() + self.db_name = "faha" def tearDown(self): + if os.path.exists(self.db_name + ".db"): + os.remove(self.db_name + ".db") del self.amity + # self.amity.all_fellows = [] # self.all_fellows = [] # self.all_rooms = [] @@ -130,7 +135,23 @@ def test_print_allocations_prints_successfully_to_screen(self): self.amity.add_person("Fello", "Dl", "S", "Y") self.assertEqual(self.amity.print_allocations(),"office allocations printed successfully") - # + + def test_save_state(self): + """ Test that save state , saves people successfully""" + self.amity.create_room("O", ["Narnia"]) + self.amity.create_room("L", ["Python"]) + self.amity.add_person("Fell", "Dl", "S", "Y") + self.amity.add_person("Fell", "Dl", "S", "Y") + self.assertEqual(self.amity.save_state(self.db_name), "successfully saved people") + + def test_load_state(self): + """ Test that the method loads people to the app succesfully""" + self.amity.create_room("O", ["Narnia"]) + self.amity.create_room("L", ["Python"]) + self.amity.add_person("Fell", "Dl", "S", "Y") + self.amity.add_person("Fell", "Dl", "S", "Y") + self.amity.save_state(self.db_name) + self.assertEqual(self.amity.load_state(self.db_name), "Successfully loaded people to the app") # def test_fellow_wants_accomodation(self): From 49ab8ae9ab00a3b26017a6b99bcebcb214eee9fe Mon Sep 17 00:00:00 2001 From: faithngetich Date: Wed, 26 Apr 2017 23:22:25 +0300 Subject: [PATCH 39/52] [chore] Refactor docopt --- app.py | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/app.py b/app.py index 430a927..a9db68f 100644 --- a/app.py +++ b/app.py @@ -8,7 +8,7 @@ amity print_room amity print_unallocated [-output=] amity load_people - amity save_state [--database=] + amity save_state (--database=) amity load_state amity (-i | --interactive) amity (-h | --help | --version) @@ -111,10 +111,15 @@ def do_reallocate_person(self, args): @docopt_cmd def do_save_state(self, args): - """Usage: save_state [--db=sqlite_database]""" - # print(args['--db']) - amity.save_state(args['--db']) - + """Persists app data into the given db + Usage: save_state (--db_name=sqlite_db) + """ + db = args['--db_name'] + amity.save_state(db) + # if db: + # else: + # amity.save_state(args['--db_name']) + @docopt_cmd def do_print_unallocated(self, args): """Usage: print_unallocated [--file=text_file]""" @@ -124,11 +129,10 @@ def do_print_unallocated(self, args): @docopt_cmd def do_print_allocations(self, args): """ - Usage: print_allocations [--output=] - Options: - -o, --output= Save allocations to file + Prints all rooms and the people in them. + Usage: print_allocations [--o=filename] """ - filename = args["--output"] + filename = args["--o"] or "" amity.print_allocations(filename) @docopt_cmd def do_load_state(self, arg): @@ -136,7 +140,8 @@ def do_load_state(self, arg): Loads data from the specified db into the app. Usage: load_state """ - self.amity.load_state(arg[""]) + amity.load_state(arg[""]) + @docopt_cmd def do_load_people(self, args): """Usage: load_state """ From 68d9542269444fca5d84b2020df9501bf019fa59 Mon Sep 17 00:00:00 2001 From: faithngetich Date: Wed, 26 Apr 2017 23:24:12 +0300 Subject: [PATCH 40/52] [chore] Refactor models file --- models/model.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/models/model.py b/models/model.py index eaec375..045ea7d 100644 --- a/models/model.py +++ b/models/model.py @@ -4,7 +4,6 @@ from sqlalchemy import Column, Integer, String, ForeignKey, Text, Boolean from sqlalchemy.ext.declarative import declarative_base - from sqlalchemy.orm import relationship, sessionmaker from sqlalchemy import create_engine @@ -20,12 +19,13 @@ class Person(Base): __tablename__ = "People" id = Column(Integer, primary_key=True, autoincrement=True, nullable=False) - name = Column(String, nullable=False) + first_name = Column(String, nullable=False) + last_name = Column(String, nullable=False) category = Column(String, nullable=False) wants_accomodation = Column(Boolean) def __repr__(self): - return 'name{}'.format(self.name) + return 'first name{} last name{}'.format(self.first_name,self.last_name) class Room(Base): From 833fbf3d2e6468c7c7e4714511e571e940e08728 Mon Sep 17 00:00:00 2001 From: faithngetich Date: Wed, 26 Apr 2017 23:26:23 +0300 Subject: [PATCH 41/52] [chore] Refactor and remove commented code --- views.py | 247 +++++++++++++++++++++---------------------------------- 1 file changed, 95 insertions(+), 152 deletions(-) diff --git a/views.py b/views.py index 3b29b47..1146e5c 100644 --- a/views.py +++ b/views.py @@ -13,15 +13,16 @@ class Amity(object): - all_staff = [] - all_fellows = [] - all_rooms = [] - office_allocations = {} - living_space_allocations = {} - all_people = [] - living_spaces_waiting_list = [] - office_spaces_waiting_list = [] - + def __init__(self): + self.all_staff = [] + self.all_fellows = [] + self.all_rooms = [] + self.office_allocations = {} + self.living_space_allocations = {} + self.all_people = [] + self.living_spaces_waiting_list = [] + self.office_spaces_waiting_list = [] + def create_room(self, room_type, list_of_rooms): """creates a specified room""" @@ -40,7 +41,7 @@ def create_room(self, room_type, list_of_rooms): self.living_space_allocations[living_space.room_name] = [] print(Fore.GREEN + "Living space {} successfully created.".format(living_space.room_name.upper())) else: - print("please specify the room_type") + print("please specify the room_type you would like to create.") def generate_random_office_spaces(self): """Generates random office""" @@ -70,9 +71,6 @@ def generate_random_living_spaces(self): def add_person(self, first_name, last_name, category, wants_accomodation='N'): """Adds person to self and randomly allocates the person""" - # check if category is FELLOW - # if category is "S" and wants_accomodation is "Y" - # if wants_accomodation == "N" or (category is "S" and wants_accomodation is "Y"): if wants_accomodation == "N" : if category is "F": # create fellow object and adds them to fellow list @@ -84,45 +82,42 @@ def add_person(self, first_name, last_name, category, wants_accomodation='N'): if allocated_office: allocated_office.members.append(fellow) # if random room selected - Amity.office_allocations[allocated_office.room_name] = allocated_office.members - - # Amity.office_allocations[allocated_office.room_name] = allocated_office.members - - print(Fore.GREEN +"You have allocated {} successfully to {}".format(fellow.first_name,allocated_office.room_name)) + self.office_allocations[allocated_office.room_name] = allocated_office.members + print(Fore.GREEN +"You have allocated {} successfully to office {}".format(fellow.first_name,allocated_office.room_name)) else: - Amity.office_spaces_waiting_list.append(fellow) - print("Sorry, no space available {} has been added to the waiting list".format(fellow.first_name)) + self.office_spaces_waiting_list.append(fellow) + print("Sorry, no space available {} has been added to the office waiting list".format(fellow.first_name)) else: # create staff object and adds them to list staff = Staff(first_name, last_name, wants_accomodation) - Amity.all_staff.append(staff) - Amity.all_people.append(staff) + self.all_staff.append(staff) + self.all_people.append(staff) allocated_office = self.generate_random_office_spaces() print(staff.person_id) if allocated_office: allocated_office.members.append(staff) # if random room selected - Amity.office_allocations[allocated_office.room_name] = allocated_office.members - print(Fore.GREEN+"You have allocated {} successfully ".format(staff.first_name)) + self.office_allocations[allocated_office.room_name] = allocated_office.members + print(Fore.GREEN+"You have allocated {} successfully to office {}.".format(staff.first_name,allocated_office.room_name)) else: - Amity.office_spaces_waiting_list.append(staff) - print(Fore.RED+"Sorry, no space available {} has been added to the waiting list".format(staff.first_name)) + self.office_spaces_waiting_list.append(staff) + print(Fore.RED+"Sorry, no space available {} has been added to the living space waiting list".format(staff.first_name)) # if wants accomodation elif category is "F": # create fellow object fellow = Fellow(first_name, last_name, wants_accomodation) - Amity.all_people.append(fellow) - Amity.all_fellows.append(fellow) + self.all_people.append(fellow) + self.all_fellows.append(fellow) allocated_office = self.generate_random_office_spaces() print(fellow.person_id) if allocated_office: # if random room selected allocated_office.members.append(fellow) - Amity.office_allocations[allocated_office.room_name] = allocated_office.members - print(Fore.GREEN+"You have allocated {} successfully to {}".format(fellow.first_name,allocated_office.room_name)) + self.office_allocations[allocated_office.room_name] = allocated_office.members + print(Fore.GREEN+"You have allocated {} successfully to office {}".format(fellow.first_name,allocated_office.room_name)) else: - Amity.office_spaces_waiting_list.append(fellow) + self.office_spaces_waiting_list.append(fellow) print(Fore.RED+"Sorry, no space available {} has been added to the waiting list".format(fellow.first_name)) # add living space @@ -130,14 +125,14 @@ def add_person(self, first_name, last_name, category, wants_accomodation='N'): if allocated_living_space: allocated_living_space.members.append(fellow) print(allocated_living_space) - Amity.living_space_allocations[allocated_living_space.room_name] = allocated_living_space.members + self.living_space_allocations[allocated_living_space.room_name] = allocated_living_space.members print(Fore.GREEN+"You have allocated {} successfully to living space {} ".format(fellow.first_name, allocated_living_space.room_name)) else: - Amity.living_spaces_waiting_list.append(fellow) + self.living_spaces_waiting_list.append(fellow) print(Fore.RED+"Sorry, no space available {} has been added to the waiting list".format(fellow.first_name)) else: if category == "S": - print("staff cannot be allocated to living space") + print("Sorry! staff is not entitled to a living space") return "staff cannot be allocated to living space" def get_person(self, person_id): @@ -162,12 +157,7 @@ def get_room(self, room_name): if self.all_rooms: for room in self.all_rooms: if room_name == room.room_name: - room_object = room - - if room_object: - return room_object - else: - return "Room name does not exist" + return room else: return "There are no rooms available" @@ -175,7 +165,7 @@ def get_person_room(self, person_id, room_type): """To return currently allocated room given a valid person id""" result = None if room_type is "O": - for room in list(self.office_allocations.keys()): + for room in self.office_allocations.keys(): if (person_id in [person.person_id for person in self.office_allocations[room]]): # returns room object if person_id match is found result = room @@ -199,35 +189,36 @@ def reallocate_person(self, person_id, new_room_name): print(person_object) return person_object elif person_object == "There are no people in the system.": - print("There are no people in the system. Add person(s) first, then reallocate") + print("There are no people in the system. Add person(s) first to the system, then reallocate") return person_object else: new_room_object = self.get_room(new_room_name) + print(new_room_object) if new_room_object == "Room name does not exist": return "Room name does not exist" elif new_room_object == "There are no rooms available": return "There are no rooms available" else: - if type(person_object) == Staff and type(new_room_object) == LivingSpace: - cprint("Cannot reallocate staff to living space.", "red") + if person_object.category == "STAFF" and new_room_object.room_type == "LIVING_SPACE": + print(Fore.RED + "Cannot reallocate staff to living space.") return "Cannot reallocate staff to living space." - elif type(new_room_object) == Office: + elif new_room_object.room_type == "OFFICE": current_room = self.get_person_room(person_id, "O") if current_room == "Person not allocated to room": # if person has no office - cprint("{} has no current office space,hence cannot reallocate".format(person_object.first_name)) + cprint("{} has no current office space,hence you cannot reallocate".format(person_object.first_name)) return "person has no current office space, hence canot reallocate" elif current_room == new_room_object: print("Cannot reallocate a person to the same room.") return "Cannot reallocate to same room." else: # remove from current office - (self.office_allocations[current_room].remove(person_object)) + self.office_allocations[current_room].remove(person_object) # append to new room - (self.office_allocations[new_room_object].append(person_object)) - print("{} {} has been reallocated from office {} to {}".format(person_object.first_name,person_object.last_name, current_room.room_name,new_room_object.room_name)) + self.office_allocations[new_room_object.room_name].append(person_object) + print(Fore.GREEN + "{} {} has been reallocated from office {} to {}".format(person_object.first_name,person_object.last_name, current_room,new_room_object)) return "Has been reallocated from office" - + def load_people(self, filename): """loads people from a txt file to the app""" with open (filename, 'r') as people_file: @@ -235,52 +226,52 @@ def load_people(self, filename): details = person_details.rstrip().split() accomodate = details[3] if len(details) == 4 else "N" self.add_person(details[0], details[1], details[2], accomodate) - print("Successfully loaded people") + print(Fore.GREEN + "Successfully loaded people to the app.") return "Successfully loaded people" - @staticmethod - def print_allocations(file_name=None): + + def print_allocations(self,file_name=None): """Prints a list of allocations onto the screen""" print(Fore.MAGENTA + "=" * 30 + "\n" + "Office Allocations\n" + "=" *30) - for room in Amity.office_allocations.keys(): + for room in self.office_allocations.keys(): if room != "None": - print (Fore.BLUE + room.upper() + "\n") - for person in Amity.office_allocations[room]: + print ("\n" +Fore.BLUE + room.upper()) + for person in selfre.office_allocations[room]: print(person) - return "office allocations printed successfully" + print(Fore.MAGENTA + "=" * 30 + "\n" + "Living spaces Allocations\n" + "=" *30) - for room in Amity.living_space_allocations.keys(): + for room in self.living_space_allocations.keys(): if room != "None": - print (Fore.BLUE +room.upper() + "\n" + "+" * 30) - for person in Amity.living_space_allocations[room]: + print ("\n" + Fore.BLUE +room.upper() ) + for person in self.living_space_allocations[room]: print(person) - return "Living space allocations printed successfully" + if file_name: nfile = open(file_name + ".txt", "a") - for room in Amity.office_allocations.keys(): + for room in self.office_allocations.keys(): if room != "None": nfile.write("\n"+ room.upper() + "\n"+ "-" *30+ "\n") - for person in Amity.office_allocations[room]: + for person in self.office_allocations[room]: nfile.write(person.full_name.upper()+"\n") - for room in Amity.living_space_allocations.keys(): + for room in self.living_space_allocations.keys(): if room != "None": nfile.write("\n" + room.upper() + "\n" + "-" * 30+ "\n") - for person in Amity.living_space_allocations[room]: + for person in self.living_space_allocations[room]: nfile.write(person.full_name.upper()+"\n") - print("%s.txt written" % file_name) + print("{}.txt has been written".format(file_name)) return "Successfully written the file" - @staticmethod - def print_unallocated(file_name=None): + def print_unallocated(self, file_name=None): """Prints all people not allocated""" - unallocated_offices = Amity.office_spaces_waiting_list - unallocated_living_spaces = Amity.living_spaces_waiting_list + print(Fore.MAGENTA + "=" * 30 + "\n" + "People in office allocation waiting list\n" + "=" * 30) + unallocated_offices = self.office_spaces_waiting_list + unallocated_living_spaces = self.living_spaces_waiting_list for person in unallocated_offices: print(person or "None") - print("=" * 30 + "\n" + "Living Spaces\n" + "=" * 30) + print(Fore.MAGENTA + "=" * 30 + "\n" + "People in Living Space waiting list\n" + "=" * 30) for person in unallocated_living_spaces: print(person or "None") - return person or "None" + # return person or "None" if file_name: file = open(file_name + ".txt", "a") @@ -289,48 +280,51 @@ def print_unallocated(file_name=None): file.write("\n" + person.full_name or "None") for person in unallocated_living_spaces: file.write("\n" + person.full_name or "None") - print("{}.txt written succesfully".format(file_name)) + print(Fore.GREEN + "{}.txt written succesfully".format(file_name)) - @staticmethod - def print_room(room_name): + + def print_room(self, room_name): """ Prints the names of all the people in room_name on the screen.""" - offices = [room for room in Amity.office_allocations if room != "None"] - living_spaces = [room for room in Amity.living_space_allocations if room != "None"] + offices = [room for room in self.office_allocations if room != "None"] + living_spaces = [room for room in self.living_space_allocations if room != "None"] if not offices or not living_spaces: - print("There are no rooms in the system.") + print("There are no rooms existing in the system.") else: if room_name not in offices and room_name not in living_spaces: - print("sorry! the room does not exist") + print(Fore.RED + "sorry! the room does not exist") return "sorry! the room does not exist" else: - print("=" * 30 + "\n Members \n" + "=" * 30) + print(Fore.MAGENTA + "=" * 30 + "\n Members \n" + "=" * 30) if room_name in offices: - for person in Amity.office_allocations[room_name]: + for person in self.office_allocations[room_name]: print(person) elif room_name in living_spaces: - for person in Amity.living_space_allocations[room_name]: + for person in self.living_space_allocations[room_name]: print(person) def load_state(self, db_name): + """loads people to the app""" # connect to the db provided - self.db_name = db_name + '.db' - self.engine = create_engine('sqlite:///' + self.db_name) - Base.metadata.bind = self.engine - # query all rooms and people - SessionMaker = sessionmaker(bind=self.engine) - session = SessionMaker() - people = session.query(Person).all() - rooms = session.query(Room).all() - # save them to the current Amity instance - for room in rooms: - Amity.all_rooms.append(room) - for person in people: - Amity.all_people.append(people) - print(Fore.GREEN + "Data from {} loaded to the app.".format(db_name)) - return "Successfully loaded people to the app" + if os.path.exists(db_name + ".db"): + self.engine = create_engine('sqlite:///' + db_name + ".db") + Base.metadata.bind = self.engine + # query all rooms and people + SessionMaker = sessionmaker(bind=self.engine) + session = SessionMaker() + people = session.query(Person).all() + rooms = session.query(Room).all() + # save them to the current Amity instance + for room in rooms: + self.create_room(room.room_type[0],[room.name]) + for person in people: + self.add_person(person.first_name, person.last_name, person.category, person.wants_accomodation) + print(Fore.GREEN + "Data from {} loaded to the app.".format(db_name)) + return "Successfully loaded people to the app" + else: + print(Fore.RED + "sorry db does not exist") + - def save_state(self, db_name): # create a db called db_name @@ -359,62 +353,11 @@ def save_state(self, db_name): for person in self.all_people: wants_accomodation = True if person.wants_accomodation == "Y" else False print(person, person.wants_accomodation) - new_person = Person(id=person.person_id, name=person.full_name, category=person.category, wants_accomodation=wants_accomodation) + new_person = Person(id=person.person_id, first_name=person.first_name, last_name=person.last_name, category=person.category, wants_accomodation=wants_accomodation) people.append(new_person) # self.session.update(new_person) self.session.add_all(people) self.session.commit() + print(Fore.GREEN +"Successfully saved people") + return("successfully saved people") - -# space = Amity() -# # # # space.create_room('O', ["MyRoom"]) -# space.create_room('O', ['VaLhAla']) -# space.create_room('L', ['valhala_']) -# space.create_room('L', ['Ruby']) - -# # space.add_person('faith', 'dede', 'F', 'Y') -# # space.add_person('faith', 'dede', 'F', 'Y') -# # space.add_person('faith', 'dede', 'F', 'Y') -# # space.add_person('faith', 'dede', 'F', 'Y') -# # space.add_person('faith', 'dede', 'F', 'Y') -# # space.add_person('faith', 'dede', 'F', 'Y') -# # space.add_person('faith', 'dede', 'F', 'Y') -# # space.add_person('faith', 'dede', 'F', 'Y') -# space.add_person('faith', 'dede', 'S', 'N') -# space.add_person('faith', 'dede', 'F', 'Y') -# # space.add_person('fath', 'dee', 'F') -# space.add_person('ndVKGungu', 'kevGBin', 'S', 'Y') -# # space.add_person('fSSWnjh', 'deme', 'F', 'Y') -# space.add_person('fkFFjh', 'dHHVme', 'F', 'N') -# # space.add_person('fAAADA', 'demBGe', 'F', 'Y') -# # space.add_person('fkjnSSjh', 'deEme', 'F', 'Y') - - - - - - - - - -# # space.reallocate_person('faith', 'dede', 'L', 'valhala') -# # print(Amity.living_spaces) -# # print(Amity.office_spaces) -# # print(space.reallocate_person('faith', 'dede', 'L', 'valhala')) -# # print(Amity.living_spaces) -# # print(Amity.all_rooms) -# # space = Amity() -# # space.add_person('faith', 'dede', 'F', 'Y') - -# # ******************* - -# # space.load_people("people.txt") -# # space.save_state("faha") -# # space.print_allocations('non-sense') -# # space.print_unallocated() -# # space.print_room('valhala_') -# space.load_state("faha") - -# # ******************* - -# # print(Amity.living_spaces) \ No newline at end of file From 89058ff5486d764a29fd49c78182a174104fe687 Mon Sep 17 00:00:00 2001 From: faithngetich Date: Wed, 26 Apr 2017 23:56:34 +0300 Subject: [PATCH 42/52] [chore] Add docstrings --- tests/test_amity.py | 57 +++++++++------------------------------------ 1 file changed, 11 insertions(+), 46 deletions(-) diff --git a/tests/test_amity.py b/tests/test_amity.py index 841b166..73d2983 100644 --- a/tests/test_amity.py +++ b/tests/test_amity.py @@ -8,34 +8,30 @@ class Amitytest(unittest.TestCase): def setUp(self): + """To set up test variables.""" self.amity = Amity() self.db_name = "faha" def tearDown(self): + """To free variables for fresh use in other tests.""" if os.path.exists(self.db_name + ".db"): os.remove(self.db_name + ".db") del self.amity - # self.amity.all_fellows = [] - # self.all_fellows = [] - # self.all_rooms = [] - # self.office_allocations = {} - # self.living_space_allocations = {} - # self.all_people = [] - # self.living_spaces_waiting_list = [] - # self.office_spaces_waiting_list = [] - def test_create_room_adds_room_succesfully(self): + """To test if create_room adds office(s) successfully.""" self.amity.create_room('O', ['Krypton']) self.assertIn('KRYPTON', [room.room_name.upper() for room in self.amity.all_rooms]) def test_add_person_adds_fellow_to_list(self): + """To test if fellow is added to fellow list""" all_fellows = len(self.amity.all_fellows) + 1 self.amity.add_person('dede','faith','F','N') self.assertEqual(len(self.amity.all_fellows), all_fellows, msg = "fellow not added") def test_add_person_adds_staff_to_list(self): + """To test if staff is added to staff list""" all_staff = len(self.amity.all_staff) + 1 self.amity.add_person('ded','fai','S','N') self.assertEqual(len(self.amity.all_staff), all_staff, msg = "staff not added") @@ -83,6 +79,7 @@ def test_if_person_is_added_to_livingspace(self): def test_fellow_does_not_want_accomodation(self): + """To test if fellow does not want accomodation""" self.amity.add_person('dedeh', 'fagh', 'F', 'N') self.assertFalse('dedeh' in self.amity.living_space_allocations, msg = 'fellow does not want accomodation') @@ -98,7 +95,6 @@ def test_add_person_adds_people_to_waiting_list_if_office_is_full(self): self.amity.add_person("Stella", "Storl", "S", "N") self.assertFalse('stella' in self.amity.office_allocations, msg = "person not reallocated succesfully to office") - def test_add_person_adds_fellows_to_living_space_waiting_list(self): """To test if add_person caters for excess people. Adds fellow to living space waiting list when offices are full. @@ -114,17 +110,14 @@ def test_add_person_adds_fellows_to_living_space_waiting_list(self): def test_print_room_does_not_print_inexistent_room(self): """To test if method prints rooms and occupants successfully.""" room_name = "I don't exist!!!" - self.assertEqual(self.amity.print_room(room_name),"sorry! the room does not exist") + self.assertEqual(self.amity.print_room(room_name),None) def test_print_unallocated_returns_all_not_in_accomodation_list(self): + """"To test print unallocated works""" self.amity.print_unallocated('') self.assertFalse('Dan' in self.amity.office_allocations, msg = "person not in accomodation list") - def test_print_rooms_returns_names(self): - self.amity.add_person('collins', 'star', 'S' 'N') - self.amity.print_room('Krypton') - self.assertFalse('dede'in self.amity.print_room('krypton')) - + def test_print_allocations_prints_successfully_to_screen(self): """To test if method prints allocations to screen.""" self.amity.create_room("O", ["Narnia"]) @@ -152,35 +145,7 @@ def test_load_state(self): self.amity.add_person("Fell", "Dl", "S", "Y") self.amity.save_state(self.db_name) self.assertEqual(self.amity.load_state(self.db_name), "Successfully loaded people to the app") - - - # def test_fellow_wants_accomodation(self): - # self.amity.create_room('O', ['bur']) - # self.amity.create_room('L', ['narnia']) - # self.amity.add_person('dede', 'fauz', 'F', 'Y') - # # print(self.amity.living_space_allocations['narnia'][0]) - # # print("DEDE" in self.amity.living_space_allocations['narnia']) - # self.assertTrue('dede' in self.amity.living_space_allocations, msg = 'fellow not in accomodation list') - - # self.assertFalse('dede' not in self.amity.accomodation_list, msg = 'fellow should be in the accomodation list') - # self.amity.add_person('dede', 'fellow', 'wants_accomodation = Y') - # self.assertRaises("Fellow already exists") - - # self.amity.create_room('O', 'valhalla') - # self.amity.reallocate_person('dede', 'fat', 'O', 'valhalla') - # self.assertIn('DEDE', 'FAT', self.amity.allocated_rooms['VALHALLA']) - - # def test_if_room_is_office(self): - # self.amity.create_room('office', 'hogwarts') - # #self.assertEqual(hogwarts.room_capacity, 6) - # offices1 = len(self.amity.offices) + 1 - # self.assertEqual(len(self.amity.offices), offices1, msg = "livingroom is not added succesfully") - - - - - -if __name__ == '__main__': - unittest.main() +if __name__ == '__main__': + unittest.main() \ No newline at end of file From 56e745ba054286ff9e2ff24297e8ab0c701f9158 Mon Sep 17 00:00:00 2001 From: faithngetich Date: Thu, 27 Apr 2017 00:06:45 +0300 Subject: [PATCH 43/52] [chore] Add docstrings --- views.py | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/views.py b/views.py index 1146e5c..06d98d6 100644 --- a/views.py +++ b/views.py @@ -13,7 +13,21 @@ class Amity(object): + """all_staff - is a list of staff objects names + + all_fellows - list of fellows object names + + office_allocations - dictionary with room names as keys and occupants list as It's value + + living_spaces_allocations - dictionary with room names as keys and occupants list as It's value + + all_people - has people's names + + living_spaces_waiting_list - Has people with no office spaces + + office_spaces_waiting_list - Has people with no living space spaces""" def __init__(self): + """initialize the class objects""" self.all_staff = [] self.all_fellows = [] self.all_rooms = [] @@ -236,7 +250,7 @@ def print_allocations(self,file_name=None): for room in self.office_allocations.keys(): if room != "None": print ("\n" +Fore.BLUE + room.upper()) - for person in selfre.office_allocations[room]: + for person in self.office_allocations[room]: print(person) print(Fore.MAGENTA + "=" * 30 + "\n" + "Living spaces Allocations\n" + "=" *30) @@ -245,7 +259,7 @@ def print_allocations(self,file_name=None): print ("\n" + Fore.BLUE +room.upper() ) for person in self.living_space_allocations[room]: print(person) - + if file_name: nfile = open(file_name + ".txt", "a") for room in self.office_allocations.keys(): @@ -260,6 +274,7 @@ def print_allocations(self,file_name=None): nfile.write(person.full_name.upper()+"\n") print("{}.txt has been written".format(file_name)) return "Successfully written the file" + return "office allocations printed successfully" def print_unallocated(self, file_name=None): """Prints all people not allocated""" @@ -327,6 +342,7 @@ def load_state(self, db_name): def save_state(self, db_name): + """Persists app data into the given db""" # create a db called db_name self.db_name = db_name + '.db' self.engine = create_engine('sqlite:///' + self.db_name) From e9a02c93b96ef7856c0c641ceeb6a1419eaecda3 Mon Sep 17 00:00:00 2001 From: faithngetich Date: Thu, 27 Apr 2017 22:38:06 +0300 Subject: [PATCH 44/52] [chore] Delete unused files --- .gitignore | 2 + non-sense.txt | 0 people.txt | 14 +++--- tests/test_amity.py | 2 +- views.py | 115 ++++++++++++++++++++------------------------ 5 files changed, 63 insertions(+), 70 deletions(-) delete mode 100644 non-sense.txt diff --git a/.gitignore b/.gitignore index 82f8525..ef8bde7 100644 --- a/.gitignore +++ b/.gitignore @@ -6,6 +6,7 @@ __pycache__/ # C extensions *.so + # Distribution / packaging .Python env/ @@ -44,6 +45,7 @@ nosetests.xml coverage.xml *,cover .hypothesis/ +cover/ # Translations *.mo diff --git a/non-sense.txt b/non-sense.txt deleted file mode 100644 index e69de29..0000000 diff --git a/people.txt b/people.txt index 6b519a0..cf52e4b 100644 --- a/people.txt +++ b/people.txt @@ -1,11 +1,11 @@ -JONATHAN NGONDI S O -AHMED YUSUB F O -EPRAHIM KIMANI F L -FAITH DEDE S O +JONATHAN NGONDI S Y +AHMED YUSUB F N +EPRAHIM KIMANI F N +FAITH DEDE S N OLUWAFEMI SULE F Y -DOMINIC WALTERS S +DOMINIC WALTERS S N SIMON PATTERSON F Y MARI LAWRENCE F Y -LEIGH RILEY S +LEIGH RILEY S N TANA LOPEZ F Y -KELLY McGUIRE S +KELLY McGUIRE S N diff --git a/tests/test_amity.py b/tests/test_amity.py index 73d2983..08cbec0 100644 --- a/tests/test_amity.py +++ b/tests/test_amity.py @@ -93,7 +93,7 @@ def test_add_person_adds_people_to_waiting_list_if_office_is_full(self): self.amity.add_person("David", "White", "S", "N") self.amity.add_person("Xie", "Yuen", "S", "N") self.amity.add_person("Stella", "Storl", "S", "N") - self.assertFalse('stella' in self.amity.office_allocations, msg = "person not reallocated succesfully to office") + self.assertFalse('stella' in self.amity.office_allocations, msg = "person not allocated succesfully to office") def test_add_person_adds_fellows_to_living_space_waiting_list(self): """To test if add_person caters for excess people. diff --git a/views.py b/views.py index 06d98d6..71a0ff1 100644 --- a/views.py +++ b/views.py @@ -41,8 +41,8 @@ def create_room(self, room_type, list_of_rooms): """creates a specified room""" for name in list_of_rooms: - if name in [room.room_name.upper() for room in self.all_rooms]: - print("sorry,{} room already exist.".format(name.upper())) + if name.upper() in [room.room_name.upper() for room in self.all_rooms]: + print(Fore.RED + "sorry! the room {} already exist.".format(name.upper())) else: if room_type.upper() == 'O': office = Office(name) @@ -55,7 +55,7 @@ def create_room(self, room_type, list_of_rooms): self.living_space_allocations[living_space.room_name] = [] print(Fore.GREEN + "Living space {} successfully created.".format(living_space.room_name.upper())) else: - print("please specify the room_type you would like to create.") + print(Fore."please specify the room_type you would like to create.") def generate_random_office_spaces(self): """Generates random office""" @@ -75,7 +75,7 @@ def generate_random_living_spaces(self): living_spaces = [room for room in self.all_rooms if room.room_type == "LIVING_SPACE"] available_living_space = [] for living_space in living_spaces: - if len(self.living_space_allocations[living_space.room_name]) < 6: + if len(self.living_space_allocations[living_space.room_name]) < 4: available_living_space.append(living_space) if available_living_space: selected_room = random.choice(available_living_space) @@ -83,10 +83,10 @@ def generate_random_living_spaces(self): selected_room = None return selected_room + def add_person(self, first_name, last_name, category, wants_accomodation='N'): - """Adds person to self and randomly allocates the person""" - if wants_accomodation == "N" : - if category is "F": + """Adds person to self and randomly allocates the person""" + if category == "F" : # create fellow object and adds them to fellow list fellow = Fellow(first_name, last_name, wants_accomodation) self.all_people.append(fellow) @@ -100,8 +100,22 @@ def add_person(self, first_name, last_name, category, wants_accomodation='N'): print(Fore.GREEN +"You have allocated {} successfully to office {}".format(fellow.first_name,allocated_office.room_name)) else: self.office_spaces_waiting_list.append(fellow) - print("Sorry, no space available {} has been added to the office waiting list".format(fellow.first_name)) - else: + print(Fore.RED + "Sorry, no space available {} has been added to the office waiting list".format(fellow.first_name)) + + if wants_accomodation == 'Y': + # add living space + allocated_living_space = self.generate_random_living_spaces() + if allocated_living_space: + allocated_living_space.members.append(fellow) + self.living_space_allocations[allocated_living_space.room_name] = allocated_living_space.members + print(Fore.GREEN+"You have allocated {} successfully to living space {} ".format(fellow.first_name, allocated_living_space.room_name)) + else: + self.living_spaces_waiting_list.append(fellow) + print(Fore.RED+"Sorry, no space available {} has been added to the living space waiting list".format(fellow.first_name)) + + elif category == "S" : + + # create fellow object and adds them to fellow list # create staff object and adds them to list staff = Staff(first_name, last_name, wants_accomodation) self.all_staff.append(staff) @@ -115,40 +129,13 @@ def add_person(self, first_name, last_name, category, wants_accomodation='N'): print(Fore.GREEN+"You have allocated {} successfully to office {}.".format(staff.first_name,allocated_office.room_name)) else: self.office_spaces_waiting_list.append(staff) - print(Fore.RED+"Sorry, no space available {} has been added to the living space waiting list".format(staff.first_name)) - - # if wants accomodation - elif category is "F": - # create fellow object - fellow = Fellow(first_name, last_name, wants_accomodation) - self.all_people.append(fellow) - self.all_fellows.append(fellow) - allocated_office = self.generate_random_office_spaces() - print(fellow.person_id) - if allocated_office: - # if random room selected - allocated_office.members.append(fellow) - self.office_allocations[allocated_office.room_name] = allocated_office.members - print(Fore.GREEN+"You have allocated {} successfully to office {}".format(fellow.first_name,allocated_office.room_name)) - else: - self.office_spaces_waiting_list.append(fellow) - print(Fore.RED+"Sorry, no space available {} has been added to the waiting list".format(fellow.first_name)) - - # add living space - allocated_living_space = self.generate_random_living_spaces() - if allocated_living_space: - allocated_living_space.members.append(fellow) - print(allocated_living_space) - self.living_space_allocations[allocated_living_space.room_name] = allocated_living_space.members - print(Fore.GREEN+"You have allocated {} successfully to living space {} ".format(fellow.first_name, allocated_living_space.room_name)) - else: - self.living_spaces_waiting_list.append(fellow) - print(Fore.RED+"Sorry, no space available {} has been added to the waiting list".format(fellow.first_name)) - else: - if category == "S": - print("Sorry! staff is not entitled to a living space") - return "staff cannot be allocated to living space" - + print(Fore.RED+"Sorry, no space available {} has been added to the waiting list".format(staff.first_name)) + + if wants_accomodation == 'Y': + print(Fore.RED + "Sorry! staff is not entitled to a living space") + return "staff cannot be allocated to living space" + + def get_person(self, person_id): """To return person object given person id.""" person_object = None @@ -167,13 +154,11 @@ def get_person(self, person_id): def get_room(self, room_name): """To return room object given room name""" - room_object = None if self.all_rooms: for room in self.all_rooms: - if room_name == room.room_name: + if room.room_name.upper() == room_name.upper(): return room - else: - return "There are no rooms available" + return ("Room does not exist") def get_person_room(self, person_id, room_type): """To return currently allocated room given a valid person id""" @@ -203,27 +188,29 @@ def reallocate_person(self, person_id, new_room_name): print(person_object) return person_object elif person_object == "There are no people in the system.": - print("There are no people in the system. Add person(s) first to the system, then reallocate") + print(Fore.RED + "Sorry!There are no people in the system. Add person(s) first to the system, then reallocate") return person_object else: new_room_object = self.get_room(new_room_name) - print(new_room_object) - if new_room_object == "Room name does not exist": + if new_room_object == "Room does not exist": + print(Fore.RED + "Room name does not exist") return "Room name does not exist" - elif new_room_object == "There are no rooms available": - return "There are no rooms available" else: if person_object.category == "STAFF" and new_room_object.room_type == "LIVING_SPACE": print(Fore.RED + "Cannot reallocate staff to living space.") return "Cannot reallocate staff to living space." elif new_room_object.room_type == "OFFICE": current_room = self.get_person_room(person_id, "O") - if current_room == "Person not allocated to room": + if current_room == new_room_object.room_name: + # if person has no office + print(Fore.RED + "{} is already allocated to {}".format(person_object.first_name, new_room_object.room_name)) + return "person ca not be reallocated to a room the person is allocated to" + elif current_room == "Person not allocated to room": # if person has no office - cprint("{} has no current office space,hence you cannot reallocate".format(person_object.first_name)) + print(Fore.YELLOW + "{} has no current office space,hence you cannot reallocate".format(person_object.first_name)) return "person has no current office space, hence canot reallocate" elif current_room == new_room_object: - print("Cannot reallocate a person to the same room.") + print(Fore.RED + "Cannot reallocate a person to the same room.") return "Cannot reallocate to same room." else: # remove from current office @@ -235,13 +222,17 @@ def reallocate_person(self, person_id, new_room_name): def load_people(self, filename): """loads people from a txt file to the app""" - with open (filename, 'r') as people_file: - for person_details in people_file: - details = person_details.rstrip().split() - accomodate = details[3] if len(details) == 4 else "N" - self.add_person(details[0], details[1], details[2], accomodate) - print(Fore.GREEN + "Successfully loaded people to the app.") - return "Successfully loaded people" + try: + with open (filename, 'r') as people_file: + for person_details in people_file: + details = person_details.rstrip().split() + accomodate = details[3] if len(details) == 4 else "N" + self.add_person(details[0], details[1], details[2], accomodate) + print(Fore.GREEN + "Successfully loaded {} to the app.".format(details[0])) + return "Successfully finished loading people" + except FileNotFoundError: + print(Fore.RED + 'file not found!') + return ('file not found') def print_allocations(self,file_name=None): From d05ad1b66e2f43d92c151afcd0301db938fe8234 Mon Sep 17 00:00:00 2001 From: faithngetich Date: Tue, 2 May 2017 00:12:48 +0300 Subject: [PATCH 45/52] [chore] Add a delete employee method --- views.py | 72 ++++++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 62 insertions(+), 10 deletions(-) diff --git a/views.py b/views.py index 71a0ff1..62f64b4 100644 --- a/views.py +++ b/views.py @@ -55,7 +55,7 @@ def create_room(self, room_type, list_of_rooms): self.living_space_allocations[living_space.room_name] = [] print(Fore.GREEN + "Living space {} successfully created.".format(living_space.room_name.upper())) else: - print(Fore."please specify the room_type you would like to create.") + print(Fore.YELLOW + "please specify the room_type you would like to create.") def generate_random_office_spaces(self): """Generates random office""" @@ -177,8 +177,7 @@ def get_person_room(self, person_id, room_type): return result else: return "Person not allocated to room" - - + def reallocate_person(self, person_id, new_room_name): """ moves person from one room to another room""" # gets person object from person id @@ -216,10 +215,61 @@ def reallocate_person(self, person_id, new_room_name): # remove from current office self.office_allocations[current_room].remove(person_object) # append to new room - self.office_allocations[new_room_object.room_name].append(person_object) - print(Fore.GREEN + "{} {} has been reallocated from office {} to {}".format(person_object.first_name,person_object.last_name, current_room,new_room_object)) - return "Has been reallocated from office" - + if len(self.office_allocations[new_room_object.room_name]) < 6: + self.office_allocations[new_room_object.room_name].append(person_object) + print(Fore.GREEN + "{} {} has been reallocated from office {} to {}".format(person_object.first_name,person_object.last_name, current_room,new_room_object)) + return "Has been reallocated from office" + else: + print(Fore.YELLOW + "Sorry!, the room is full") + + def delete_employee(self, person_id): + person_object = self.get_person(person_id) + if person_object == "Invalid person id": + # prints id does not exist + print(person_object) + return person_object + for person_object in self.all_fellows: + if person_object in self.all_fellows: + self.all_fellows.remove(person_object) + print("{} {} deleted".format(person_object.first_name,person_object.last_name)) + + # delete name name if name exists + if person_object in self.office_spaces_waiting_list: + self.office_spaces_waiting_list.remove(person_object) + print(Fore.GREEN + "{} deleted from unallocated space".format(person_object.first_name,person_object.last_name)) + return "deleted from unallocated space" + elif person_object in self.office_allocations: + self.office_allocations[name].remove(person_object) + # self.office[name].occupants.remove(full_name) + print(Fore.GREEN + "{} deleted from office space".format(person_object.first_name,person_object.last_name)) + + if person_object in self.all_fellows: + if person_object in self.living_space_allocations: + self.all_fellows.remove(person_object) + # delete name name if name exists else return none + self.living_space_allocations[person_object].occupants.remove(person_object) + self.all_fellows.remove(person_object) + print(Fore.GREEN +"{} {} deleted from living space".format(fperson_object.first_name,person_object.last_name)) + return "deleted from living_space" + if person_object in self.living_spaces_waiting_list: + self.living_spaces_waiting_list.remove(person_object) + print(Fore.GREEN +"{} {} deleted from unallocated living space".format.first_name,person_object.last_name) + + print(Fore.GREEN + "{} {} has been deleted from Amity".format(person_object.first_name,person_object.last_name)) + return "fellow deleted" + for person_object in self.all_staff: + if person_object in self.all_staff: + if person_object in self.office_spaces_waiting_list: + self.staff.remove(person_object) + # delete name name if name exists else return none + self.office_spaces_waiting_list.pop(person_object) + if person_object in self.office: + self.office_allocations[person_object].occupants.remove(person_object) + print(Fore.GREEN + "{} {} has been deleted from the system".format(person_object.first_name,person_object.last_name)) + + return "staff deleted" + + def load_people(self, filename): """loads people from a txt file to the app""" try: @@ -242,14 +292,14 @@ def print_allocations(self,file_name=None): if room != "None": print ("\n" +Fore.BLUE + room.upper()) for person in self.office_allocations[room]: - print(person) + print(person.person_id, person) print(Fore.MAGENTA + "=" * 30 + "\n" + "Living spaces Allocations\n" + "=" *30) for room in self.living_space_allocations.keys(): if room != "None": print ("\n" + Fore.BLUE +room.upper() ) for person in self.living_space_allocations[room]: - print(person) + print(person.person_id, person ) if file_name: nfile = open(file_name + ".txt", "a") @@ -266,6 +316,8 @@ def print_allocations(self,file_name=None): print("{}.txt has been written".format(file_name)) return "Successfully written the file" return "office allocations printed successfully" + + def print_unallocated(self, file_name=None): """Prints all people not allocated""" @@ -295,7 +347,7 @@ def print_room(self, room_name): offices = [room for room in self.office_allocations if room != "None"] living_spaces = [room for room in self.living_space_allocations if room != "None"] if not offices or not living_spaces: - print("There are no rooms existing in the system.") + print(Fore.YELLOW + "There are no rooms existing in the system.") else: if room_name not in offices and room_name not in living_spaces: print(Fore.RED + "sorry! the room does not exist") From 0735b7e55c33da8a5fbee6933ab786cde52af05e Mon Sep 17 00:00:00 2001 From: faithngetich Date: Tue, 2 May 2017 00:13:26 +0300 Subject: [PATCH 46/52] [chore] Add a delete rooms method --- views.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/views.py b/views.py index 62f64b4..5017b34 100644 --- a/views.py +++ b/views.py @@ -269,6 +269,15 @@ def delete_employee(self, person_id): return "staff deleted" + def delete_rooms(self, room_name): + room_object = self.get_room + if room_object == "Room does not exist": + print(room_object) + return room_object + for room_object in self.all_rooms: + self.all_rooms.remove(room_object) + print(Fore.GREEN + "{} has been deleted".format(room_object.room_name)) + return 'room deleted ' def load_people(self, filename): """loads people from a txt file to the app""" From efee5b6183b3e2db7e790ee22d0549127170c858 Mon Sep 17 00:00:00 2001 From: faithngetich Date: Tue, 2 May 2017 00:14:55 +0300 Subject: [PATCH 47/52] [chore] Name test methods correctly --- tests/test_amity.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/tests/test_amity.py b/tests/test_amity.py index 08cbec0..476e543 100644 --- a/tests/test_amity.py +++ b/tests/test_amity.py @@ -18,7 +18,7 @@ def tearDown(self): os.remove(self.db_name + ".db") del self.amity - def test_create_room_adds_room_succesfully(self): + def test_create_room(self): """To test if create_room adds office(s) successfully.""" self.amity.create_room('O', ['Krypton']) self.assertIn('KRYPTON', [room.room_name.upper() for room in self.amity.all_rooms]) @@ -44,12 +44,12 @@ def test_staff_not_in_accomodation_list(self): self.assertNotEqual(len(self.amity.living_space_allocations['bonivile']), new_staff, msg = "staff cannot be allocated to living space") - def test_office_is_created_successfully(self): + def test_office_is_created(self): """Tests offices are created""" self.amity.create_room('O', ['Krypto']) self.assertTrue('Krypto' in self.amity.office_allocations.keys()) - def test_living_space_is_created_successfully(self): + def test_living_space_is_created(self): """Tests living space are created""" self.amity.create_room('L', ['Krpto']) self.assertTrue('Krpto' in self.amity.living_space_allocations.keys()) @@ -83,7 +83,7 @@ def test_fellow_does_not_want_accomodation(self): self.amity.add_person('dedeh', 'fagh', 'F', 'N') self.assertFalse('dedeh' in self.amity.living_space_allocations, msg = 'fellow does not want accomodation') - def test_add_person_adds_people_to_waiting_list_if_office_is_full(self): + def test_add_person_adds_people_to_waiting_list(self): """To test if add_person caters for excess people. Adds fellow/staff to office waiting list when offices are full. """ @@ -95,7 +95,7 @@ def test_add_person_adds_people_to_waiting_list_if_office_is_full(self): self.amity.add_person("Stella", "Storl", "S", "N") self.assertFalse('stella' in self.amity.office_allocations, msg = "person not allocated succesfully to office") - def test_add_person_adds_fellows_to_living_space_waiting_list(self): + def test_add_person_adds_fellows(self): """To test if add_person caters for excess people. Adds fellow to living space waiting list when offices are full. """ @@ -107,18 +107,18 @@ def test_add_person_adds_fellows_to_living_space_waiting_list(self): # self.amity.add_person("Stella", "Storl", "S", "Y") self.assertFalse('stella' in self.amity.living_space_allocations, msg = "person not reallocated succesfully to living space") - def test_print_room_does_not_print_inexistent_room(self): + def test_print_room_does_not_print(self): """To test if method prints rooms and occupants successfully.""" room_name = "I don't exist!!!" self.assertEqual(self.amity.print_room(room_name),None) - def test_print_unallocated_returns_all_not_in_accomodation_list(self): + def test_print_unallocated(self): """"To test print unallocated works""" self.amity.print_unallocated('') self.assertFalse('Dan' in self.amity.office_allocations, msg = "person not in accomodation list") - def test_print_allocations_prints_successfully_to_screen(self): + def test_print_allocations_prints(self): """To test if method prints allocations to screen.""" self.amity.create_room("O", ["Narnia"]) self.amity.create_room("living_space", ["Python"]) From 6668ed84b28c2a7e34cd24028df7e156b3accdd4 Mon Sep 17 00:00:00 2001 From: faithngetich Date: Tue, 2 May 2017 00:21:12 +0300 Subject: [PATCH 48/52] [chore] Add missing methods --- app.py | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/app.py b/app.py index a9db68f..c97224b 100644 --- a/app.py +++ b/app.py @@ -2,7 +2,9 @@ """ Usage: amity create_room (O|L) ... + amity delete_rooms(args['']) amity add_person (F | S) [--wants_accomodation=value] + amity delete_employee(int(args[''])) amity print_allocations [-output=] amity reallocate_person amity print_room @@ -110,7 +112,7 @@ def do_reallocate_person(self, args): args[''])) @docopt_cmd - def do_save_state(self, args): + def save_state(self, args): """Persists app data into the given db Usage: save_state (--db_name=sqlite_db) """ @@ -134,6 +136,22 @@ def do_print_allocations(self, args): """ filename = args["--o"] or "" amity.print_allocations(filename) + + @docopt_cmd + def do_delete_employee(self, args): + """Usage: delete_employee """ + if args[""].isalpha(): + print("person id cannot be string") + return + else: + (amity.delete_employee(int(args['']))) + + @docopt_cmd + def do_delete_rooms(self, args): + """Usage: delete_room """ + amity.delete_rooms(args['']) + + @docopt_cmd def do_load_state(self, arg): """ From e7128321a9556887a4bf17cda5034a9a5e90a25a Mon Sep 17 00:00:00 2001 From: faithngetich Date: Tue, 2 May 2017 00:21:44 +0300 Subject: [PATCH 49/52] [chore] Refactor code --- ingine.txt | 0 models/rooms.py | 1 + 2 files changed, 1 insertion(+) delete mode 100644 ingine.txt diff --git a/ingine.txt b/ingine.txt deleted file mode 100644 index e69de29..0000000 diff --git a/models/rooms.py b/models/rooms.py index fe0b11c..c4b77e8 100644 --- a/models/rooms.py +++ b/models/rooms.py @@ -3,6 +3,7 @@ def __init__(self, room_name): self.room_id = id(self) self.room_name = room_name self.members = [] + self.room_capacity = 0 def __str__(self): """To make the class human readable.""" From e43c46ba17be813bb28c9d50e36ab64ec1795031 Mon Sep 17 00:00:00 2001 From: faithngetich Date: Tue, 2 May 2017 00:23:31 +0300 Subject: [PATCH 50/52] [chore] Remove unused space --- app.py | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/app.py b/app.py index c97224b..2e8e174 100644 --- a/app.py +++ b/app.py @@ -74,19 +74,12 @@ class AmitySystem(cmd.Cmd): @docopt_cmd def do_create_room(self, args): """Usage: create_room (O|L) ...""" - # rooms = args[""] - # types = args["(O|L)"] - # for room in rooms: - # r_type = types[rooms.index(room)] - # amity.create_room(r_type) - room_type = None if args["O"].upper() == 'O': room_type = "O" else: room_type = "L" amity.create_room(room_type, args[""]) - # print(args[""]) @docopt_cmd def do_add_person(self, args): @@ -118,16 +111,12 @@ def save_state(self, args): """ db = args['--db_name'] amity.save_state(db) - # if db: - # else: - # amity.save_state(args['--db_name']) @docopt_cmd def do_print_unallocated(self, args): """Usage: print_unallocated [--file=text_file]""" amity.print_unallocated(args['--file']) - @docopt_cmd def do_print_allocations(self, args): """ @@ -151,7 +140,6 @@ def do_delete_rooms(self, args): """Usage: delete_room """ amity.delete_rooms(args['']) - @docopt_cmd def do_load_state(self, arg): """ @@ -165,7 +153,6 @@ def do_load_people(self, args): """Usage: load_state """ amity.load_people(args[""]) - @docopt_cmd def do_print_room(self, args): """Usage: print_room """ @@ -183,15 +170,12 @@ def do_load_people(self, args): """Usage: load_state """ amity.load_people(args[""]) - - def do_quit(self, arg): """Quits out of Interactive Mode.""" print('Thank you for using Amity. Adios!') exit() - opt = docopt(__doc__, sys.argv[1:]) if opt['--interactive']: From ee58988bb62d5fb620b30234d77cbde403b399ca Mon Sep 17 00:00:00 2001 From: faithngetich Date: Tue, 2 May 2017 14:15:28 +0300 Subject: [PATCH 51/52] [chore] Refactor delete methods --- app.py | 14 +++++--- views.py | 108 +++++++++++++++++++++++++++++-------------------------- 2 files changed, 67 insertions(+), 55 deletions(-) diff --git a/app.py b/app.py index 2e8e174..7da00eb 100644 --- a/app.py +++ b/app.py @@ -61,9 +61,7 @@ def intro(): 'blue', attrs=['bold']) print("Welcome to Amity! Here is a list of commands to get you started." + " Type 'help' anytime to access documented commands") - print("\n\n\n\n\n") - # print(amity) - # print(amity.__dict__) + print("\n\n") cprint(__doc__, 'magenta') @@ -80,6 +78,7 @@ def do_create_room(self, args): else: room_type = "L" amity.create_room(room_type, args[""]) + @docopt_cmd def do_add_person(self, args): @@ -105,13 +104,13 @@ def do_reallocate_person(self, args): args[''])) @docopt_cmd - def save_state(self, args): + def do_save_state(self, args): """Persists app data into the given db Usage: save_state (--db_name=sqlite_db) """ db = args['--db_name'] amity.save_state(db) - + @docopt_cmd def do_print_unallocated(self, args): """Usage: print_unallocated [--file=text_file]""" @@ -140,6 +139,7 @@ def do_delete_rooms(self, args): """Usage: delete_room """ amity.delete_rooms(args['']) + @docopt_cmd def do_load_state(self, arg): """ @@ -153,6 +153,7 @@ def do_load_people(self, args): """Usage: load_state """ amity.load_people(args[""]) + @docopt_cmd def do_print_room(self, args): """Usage: print_room """ @@ -170,12 +171,15 @@ def do_load_people(self, args): """Usage: load_state """ amity.load_people(args[""]) + + def do_quit(self, arg): """Quits out of Interactive Mode.""" print('Thank you for using Amity. Adios!') exit() + opt = docopt(__doc__, sys.argv[1:]) if opt['--interactive']: diff --git a/views.py b/views.py index 5017b34..9e22016 100644 --- a/views.py +++ b/views.py @@ -100,7 +100,7 @@ def add_person(self, first_name, last_name, category, wants_accomodation='N'): print(Fore.GREEN +"You have allocated {} successfully to office {}".format(fellow.first_name,allocated_office.room_name)) else: self.office_spaces_waiting_list.append(fellow) - print(Fore.RED + "Sorry, no space available {} has been added to the office waiting list".format(fellow.first_name)) + print(Fore.YELLOW + "Sorry, no space available {} has been added to the office waiting list".format(fellow.first_name)) if wants_accomodation == 'Y': # add living space @@ -111,7 +111,7 @@ def add_person(self, first_name, last_name, category, wants_accomodation='N'): print(Fore.GREEN+"You have allocated {} successfully to living space {} ".format(fellow.first_name, allocated_living_space.room_name)) else: self.living_spaces_waiting_list.append(fellow) - print(Fore.RED+"Sorry, no space available {} has been added to the living space waiting list".format(fellow.first_name)) + print(Fore.YELLOW+"Sorry, no space available {} has been added to the living space waiting list".format(fellow.first_name)) elif category == "S" : @@ -129,7 +129,7 @@ def add_person(self, first_name, last_name, category, wants_accomodation='N'): print(Fore.GREEN+"You have allocated {} successfully to office {}.".format(staff.first_name,allocated_office.room_name)) else: self.office_spaces_waiting_list.append(staff) - print(Fore.RED+"Sorry, no space available {} has been added to the waiting list".format(staff.first_name)) + print(Fore.YELLOW+"Sorry, no space available {} has been added to the waiting list".format(staff.first_name)) if wants_accomodation == 'Y': print(Fore.RED + "Sorry! staff is not entitled to a living space") @@ -158,7 +158,20 @@ def get_room(self, room_name): for room in self.all_rooms: if room.room_name.upper() == room_name.upper(): return room - return ("Room does not exist") + return ("Room does not exist") + + def delete_from_allocations(self, id, allocation_obj): + for room in allocation_obj: + for person in allocation_obj[room]: + if person.person_id == id: + allocation_obj[room].remove(person) + + def check_in_allocations(self, id, allocation_obj): + for room in allocation_obj: + for person in allocation_obj[room]: + if person.person_id == id: + return True + return False def get_person_room(self, person_id, room_type): """To return currently allocated room given a valid person id""" @@ -196,20 +209,20 @@ def reallocate_person(self, person_id, new_room_name): return "Room name does not exist" else: if person_object.category == "STAFF" and new_room_object.room_type == "LIVING_SPACE": - print(Fore.RED + "Cannot reallocate staff to living space.") + print(Fore.YELLOW + "Cannot reallocate staff to living space.") return "Cannot reallocate staff to living space." elif new_room_object.room_type == "OFFICE": current_room = self.get_person_room(person_id, "O") if current_room == new_room_object.room_name: # if person has no office - print(Fore.RED + "{} is already allocated to {}".format(person_object.first_name, new_room_object.room_name)) + print(Fore.YELLOW + "{} is already allocated to {}".format(person_object.first_name, new_room_object.room_name)) return "person ca not be reallocated to a room the person is allocated to" elif current_room == "Person not allocated to room": # if person has no office print(Fore.YELLOW + "{} has no current office space,hence you cannot reallocate".format(person_object.first_name)) return "person has no current office space, hence canot reallocate" elif current_room == new_room_object: - print(Fore.RED + "Cannot reallocate a person to the same room.") + print(Fore.YELLOW + "Cannot reallocate a person to the same room.") return "Cannot reallocate to same room." else: # remove from current office @@ -228,56 +241,51 @@ def delete_employee(self, person_id): # prints id does not exist print(person_object) return person_object - for person_object in self.all_fellows: + else: if person_object in self.all_fellows: self.all_fellows.remove(person_object) - print("{} {} deleted".format(person_object.first_name,person_object.last_name)) - - # delete name name if name exists - if person_object in self.office_spaces_waiting_list: - self.office_spaces_waiting_list.remove(person_object) - print(Fore.GREEN + "{} deleted from unallocated space".format(person_object.first_name,person_object.last_name)) - return "deleted from unallocated space" - elif person_object in self.office_allocations: - self.office_allocations[name].remove(person_object) - # self.office[name].occupants.remove(full_name) - print(Fore.GREEN + "{} deleted from office space".format(person_object.first_name,person_object.last_name)) - if person_object in self.all_fellows: - if person_object in self.living_space_allocations: - self.all_fellows.remove(person_object) - # delete name name if name exists else return none - self.living_space_allocations[person_object].occupants.remove(person_object) - self.all_fellows.remove(person_object) - print(Fore.GREEN +"{} {} deleted from living space".format(fperson_object.first_name,person_object.last_name)) - return "deleted from living_space" - if person_object in self.living_spaces_waiting_list: - self.living_spaces_waiting_list.remove(person_object) - print(Fore.GREEN +"{} {} deleted from unallocated living space".format.first_name,person_object.last_name) - - print(Fore.GREEN + "{} {} has been deleted from Amity".format(person_object.first_name,person_object.last_name)) - return "fellow deleted" - for person_object in self.all_staff: if person_object in self.all_staff: - if person_object in self.office_spaces_waiting_list: - self.staff.remove(person_object) - # delete name name if name exists else return none - self.office_spaces_waiting_list.pop(person_object) - if person_object in self.office: - self.office_allocations[person_object].occupants.remove(person_object) - print(Fore.GREEN + "{} {} has been deleted from the system".format(person_object.first_name,person_object.last_name)) + self.all_staff.remove(person_object) + + if person_object in self.all_people: + self.all_people.remove(person_object) + + # delete name name if name exists + if person_object in self.office_spaces_waiting_list: + self.office_spaces_waiting_list.remove(person_object) + print(Fore.GREEN + "{} deleted from unallocated space".format(person_object.first_name,person_object.last_name)) - return "staff deleted" + if self.check_in_allocations(person_id, self.office_allocations): + self.delete_from_allocations(person_id, self.office_allocations) + print(Fore.GREEN + "{} deleted from office space".format(person_object.first_name,person_object.last_name)) + + if self.check_in_allocations(person_id, self.living_space_allocations): + self.delete_from_allocations(person_id, self.living_space_allocations) + print(Fore.GREEN +"{} {} deleted from living space".format(person_object.first_name, person_object.last_name)) + + if person_object in self.living_spaces_waiting_list: + self.living_spaces_waiting_list.remove(person_object) + print(Fore.GREEN + "{} {} deleted from unallocated living space".format(person_object.first_name, person_object.last_name)) + + print(Fore.GREEN + "Employee {} {} has been deleted from the system".format(person_object.first_name, person_object.last_name)) + return "employee deleted" def delete_rooms(self, room_name): - room_object = self.get_room + room_object = self.get_room(room_name) if room_object == "Room does not exist": - print(room_object) - return room_object + print("Room does not exist") + for room_object in self.all_rooms: - self.all_rooms.remove(room_object) - print(Fore.GREEN + "{} has been deleted".format(room_object.room_name)) - return 'room deleted ' + if room_object.room_name == room_name: + self.all_rooms.remove(room_object) + print(Fore.GREEN + "{} has been deleted".format(room_object.room_name)) + + if room_name in self.office_allocations.keys(): + del self.office_allocations[room_name] + + if room_name in self.living_space_allocations.keys(): + del self.living_space_allocations[room_name] def load_people(self, filename): """loads people from a txt file to the app""" @@ -334,10 +342,10 @@ def print_unallocated(self, file_name=None): unallocated_offices = self.office_spaces_waiting_list unallocated_living_spaces = self.living_spaces_waiting_list for person in unallocated_offices: - print(person or "None") + print(person.person_id, person or "None") print(Fore.MAGENTA + "=" * 30 + "\n" + "People in Living Space waiting list\n" + "=" * 30) for person in unallocated_living_spaces: - print(person or "None") + print(person.person_id, person or "None") # return person or "None" if file_name: From fee538caf3367b8cb18c0eb14f442767c688804f Mon Sep 17 00:00:00 2001 From: faithngetich Date: Tue, 2 May 2017 15:04:41 +0300 Subject: [PATCH 52/52] [chore] Refactor delete room --- app.py | 1 + views.py | 5 ++--- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app.py b/app.py index 7da00eb..1c68fe9 100644 --- a/app.py +++ b/app.py @@ -10,6 +10,7 @@ amity print_room amity print_unallocated [-output=] amity load_people + amity delete_rooms(args['']) amity save_state (--database=) amity load_state amity (-i | --interactive) diff --git a/views.py b/views.py index 9e22016..44941bf 100644 --- a/views.py +++ b/views.py @@ -272,6 +272,7 @@ def delete_employee(self, person_id): return "employee deleted" def delete_rooms(self, room_name): + room_name = room_name.upper() room_object = self.get_room(room_name) if room_object == "Room does not exist": print("Room does not exist") @@ -393,13 +394,11 @@ def load_state(self, db_name): for room in rooms: self.create_room(room.room_type[0],[room.name]) for person in people: - self.add_person(person.first_name, person.last_name, person.category, person.wants_accomodation) + self.add_person(person.first_name, person.last_name, person.category[0], 'Y' if person.wants_accomodation else 'N') print(Fore.GREEN + "Data from {} loaded to the app.".format(db_name)) return "Successfully loaded people to the app" else: print(Fore.RED + "sorry db does not exist") - - def save_state(self, db_name): """Persists app data into the given db"""