File size: 4,425 Bytes
92ab38b 5f90435 a44b04f dfe73bd 92ab38b dfe73bd 92ab38b dfe73bd 92ab38b a44b04f 92ab38b dfe73bd 92ab38b dfe73bd 92ab38b 517d947 dfe73bd 92ab38b 5f90435 a44b04f dfe73bd a44b04f dfe73bd 92ab38b a44b04f 517d947 5f90435 a44b04f 5f90435 517d947 a44b04f 517d947 a44b04f |
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 |
import os
import requests
import streamlit as st
import pandas as pd
from scraper import scrape_tariffs
# Streamlit App: Electricity Bill & Carbon Footprint Estimator
st.title("π Electricity Bill & Carbon Footprint Estimator")
st.sidebar.header("βοΈ User Input")
# Tariff URLs for scraping
tariff_urls = {
"IESCO": "https://iesco.com.pk/index.php/customer-services/tariff-guide",
"FESCO": "https://fesco.com.pk/tariff",
"HESCO": "http://www.hesco.gov.pk/htmls/tariffs.htm",
"KE": "https://www.ke.com.pk/customer-services/tariff-structure/",
"LESCO": "https://www.lesco.gov.pk/ElectricityTariffs",
"PESCO": "https://pesconlinebill.pk/pesco-tariff/",
"QESCO": "http://qesco.com.pk/Tariffs.aspx",
"TESCO": "https://tesco.gov.pk/index.php/electricity-traiff",
}
# Predefined appliances and their power in watts
appliances = {
"LED Bulb (10W)": 10,
"Ceiling Fan (75W)": 75,
"Refrigerator (150W)": 150,
"Air Conditioner (1.5 Ton, 1500W)": 1500,
"Washing Machine (500W)": 500,
"Television (100W)": 100,
"Laptop (65W)": 65,
"Iron (1000W)": 1000,
"Microwave Oven (1200W)": 1200,
"Water Heater (2000W)": 2000,
}
def scrape_data():
"""
Scrapes tariff data from the provided URLs.
"""
st.info("π Scraping tariff data... Please wait.")
scrape_tariffs(list(tariff_urls.values()))
st.success("β
Tariff data scraping complete.")
def calculate_carbon_footprint(monthly_energy_kwh):
"""
Calculates the carbon footprint based on energy consumption in kWh.
"""
carbon_emission_factor = 0.75 # kg CO2 per kWh
return monthly_energy_kwh * carbon_emission_factor
# Sidebar: Scrape Tariff Data
if st.sidebar.button("Scrape Tariff Data"):
scrape_data()
# Sidebar: Tariff Selection
st.sidebar.subheader("π‘ Select Tariff")
try:
tariff_data = pd.read_csv("data/tariffs.csv")
tariff_types = tariff_data["category"].unique()
selected_tariff = st.sidebar.selectbox("Select your tariff category:", tariff_types)
rate_per_kwh = tariff_data[tariff_data["category"] == selected_tariff]["rate"].iloc[0]
st.sidebar.write(f"Rate per kWh: **{rate_per_kwh} PKR**")
except FileNotFoundError:
st.sidebar.error("β οΈ Tariff data not found. Please scrape the data first.")
rate_per_kwh = 0
# Sidebar: User Inputs for Appliances
st.sidebar.subheader("π Add Appliances")
selected_appliance = st.sidebar.selectbox("Select an appliance:", list(appliances.keys()))
appliance_power = appliances[selected_appliance]
appliance_quantity = st.sidebar.number_input(
"Enter quantity:", min_value=1, max_value=10, value=1
)
usage_hours = st.sidebar.number_input(
"Enter usage hours per day:", min_value=1, max_value=24, value=5
)
# Add appliance details to the main list
if "appliance_list" not in st.session_state:
st.session_state["appliance_list"] = []
if st.sidebar.button("Add Appliance"):
st.session_state["appliance_list"].append(
{
"appliance": selected_appliance,
"power": appliance_power,
"quantity": appliance_quantity,
"hours": usage_hours,
}
)
# Display the list of added appliances
st.subheader("π Added Appliances")
if st.session_state["appliance_list"]:
for idx, appliance in enumerate(st.session_state["appliance_list"], start=1):
st.write(
f"{idx}. **{appliance['appliance']}** - "
f"{appliance['power']}W, {appliance['quantity']} unit(s), "
f"{appliance['hours']} hours/day"
)
# Electricity Bill and Carbon Footprint Calculation
if st.session_state["appliance_list"] and rate_per_kwh > 0:
total_daily_energy_kwh = sum(
(appliance["power"] * appliance["quantity"] * appliance["hours"]) / 1000
for appliance in st.session_state["appliance_list"]
)
monthly_energy_kwh = total_daily_energy_kwh * 30 # Assume 30 days in a month
bill_amount = monthly_energy_kwh * rate_per_kwh # Dynamic tariff rate
carbon_footprint = calculate_carbon_footprint(monthly_energy_kwh)
st.subheader("π΅ Electricity Bill & π Carbon Footprint")
st.write(f"π΅ **Estimated Electricity Bill**: **{bill_amount:.2f} PKR**")
st.write(f"π **Estimated Carbon Footprint**: **{carbon_footprint:.2f} kg CO2 per month**")
else:
st.info("βΉοΈ Add appliances to calculate the electricity bill and carbon footprint.")
|