implemented existing Solar Panel #7
			
				
			
		
		
		
	| 
						 | 
				
			
			@ -1,8 +1,13 @@
 | 
			
		|||
import tkinter
 | 
			
		||||
import threading
 | 
			
		||||
 | 
			
		||||
import selenium.webdriver.firefox.service
 | 
			
		||||
import webdriver_manager.chrome
 | 
			
		||||
from selenium import webdriver
 | 
			
		||||
from selenium.webdriver.chrome.service import Service
 | 
			
		||||
from selenium.webdriver.firefox.service import Service
 | 
			
		||||
from webdriver_manager.chrome import ChromeDriverManager
 | 
			
		||||
from webdriver_manager.firefox import DriverManager
 | 
			
		||||
from selenium.webdriver.common.by import By
 | 
			
		||||
from selenium.webdriver.common.keys import Keys
 | 
			
		||||
from PIL import Image
 | 
			
		||||
| 
						 | 
				
			
			@ -16,8 +21,9 @@ from selenium.webdriver.common.action_chains import ActionChains
 | 
			
		|||
import json
 | 
			
		||||
import requests
 | 
			
		||||
import statistics
 | 
			
		||||
from webdriver_manager.firefox import GeckoDriverManager
 | 
			
		||||
 | 
			
		||||
DropDownLabels = ["Street: ", "Number: ", "Postal code: ", "City: ", "coordinate X", "coordinate Y", "Sonnendach URL: ", "Suitability:", "Image Filename: ", "PV Production 100", "Value Electricity production", "Roof area"]
 | 
			
		||||
DropDownLabels = ["Street: ", "Number: ", "Postal code: ", "City: ", "coordinate X", "coordinate Y", "Sonnendach URL: ", "Suitability:", "Image Filename: ", "PV Production 100", "Value Electricity production", "Roof area", "existing PV Production"]
 | 
			
		||||
file_split_char = ","
 | 
			
		||||
minRoofSize = 2
 | 
			
		||||
minSuitability = 3
 | 
			
		||||
| 
						 | 
				
			
			@ -28,14 +34,16 @@ stopThread = False
 | 
			
		|||
filename_adresslist = ""
 | 
			
		||||
adresslist = ""
 | 
			
		||||
step = 0
 | 
			
		||||
service = Service(ChromeDriverManager().install())
 | 
			
		||||
driver = webdriver.Chrome(service=service)
 | 
			
		||||
# service = Service(webdriver_manager.chrome.ChromeDriverManager().install())
 | 
			
		||||
service = selenium.webdriver.firefox.service.Service(GeckoDriverManager().install())
 | 
			
		||||
# driver = webdriver.Chrome(service=service)
 | 
			
		||||
driver = webdriver.Firefox(service=service)
 | 
			
		||||
driver.minimize_window()
 | 
			
		||||
outputtext = "Welcome to application Sonnendach\n"
 | 
			
		||||
columnIndexes = []
 | 
			
		||||
storeToDolibarr = True
 | 
			
		||||
dolibarrURL = ""
 | 
			
		||||
dolibarrApiKey = ""
 | 
			
		||||
storeToDolibarr = False
 | 
			
		||||
dolibarrURL = "https://doli.solar-evolution.ch/api/index.php/thirdparties"
 | 
			
		||||
dolibarrApiKey = "riE0jT3yvpIT"
 | 
			
		||||
dolibarrCountryID = "6" # 6 = Schweiz
 | 
			
		||||
dolibarrCountryCode = "CH"
 | 
			
		||||
dolibarrStateID = "403" # 403 = Kanton Zürich
 | 
			
		||||
| 
						 | 
				
			
			@ -166,11 +174,11 @@ def search_adresses(adress_list, filename_adresslist, driver, mainText):
 | 
			
		|||
                            if(float(roof['attributes']['flaeche']) > minRoofSize and int(roof['attributes']['klasse']) >= minSuitability):
 | 
			
		||||
                                sumEnergyRoofs = sumEnergyRoofs + energy
 | 
			
		||||
                                sumRoofArea = sumRoofArea + float(roof['attributes']['flaeche'])
 | 
			
		||||
                                suitabilities.append(int(roof['attributes']['klasse']) * float(roof['attributes']['flaeche']))
 | 
			
		||||
                                suitabilities.append(int(roof['attributes']['klasse']))
 | 
			
		||||
 | 
			
		||||
                        featureId = str(bestRoof['featureId'])
 | 
			
		||||
                        url = "https://www.uvek-gis.admin.ch/BFE/sonnendach/index.html?featureId=" + featureId + "&lang=de"
 | 
			
		||||
                        suitability = statistics.mean(suitabilities) / sumRoofArea
 | 
			
		||||
                        suitability = max(suitabilities)
 | 
			
		||||
                        value_electricity_production = sumEnergyRoofs * electricityPrice
 | 
			
		||||
                    else:
 | 
			
		||||
                        found = False
 | 
			
		||||
| 
						 | 
				
			
			@ -179,8 +187,33 @@ def search_adresses(adress_list, filename_adresslist, driver, mainText):
 | 
			
		|||
 | 
			
		||||
            roof_is_suitable = True # TODO decide if roof is suitable
 | 
			
		||||
 | 
			
		||||
            if(found and createImages.get() > 0 and roof_is_suitable):
 | 
			
		||||
                image_filename = suitability + " - " + address_string + ".png"
 | 
			
		||||
            existing_solar_panel_power = "none"
 | 
			
		||||
            roof_has_solarpanel = False # TODO check if roof has solar Panel
 | 
			
		||||
 | 
			
		||||
            #Check if there is solar panel existing
 | 
			
		||||
            address_string_for_existing_solarpanel = adress[columnIndexes[0]] + " " + adress[columnIndexes[1]] + ", " + adress[columnIndexes[2]] + " " + adress[columnIndexes[3]]
 | 
			
		||||
            try:
 | 
			
		||||
                params = {
 | 
			
		||||
                    'searchText': str(address_string_for_existing_solarpanel),
 | 
			
		||||
                    'searchField': 'address',
 | 
			
		||||
                    'layer': "ch.bfe.elektrizitaetsproduktionsanlagen",
 | 
			
		||||
                    'returnGeometry': 'false',
 | 
			
		||||
                    'contains': 'false'
 | 
			
		||||
                }
 | 
			
		||||
                repsonse_solar_panel = requests.get('https://api3.geo.admin.ch/rest/services/api/MapServer/find',
 | 
			
		||||
                                                    params=params)
 | 
			
		||||
                repsonse_solar_panel_decoded = json.loads(repsonse_solar_panel.content.decode())
 | 
			
		||||
                print(repsonse_solar_panel_decoded)
 | 
			
		||||
                results = (repsonse_solar_panel_decoded['results'])
 | 
			
		||||
                if(len(results) > 0):
 | 
			
		||||
                    existing_solar_panel_power = results[0]['attributes']['total_power']
 | 
			
		||||
 | 
			
		||||
            except:
 | 
			
		||||
                existing_solar_panel_power = "not-found"
 | 
			
		||||
                roof_has_solarpanel = False
 | 
			
		||||
 | 
			
		||||
            if(found and createImages.get() > 0 and roof_is_suitable and (not roof_has_solarpanel)):
 | 
			
		||||
                image_filename = address_string + ".png"
 | 
			
		||||
                create_images(address_string, driver, image_filename, image_folder_map, image_folder_production, image_folder_qrcode,
 | 
			
		||||
                              url)
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -190,7 +223,7 @@ def search_adresses(adress_list, filename_adresslist, driver, mainText):
 | 
			
		|||
            print("saving Address: " + address_string)
 | 
			
		||||
            save_information_to_addresslist(adress, adress_list, columnIndexes, coordinates, file_split_char, i,
 | 
			
		||||
                                            image_filename, sumEnergyRoofs, sumRoofArea, suitability, url,
 | 
			
		||||
                                            value_electricity_production)
 | 
			
		||||
                                            value_electricity_production, existing_solar_panel_power)
 | 
			
		||||
 | 
			
		||||
            save_addresslist_in_file(adress_list, filename_adresslist)
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -220,7 +253,7 @@ def search_adresses(adress_list, filename_adresslist, driver, mainText):
 | 
			
		|||
 | 
			
		||||
def save_information_to_addresslist(adress, adress_list, columnIndexes, coordinates, file_split_char, list_index,
 | 
			
		||||
                                    image_filename, pv_Production100, roof_area, suitability, url,
 | 
			
		||||
                                    value_electricity_production):
 | 
			
		||||
                                    value_electricity_production, existing_solar_panel_power):
 | 
			
		||||
    # Save Information in Addresslist
 | 
			
		||||
    adress[columnIndexes[4]] = str(coordinates[0])
 | 
			
		||||
    adress[columnIndexes[5]] = str(coordinates[1])
 | 
			
		||||
| 
						 | 
				
			
			@ -230,6 +263,7 @@ def save_information_to_addresslist(adress, adress_list, columnIndexes, coordina
 | 
			
		|||
    adress[columnIndexes[9]] = pv_Production100
 | 
			
		||||
    adress[columnIndexes[10]] = value_electricity_production
 | 
			
		||||
    adress[columnIndexes[11]] = roof_area
 | 
			
		||||
    adress[columnIndexes[12]] = existing_solar_panel_power
 | 
			
		||||
    new_line_string = ""
 | 
			
		||||
    for j in adress:
 | 
			
		||||
        new_line_string = new_line_string + str(j) + file_split_char
 | 
			
		||||
| 
						 | 
				
			
			@ -348,9 +382,11 @@ def create_images(address_string, driver, image_filename, image_folder_map, imag
 | 
			
		|||
def read_adresslist(filename_adresslist):
 | 
			
		||||
    returnvalues = []
 | 
			
		||||
    try:
 | 
			
		||||
        print("reading File", filename_adresslist)
 | 
			
		||||
        adress_file = open(filename_adresslist, "r", encoding="utf-8")
 | 
			
		||||
        adress_list = adress_file.read().splitlines()
 | 
			
		||||
        adress_file.close()
 | 
			
		||||
        print("closed File", filename_adresslist)
 | 
			
		||||
        returnvalues.append(True)
 | 
			
		||||
        returnvalues.append(adress_list)
 | 
			
		||||
    except:
 | 
			
		||||
| 
						 | 
				
			
			@ -485,5 +521,3 @@ button1.grid(row=3, column=1, padx=10, pady=3)
 | 
			
		|||
button2 = tkinter.Button(frameButtons, text="EXIT", command=command_exit, width=20, height=2, bg="#FCCA03")
 | 
			
		||||
button2.grid(row=3, column=2, padx=10, pady=3)
 | 
			
		||||
root.mainloop()
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue