Compare commits

..

No commits in common. "1827d21aeb3c6ee28faa6dda99f66eedcde411f9" and "5813ea4c0d451f961b4fedd1a14889e630795e49" have entirely different histories.

1 changed files with 14 additions and 48 deletions

View File

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