Indice d'analyse comparative de la durabilité de l'hôtel Cornell

class CarbonFootprint:
    """ This class calculates the carbon footprint of a hotel """
    def __init__(
            self,
            energy_usage: float,                     # kWh
            total_floor_area: float,                 # in square meters
            num_rooms: int,                          # number of rooms
            num_occupied_rooms: int,                 # number of occupied rooms
            total_energy_generated_renewable: float  # kWh
    ):
        """ Initialize the class """
        self.total_carbon_footprint = 0  # kg CO2
        self.energy_usage = energy_usage
        self.total_floor_area = total_floor_area
        self.num_rooms = num_rooms
        self.num_occupied_rooms = num_occupied_rooms
        self.total_energy_generated_renewable = total_energy_generated_renewable

    def calc_carbon_footprint_from_kwh(self) -> float:
        """ Calculate the carbon footprint of a hotel """
        co2_per_kwh = 0.433  # kg CO2 per kWh
        return self.energy_usage * co2_per_kwh

    # Measure 2
    def calc_carbon_footprint_per_room(self) -> float:
        """ Calculate the carbon footprint of the property divided by total number of rooms """
        return self.total_carbon_footprint / self.num_rooms

    # Measure 3
    def calc_carbon_footprint_occupied(self) -> float:
        """ Calculate carbon footprint of the property divided by number of OCCUPIED rooms """
        return self.total_carbon_footprint / self.num_occupied_rooms

    # Measure 4
    def calc_carbon_footprint_per_sqm(self) -> float:
        """Calculate total carbon footprint of the property divided by the total floor area in SQUARE METERS"""
        return self.total_carbon_footprint / self.total_floor_area

    # Measure 5
    def calc_energy_usage_per_occupied(self) -> float:
        """ Total energy usage of the property divided by number of OCCUPIED rooms"""
        return self.energy_usage / self.num_occupied_rooms

    # Measure 6
    def calc_energy_usage_per_sqm(self) -> float:
        """ Total energy usage of the property divided by floor area of the property in SQUARE METERS """
        return self.energy_usage / self.total_floor_area

    # Measure 12
    def calc_renewable_energy_percentage(self, total_energy_generated_renewable: float = 0) -> float:
        """ Percentage of property's total energy that is generated from renewable sources """
        if total_energy_generated_renewable != 0:
            return (self.total_energy_generated_renewable / self.energy_usage) * 100
        else:
            return 0


if __name__ == "__main__":
    # Create an instance of the CarbonFootprint class
    today_carbon_footprint = CarbonFootprint(
        energy_usage=1514,  # kWh
        total_floor_area=9999,  # m2
        num_rooms=75,  # number of rooms in the property
        num_occupied_rooms=64,
        total_energy_generated_renewable=0  # kWh
    )

    # Print the results
    print("Energy Usage:", today_carbon_footprint.energy_usage, "kWh")
    print("Total Floor Area:", today_carbon_footprint.total_floor_area, "m2")
    print("Number of Rooms:", today_carbon_footprint.num_rooms, "rooms")
    print("Number of Occupied Rooms:", today_carbon_footprint.num_occupied_rooms, "rooms")
    print("Total Energy Generated from Renewable Sources:", today_carbon_footprint.total_energy_generated_renewable,
          "kWh")
    print("Percentage of Energy Generated from Renewable Sources:",
          today_carbon_footprint.calc_renewable_energy_percentage(), "%", end="\n\n")

    # Calculate the carbon footprint of the property
    today_carbon_footprint.total_carbon_footprint = today_carbon_footprint.calc_carbon_footprint_from_kwh()
    print("Total carbon footprint of the property:", round(today_carbon_footprint.total_carbon_footprint, 2), "kg CO2")

    # Measure 2
    print("Carbon footprint per room:", round(today_carbon_footprint.calc_carbon_footprint_per_room(), 2), "kg CO2")

    # Measure 3
    print("Carbon footprint per occupied room:", round(today_carbon_footprint.calc_carbon_footprint_occupied(), 2),
          "kg CO2")

    # Measure 4
    print("Carbon footprint per square meter:", round(today_carbon_footprint.calc_carbon_footprint_per_sqm(), 3),
          "kg CO2")

    # Measure 5
    print("Energy usage per occupied room:", round(today_carbon_footprint.calc_energy_usage_per_occupied(), 2), "kWh")

    # Measure 6
    print("Energy usage per square meter:", round(today_carbon_footprint.calc_energy_usage_per_sqm(), 3), "kWh")

    # Measure 12
    print("Percentage of energy generated from renewable sources:",
          today_carbon_footprint.calc_renewable_energy_percentage(), "%")
Ugly Unicorn