File size: 2,149 Bytes
f455440
d25ef58
f455440
d25ef58
91b68d8
f455440
8b76fae
d57640e
8b76fae
 
f455440
 
 
91b68d8
f455440
 
 
 
 
 
91b68d8
f455440
 
 
91b68d8
 
 
 
 
 
 
 
d57640e
f455440
 
91b68d8
 
 
 
 
f7e5ea3
d57640e
91b68d8
 
 
8b76fae
f455440
91b68d8
 
 
d57640e
91b68d8
 
8b76fae
f455440
 
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
# streamlit_app.py
import streamlit as st
import scraper

# URLs for different companies
tariff_urls = {
    "IESCO": "https://iesco.com.pk/index.php/customer-services/tariff-guide",
    # Add other companies as needed
}

def main():
    st.title("PowerCalc: AI-Driven Bill & Carbon Footprint Tracker")
    
    # User input
    company = st.selectbox("Select your electricity company", list(tariff_urls.keys()))
    appliance_name = st.text_input("Appliance Name")
    load = st.number_input("Load of Appliance (kW)", min_value=0.0)
    daily_usage = st.number_input("Daily Usage Time (hours)", min_value=0.0)
    
    if st.button("Calculate"):
        # Fetch the tariff data for the selected company
        url = tariff_urls.get(company)
        tariff_data = scraper.fetch_tariff_data(url)
        
        if tariff_data:
            # Calculate monthly bill and carbon footprint
            monthly_bill = calculate_monthly_bill(tariff_data, load, daily_usage)
            carbon_footprint = calculate_carbon_footprint(load, daily_usage)
            
            st.write(f"Monthly Bill for {appliance_name}: Rs. {monthly_bill}")
            st.write(f"Carbon Footprint: {carbon_footprint} kg CO2")
        else:
            st.error("Error fetching tariff data. Please try again.")

def calculate_monthly_bill(tariff_data, load, daily_usage):
    daily_consumption = load * daily_usage  # kWh per day
    monthly_consumption = daily_consumption * 30  # kWh per month
    
    total_bill = 0
    for slab in tariff_data:
        if monthly_consumption > slab['lower_limit']:
            consumption_in_slab = min(monthly_consumption, slab['upper_limit']) - slab['lower_limit']
            total_bill += consumption_in_slab * slab['rate']
    
    return round(total_bill, 2)

def calculate_carbon_footprint(load, daily_usage):
    daily_consumption = load * daily_usage  # kWh per day
    monthly_consumption = daily_consumption * 30  # kWh per month
    
    emissions_factor = 0.92  # kg CO2 per kWh
    carbon_footprint = monthly_consumption * emissions_factor
    return round(carbon_footprint, 2)

if __name__ == "__main__":
    main()