Advertisement
KNenov96

Untitled

Mar 31st, 2023
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.34 KB | None | 0 0
  1. from project.band_members.singer import Singer
  2. from project.band_members.drummer import Drummer
  3. from project.band_members.guitarist import Guitarist
  4. from project.band import Band
  5. from project.concert import Concert
  6.  
  7.  
  8. class ConcertTrackerApp:
  9.     def __init__(self):
  10.         self.bands = []
  11.         self.musicians = []
  12.         self.concerts = []
  13.  
  14.     def create_musician(self, musician_type: str, name: str, age: int):
  15.         valid_musicians_types = {"Guitarist": Guitarist, "Drummer": Drummer, "Singer": Singer}
  16.         if musician_type not in valid_musicians_types.keys():
  17.             raise ValueError("Invalid musician type!")
  18.         if name in (musician.name for musician in self.musicians):
  19.             raise Exception(f"{name} is already a musician!")
  20.         self.musicians.append(valid_musicians_types[musician_type](name, age))
  21.         return f"{name} is now a {musician_type}."
  22.  
  23.     def create_band(self, name: str):
  24.         if name in (band.name for band in self.bands):
  25.             raise Exception(f"{name} band is already created!")
  26.         self.bands.append(Band(name))
  27.         return f"{name} was created."
  28.  
  29.     def create_concert(self, genre: str, audience: int, ticket_price: float, expenses: float, place: str):
  30.         if place in (concert.place for concert in self.concerts):
  31.             match_concert = [x for x in self.concerts if x.place == place][0]
  32.             raise Exception(f"{place} is already registered for {match_concert.genre} concert!")
  33.         self.concerts.append(Concert(genre, audience, ticket_price, expenses, place))
  34.         return f"{genre} concert in {place} was added."
  35.  
  36.     def add_musician_to_band(self, musician_name: str, band_name: str):
  37.         if musician_name not in (musician.name for musician in self.musicians):
  38.             raise Exception(f"{musician_name} isn't a musician!")
  39.  
  40.         if band_name not in (band.name for band in self.bands):
  41.             raise Exception(f"{band_name} isn't a band!")
  42.  
  43.         band = [band for band in self.bands if band.name == band_name][0]
  44.         musician = [musician for musician in self.musicians if musician.name == musician_name][0]
  45.         band.members.append(musician)
  46.         return f"{musician_name} was added to {band_name}."
  47.  
  48.     def remove_musician_from_band(self, musician_name: str, band_name: str):
  49.         if band_name not in (band.name for band in self.bands):
  50.             raise Exception(f"{band_name} isn't a band!")
  51.         band = [band for band in self.bands if band.name == band_name][0]
  52.  
  53.         if musician_name not in (x.name for x in band.members):
  54.             raise Exception(f"{musician_name} isn't a member of {band_name}!")
  55.  
  56.         musician = [musician for musician in self.musicians if musician.name == musician_name][0]
  57.         band.members.remove(musician)
  58.         return f"{musician_name} was removed from {band_name}."
  59.  
  60.     def start_concert(self, concert_place: str, band_name: str):
  61.         band = [bands for bands in self.bands if bands.name == band_name][0]
  62.  
  63.         available_musicians = [musician for musician in band.members]
  64.         types_musicians = ['Singer', 'Guitarist', 'Drummer']
  65.         if not all(item in (x.__class__.__name__ for x in available_musicians) for item in types_musicians ):
  66.             raise Exception(f"{band_name} can't start the concert because it doesn't have enough members!")
  67.  
  68.         concert = [concert for concert in self.concerts if concert.place == concert_place][0]
  69.         played_genre = concert.genre
  70.         available_skills = []
  71.         for skill in [musician.skills for musician in available_musicians]:
  72.                 available_skills.extend(skill)
  73.  
  74.         needed_skills = {"Rock": ["play the drums with drumsticks", "sing high pitch notes", "play rock"],
  75.                          "Metal": ["play the drums with drumsticks", "sing low pitch notes", "play metal"],
  76.                          "Jazz": ["play the drums with drum brushes", "sing high pitch notes", "sing low pitch notes",
  77.                                   "play jazz"]}
  78.  
  79.         if not set(needed_skills[played_genre]).issubset(set(available_skills)):
  80.             raise Exception(f"The {band_name} band is not ready to play at the concert!")
  81.  
  82.         profit = (concert.audience * concert.ticket_price) - concert.expenses
  83.  
  84.         return f"{band_name} gained {profit:.2f}$ from the {concert.genre} concert in {concert_place}."
  85.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement