-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCLASS_DIAGRAM.py
More file actions
263 lines (219 loc) · 13.6 KB
/
Copy pathCLASS_DIAGRAM.py
File metadata and controls
263 lines (219 loc) · 13.6 KB
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
"""
ASCII Class Diagram - Sustainable Resource Management System
Visual representation of the OOP architecture
"""
CLASS_HIERARCHY = """
╔══════════════════════════════════════════════════════════════════╗
║ SUSTAINABLE RESOURCE MANAGEMENT SYSTEM ║
║ CLASS HIERARCHY DIAGRAM ║
╚══════════════════════════════════════════════════════════════════╝
┌─────────────────────────────────────────────────────────────────┐
│ ABSTRACTION LAYER │
└─────────────────────────────────────────────────────────────────┘
╔════════════════════╗
║ Resource (ABC) ║ ← Abstract Base Class
╠════════════════════╣
║ - name ║
║ - _total_available ║ ← Protected (Encapsulation)
║ - _available ║ ← Protected (Encapsulation)
║ - renewable ║
╠════════════════════╣
║ + update_availability() ║
║ + report_usage()* ║ ← Abstract (Polymorphism)
║ + get_status() ║
║ + @property methods║ ← Getters (Encapsulation)
╚════════════════════╝
│
│ Inheritance
┌─────────────────┴─────────────────┐
│ │ │
▼ ▼ ▼
┌──────────────┐ ┌──────────────┐ ┌──────────────┐
│WaterResource │ │EnergyResource│ │WasteResource │
├──────────────┤ ├──────────────┤ ├──────────────┤
│+ water_type │ │+ energy_type │ │+ waste_type │
│+ unit │ │+ unit │ │+ unit │
├──────────────┤ ├──────────────┤ ├──────────────┤
│+ report_usage│ │+ report_usage│ │+ report_usage│
│+ check_cont..│ │+ calc_carbon │ │+ get_recycl..│
└──────────────┘ └──────────────┘ └──────────────┘
│ │ │
└───────────────────┴───────────────────┘
│
│ Used by (Composition)
▼
┌──────────────────┐
│ Consumer │
├──────────────────┤
│ - consumer_id │
│ - name │
│ - _assigned_res..│ ← Resources (Composition)
│ - _usage_log │ ← Protected
├──────────────────┤
│ + assign_resource() │
│ + use_resource() │
│ + generate_report() │
└──────────────────┘
│
│ Managed by
▼
┌──────────────────┐
│ResourceManager │ ← Orchestration
├──────────────────┤
│ - _resources │ ← Dict of Resources
│ - _consumers │ ← Dict of Consumers
├──────────────────┤
│ + add_resource() │
│ + add_consumer() │
│ + generate_report() │
│ + calc_sustainability│
│ + get_recommendations│
└──────────────────┘
┌─────────────────────────────────────────────────────────────────┐
│ OOP PRINCIPLES MAPPING │
└─────────────────────────────────────────────────────────────────┘
[1] ABSTRACTION
• Resource class is abstract (ABC)
• Cannot be instantiated directly
• Defines common interface for all resources
• report_usage() is abstract method
[2] INHERITANCE
• WaterResource ← inherits from → Resource
• EnergyResource ← inherits from → Resource
• WasteResource ← inherits from → Resource
• All children get parent's attributes and methods
• Children can add their own specific features
[3] ENCAPSULATION
• Protected attributes: _total_available, _available, _usage_history
• Public getter properties: total_available, available, used
• Controlled access through methods
• Data validation in update_availability()
[4] POLYMORPHISM
• report_usage() implemented differently in each subclass
• Same method call, different behavior
• Enables uniform interface across resource types
┌─────────────────────────────────────────────────────────────────┐
│ RELATIONSHIPS │
└─────────────────────────────────────────────────────────────────┘
IS-A Relationship (Inheritance):
WaterResource IS-A Resource
EnergyResource IS-A Resource
WasteResource IS-A Resource
HAS-A Relationship (Composition):
Consumer HAS-A Dictionary of Resources
Consumer HAS-A Usage Log
ResourceManager HAS-A Dictionary of Resources
ResourceManager HAS-A Dictionary of Consumers
┌─────────────────────────────────────────────────────────────────┐
│ DATA FLOW │
└─────────────────────────────────────────────────────────────────┘
1. User Action (Streamlit UI)
↓
2. ResourceManager (Orchestration)
↓
3. Consumer (Business Logic)
↓
4. Resource (Data Validation)
↓
5. Update State (Encapsulation)
↓
6. Return Result (to UI)
┌─────────────────────────────────────────────────────────────────┐
│ METHOD VISIBILITY │
└─────────────────────────────────────────────────────────────────┘
PUBLIC Methods (accessible to all):
✓ update_availability()
✓ report_usage()
✓ get_status()
✓ assign_resource()
✓ use_resource()
PROTECTED Attributes (convention, not enforced):
_ _total_available
_ _available
_ _assigned_resources
_ _usage_log
ACCESSIBLE via Properties (getters):
@ property total_available
@ property available
@ property used
@ property usage_percentage
┌─────────────────────────────────────────────────────────────────┐
│ DESIGN PATTERNS │
└─────────────────────────────────────────────────────────────────┘
[1] Template Method Pattern
Resource.get_status() provides template
Subclasses use parent implementation
[2] Strategy Pattern
Different report_usage() implementations
Interchangeable algorithms
[3] Manager Pattern
ResourceManager orchestrates all components
Central point of control
[4] Composition Pattern
Consumer contains Resources
Flexible relationship
┌─────────────────────────────────────────────────────────────────┐
│ FILE ARCHITECTURE │
└─────────────────────────────────────────────────────────────────┘
resource_management.py (BACKEND)
├── Resource (ABC)
├── WaterResource
├── EnergyResource
├── WasteResource
├── Consumer
└── ResourceManager
app.py (FRONTEND)
├── load_custom_css()
├── init_session_state()
├── render_dashboard()
├── render_resource_management()
├── render_consumer_management()
├── render_consumption_tracking()
└── render_reports()
┌─────────────────────────────────────────────────────────────────┐
│ EXECUTION FLOW │
└─────────────────────────────────────────────────────────────────┘
START: streamlit run app.py
│
├─> Load CSS (styling)
├─> Initialize Session State
│ └─> Create ResourceManager
│ └─> Load Demo Data
│ ├─> Create Resources (Water, Energy, Waste)
│ ├─> Create Consumers
│ └─> Assign Resources to Consumers
│
├─> Render Navigation (Sidebar)
│
└─> Render Selected Page
├─> Dashboard (Metrics, Charts, Alerts)
├─> Resources (Add, View, Manage)
├─> Consumers (Add, View, Reports)
├─> Consumption (Record Usage, Validate)
└─> Reports (Analytics, Sustainability)
┌─────────────────────────────────────────────────────────────────┐
│ KEY FEATURES SUMMARY │
└─────────────────────────────────────────────────────────────────┘
Backend (OOP):
✓ 6 Classes (1 abstract, 3 inherited, 2 managers)
✓ 40+ Methods
✓ Complete error handling
✓ Type hints throughout
✓ Comprehensive docstrings
Frontend (Streamlit):
✓ 5 Interactive pages
✓ Custom CSS animations
✓ Plotly charts
✓ Real-time validation
✓ Professional design
Documentation:
✓ README.md (Installation & Usage)
✓ OOP_DOCUMENTATION.md (Learning Guide)
✓ DEMO_GUIDE.md (Presentation Script)
✓ PROJECT_SUMMARY.md (Overview)
✓ This file (Visual Reference)
═══════════════════════════════════════════════════════════════════
END OF CLASS DIAGRAM
═══════════════════════════════════════════════════════════════════
"""
print(CLASS_HIERARCHY)