Python program to allocate people to rooms in Andela's Amity.
- Clone the repo to any directory on your PC from which you can run python (preferrably with a virtual environment).
- Run
pip install -r requirements.txt
to install all dependencies. - Finally run
python allocator.py
and voila! Start allocating!
The program is should guide you from there but if not, feel free to use the help command anytime.
- Run the following command in the root program's root package:
nosetests
- To test with coverage reports:
nosetests --with-coverage --cover-package=allocator
This application runs as a command interpreter.
- Typically you start by loading or inputing data for teams and rooms. (NOTE: There are defaults for this, you only need call the bare minimum commands without any arguments).
- Next you run the 'allocate' command to allocate person to rooms.
- Finally you can query for room or team allocation data and 'print' it to the console or 'save' to a file.
See below for the list of commands and their usage:
Loads data from text files to populate either the 'team' or 'rooms'. Has the format:
load [<target>(team|rooms) ['<filepath>'] ] [<mode>(:o|:a)]
-
target:
The target data to populate. Value can be eitherteam
orrooms
. Note that although setting target is optional, the other options have no effect unless it is specified. Calling load without target loads both rooms and teams with the default filepath and mode settings. -
filepath:
Optional. Path to the input file wrapped in single-quotes''
. Can be absolute or relative. Defaults to '/data/input_persons_ext.txt' for team and '/data/input_rooms_ext.txt' for rooms. -
mode:
Optional. Specifies how the data is added to target.
:o
to overwrite previously loaded data.
:a
to append to previously loaded data.
Defaults to:o
.Examples:
load team './data/input_persons_ext.txt' :a
load rooms
Collects data from command line to populate either the 'team' or 'rooms'. Has the format:
input <target>(team|rooms) '<cslist>' [<mode>(:o|:a)]
-
target:
The target data to populate. Value can be eitherteam
orrooms
. Note that although setting target is optional, the other options have no effect unless it is specified. Calling load without target loads both rooms and teams with the default filepath and mode settings. -
cslist:
Comma seperated list of input lines for persons or rooms wrapped in single-quotes''
. -
mode:
Optional. Specifies how the data is added to target.
:o
to overwrite previously loaded data.
:a
to append to previously loaded data.
Defaults to:a
.Examples:
input team 'ANDREW PHILLIPS FELLOW Y M, MATTHEW O'CONNOR STAFF' :o
input room 'HAMMER OFFICE STAFF, SAPELE LIVING F'
Allocates persons to rooms using optional or default constraints. Has the format:
allocate [<sep_gender>(g+|g-)] [<sep_roles>(r+|r-)]
-
sep_gender:
Optional. Specifies whether genders should be separated when allocating fellows to living spaces.
g+
to seperate genders.
g-
to allow different genders to share living spaces. lol...in your dreams ;)
Defaults tog+
. -
sep_roles:
Optional. Specifies whether roles (staff and fellows) should be separated when allocating persons to office spaces.
r+
to seperate roles.
r-
to allow staff and fellows to share office spaces. Not bad huh?
Defaults tor+
.Examples:
allocate g+ r-
allocate
Outputs team or room data to the console. Filter options are available. Has the format:
print <target>(team|room) [<filters>(see the filter tables below)]
-
target:
Target data to output. Value can be eitherteam
orrooms
. -
filters:
Optional. Filters the output using combinations of constraints:Room filters meaning os
orls
office spaces or living spaces st
orfw
for staffor _for fellows ml
orfm
for males or for females oc+
oroc-
has occupants or no occupants cf+
orcf-
is full capacity or not full capacity Person filters meaning st
orfw
staff or fellows ml
orfm
male or female o+
oro-
have office space or don't have office space l+
orl-
have living space or don't have living space w+
orw-
want living space or don't want living space NOTE: for rooms filters, any of the five pairs can be combined in the same command. The same hold true for person filteres.
Examples:
print rooms os fw c+
# prints office-spaces for fellows that are filled to capacity.
print team fw fm w+ l-
# prints female fellows that want but have not been allocated living spaces.
Outputs team or room data to a file. Filter options are available. Use the format:
save <target>(team|room) [<filters>(any combination from the list below)] ['<filepath>'] [<mode>(:o|:a)]
-
target:
Same as in 'print' command. -
filters:
Same as in 'print' command. -
filepath:
Optional path to the output file wrapped in single-quotes''
. Can be absolute or relative.
Defaults to './data/output.txt'. -
mode:
Optional. Specifies how the data is written to file.
:o
to overwrite previous saved content.
:a
to append to previously saved content.
Defaults to:o
.Examples:
save rooms os fw c- '/data/output.txt' :a
save team fw ml l-