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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import math
|
| 3 |
+
|
| 4 |
+
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):
|
| 5 |
+
# Convert inputs to metric if necessary
|
| 6 |
+
if unit_system == "Imperial":
|
| 7 |
+
length = length * 0.3048 # feet to meters
|
| 8 |
+
width = width * 0.3048 # feet to meters
|
| 9 |
+
thickness = thickness * 0.0254 # inches to meters
|
| 10 |
+
|
| 11 |
+
# Calculate plaster area
|
| 12 |
+
plaster_area = length * width
|
| 13 |
+
|
| 14 |
+
# Calculate wet mortar volume
|
| 15 |
+
wet_mortar_volume = plaster_area * thickness
|
| 16 |
+
|
| 17 |
+
# Calculate dry mortar volume (accounting for dry volume factor)
|
| 18 |
+
dry_mortar_volume = wet_mortar_volume * dry_volume_factor
|
| 19 |
+
|
| 20 |
+
# Calculate total dry mortar volume with wastage
|
| 21 |
+
total_dry_mortar = dry_mortar_volume * (1 + wastage_percent/100)
|
| 22 |
+
|
| 23 |
+
# Calculate cement and sand quantities
|
| 24 |
+
total_parts = cement_ratio + sand_ratio
|
| 25 |
+
cement_volume = (cement_ratio / total_parts) * total_dry_mortar
|
| 26 |
+
sand_volume = (sand_ratio / total_parts) * total_dry_mortar
|
| 27 |
+
|
| 28 |
+
# Convert cement volume to weight and bags
|
| 29 |
+
cement_density = 1440 # kg/m3
|
| 30 |
+
cement_weight = cement_volume * cement_density
|
| 31 |
+
cement_bags = cement_weight / cement_bag_weight
|
| 32 |
+
|
| 33 |
+
# Calculate costs
|
| 34 |
+
cement_cost = cement_bags * cement_bag_price
|
| 35 |
+
total_plaster_cost = plaster_area * plaster_price_per_m2
|
| 36 |
+
|
| 37 |
+
return {
|
| 38 |
+
"Plaster area": plaster_area,
|
| 39 |
+
"Wet mortar volume": wet_mortar_volume,
|
| 40 |
+
"Dry mortar volume": dry_mortar_volume,
|
| 41 |
+
"Total dry mortar (with wastage)": total_dry_mortar,
|
| 42 |
+
"Cement volume": cement_volume,
|
| 43 |
+
"Cement weight": cement_weight,
|
| 44 |
+
"Cement bags": cement_bags,
|
| 45 |
+
"Sand volume": sand_volume,
|
| 46 |
+
"Cement cost": cement_cost,
|
| 47 |
+
"Total plaster cost": total_plaster_cost
|
| 48 |
+
}
|
| 49 |
+
|
| 50 |
+
def calculate_paint(length, width, subtract_area, coats, coverage_per_liter, paint_price_per_liter, unit_system):
|
| 51 |
+
# Convert inputs to metric if necessary
|
| 52 |
+
if unit_system == "Imperial":
|
| 53 |
+
length = length * 0.3048 # feet to meters
|
| 54 |
+
width = width * 0.3048 # feet to meters
|
| 55 |
+
subtract_area = subtract_area * 0.0929 # sqft to sqm
|
| 56 |
+
|
| 57 |
+
# Calculate total paintable area
|
| 58 |
+
total_area = (length * width) - subtract_area
|
| 59 |
+
|
| 60 |
+
# Calculate total paint required
|
| 61 |
+
total_liters = (total_area * coats) / coverage_per_liter
|
| 62 |
+
|
| 63 |
+
# Calculate total cost
|
| 64 |
+
total_cost = total_liters * paint_price_per_liter
|
| 65 |
+
|
| 66 |
+
return {
|
| 67 |
+
"Total area": total_area,
|
| 68 |
+
"Total liters": total_liters,
|
| 69 |
+
"Total cost": total_cost
|
| 70 |
+
}
|
| 71 |
+
|
| 72 |
+
def calculate_tiles(floor_length, floor_width, tile_length, tile_width, wastage_percent, tile_price_per_m2, unit_system):
|
| 73 |
+
# Convert inputs to metric if necessary
|
| 74 |
+
if unit_system == "Imperial":
|
| 75 |
+
floor_length = floor_length * 0.3048 # feet to meters
|
| 76 |
+
floor_width = floor_width * 0.3048 # feet to meters
|
| 77 |
+
tile_length = tile_length * 0.0254 # inches to meters
|
| 78 |
+
tile_width = tile_width * 0.0254 # inches to meters
|
| 79 |
+
|
| 80 |
+
# Calculate floor area
|
| 81 |
+
floor_area = floor_length * floor_width
|
| 82 |
+
|
| 83 |
+
# Calculate tile area
|
| 84 |
+
tile_area = tile_length * tile_width
|
| 85 |
+
|
| 86 |
+
# Calculate number of tiles needed (without wastage)
|
| 87 |
+
num_tiles = floor_area / tile_area
|
| 88 |
+
|
| 89 |
+
# Add wastage
|
| 90 |
+
total_tiles = num_tiles * (1 + wastage_percent/100)
|
| 91 |
+
|
| 92 |
+
# Calculate total cost
|
| 93 |
+
total_cost = floor_area * tile_price_per_m2
|
| 94 |
+
|
| 95 |
+
return {
|
| 96 |
+
"Floor area": floor_area,
|
| 97 |
+
"Tile area": tile_area,
|
| 98 |
+
"Number of tiles (without wastage)": num_tiles,
|
| 99 |
+
"Total tiles (with wastage)": math.ceil(total_tiles),
|
| 100 |
+
"Total cost": total_cost
|
| 101 |
+
}
|
| 102 |
+
|
| 103 |
+
def main():
|
| 104 |
+
st.title("Construction Calculator")
|
| 105 |
+
|
| 106 |
+
# Sidebar for navigation
|
| 107 |
+
st.sidebar.title("Navigation")
|
| 108 |
+
calculation_type = st.sidebar.radio(
|
| 109 |
+
"Select Calculation Type",
|
| 110 |
+
("Plaster", "Paint", "Tiles")
|
| 111 |
+
)
|
| 112 |
+
|
| 113 |
+
# Unit system selection
|
| 114 |
+
unit_system = st.sidebar.radio("Unit System", ("Metric", "Imperial"))
|
| 115 |
+
|
| 116 |
+
if calculation_type == "Plaster":
|
| 117 |
+
st.header("Plaster Calculation")
|
| 118 |
+
|
| 119 |
+
col1, col2 = st.columns(2)
|
| 120 |
+
|
| 121 |
+
with col1:
|
| 122 |
+
length = st.number_input("Length", min_value=0.0, value=1.0)
|
| 123 |
+
width = st.number_input("Width", min_value=0.0, value=1.0)
|
| 124 |
+
thickness = st.number_input("Plaster Thickness (m)", min_value=0.0, value=0.02)
|
| 125 |
+
|
| 126 |
+
st.subheader("Mortar Ratio")
|
| 127 |
+
cement_ratio = st.number_input("Cement", min_value=1, value=1)
|
| 128 |
+
sand_ratio = st.number_input("Sand", min_value=1, value=5)
|
| 129 |
+
|
| 130 |
+
with col2:
|
| 131 |
+
cement_bag_weight = st.number_input("Cement Bag Weight (kg)", min_value=0.0, value=50.0)
|
| 132 |
+
dry_volume_factor = st.number_input("Dry Volume Factor", min_value=0.0, value=1.27)
|
| 133 |
+
wastage_percent = st.number_input("Wastage %", min_value=0.0, value=2.0)
|
| 134 |
+
cement_bag_price = st.number_input("Cement Bag Price ($)", min_value=0.0, value=0.0)
|
| 135 |
+
plaster_price_per_m2 = st.number_input("Plaster Price per m² ($)", min_value=0.0, value=0.0)
|
| 136 |
+
|
| 137 |
+
if st.button("Calculate Plaster"):
|
| 138 |
+
results = calculate_plaster(
|
| 139 |
+
length, width, thickness, cement_ratio, sand_ratio,
|
| 140 |
+
cement_bag_weight, dry_volume_factor, wastage_percent,
|
| 141 |
+
cement_bag_price, plaster_price_per_m2, unit_system
|
| 142 |
+
)
|
| 143 |
+
|
| 144 |
+
st.subheader("Results")
|
| 145 |
+
st.table({
|
| 146 |
+
"Material": [
|
| 147 |
+
"Plaster area", "Wet mortar volume", "Dry mortar volume",
|
| 148 |
+
"Total dry mortar (with wastage)", "Cement volume",
|
| 149 |
+
"Cement weight", "Cement bags", "Sand volume",
|
| 150 |
+
"Cement cost", "Total plaster cost"
|
| 151 |
+
],
|
| 152 |
+
"Quantity": [
|
| 153 |
+
f"{results['Plaster area']:.2f} m²",
|
| 154 |
+
f"{results['Wet mortar volume']:.4f} m³",
|
| 155 |
+
f"{results['Dry mortar volume']:.4f} m³",
|
| 156 |
+
f"{results['Total dry mortar (with wastage)']:.4f} m³",
|
| 157 |
+
f"{results['Cement volume']:.4f} m³",
|
| 158 |
+
f"{results['Cement weight']:.2f} kg",
|
| 159 |
+
f"{results['Cement bags']:.2f} bags",
|
| 160 |
+
f"{results['Sand volume']:.4f} m³",
|
| 161 |
+
f"${results['Cement cost']:.2f}",
|
| 162 |
+
f"${results['Total plaster cost']:.2f}"
|
| 163 |
+
]
|
| 164 |
+
})
|
| 165 |
+
|
| 166 |
+
st.subheader("Calculation Steps")
|
| 167 |
+
st.write(f"1. Plaster Area = Length × Width = {length} × {width} = {results['Plaster area']:.2f} m²")
|
| 168 |
+
st.write(f"2. Wet Mortar Volume = Plaster Area × Thickness = {results['Plaster area']:.2f} × {thickness} = {results['Wet mortar volume']:.4f} m³")
|
| 169 |
+
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³")
|
| 170 |
+
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³")
|
| 171 |
+
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³")
|
| 172 |
+
st.write(f"6. Cement Weight = Cement Volume × Cement Density (1440 kg/m³) = {results['Cement volume']:.4f} × 1440 = {results['Cement weight']:.2f} kg")
|
| 173 |
+
st.write(f"7. Cement Bags = Cement Weight / Bag Weight = {results['Cement weight']:.2f} / {cement_bag_weight} = {results['Cement bags']:.2f} bags")
|
| 174 |
+
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³")
|
| 175 |
+
st.write(f"9. Cement Cost = Cement Bags × Bag Price = {results['Cement bags']:.2f} × {cement_bag_price} = ${results['Cement cost']:.2f}")
|
| 176 |
+
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}")
|
| 177 |
+
|
| 178 |
+
elif calculation_type == "Paint":
|
| 179 |
+
st.header("Paint Calculation")
|
| 180 |
+
|
| 181 |
+
col1, col2 = st.columns(2)
|
| 182 |
+
|
| 183 |
+
with col1:
|
| 184 |
+
length = st.number_input("Length", min_value=0.0, value=1.0)
|
| 185 |
+
width = st.number_input("Width", min_value=0.0, value=1.0)
|
| 186 |
+
subtract_area = st.number_input("Subtract Area", min_value=0.0, value=0.0)
|
| 187 |
+
|
| 188 |
+
with col2:
|
| 189 |
+
coats = st.number_input("Number of Coats", min_value=1, value=1)
|
| 190 |
+
coverage_per_liter = st.number_input("Coverage per Liter (m²)", min_value=0.0, value=9.5)
|
| 191 |
+
paint_price_per_liter = st.number_input("Paint Price per Liter ($)", min_value=0.0, value=0.0)
|
| 192 |
+
|
| 193 |
+
if st.button("Calculate Paint"):
|
| 194 |
+
results = calculate_paint(
|
| 195 |
+
length, width, subtract_area, coats,
|
| 196 |
+
coverage_per_liter, paint_price_per_liter, unit_system
|
| 197 |
+
)
|
| 198 |
+
|
| 199 |
+
st.subheader("Results")
|
| 200 |
+
st.table({
|
| 201 |
+
"Material": ["Total area", "Total liters", "Total cost"],
|
| 202 |
+
"Quantity": [
|
| 203 |
+
f"{results['Total area']:.2f} m²",
|
| 204 |
+
f"{results['Total liters']:.2f} liters",
|
| 205 |
+
f"${results['Total cost']:.2f}"
|
| 206 |
+
]
|
| 207 |
+
})
|
| 208 |
+
|
| 209 |
+
st.subheader("Calculation Steps")
|
| 210 |
+
st.write(f"1. Total Area = (Length × Width) - Subtract Area = ({length} × {width}) - {subtract_area} = {results['Total area']:.2f} m²")
|
| 211 |
+
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")
|
| 212 |
+
st.write(f"3. Total Cost = Total Liters × Price per Liter = {results['Total liters']:.2f} × {paint_price_per_liter} = ${results['Total cost']:.2f}")
|
| 213 |
+
|
| 214 |
+
elif calculation_type == "Tiles":
|
| 215 |
+
st.header("Tiles Calculation")
|
| 216 |
+
|
| 217 |
+
st.subheader("Floor Dimensions")
|
| 218 |
+
col1, col2 = st.columns(2)
|
| 219 |
+
|
| 220 |
+
with col1:
|
| 221 |
+
floor_length = st.number_input("Floor Length", min_value=0.0, value=1.0)
|
| 222 |
+
floor_width = st.number_input("Floor Width", min_value=0.0, value=1.0)
|
| 223 |
+
|
| 224 |
+
st.subheader("Tile Dimensions")
|
| 225 |
+
with col2:
|
| 226 |
+
tile_length = st.number_input("Tile Length", min_value=0.0, value=0.3)
|
| 227 |
+
tile_width = st.number_input("Tile Width", min_value=0.0, value=0.3)
|
| 228 |
+
|
| 229 |
+
st.subheader("Other Parameters")
|
| 230 |
+
wastage_percent = st.number_input("Wastage %", min_value=0.0, value=5.0)
|
| 231 |
+
tile_price_per_m2 = st.number_input("Tile Price per m² ($)", min_value=0.0, value=0.0)
|
| 232 |
+
|
| 233 |
+
if st.button("Calculate Tiles"):
|
| 234 |
+
results = calculate_tiles(
|
| 235 |
+
floor_length, floor_width, tile_length, tile_width,
|
| 236 |
+
wastage_percent, tile_price_per_m2, unit_system
|
| 237 |
+
)
|
| 238 |
+
|
| 239 |
+
st.subheader("Results")
|
| 240 |
+
st.table({
|
| 241 |
+
"Material": [
|
| 242 |
+
"Floor area", "Tile area", "Number of tiles (without wastage)",
|
| 243 |
+
"Total tiles (with wastage)", "Total cost"
|
| 244 |
+
],
|
| 245 |
+
"Quantity": [
|
| 246 |
+
f"{results['Floor area']:.2f} m²",
|
| 247 |
+
f"{results['Tile area']:.4f} m²",
|
| 248 |
+
f"{results['Number of tiles (without wastage)']:.0f}",
|
| 249 |
+
f"{results['Total tiles (with wastage)']}",
|
| 250 |
+
f"${results['Total cost']:.2f}"
|
| 251 |
+
]
|
| 252 |
+
})
|
| 253 |
+
|
| 254 |
+
st.subheader("Calculation Steps")
|
| 255 |
+
st.write(f"1. Floor Area = Length × Width = {floor_length} × {floor_width} = {results['Floor area']:.2f} m²")
|
| 256 |
+
st.write(f"2. Tile Area = Tile Length × Tile Width = {tile_length} × {tile_width} = {results['Tile area']:.4f} m²")
|
| 257 |
+
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}")
|
| 258 |
+
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)']}")
|
| 259 |
+
st.write(f"5. Total Cost = Floor Area × Price per m² = {results['Floor area']:.2f} × {tile_price_per_m2} = ${results['Total cost']:.2f}")
|
| 260 |
+
|
| 261 |
+
if __name__ == "__main__":
|
| 262 |
+
main()
|