Advertisement
Kamend1

Untitled

Mar 28th, 2024
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.73 KB | None | 0 0
  1. from typing import List
  2.  
  3. from project.climbers.base_climber import BaseClimber
  4. from project.climbers.arctic_climber import ArcticClimber
  5. from project.climbers.summit_climber import SummitClimber
  6. from project.peaks.base_peak import BasePeak
  7. from project.peaks.arctic_peak import ArcticPeak
  8. from project.peaks.summit_peak import SummitPeak
  9.  
  10.  
  11. class SummitQuestManagerApp:
  12.     VALID_CLIMBERS = ['ArcticClimber', 'SummitClimber']
  13.     VALID_PEAKS = ['ArcticPeak', 'SummitPeak']
  14.  
  15.     def __init__(self):
  16.         self.climbers: List[BaseClimber] = []
  17.         self.peaks: List[BasePeak] = []
  18.  
  19.     def register_climber(self, climber_type: str, climber_name: str):
  20.         if climber_type not in self.VALID_CLIMBERS:
  21.             return f"{climber_type} doesn't exist in our register."
  22.  
  23.         if self.climbers:
  24.             for climber in self.climbers:
  25.                 if climber.name == climber_name:
  26.                     return f"{climber_name} has been already registered."
  27.  
  28.         climber_object = globals()[climber_type]
  29.         climber = climber_object(climber_name)
  30.         self.climbers.append(climber)
  31.         return f"{climber_name} is successfully registered as a {climber_type}."
  32.  
  33.     def peak_wish_list(self, peak_type: str, peak_name: str, peak_elevation: int):
  34.         if peak_type not in self.VALID_PEAKS:
  35.             return f"{peak_type} is an unknown type of peak."
  36.  
  37.         peak_object = globals()[peak_type]
  38.         peak = peak_object(peak_name, peak_elevation)
  39.         self.peaks.append(peak)
  40.         return f"{peak_name} is successfully added to the wish list as a {peak_type}."
  41.  
  42.     def check_gear(self, climber_name: str, peak_name: str, gear: List[str]):
  43.         peak = next(filter(lambda p: p.name == peak_name, self.peaks))
  44.         climber = next(filter(lambda c: c.name == climber_name, self.climbers))
  45.  
  46.         missing_gear = [item for item in peak.RECOMMENDED_GEAR if item not in gear]
  47.  
  48.         if missing_gear:
  49.             climber.is_prepared = False
  50.             return (f"{climber_name} is not prepared to climb {peak_name}. "
  51.                     f"Missing gear: {', '.join(sorted(missing_gear))}.")
  52.  
  53.         return f"{climber_name} is prepared to climb {peak_name}."
  54.  
  55.     def perform_climbing(self, climber_name: str, peak_name: str):
  56.         try:
  57.             climber = next(filter(lambda c: c.name == climber_name, self.climbers))
  58.         except StopIteration:
  59.             return f"Climber {climber_name} is not registered yet."
  60.  
  61.         try:
  62.             peak = next(filter(lambda p: p.name == peak_name, self.peaks))
  63.         except StopIteration:
  64.             return f"Peak {peak_name} is not part of the wish list."
  65.  
  66.         if climber.can_climb() and climber.is_prepared:
  67.             climber.climb(peak)
  68.             return f"{climber_name} conquered {peak_name} whose difficulty level is {peak.difficulty_level}."
  69.  
  70.         if not climber.is_prepared:
  71.             return f"{climber_name} will need to be better prepared next time."
  72.  
  73.         if not climber.can_climb():
  74.             climber.rest()
  75.             return f"{climber_name} needs more strength to climb {peak_name} and is therefore taking some rest."
  76.  
  77.     def get_statistics(self):
  78.         climbers_to_sort = [climber for climber in self.climbers if len(climber.conquered_peaks) > 0]
  79.         sorted_climbers = sorted(climbers_to_sort, key=lambda x: (-len(x.conquered_peaks), x.name))
  80.  
  81.         conquered_peaks = set()
  82.         for climber in self.climbers:
  83.             for peak in climber.conquered_peaks:
  84.                 conquered_peaks.add(peak)
  85.  
  86.         result = "Total climbed peaks: " + str(len(conquered_peaks)) + "\n**Climber's statistics:**\n" \
  87.                  + '\n'.join(str(climber) for climber in sorted_climbers)
  88.  
  89.         return result
  90.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement