1. Python / Говнокод #28655

    −1

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    def get_decrease_fan_speed_delta(fan_speed: float, delta: float, turn_off: bool):
        # if the fan is already running slower than minimum speed
        if fan_speed < MIN_FAN_SPEED:
            # we ignore the turn_off argument and always set the fan off
            return -fan_speed
        # if fan would be running slower than minimum speed after decreasing it by delta:
        if (fan_speed - delta) < MIN_FAN_SPEED:
            if turn_off:
                return -fan_speed  # turn the fan off
            else:
                return -fan_speed + MIN_FAN_SPEED  # make it run at minimum speed
        return -delta
    
    
    def get_increase_fan_speed_delta(fan_speed, delta):
        new_fan_speed = fan_speed + delta
        # if fan would be running faster than maximum speed
        if new_fan_speed > 100:
            return 100 - fan_speed  # cap it at 100%
        elif new_fan_speed < MIN_FAN_SPEED:
            return MIN_FAN_SPEED - fan_speed  # jump to minimum fan speed
        return delta
    
    
    def compute_fan_speed_delta(temp: float, temp_delta: float, fan_speed: float):
        if temp >= HOT:
            return get_increase_fan_speed_delta(fan_speed, 100.0)
    
        if temp <= COLD:
            # if temperature is decreasing, we slowly decrease the fan speed
            if temp_delta < 0.0:
                return get_decrease_fan_speed_delta(fan_speed, FAN_DELTA, turn_off=True)
            # if temperature is constant or increasing we don't change fan speed
            # until it rises above COLD
            return 0.0
    
        # if temperature is decreasing we decrease fan speed slowly
        if temp_delta < 0.0:
            return get_decrease_fan_speed_delta(fan_speed, FAN_DELTA, turn_off=False)
    
        # if temperature is increasing we increase fan speed slowly
        if temp_delta > 0.0:
            return get_increase_fan_speed_delta(fan_speed, FAN_DELTA)
    
        # if temperature is not changing, don't change the fan speed
        return 0.0

    Запостил: GAMER, 30 Марта 2023

    Комментарии (3) RSS

    Добавить комментарий