File size: 12,901 Bytes
6b80920
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import streamlit as st
import math

def calculate_plaster(length, width, thickness, cement_ratio, sand_ratio, cement_bag_weight, dry_volume_factor, wastage_percent, cement_bag_price, plaster_price_per_m2, unit_system):
    # Convert inputs to metric if necessary
    if unit_system == "Imperial":
        length = length * 0.3048  # feet to meters
        width = width * 0.3048    # feet to meters
        thickness = thickness * 0.0254  # inches to meters
    
    # Calculate plaster area
    plaster_area = length * width
    
    # Calculate wet mortar volume
    wet_mortar_volume = plaster_area * thickness
    
    # Calculate dry mortar volume (accounting for dry volume factor)
    dry_mortar_volume = wet_mortar_volume * dry_volume_factor
    
    # Calculate total dry mortar volume with wastage
    total_dry_mortar = dry_mortar_volume * (1 + wastage_percent/100)
    
    # Calculate cement and sand quantities
    total_parts = cement_ratio + sand_ratio
    cement_volume = (cement_ratio / total_parts) * total_dry_mortar
    sand_volume = (sand_ratio / total_parts) * total_dry_mortar
    
    # Convert cement volume to weight and bags
    cement_density = 1440  # kg/m3
    cement_weight = cement_volume * cement_density
    cement_bags = cement_weight / cement_bag_weight
    
    # Calculate costs
    cement_cost = cement_bags * cement_bag_price
    total_plaster_cost = plaster_area * plaster_price_per_m2
    
    return {
        "Plaster area": plaster_area,
        "Wet mortar volume": wet_mortar_volume,
        "Dry mortar volume": dry_mortar_volume,
        "Total dry mortar (with wastage)": total_dry_mortar,
        "Cement volume": cement_volume,
        "Cement weight": cement_weight,
        "Cement bags": cement_bags,
        "Sand volume": sand_volume,
        "Cement cost": cement_cost,
        "Total plaster cost": total_plaster_cost
    }

def calculate_paint(length, width, subtract_area, coats, coverage_per_liter, paint_price_per_liter, unit_system):
    # Convert inputs to metric if necessary
    if unit_system == "Imperial":
        length = length * 0.3048  # feet to meters
        width = width * 0.3048    # feet to meters
        subtract_area = subtract_area * 0.0929  # sqft to sqm
    
    # Calculate total paintable area
    total_area = (length * width) - subtract_area
    
    # Calculate total paint required
    total_liters = (total_area * coats) / coverage_per_liter
    
    # Calculate total cost
    total_cost = total_liters * paint_price_per_liter
    
    return {
        "Total area": total_area,
        "Total liters": total_liters,
        "Total cost": total_cost
    }

def calculate_tiles(floor_length, floor_width, tile_length, tile_width, wastage_percent, tile_price_per_m2, unit_system):
    # Convert inputs to metric if necessary
    if unit_system == "Imperial":
        floor_length = floor_length * 0.3048  # feet to meters
        floor_width = floor_width * 0.3048    # feet to meters
        tile_length = tile_length * 0.0254    # inches to meters
        tile_width = tile_width * 0.0254      # inches to meters
    
    # Calculate floor area
    floor_area = floor_length * floor_width
    
    # Calculate tile area
    tile_area = tile_length * tile_width
    
    # Calculate number of tiles needed (without wastage)
    num_tiles = floor_area / tile_area
    
    # Add wastage
    total_tiles = num_tiles * (1 + wastage_percent/100)
    
    # Calculate total cost
    total_cost = floor_area * tile_price_per_m2
    
    return {
        "Floor area": floor_area,
        "Tile area": tile_area,
        "Number of tiles (without wastage)": num_tiles,
        "Total tiles (with wastage)": math.ceil(total_tiles),
        "Total cost": total_cost
    }

def main():
    st.title("Construction Calculator")
    
    # Sidebar for navigation
    st.sidebar.title("Navigation")
    calculation_type = st.sidebar.radio(
        "Select Calculation Type",
        ("Plaster", "Paint", "Tiles")
    )
    
    # Unit system selection
    unit_system = st.sidebar.radio("Unit System", ("Metric", "Imperial"))
    
    if calculation_type == "Plaster":
        st.header("Plaster Calculation")
        
        col1, col2 = st.columns(2)
        
        with col1:
            length = st.number_input("Length", min_value=0.0, value=1.0)
            width = st.number_input("Width", min_value=0.0, value=1.0)
            thickness = st.number_input("Plaster Thickness (m)", min_value=0.0, value=0.02)
            
            st.subheader("Mortar Ratio")
            cement_ratio = st.number_input("Cement", min_value=1, value=1)
            sand_ratio = st.number_input("Sand", min_value=1, value=5)
        
        with col2:
            cement_bag_weight = st.number_input("Cement Bag Weight (kg)", min_value=0.0, value=50.0)
            dry_volume_factor = st.number_input("Dry Volume Factor", min_value=0.0, value=1.27)
            wastage_percent = st.number_input("Wastage %", min_value=0.0, value=2.0)
            cement_bag_price = st.number_input("Cement Bag Price ($)", min_value=0.0, value=0.0)
            plaster_price_per_m2 = st.number_input("Plaster Price per m² ($)", min_value=0.0, value=0.0)
        
        if st.button("Calculate Plaster"):
            results = calculate_plaster(
                length, width, thickness, cement_ratio, sand_ratio,
                cement_bag_weight, dry_volume_factor, wastage_percent,
                cement_bag_price, plaster_price_per_m2, unit_system
            )
            
            st.subheader("Results")
            st.table({
                "Material": [
                    "Plaster area", "Wet mortar volume", "Dry mortar volume",
                    "Total dry mortar (with wastage)", "Cement volume",
                    "Cement weight", "Cement bags", "Sand volume",
                    "Cement cost", "Total plaster cost"
                ],
                "Quantity": [
                    f"{results['Plaster area']:.2f} m²",
                    f"{results['Wet mortar volume']:.4f} m³",
                    f"{results['Dry mortar volume']:.4f} m³",
                    f"{results['Total dry mortar (with wastage)']:.4f} m³",
                    f"{results['Cement volume']:.4f} m³",
                    f"{results['Cement weight']:.2f} kg",
                    f"{results['Cement bags']:.2f} bags",
                    f"{results['Sand volume']:.4f} m³",
                    f"${results['Cement cost']:.2f}",
                    f"${results['Total plaster cost']:.2f}"
                ]
            })
            
            st.subheader("Calculation Steps")
            st.write(f"1. Plaster Area = Length × Width = {length} × {width} = {results['Plaster area']:.2f} m²")
            st.write(f"2. Wet Mortar Volume = Plaster Area × Thickness = {results['Plaster area']:.2f} × {thickness} = {results['Wet mortar volume']:.4f} m³")
            st.write(f"3. Dry Mortar Volume = Wet Mortar Volume × Dry Volume Factor = {results['Wet mortar volume']:.4f} × {dry_volume_factor} = {results['Dry mortar volume']:.4f} m³")
            st.write(f"4. Total Dry Mortar (with {wastage_percent}% wastage) = {results['Dry mortar volume']:.4f} × {1 + wastage_percent/100} = {results['Total dry mortar (with wastage)']:.4f} m³")
            st.write(f"5. Cement Volume = (Cement Ratio / Total Parts) × Total Dry Mortar = ({cement_ratio}/{cement_ratio + sand_ratio}) × {results['Total dry mortar (with wastage)']:.4f} = {results['Cement volume']:.4f} m³")
            st.write(f"6. Cement Weight = Cement Volume × Cement Density (1440 kg/m³) = {results['Cement volume']:.4f} × 1440 = {results['Cement weight']:.2f} kg")
            st.write(f"7. Cement Bags = Cement Weight / Bag Weight = {results['Cement weight']:.2f} / {cement_bag_weight} = {results['Cement bags']:.2f} bags")
            st.write(f"8. Sand Volume = (Sand Ratio / Total Parts) × Total Dry Mortar = ({sand_ratio}/{cement_ratio + sand_ratio}) × {results['Total dry mortar (with wastage)']:.4f} = {results['Sand volume']:.4f} m³")
            st.write(f"9. Cement Cost = Cement Bags × Bag Price = {results['Cement bags']:.2f} × {cement_bag_price} = ${results['Cement cost']:.2f}")
            st.write(f"10. Total Plaster Cost = Plaster Area × Price per m² = {results['Plaster area']:.2f} × {plaster_price_per_m2} = ${results['Total plaster cost']:.2f}")
    
    elif calculation_type == "Paint":
        st.header("Paint Calculation")
        
        col1, col2 = st.columns(2)
        
        with col1:
            length = st.number_input("Length", min_value=0.0, value=1.0)
            width = st.number_input("Width", min_value=0.0, value=1.0)
            subtract_area = st.number_input("Subtract Area", min_value=0.0, value=0.0)
        
        with col2:
            coats = st.number_input("Number of Coats", min_value=1, value=1)
            coverage_per_liter = st.number_input("Coverage per Liter (m²)", min_value=0.0, value=9.5)
            paint_price_per_liter = st.number_input("Paint Price per Liter ($)", min_value=0.0, value=0.0)
        
        if st.button("Calculate Paint"):
            results = calculate_paint(
                length, width, subtract_area, coats,
                coverage_per_liter, paint_price_per_liter, unit_system
            )
            
            st.subheader("Results")
            st.table({
                "Material": ["Total area", "Total liters", "Total cost"],
                "Quantity": [
                    f"{results['Total area']:.2f} m²",
                    f"{results['Total liters']:.2f} liters",
                    f"${results['Total cost']:.2f}"
                ]
            })
            
            st.subheader("Calculation Steps")
            st.write(f"1. Total Area = (Length × Width) - Subtract Area = ({length} × {width}) - {subtract_area} = {results['Total area']:.2f} m²")
            st.write(f"2. Total Paint Required = (Total Area × Number of Coats) / Coverage per Liter = ({results['Total area']:.2f} × {coats}) / {coverage_per_liter} = {results['Total liters']:.2f} liters")
            st.write(f"3. Total Cost = Total Liters × Price per Liter = {results['Total liters']:.2f} × {paint_price_per_liter} = ${results['Total cost']:.2f}")
    
    elif calculation_type == "Tiles":
        st.header("Tiles Calculation")
        
        st.subheader("Floor Dimensions")
        col1, col2 = st.columns(2)
        
        with col1:
            floor_length = st.number_input("Floor Length", min_value=0.0, value=1.0)
            floor_width = st.number_input("Floor Width", min_value=0.0, value=1.0)
        
        st.subheader("Tile Dimensions")
        with col2:
            tile_length = st.number_input("Tile Length", min_value=0.0, value=0.3)
            tile_width = st.number_input("Tile Width", min_value=0.0, value=0.3)
        
        st.subheader("Other Parameters")
        wastage_percent = st.number_input("Wastage %", min_value=0.0, value=5.0)
        tile_price_per_m2 = st.number_input("Tile Price per m² ($)", min_value=0.0, value=0.0)
        
        if st.button("Calculate Tiles"):
            results = calculate_tiles(
                floor_length, floor_width, tile_length, tile_width,
                wastage_percent, tile_price_per_m2, unit_system
            )
            
            st.subheader("Results")
            st.table({
                "Material": [
                    "Floor area", "Tile area", "Number of tiles (without wastage)",
                    "Total tiles (with wastage)", "Total cost"
                ],
                "Quantity": [
                    f"{results['Floor area']:.2f} m²",
                    f"{results['Tile area']:.4f} m²",
                    f"{results['Number of tiles (without wastage)']:.0f}",
                    f"{results['Total tiles (with wastage)']}",
                    f"${results['Total cost']:.2f}"
                ]
            })
            
            st.subheader("Calculation Steps")
            st.write(f"1. Floor Area = Length × Width = {floor_length} × {floor_width} = {results['Floor area']:.2f} m²")
            st.write(f"2. Tile Area = Tile Length × Tile Width = {tile_length} × {tile_width} = {results['Tile area']:.4f} m²")
            st.write(f"3. Number of Tiles (without wastage) = Floor Area / Tile Area = {results['Floor area']:.2f} / {results['Tile area']:.4f} = {results['Number of tiles (without wastage)']:.0f}")
            st.write(f"4. Total Tiles (with {wastage_percent}% wastage) = {results['Number of tiles (without wastage)']:.0f} × {1 + wastage_percent/100} = {results['Total tiles (with wastage)']}")
            st.write(f"5. Total Cost = Floor Area × Price per m² = {results['Floor area']:.2f} × {tile_price_per_m2} = ${results['Total cost']:.2f}")

if __name__ == "__main__":
    main()