Below is a Python “Occupancy Comfort Calculator” example. It’s a simple CLI tool that combines:
- Occupancy density (people / m²)
- Thermal comfort (difference from a set‐point temperature)
- Humidity comfort (difference from a set‐point RH)
and spits out an overall “Comfort Index” (0–100).
You can of course extend it later (e.g. add PMV/PPD, CO₂, noise, lighting, ASHRAE standards, etc.).
#!/usr/bin/env python3
"""
occupancy_comfort.py
A simple Occupancy Comfort Calculator.
"""
import argparse
def occupancy_density(people: int, area_m2: float) -> float:
"""People per square meter."""
return people / area_m2 if area_m2 > 0 else float('inf')
def density_score(density: float) -> float:
"""
Maps occupancy density to a score 0–100:
density <= 0.05 → very spacious → score ~100
density >= 0.25 → very crowded → score ~0
Linear in between.
"""
if density <= 0.05:
return 100.0
if density >= 0.25:
return 0.0
# linear interpolation between (0.05, 100) and (0.25, 0)
return max(0.0, min(100.0, (0.25 - density) / (0.20) * 100))
def thermal_score(temp: float, setpoint: float = 22.0, deadband: float = 2.0) -> float:
"""
Scores thermal comfort: ±deadband°C around setpoint → 100
Each °C beyond reduces score linearly to 0 at ±5°C.
"""
delta = abs(temp - setpoint)
if delta <= deadband:
return 100.0
if delta >= 5.0:
return 0.0
# between deadband and 5°C: linear drop
return max(0.0, (5.0 - delta) / (5.0 - deadband) * 100)
def humidity_score(rh: float, setpoint: float = 50.0, deadband: float = 10.0) -> float:
"""
Scores humidity comfort: ±deadband%RH around setpoint → 100
Each %RH beyond reduces linearly to 0 at ±30%RH.
"""
delta = abs(rh - setpoint)
if delta <= deadband:
return 100.0
if delta >= 30.0:
return 0.0
return max(0.0, (30.0 - delta) / (30.0 - deadband) * 100)
def overall_comfort(scores: list[float]) -> float:
"""Simple average of individual scores."""
return sum(scores) / len(scores)
def main():
parser = argparse.ArgumentParser(
description="Occupancy Comfort Calculator"
)
parser.add_argument("--people", type=int, required=True, help="Number of occupants")
parser.add_argument("--area", type=float, required=True, help="Room area in m²")
parser.add_argument("--temp", type=float, required=True, help="Current temperature (°C)")
parser.add_argument("--rh", type=float, required=True, help="Current relative humidity (%)")
parser.add_argument("--set-t", type=float, default=22.0, help="Thermal set‐point (°C)")
parser.add_argument("--set-rh", type=float, default=50.0, help="Humidity set‐point (%)")
args = parser.parse_args()
dens = occupancy_density(args.people, args.area)
ds = density_score(dens)
ts = thermal_score(args.temp, args.set_t)
hs = humidity_score(args.rh, args.set_rh)
overall = overall_comfort([ds, ts, hs])
print(f"\n--- Occupancy Comfort Report ---")
print(f" Occupancy density: {dens:.3f} people/m²")
print(f" → Density score : {ds:.1f}/100")
print(f" Temperature : {args.temp:.1f}°C (set‐point {args.set_t}°C)")
print(f" → Thermal score : {ts:.1f}/100")
print(f" Humidity : {args.rh:.1f}% (set‐point {args.set_rh}%)")
print(f" → Humidity score: {hs:.1f}/100")
print(f"\n Overall Comfort Index: {overall:.1f}/100")
print(f"--------------------------------\n")
if __name__ == "__main__":
main()
How to run:
$ python occupancy_comfort.py --people 8 --area 40 \
--temp 24.5 --rh 55
Sample output:
--- Occupancy Comfort Report ---
Occupancy density: 0.200 people/m²
→ Density score : 25.0/100
Temperature : 24.5°C (set‐point 22.0°C)
→ Thermal score : 87.5/100
Humidity : 55.0% (set‐point 50.0%)
→ Humidity score: 83.3/100
Overall Comfort Index: 65.3/100
--------------------------------
Feel free to adjust the scoring curves or plug in a more advanced thermal‐comfort model (e.g. PMV/PPD from pythermalcomfort) or add CO₂ and ventilation requirements. Let me know if you’d like to extend it! 😊