-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 261156f
Showing
30 changed files
with
384 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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,49 @@ | ||
import inventory | ||
import guitar | ||
import guitarSpec | ||
import enum | ||
|
||
|
||
class Type(enum.Enum): | ||
ACOUSTIC = "ACOUSTIC" | ||
ELECTRIC = "ELECTRIC" | ||
|
||
|
||
class Builder(enum.Enum): | ||
FENDER = "FENDER" | ||
MARTIN = "MARTIN" | ||
GIBSON = "GIBSON" | ||
|
||
|
||
class Wood(enum.Enum): | ||
CEDAR = "CEDAR" | ||
MAPLE = "MAPLE" | ||
COCOBOLO = "COCOBOLO" | ||
ALDER = "ALDER" | ||
|
||
|
||
class FindGuitarTester(): | ||
def main(self): | ||
num_of_strings = 12 | ||
self.inv = inventory.Inventory() | ||
|
||
customer_guitar = guitarSpec.GuitarSpec( | ||
Builder.FENDER, "Sratocastor", Type.ELECTRIC, Wood.ALDER, Wood.ALDER, num_of_strings) | ||
self.initialize_inventory() | ||
|
||
gtrs_found = self.inv.search(customer_guitar) | ||
print("Not found") if not gtrs_found else self.inv.display_guitar(gtrs_found) | ||
|
||
def initialize_inventory(self): | ||
guitar_spec1 = guitarSpec.GuitarSpec(Builder.FENDER, | ||
"abc", Type.ELECTRIC, Wood.ALDER, Wood.ALDER,12) | ||
guitar_spec2 = guitarSpec.GuitarSpec(Builder.FENDER, | ||
"sratocastor", Type.ELECTRIC, Wood.ALDER, Wood.ALDER,12) | ||
self.inv.add_guitar("V95693", 1499.95, guitar_spec1) | ||
self.inv.add_guitar("V95123", 1543.95, guitar_spec2) | ||
self.inv.add_guitar("V54312", 1249.95, guitar_spec2) | ||
|
||
|
||
|
||
obj = FindGuitarTester() | ||
obj.main() |
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains 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,5 @@ | ||
class Guitar: | ||
def __init__(self, srl_num, price, guitar_spec): | ||
self.serial_num = srl_num | ||
self.price = price | ||
self.guitar_spec = guitar_spec |
This file contains 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,25 @@ | ||
class GuitarSpec: | ||
|
||
def __init__(self, builder, model, guitar_type, b_wood, t_wood, num): | ||
self.builder = builder | ||
self.model = model | ||
self.g_type = guitar_type | ||
self.back_wood = b_wood | ||
self.top_wood = t_wood | ||
self.num_strings = num | ||
|
||
def match_specs(self,guitar_inv,gtr_to_search): | ||
if gtr_to_search.builder and gtr_to_search.builder != "" and gtr_to_search.builder != guitar_inv.guitar_spec.builder: | ||
return 0 | ||
if gtr_to_search.model and gtr_to_search.model != "" and gtr_to_search.model.lower() != guitar_inv.guitar_spec.model: | ||
return 0 | ||
if gtr_to_search.g_type and gtr_to_search.g_type != "" and gtr_to_search.g_type != guitar_inv.guitar_spec.g_type: | ||
return 0 | ||
if gtr_to_search.back_wood and gtr_to_search.back_wood != "" and gtr_to_search.back_wood != guitar_inv.guitar_spec.back_wood: | ||
return 0 | ||
if gtr_to_search.top_wood and gtr_to_search.top_wood != "" and gtr_to_search.top_wood != guitar_inv.guitar_spec.top_wood: | ||
return 0 | ||
if gtr_to_search.num_strings and gtr_to_search.num_strings != 0 and gtr_to_search.num_strings != guitar_inv.guitar_spec.num_strings: | ||
return 0 | ||
|
||
return 1 |
This file contains 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,32 @@ | ||
import guitar | ||
import guitarSpec | ||
class Inventory(guitarSpec.GuitarSpec): | ||
def __init__(self): | ||
self.guitar_list = [] | ||
|
||
def add_guitar(self, srl_num, price, guitar_spec): | ||
self.guitar_list.append(guitar.Guitar(srl_num, price, guitar_spec)) | ||
|
||
def display_guitar(self, gtrs_list): | ||
for i in range(len(gtrs_list)): | ||
print("Guitar :", i+1) | ||
print("serial number:", gtrs_list[i].serial_num) | ||
print("builder version = ", gtrs_list[i].guitar_spec.builder) | ||
print("type = ", gtrs_list[i].guitar_spec.g_type) | ||
print("backwood = ", gtrs_list[i].guitar_spec.back_wood) | ||
print("topWood = ", gtrs_list[i].guitar_spec.top_wood) | ||
print("price = ", gtrs_list[i].price) | ||
print("num of strings = ", gtrs_list[i].guitar_spec.num_strings) | ||
|
||
def get_guitar(self, srl_num): | ||
for gtr in self.guitar_list: | ||
if gtr.srl_num == srl_num: | ||
return gtr | ||
return None | ||
|
||
def search(self, gtr_to_search): | ||
gtrs_found = [] | ||
for i in range(len(self.guitar_list)): | ||
if self.match_specs(self.guitar_list[i], gtr_to_search): | ||
gtrs_found.append(self.guitar_list[i]) | ||
return gtrs_found |
This file contains 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,10 @@ | ||
class Bark: | ||
def __init__(self,bark_sound): | ||
self.bark_sound = bark_sound | ||
|
||
def get_sound(self): | ||
return self.bark_sound | ||
|
||
#compares 2 bark objects | ||
def equals(self,stored_bark): | ||
return True if self.get_sound().lower().__eq__(stored_bark.get_sound().lower()) else False |
This file contains 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,16 @@ | ||
import DogDoor | ||
import Bark | ||
class BarkRecognizer: | ||
def __init__(self,dog_door): | ||
self.dog_door = dog_door | ||
|
||
# Listens to the barking and sends the request to the DogDoor class to open the door | ||
def recognize(self,bark_heard,time): | ||
# check if bark_heard is stored in the dog door | ||
for bark in self.dog_door.bark: | ||
if bark_heard.equals(bark): | ||
print("Door opens after hearing Bruce bark") | ||
self.dog_door.open(time) | ||
return | ||
|
||
print("Bark not recognized") |
This file contains 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,29 @@ | ||
import time | ||
class DogDoor: | ||
def __init__(self): | ||
self.door_open = False | ||
self.bark = [] | ||
|
||
#store the owner's dog's bark | ||
def store_bark(self,bark): | ||
self.bark = [brk for brk in bark] | ||
|
||
#open the door | ||
def open(self,t): | ||
self.door_open = True | ||
self.wait(t) | ||
self.close() | ||
|
||
#close the door | ||
def close(self): | ||
self.door_open = False | ||
|
||
#check if the door is open | ||
def is_open(self): | ||
return self.door_open | ||
|
||
# wait for 5 seconds and then close the door | ||
def wait(self,t): | ||
for i in range(t): | ||
time.sleep(1) | ||
|
This file contains 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,35 @@ | ||
import DogDoor | ||
# import Remote | ||
import BarkRecognizer | ||
import Bark | ||
class DogDoorSimulator: | ||
|
||
def main(self): | ||
no_of_barks = 3 | ||
dog_door = DogDoor.DogDoor() | ||
# store multiple barks in the dog door | ||
barks = [] | ||
for i in range(no_of_barks): | ||
barks.append(Bark.Bark("bark"+str(i+1))) | ||
dog_door.store_bark(barks) | ||
print("Bruce starts barking") | ||
#call bark recognizer to recognize the sound | ||
bark_recognizer = BarkRecognizer.BarkRecognizer(dog_door) | ||
bark_recognizer.recognize(Bark.Bark("bark2"),3) | ||
print("Bruce has gone outside...") | ||
print("Bruce's all done ...") | ||
print("... but he is stuck outside") | ||
|
||
#Simulate a bark of neighbor's dog | ||
print("Neighbor's dog start barking") | ||
bark_recognizer.recognize(Bark.Bark("yip"),3) | ||
|
||
#Simulate hardware hearing another bark | ||
print("Bruce starts barking") | ||
bark_recognizer.recognize(Bark.Bark("bark1"),3) | ||
print("Bruce is back inside") | ||
# print("Check if door is closed") | ||
# print("Door is open") if dog_door.is_open() else print("Door is closed") | ||
|
||
obj = DogDoorSimulator() | ||
obj.main() |
This file contains 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,11 @@ | ||
class Remote: | ||
def __init__(self,dog_door): | ||
self.dog_door = dog_door | ||
|
||
def press_button(self,time): | ||
if self.dog_door.is_open(): | ||
print("Closing the door...") | ||
self.dog_door.close() | ||
else: | ||
print("Opening the door...") | ||
self.dog_door.open(time) |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
76 changes: 76 additions & 0 deletions
76
ch-5(added_support_for_other instruments_in_guitar_shop)/FindGuitarTester.py
This file contains 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,76 @@ | ||
import inventory | ||
import InstrumentSpec | ||
import Instrument | ||
import enum | ||
|
||
class Type(enum.Enum): | ||
ACOUSTIC = "ACOUSTIC" | ||
ELECTRIC = "ELECTRIC" | ||
|
||
class Builder(enum.Enum): | ||
FENDER = "FENDER" | ||
MARTIN = "MARTIN" | ||
GIBSON = "GIBSON" | ||
|
||
class InstrumentCategory(enum.Enum): | ||
GUITAR = "GUITAR" | ||
MANDOLIN = "MANDOLIN" | ||
BANJO = "BANJO" | ||
DOBROS = "DOBROS" | ||
FIDDLES = "FIDDLES" | ||
|
||
class Wood(enum.Enum): | ||
CEDAR = "CEDAR" | ||
MAPLE = "MAPLE" | ||
COCOBOLO = "COCOBOLO" | ||
ALDER = "ALDER" | ||
|
||
class Style(enum.Enum): | ||
STYLE1 = "BOLLYWOOD" | ||
STYLE2 = "HOLLYWOOD" | ||
|
||
class FindGuitarTester(): | ||
def main(self): | ||
self.num_of_strings = 12 | ||
self.inv = inventory.Inventory() | ||
|
||
customer_specs = {"model":"abc"} | ||
instr_spec = InstrumentSpec.InstrumentSpec(customer_specs) | ||
self.initialize_inventory() | ||
|
||
instruments_found = self.inv.search(instr_spec) | ||
|
||
print("Instrument Not found") if not instruments_found else [print(i.srl_num) for i in instruments_found] | ||
|
||
def initialize_inventory(self): | ||
specs1 = {"instrument":InstrumentCategory.GUITAR,"strings":12,"builder":Builder.FENDER, "type":Type.ELECTRIC, "model":"Sratocastor","back_wood":Wood.ALDER,"top_wood":Wood.ALDER } | ||
instrument1 = Instrument.Instrument("1", 1499.95, specs1) | ||
|
||
specs2 = {"instrument":InstrumentCategory.GUITAR,"strings":10,"builder":Builder.FENDER, "type":Type.ELECTRIC, "model":"abc","back_wood":Wood.ALDER,"top_wood":Wood.ALDER } | ||
instrument2 = Instrument.Instrument("2", 1543.95, specs2) | ||
|
||
specs3 = {"instrument":InstrumentCategory.GUITAR,"strings":12,"builder":Builder.FENDER, "type":Type.ELECTRIC, "model":"Sratocastor","back_wood":Wood.ALDER,"top_wood":Wood.ALDER } | ||
instrument3 = Instrument.Instrument("3", 1249.95, specs3) | ||
|
||
specs4 = {"instrument":InstrumentCategory.MANDOLIN,"style":Style.STYLE1,"builder":Builder.FENDER, "type":Type.ELECTRIC, "model":"abc","back_wood":Wood.ALDER,"top_wood":Wood.ALDER } | ||
instrument4 = Instrument.Instrument("4", 1543.95, specs4) | ||
|
||
specs5 = {"instrument":InstrumentCategory.MANDOLIN,"style":Style.STYLE2,"builder":Builder.FENDER, "type":Type.ELECTRIC, "model":"Sratocastor","back_wood":Wood.ALDER,"top_wood":Wood.ALDER } | ||
instrument5 = Instrument.Instrument("5", 1249.95, specs5) | ||
|
||
specs6 = {"instrument":InstrumentCategory.BANJO,"builder":Builder.FENDER, "type":Type.ELECTRIC, "model":"abc","back_wood":Wood.ALDER,"top_wood":Wood.ALDER } | ||
instrument6 = Instrument.Instrument("6", 1543.95, specs6) | ||
|
||
specs7 = {"instrument":InstrumentCategory.BANJO,"builder":Builder.FENDER, "type":Type.ELECTRIC, "model":"Sratocastor","back_wood":Wood.ALDER,"top_wood":Wood.ALDER } | ||
instrument7 = Instrument.Instrument("7", 1249.95, specs7) | ||
|
||
self.inv.add_instrument(instrument1) | ||
self.inv.add_instrument(instrument2) | ||
self.inv.add_instrument(instrument3) | ||
self.inv.add_instrument(instrument4) | ||
self.inv.add_instrument(instrument5) | ||
self.inv.add_instrument(instrument6) | ||
self.inv.add_instrument(instrument7) | ||
|
||
obj = FindGuitarTester() | ||
obj.main() |
9 changes: 9 additions & 0 deletions
9
ch-5(added_support_for_other instruments_in_guitar_shop)/Instrument.py
This file contains 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,9 @@ | ||
class Instrument(): | ||
|
||
def __init__(self, srl_num, price, spec): | ||
self.srl_num = srl_num | ||
self.price = price | ||
self.instrument_spec = spec | ||
|
||
def get_spec(self): | ||
return self.instrument_spec |
17 changes: 17 additions & 0 deletions
17
ch-5(added_support_for_other instruments_in_guitar_shop)/InstrumentSpec.py
This file contains 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,17 @@ | ||
import collections | ||
|
||
class InstrumentSpec(): | ||
def __init__(self, spec): | ||
self.spec = spec | ||
|
||
def get_all_specs(self): | ||
return self.specs | ||
|
||
def get_spec(self, key_spec): | ||
return self.specs[key_spec] | ||
|
||
def match_spec(self, instrument_spec): | ||
for key in self.spec.keys(): | ||
if key in instrument_spec and self.spec[key] != instrument_spec[key]: | ||
return 0 | ||
return 1 |
Binary file added
BIN
+648 Bytes
...added_support_for_other instruments_in_guitar_shop)/__pycache__/Instrument.cpython-37.pyc
Binary file not shown.
Binary file added
BIN
+1010 Bytes
...d_support_for_other instruments_in_guitar_shop)/__pycache__/InstrumentSpec.cpython-37.pyc
Binary file not shown.
Binary file added
BIN
+694 Bytes
ch-5(added_support_for_other instruments_in_guitar_shop)/__pycache__/Mandolin.cpython-37.pyc
Binary file not shown.
Binary file added
BIN
+866 Bytes
...ded_support_for_other instruments_in_guitar_shop)/__pycache__/MandolinSpec.cpython-37.pyc
Binary file not shown.
Binary file added
BIN
+693 Bytes
ch-5(added_support_for_other instruments_in_guitar_shop)/__pycache__/guitar.cpython-37.pyc
Binary file not shown.
Binary file added
BIN
+845 Bytes
...added_support_for_other instruments_in_guitar_shop)/__pycache__/guitarSpec.cpython-37.pyc
Binary file not shown.
Binary file added
BIN
+1.02 KB
...(added_support_for_other instruments_in_guitar_shop)/__pycache__/inventory.cpython-37.pyc
Binary file not shown.
19 changes: 19 additions & 0 deletions
19
ch-5(added_support_for_other instruments_in_guitar_shop)/inventory.py
This file contains 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,19 @@ | ||
class Inventory: | ||
def __init__(self): | ||
self.store = [] | ||
|
||
def add_instrument(self, instrument): | ||
self.store.append(instrument) | ||
|
||
def get_instrument(self, srl_num): | ||
for instrument in self.store: | ||
if instrument.srl_num == srl_num: | ||
return instrument | ||
return None | ||
|
||
def search(self, specs_to_search): | ||
instruments_found = [] | ||
for instrument in self.store: | ||
if specs_to_search.match_spec(instrument.get_spec()): | ||
instruments_found.append(instrument) | ||
return instruments_found |
This file contains 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,27 @@ | ||
import Tile | ||
class Board: | ||
def __init__(self, height, width): | ||
self.height = height | ||
self.width = width | ||
self.board = [[Tile.Tile() for _ in range(width)] for _ in range(height)] | ||
|
||
def get_tile(self, x, y): | ||
return self.board[x-1][y-1] | ||
|
||
def add_unit(self,unit, x, y): | ||
tile = self.get_tile(x,y) | ||
tile.add_unit(unit) | ||
|
||
def get_unit(self, x, y): | ||
tile = self.get_tile(x,y) | ||
return tile.get_unit() | ||
|
||
#remove given unit from one tile | ||
def remove_unit(self,unit,x,y): | ||
tile = self.get_tile(x,y) | ||
tile.remove_unit(unit) | ||
|
||
#remove all units from one tile | ||
def remove_all_units(self,x,y): | ||
tile = self.get_tile(x,y) | ||
tile.remove_all_units() |
Oops, something went wrong.