-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
115 lines (94 loc) · 3.66 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
import tkinter as tk
from tkinter import ttk
def get_frostBuildUp(x):
if x < 2:
return (1, 0, 0) # Thin, Medium, Thick
elif 2 <= x <= 5:
return (0, (5 - x) / 3, (x - 2) / 3) # Thin, Medium, Thick
else:
return (0, 0, 1) # Thin, Medium, Thick
def get_tempInside(x):
if x < -18:
return (1, 0, 0) # Very Cold, Cold, Moderate
elif -18 <= x <= -10:
return (0, (-10 - x) / 8, (x + 18) / 8) # Very Cold, Cold, Moderate
elif -10 < x <= -1:
return (0, 0, 1) # Very Cold, Cold, Moderate
else:
return (0, 0, 1) # Very Cold, Cold, Moderate
def get_doorOpeningFreq(x):
if x < 5:
return (1, 0, 0) # Rarely, Occasionally, Frequently
elif 5 <= x <= 7:
return (0, (7 - x) / 2, (x - 5) / 2) # Rarely, Occasionally, Frequently
else:
return (0, 0, 1) # Rarely, Occasionally, Frequently
def get_tempOutside(x):
if x < 20:
return (1, 0, 0) # Cold, Moderate, Warm
elif 20 <= x <= 30:
return (0, (30 - x) / 10, (x - 20) / 10) # Cold, Moderate, Warm
else:
return (0, 0, 1) # Cold, Moderate, Warm
def defrost_cycle_weighted(frost_buildup, temp_inside, door_open_freq, temp_outside):
# Get fuzzy values
frost_values = get_frostBuildUp(frost_buildup)
temp_inside_values = get_tempInside(temp_inside)
door_open_freq_values = get_doorOpeningFreq(door_open_freq)
temp_outside_values = get_tempOutside(temp_outside)
# Initialize defrost cycle score
defrost_score = 0
# Apply rules
if frost_values[2] > 0: # Thick frost
defrost_score += 2
elif frost_values[1] > 0: # Medium frost
defrost_score += 1
if temp_inside_values[0] > 0: # Very Cold
defrost_score += 1
elif temp_inside_values[1] > 0: # Cold
defrost_score += 0.5
if door_open_freq_values[2] > 0: # Frequently
defrost_score -= 0.5
elif door_open_freq_values[1] > 0: # Occasionally
defrost_score -= 0.25
if temp_outside_values[0] > 0: # Cold outside
defrost_score += 0.5
elif temp_outside_values[2] > 0: # Warm outside
defrost_score -= 0.5
# Determine cycle based on score
if defrost_score >= 2:
return "Long"
elif defrost_score >= 1:
return "Medium"
else:
return "Short"
def simulate_defrost():
frost_buildup = frost_slider.get()
temp_inside = temp_inside_slider.get()
door_open_freq = door_freq_slider.get()
temp_outside = temp_outside_slider.get()
cycle_time = defrost_cycle_weighted(frost_buildup, temp_inside, door_open_freq, temp_outside)
result_label.config(text=f"Defrost cycle: {cycle_time}")
root = tk.Tk()
root.title("Refrigerator Defrost Simulator")
frost_label = tk.Label(root, text="Frost buildup (mm):")
frost_label.pack()
frost_slider = tk.Scale(root, from_=0, to_=10, orient="horizontal")
frost_slider.pack()
temp_inside_label = tk.Label(root, text="Temperature inside (°C):")
temp_inside_label.pack()
temp_inside_slider = tk.Scale(root, from_=-25, to_=5, orient="horizontal")
temp_inside_slider.pack()
door_freq_label = tk.Label(root, text="Door opening frequency (times per day):")
door_freq_label.pack()
door_freq_slider = tk.Scale(root, from_=0, to_=10, orient="horizontal")
door_freq_slider.pack()
temp_outside_label = tk.Label(root, text="Temperature outside (°C):")
temp_outside_label.pack()
temp_outside_slider = tk.Scale(root, from_=0, to_=40, orient="horizontal")
temp_outside_slider.pack()
start_button = tk.Button(root, text="Start Defrost Simulation", command=simulate_defrost)
start_button.pack()
result_label = tk.Label(root, text="Defrost cycle: ", font=("Arial", 14))
result_label.pack()
root.mainloop()