-
Notifications
You must be signed in to change notification settings - Fork 0
Ch refactor #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
faithngetich
wants to merge
52
commits into
master
Choose a base branch
from
ch-refactor
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Ch refactor #2
Changes from all commits
Commits
Show all changes
52 commits
Select commit
Hold shift + click to select a range
a0f3849
Initial commit
faithngetich c2e774e
add gitignore content
faithngetich d448eb3
add test cases
faithngetich 09768e6
create models
faithngetich 6e25acf
add logic
faithngetich ae804a3
[Chore] create class person
faithngetich 14595cc
[Chore] add sub class staff
faithngetich 1fca985
[Chore] create sub class Staff
faithngetich dd77b82
[Chore] create super class Room
faithngetich a5d7e88
[Chore] create sub class Office
faithngetich 09f8ec8
[Chore] create sub class living space
faithngetich 193e906
[Chore] Add attribute room capacity
faithngetich 08c0046
[Chore] Remove existing functionality
faithngetich b311633
[chore] Add create room function
faithngetich fa0aaed
[chore] test create room method works
faithngetich 9ccf89f
[chore] Add an add person method
faithngetich d24108c
[chore] Add reallocate function
faithngetich 34fe90c
[chore] refactor the reallocation method
faithngetich 42d7496
[chore] Add load people method
faithngetich eb37b18
[chore] Refactor the create room method
faithngetich 2deaae9
[chore] Add print allocation method
faithngetich 47f641c
[chore] Add print room method
faithngetich 658095a
[chore] Refactor add person method
faithngetich 6c8ae3d
[chore] Add a docopt app file
faithngetich c57049b
[chore] Add a save state method
faithngetich bda2874
[chore] Remove commented code
faithngetich 5088d4f
[chore] Ignore and delete all db files
faithngetich 47488ea
[chore] Refactor docopt file
faithngetich df0a0a2
[chore] Remove unused code
faithngetich 337deb5
[chore] make all the functionality work
faithngetich 9793ebc
[chore] deny staff accomodation
faithngetich 1b8ecb4
[chore] Test reallocate function works
faithngetich 9c33212
[chore] Test staff is added to all staff list
faithngetich 456f7e4
[chore] Test office is created successfully
faithngetich 68aa22d
[chore] Add more test methods
faithngetich 00da78c
[chore] Update requirements
faithngetich 2f81055
[chore] Refactor docopt file
faithngetich 0b40614
[chore] Add load state test
faithngetich 49ab8ae
[chore] Refactor docopt
faithngetich 68d9542
[chore] Refactor models file
faithngetich 833fbf3
[chore] Refactor and remove commented code
faithngetich 89058ff
[chore] Add docstrings
faithngetich 56e745b
[chore] Add docstrings
faithngetich e9a02c9
[chore] Delete unused files
faithngetich d05ad1b
[chore] Add a delete employee method
faithngetich 0735b7e
[chore] Add a delete rooms method
faithngetich efee5b6
[chore] Name test methods correctly
faithngetich 6668ed8
[chore] Add missing methods
faithngetich e712832
[chore] Refactor code
faithngetich e43c46b
[chore] Remove unused space
faithngetich ee58988
[chore] Refactor delete methods
faithngetich fee538c
[chore] Refactor delete room
faithngetich File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| [report] | ||
| omit= | ||
| *tests/* | ||
| */python?.?/* |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,193 @@ | ||
|
|
||
| """ | ||
| Usage: | ||
| amity create_room (O|L) <room_name>... | ||
| amity delete_rooms(args['<room_name>']) | ||
| amity add_person <first_name> <last_name> (F | S) [--wants_accomodation=value] | ||
| amity delete_employee(int(args['<person_id>'])) | ||
| amity print_allocations [-output=<filename>] | ||
| amity reallocate_person <person_id> <new_room> | ||
| amity print_room <room_name> | ||
| amity print_unallocated [-output=<filename>] | ||
| amity load_people <filename> | ||
| amity delete_rooms(args['<room_name>']) | ||
| amity save_state (--database=<sqlite_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=<opt> Person wants accomodation [default: N] | ||
| -d, --database=<sqlite_database> Save state to specified database [default: amity_db] | ||
| """ | ||
| import cmd, os, sys | ||
| from docopt import docopt, DocoptExit | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider adding a line of separation between all your import statements, e.g: |
||
| from pyfiglet import figlet_format | ||
| from termcolor import cprint | ||
| 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") | ||
| print("\n\n") | ||
| cprint(__doc__, 'magenta') | ||
|
|
||
|
|
||
| class AmitySystem(cmd.Cmd): | ||
| prompt = '(Amity) ' | ||
| file = None | ||
|
|
||
| @docopt_cmd | ||
| def do_create_room(self, args): | ||
| """Usage: create_room (O|L) <room_name>...""" | ||
| room_type = None | ||
| if args["O"].upper() == 'O': | ||
| room_type = "O" | ||
| else: | ||
| room_type = "L" | ||
| amity.create_room(room_type, args["<room_name>"]) | ||
|
|
||
|
|
||
| @docopt_cmd | ||
| def do_add_person(self, args): | ||
| """ | ||
| Usage: add_person <first_name> <last_name> (F | S) [--wants_accomodation=value] | ||
| """ | ||
| if args["F"].upper() == 'F': | ||
| category = "F" | ||
| else: | ||
| category = "S" | ||
| first_name = args["<first_name>"] | ||
| last_name = args["<last_name>"] | ||
| amity.add_person(first_name, last_name, category, args["--wants_accomodation"]) | ||
|
|
||
| @docopt_cmd | ||
| def do_reallocate_person(self, args): | ||
| """Usage: reallocate_person <person_id> <new_room>""" | ||
| if args["<person_id>"].isalpha(): | ||
| print("person id cannot be string") | ||
| return | ||
| else: | ||
| (amity.reallocate_person(int(args['<person_id>']), | ||
| args['<new_room>'])) | ||
|
|
||
| @docopt_cmd | ||
| 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]""" | ||
| amity.print_unallocated(args['--file']) | ||
|
|
||
| @docopt_cmd | ||
| def do_print_allocations(self, args): | ||
| """ | ||
| Prints all rooms and the people in them. | ||
| Usage: print_allocations [--o=filename] | ||
| """ | ||
| filename = args["--o"] or "" | ||
| amity.print_allocations(filename) | ||
|
|
||
| @docopt_cmd | ||
| def do_delete_employee(self, args): | ||
| """Usage: delete_employee <person_id>""" | ||
| if args["<person_id>"].isalpha(): | ||
| print("person id cannot be string") | ||
| return | ||
| else: | ||
| (amity.delete_employee(int(args['<person_id>']))) | ||
|
|
||
| @docopt_cmd | ||
| def do_delete_rooms(self, args): | ||
| """Usage: delete_room <room_name>""" | ||
| amity.delete_rooms(args['<room_name>']) | ||
|
|
||
|
|
||
| @docopt_cmd | ||
| def do_load_state(self, arg): | ||
| """ | ||
| Loads data from the specified db into the app. | ||
| Usage: load_state <filename> | ||
| """ | ||
| amity.load_state(arg["<filename>"]) | ||
|
|
||
| @docopt_cmd | ||
| def do_load_people(self, args): | ||
| """Usage: load_state <text_file>""" | ||
| amity.load_people(args["<text_file>"]) | ||
|
|
||
|
|
||
| @docopt_cmd | ||
| def do_print_room(self, args): | ||
| """Usage: print_room <room_name>""" | ||
|
|
||
| room_name = args["<room_name>"] | ||
| amity.print_room(room_name) | ||
| @docopt_cmd | ||
| def do_clear(self, arg): | ||
| """Clears screen""" | ||
|
|
||
| os.system('clear') | ||
|
|
||
| @docopt_cmd | ||
| def do_load_people(self, args): | ||
| """Usage: load_state <text_file>""" | ||
| amity.load_people(args["<text_file>"]) | ||
|
|
||
|
|
||
|
|
||
| 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']: | ||
| os.system('clear') | ||
| intro() | ||
| AmitySystem().cmdloop() | ||
|
|
||
| print(opt) | ||
|
|
||
|
|
||
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| import os | ||
| import sys | ||
| import sqlalchemy | ||
|
|
||
| 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 | ||
|
|
||
|
|
||
|
|
||
|
|
||
| Base = declarative_base() | ||
|
|
||
|
|
||
| class Person(Base): | ||
| """creates a people's table""" | ||
| __tablename__ = "People" | ||
|
|
||
| id = Column(Integer, primary_key=True, autoincrement=True, 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 'first name{} last name{}'.format(self.first_name,self.last_name) | ||
|
|
||
|
|
||
| class Room(Base): | ||
| """creates rooms tables""" | ||
| __tablename__ = "Rooms" | ||
|
|
||
| id = Column(Integer, primary_key=True, autoincrement=True) | ||
| name = Column(String, nullable=False) | ||
| room_type = Column(String, nullable=False) | ||
| room_capacity = Column(Integer, nullable=False) | ||
| occupants = Column(String,nullable=True) | ||
|
|
||
|
|
||
| class DatabaseCreator(object): | ||
| """creating database connection to object""" | ||
| def __init__(self, db_name=None): | ||
| self.db_name = db_name + '.db' | ||
| self.engine = create_engine('sqlite:///' + self.db_name) | ||
| Base.metadata.create_all(self.engine) | ||
| session_maker = sessionmaker(bind=self.engine) | ||
| self.session = session_maker() | ||
|
|
||
|
|
||
|
|
||
|
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider removing files and directories that you do not have in your project.