Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,6 +2,7 @@
|
|
| 2 |
import streamlit as st
|
| 3 |
import scraper
|
| 4 |
|
|
|
|
| 5 |
tariff_urls = {
|
| 6 |
"IESCO": "https://iesco.com.pk/index.php/customer-services/tariff-guide",
|
| 7 |
"FESCO": "https://fesco.com.pk/tariff",
|
|
@@ -16,27 +17,51 @@ tariff_urls = {
|
|
| 16 |
def main():
|
| 17 |
st.title("PowerCalc: AI-Driven Bill & Carbon Footprint Tracker")
|
| 18 |
|
|
|
|
| 19 |
company = st.selectbox("Select your electricity company", list(tariff_urls.keys()))
|
| 20 |
appliance_name = st.text_input("Appliance Name")
|
| 21 |
load = st.number_input("Load of Appliance (kW)", min_value=0.0)
|
| 22 |
daily_usage = st.number_input("Daily Usage Time (hours)", min_value=0.0)
|
| 23 |
|
| 24 |
if st.button("Calculate"):
|
|
|
|
| 25 |
url = tariff_urls.get(company)
|
| 26 |
tariff_data = scraper.fetch_tariff_data(url)
|
| 27 |
-
monthly_bill = calculate_monthly_bill(tariff_data, load, daily_usage)
|
| 28 |
-
carbon_footprint = calculate_carbon_footprint(load, daily_usage)
|
| 29 |
|
| 30 |
-
|
| 31 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
|
| 33 |
def calculate_monthly_bill(tariff_data, load, daily_usage):
|
| 34 |
-
|
| 35 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
|
| 37 |
def calculate_carbon_footprint(load, daily_usage):
|
| 38 |
-
|
| 39 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
|
| 41 |
if __name__ == "__main__":
|
| 42 |
main()
|
|
|
|
| 2 |
import streamlit as st
|
| 3 |
import scraper
|
| 4 |
|
| 5 |
+
# URLs for different companies
|
| 6 |
tariff_urls = {
|
| 7 |
"IESCO": "https://iesco.com.pk/index.php/customer-services/tariff-guide",
|
| 8 |
"FESCO": "https://fesco.com.pk/tariff",
|
|
|
|
| 17 |
def main():
|
| 18 |
st.title("PowerCalc: AI-Driven Bill & Carbon Footprint Tracker")
|
| 19 |
|
| 20 |
+
# User input
|
| 21 |
company = st.selectbox("Select your electricity company", list(tariff_urls.keys()))
|
| 22 |
appliance_name = st.text_input("Appliance Name")
|
| 23 |
load = st.number_input("Load of Appliance (kW)", min_value=0.0)
|
| 24 |
daily_usage = st.number_input("Daily Usage Time (hours)", min_value=0.0)
|
| 25 |
|
| 26 |
if st.button("Calculate"):
|
| 27 |
+
# Fetch the tariff data for the selected company
|
| 28 |
url = tariff_urls.get(company)
|
| 29 |
tariff_data = scraper.fetch_tariff_data(url)
|
|
|
|
|
|
|
| 30 |
|
| 31 |
+
if tariff_data:
|
| 32 |
+
# Calculate monthly bill and carbon footprint
|
| 33 |
+
monthly_bill = calculate_monthly_bill(tariff_data, load, daily_usage)
|
| 34 |
+
carbon_footprint = calculate_carbon_footprint(load, daily_usage)
|
| 35 |
+
|
| 36 |
+
st.write(f"Monthly Bill for {appliance_name}: Rs. {monthly_bill}")
|
| 37 |
+
st.write(f"Carbon Footprint: {carbon_footprint} kg CO2")
|
| 38 |
+
else:
|
| 39 |
+
st.write("Error fetching tariff data. Please try again.")
|
| 40 |
|
| 41 |
def calculate_monthly_bill(tariff_data, load, daily_usage):
|
| 42 |
+
daily_consumption = load * daily_usage # kWh per day
|
| 43 |
+
monthly_consumption = daily_consumption * 30 # kWh per month
|
| 44 |
+
|
| 45 |
+
total_bill = 0
|
| 46 |
+
for slab in tariff_data:
|
| 47 |
+
slab_range = slab['slab'].split('-')
|
| 48 |
+
lower_limit = float(slab_range[0])
|
| 49 |
+
upper_limit = float(slab_range[1]) if len(slab_range) > 1 else float('inf')
|
| 50 |
+
|
| 51 |
+
if monthly_consumption > lower_limit:
|
| 52 |
+
consumption_in_slab = min(monthly_consumption, upper_limit) - lower_limit
|
| 53 |
+
total_bill += consumption_in_slab * slab['rate']
|
| 54 |
+
|
| 55 |
+
return round(total_bill, 2)
|
| 56 |
|
| 57 |
def calculate_carbon_footprint(load, daily_usage):
|
| 58 |
+
daily_consumption = load * daily_usage # kWh per day
|
| 59 |
+
monthly_consumption = daily_consumption * 30 # kWh per month
|
| 60 |
+
|
| 61 |
+
# Assuming 0.92 kg CO2 per kWh
|
| 62 |
+
emissions_factor = 0.92
|
| 63 |
+
carbon_footprint = monthly_consumption * emissions_factor
|
| 64 |
+
return round(carbon_footprint, 2)
|
| 65 |
|
| 66 |
if __name__ == "__main__":
|
| 67 |
main()
|