Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rohin new front end #12

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fixed problems
fixed commit problems
Rraina12310 committed Oct 30, 2024
commit 7e46d0e88a595400c6f81f6fa69868a8dd07dfec
Binary file modified src/solar_calculator/__pycache__/location.cpython-312.pyc
Binary file not shown.
126 changes: 85 additions & 41 deletions src/solar_calculator/app.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,25 @@
import requests
import requests
import os
import math
from location import location # Assumed to be a custom module for getting location data
from flask import Flask, jsonify, request
from flask_cors import CORS


# Initialize Flask application
app = Flask(__name__)
CORS(app) # Enable Cross-Origin Resource Sharing (CORS)


# NREL PVWatts API URL
url = 'https://developer.nrel.gov/api/pvwatts/v8.json'


##Constants
ppr = 0.375 #power panel rating of LG NeON 2 solar panels in kW
cost_perW = 2.75 #average cost for a solar panel per watt of power panel rating in dollars


# Flask route to handle POST requests for system information
@app.route('/getSystemInfo', methods=['POST'])
def get_system_info():
@@ -23,83 +32,118 @@ def get_system_info():
print(pvw_result)
return jsonify(pvw_result) # Return the results as JSON




# Read the API key from a text file
api_file = open("api-keys.txt", "r")
line = api_file.readlines()[0]
api_key = line.split(',')[1] # Extract API key from the file
#api_file = open("api-keys.txt", "r")
#line = api_file.readlines()[0]
#print(line)
#api_key = line.split(',')[1] # Extract API key from the file
api_key = '5cfaHYaMmcrwrpWaI6b3940c9vhzgiTYVG3fB4Sg'






# Function to process system information using PVWatts API
def process_system_info(address, annual_energy_use):
global results
results = "none"
if address is None or annual_energy_use is None: # Check if address and annual energy use are provided
print("No System Info.")
return results # Return default results if missing


loc = location(address) # Get location details (latitude and longitude) from the 'location' module
params = {
params_min = {
"api_key": 'DEMO_KEY', # API key for the request
"azimuth": 0, # Azimuth angle for solar panels
"azimuth": 180, # Azimuth angle for solar panels (0 for true north, 90 for east, 180 for south, and 270 for west)
"lat": loc.latitude, # Latitude of the location
"lon": loc.longitude, # Longitude of the location
"system_capacity": 4, # System capacity in kW
"system_capacity": 0.375, # System capacity in kW
"losses": 14, # Estimated system losses (%)
"array_type": 1, # Fixed tilt array type
"module_type": 0, # Standard module type
"gcr": 0.4, # Ground cover ratio
"dc_ac_ratio": 1.2, # DC to AC size ratio
"inv_eff": 96.0, # Inverter efficiency (%)
"radius": 0, # Search radius for weather data
"dataset": "nsrdb", # Dataset for solar data
"tilt": 10 # Tilt angle of the panels
}
"tilt": 30 # Tilt angle of the panels (usually between 20-30)
}


#creating a second set of paramaters so that the program can output a range from the min number of panels needed to the max number
params_max = params_min.copy()
params_max["azimuth"] = 90 #assuming the azimuth is east facing

# Make a GET request to PVWatts API
response = requests.get(url, params=params)
data = response.json() # Convert response to JSON format

response = requests.get(url, params=params_min)
response2 = requests.get(url, params = params_max)
data_min = response.json() # Convert response to JSON format
data_max = response2.json() # Convert response to JSON format

# Check if the response contains necessary data
if 'outputs' in data and 'ac_annual' in data['outputs']:
ac_annual = data['outputs']['ac_annual'] # Annual AC energy output in kWh
solrad_annual = data['outputs']['solrad_annual'] # Annual solar radiation
capacity_factor = data['outputs']['capacity_factor'] # Capacity factor

if 'outputs' in data_min and 'ac_annual' in data_min['outputs']:
ac_annual_min = data_min['outputs']['ac_annual'] # Annual AC energy output in kWh
ac_annual_max = data_max['outputs']['ac_annual']
solrad_monthly = data_min['outputs']['solrad_monthly'] # Annual solar radiation
capacity_factor = data_min['outputs']['capacity_factor'] # Capacity factor
ac_monthly = data_min['outputs']['ac_monthly']
# Calculate additional system details
pv_system = get_pv_system(annual_energy_use) # Calculate PV system size
num_panels = get_num_panels(pv_system) # Calculate number of panels needed
num_batteries = get_num_batteries(pv_system) # Calculate number of batteries needed
pv_cost = get_pv_cost(pv_system, num_panels, num_batteries) # Calculate total cost of PV system

#pv_system = get_pv_system(annual_energy_use) # Calculate PV system size
#num_batteries = get_num_batteries(pv_system) # Calculate number of batteries needed
num_panels_min = math.ceil(annual_energy_use/ac_annual_min)
num_panels_max = math.ceil(annual_energy_use/ac_annual_max)
pv_system_cost_min = ppr * 1000 * cost_perW * num_panels_min
pv_system_cost_max = ppr * 1000 * cost_perW * num_panels_max

# Store results in a dictionary
results = {
"ac_annual": ac_annual,
"solrad_annual": solrad_annual,
"capacity_factor": capacity_factor,
"pv_system": pv_system,
"num_panels": num_panels,
"num_batteries": num_batteries,
"pv_cost": pv_cost
"ac_monthly" : ac_monthly,
"ac_annual": ac_annual_min,
#"solrad_monthly": solrad_monthly,
#"capacity_factor": capacity_factor,
#"pv_system": pv_system,
"num_panels": (num_panels_min, num_panels_max),
#"num_batteries": num_batteries,
"pv_system_cost": (pv_system_cost_min, pv_system_cost_max)
}
# Print estimated results
print(f"\nEstimated annual AC energy production: {ac_annual} kWh")
print(f"Estimated annual solar radiation: {solrad_annual}")
print(f"Estimated annual solar radiation: {capacity_factor}")

print(f"Estimated Cost for Solar Panels: {results['pv_system_cost']}")
print(f"Num Pannels: {results["num_panels"]}")




return results


# Function to estimate daily energy production per panel
# ppr = Panel Power Rating(Using LG NeON 2 as default panel specifications), rad = avg daily solar radiation for
# a particular month, eff = system efficiency (1-(losses/100)), cons = monthly energy consumption
# ppr MUST BE IN kW NOT W
""" def get_num_panels(ppr, rad, eff, cons):
return (math.ceil(cons/(ppr * rad * eff * 30))) """




# Function to estimate the PV system size based on annual energy use
def get_pv_system(annual_energy_use):
return (((annual_energy_use / 365) * 1.29)/ 5.07)

# Function to calculate the number of solar panels needed
def get_num_panels(pv_system):
return round((pv_system / 0.365), 0)

# Function to calculate the number of batteries needed
def get_num_batteries(pv_system):
return round(((pv_system * 3) / 4.8), 0)


# Function to calculate the total cost of the PV system
def get_pv_cost(pv_system, num_panels, num_batteries):
panel_cost = (num_panels * 1.8 * 108) + (3270 * pv_system) # Calculate cost of panels
battery_cost = 535 * num_batteries # Calculate cost of batteries
return (0.7 * (panel_cost + battery_cost)) # Return total cost with a 30% reduction


#print(process_system_info("453 Booth Street, Ottawa ON",10000)["pv_cost"])
process_system_info("1600 Pennsylvania Ave, Dallas, TX 75201",12000)
print("hello")