Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from project.band_members.singer import Singer
- from project.band_members.drummer import Drummer
- from project.band_members.guitarist import Guitarist
- from project.band import Band
- from project.concert import Concert
- class ConcertTrackerApp:
- def __init__(self):
- self.bands = []
- self.musicians = []
- self.concerts = []
- def create_musician(self, musician_type: str, name: str, age: int):
- valid_musicians_types = {"Guitarist": Guitarist, "Drummer": Drummer, "Singer": Singer}
- if musician_type not in valid_musicians_types.keys():
- raise ValueError("Invalid musician type!")
- if name in (musician.name for musician in self.musicians):
- raise Exception(f"{name} is already a musician!")
- self.musicians.append(valid_musicians_types[musician_type](name, age))
- return f"{name} is now a {musician_type}."
- def create_band(self, name: str):
- if name in (band.name for band in self.bands):
- raise Exception(f"{name} band is already created!")
- self.bands.append(Band(name))
- return f"{name} was created."
- def create_concert(self, genre: str, audience: int, ticket_price: float, expenses: float, place: str):
- if place in (concert.place for concert in self.concerts):
- match_concert = [x for x in self.concerts if x.place == place][0]
- raise Exception(f"{place} is already registered for {match_concert.genre} concert!")
- self.concerts.append(Concert(genre, audience, ticket_price, expenses, place))
- return f"{genre} concert in {place} was added."
- def add_musician_to_band(self, musician_name: str, band_name: str):
- if musician_name not in (musician.name for musician in self.musicians):
- raise Exception(f"{musician_name} isn't a musician!")
- if band_name not in (band.name for band in self.bands):
- raise Exception(f"{band_name} isn't a band!")
- band = [band for band in self.bands if band.name == band_name][0]
- musician = [musician for musician in self.musicians if musician.name == musician_name][0]
- band.members.append(musician)
- return f"{musician_name} was added to {band_name}."
- def remove_musician_from_band(self, musician_name: str, band_name: str):
- if band_name not in (band.name for band in self.bands):
- raise Exception(f"{band_name} isn't a band!")
- band = [band for band in self.bands if band.name == band_name][0]
- if musician_name not in (x.name for x in band.members):
- raise Exception(f"{musician_name} isn't a member of {band_name}!")
- musician = [musician for musician in self.musicians if musician.name == musician_name][0]
- band.members.remove(musician)
- return f"{musician_name} was removed from {band_name}."
- def start_concert(self, concert_place: str, band_name: str):
- band = [bands for bands in self.bands if bands.name == band_name][0]
- available_musicians = [musician for musician in band.members]
- types_musicians = ['Singer', 'Guitarist', 'Drummer']
- if not all(item in (x.__class__.__name__ for x in available_musicians) for item in types_musicians ):
- raise Exception(f"{band_name} can't start the concert because it doesn't have enough members!")
- concert = [concert for concert in self.concerts if concert.place == concert_place][0]
- played_genre = concert.genre
- available_skills = []
- for skill in [musician.skills for musician in available_musicians]:
- available_skills.extend(skill)
- needed_skills = {"Rock": ["play the drums with drumsticks", "sing high pitch notes", "play rock"],
- "Metal": ["play the drums with drumsticks", "sing low pitch notes", "play metal"],
- "Jazz": ["play the drums with drum brushes", "sing high pitch notes", "sing low pitch notes",
- "play jazz"]}
- if not set(needed_skills[played_genre]).issubset(set(available_skills)):
- raise Exception(f"The {band_name} band is not ready to play at the concert!")
- profit = (concert.audience * concert.ticket_price) - concert.expenses
- return f"{band_name} gained {profit:.2f}$ from the {concert.genre} concert in {concert_place}."
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement