Compare commits
2 Commits
main
...
making_ima
Author | SHA1 | Date |
---|---|---|
|
3da728df7d | |
|
70c6c0d63d |
|
@ -0,0 +1,40 @@
|
||||||
|
import matplotlib.pyplot as plt
|
||||||
|
import numpy as np
|
||||||
|
|
||||||
|
def create_barchart(barChartMonth, barChartData, color, image_folder_barcharts, image_filename):
|
||||||
|
barChartMonth.reverse()
|
||||||
|
barChartData.reverse()
|
||||||
|
|
||||||
|
max_wert = max(barChartData)
|
||||||
|
min_wert = min(barChartData)
|
||||||
|
skala = max_wert + max_wert * 0.1
|
||||||
|
|
||||||
|
plt.figure(figsize=(7, 3))
|
||||||
|
plt.bar(barChartMonth, barChartData, color=color)
|
||||||
|
|
||||||
|
plt.ylabel('Stromproduktion in Franken', fontsize=12)
|
||||||
|
|
||||||
|
plt.ylim(0, skala)
|
||||||
|
|
||||||
|
# Turn off the frame (border) around the graphic
|
||||||
|
ax = plt.gca() # Get the current axis
|
||||||
|
ax.spines['top'].set_visible(False)
|
||||||
|
ax.spines['right'].set_visible(False)
|
||||||
|
ax.spines['bottom'].set_visible(False)
|
||||||
|
|
||||||
|
plt.xticks(barChartMonth)
|
||||||
|
# Set the x-axis limits to remove extra space on the right
|
||||||
|
# plt.xlim(barChartMonth[0], barChartMonth[-1])
|
||||||
|
|
||||||
|
plt.savefig(f"{image_folder_barcharts}{image_filename}", bbox_inches='tight')
|
||||||
|
plt.show()
|
||||||
|
|
||||||
|
|
||||||
|
barChartMonth = [8, 7, 6, 5, 4, 3, 2, 1, 12, 11, 10, 9]
|
||||||
|
barChartMonth = [str(item) for item in barChartMonth]
|
||||||
|
|
||||||
|
barChartData=[612.9508602242413, 774.9497310367794, 905.1661458663121, 700.3920174038531, 455.8453881411557, 362.9725109507848, 243.91420489011418, 106.40652073925607, 98.73508056571949, 140.51124465669344, 293.31970563938467, 442.59112071461107]
|
||||||
|
image_folder_barcharts = "barcharts/"
|
||||||
|
image_filename = "test-file.png"
|
||||||
|
color = "red"
|
||||||
|
create_barchart(barChartMonth, barChartData, color, image_folder_barcharts, image_filename)
|
109
Sonnendach.py
109
Sonnendach.py
|
@ -1,8 +1,6 @@
|
||||||
import tkinter
|
import tkinter
|
||||||
import threading
|
import threading
|
||||||
import matplotlib.pyplot as plt
|
import matplotlib.pyplot as plt
|
||||||
plt.switch_backend("Agg") # Set the backend dynamically
|
|
||||||
from urllib.parse import urlencode, quote_plus
|
|
||||||
|
|
||||||
import selenium.webdriver.firefox.service
|
import selenium.webdriver.firefox.service
|
||||||
import webdriver_manager.chrome
|
import webdriver_manager.chrome
|
||||||
|
@ -26,12 +24,11 @@ import requests
|
||||||
import statistics
|
import statistics
|
||||||
from webdriver_manager.firefox import GeckoDriverManager
|
from webdriver_manager.firefox import GeckoDriverManager
|
||||||
|
|
||||||
DropDownLabels = ["Street: ", "Number: ", "Postal code: ", "City: ", "coordinate X", "coordinate Y", "Sonnendach URL: ", "Suitability:", "Image Filename: ", "PV Production 75", "Value Electricity production", "Roof area", "existing PV Production Power", "existing PV Production begining of operation","id", "firstname", "lastname"]
|
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 = ";"
|
file_split_char = ","
|
||||||
minRoofSize = 5
|
minRoofSize = 2
|
||||||
minSuitability = 3
|
minSuitability = 3
|
||||||
electricityPrice = 0.11556
|
electricityPrice = 0.198
|
||||||
electricityUsageFactor = 0.75
|
|
||||||
OptionList = []
|
OptionList = []
|
||||||
exit = False
|
exit = False
|
||||||
stopThread = False
|
stopThread = False
|
||||||
|
@ -178,12 +175,11 @@ def search_adresses(adress_list, filename_adresslist, driver, mainText):
|
||||||
barChartMonth = response_all_roofs_decoded[0]['attributes']['monate']
|
barChartMonth = response_all_roofs_decoded[0]['attributes']['monate']
|
||||||
barChartData = [0] * 12
|
barChartData = [0] * 12
|
||||||
for roof in response_all_roofs_decoded:
|
for roof in response_all_roofs_decoded:
|
||||||
energy = float(roof['attributes']['gstrahlung'])*0.2*0.8*electricityUsageFactor
|
energy = float(roof['attributes']['gstrahlung'])*0.2*0.8
|
||||||
|
if(energy > bestRoofEnergy):
|
||||||
if(float(roof['attributes']['flaeche']) > minRoofSize and int(roof['attributes']['klasse']) >= minSuitability):
|
|
||||||
if (energy > bestRoofEnergy):
|
|
||||||
bestRoofEnergy = energy
|
bestRoofEnergy = energy
|
||||||
bestRoof = roof
|
bestRoof = roof
|
||||||
|
if(float(roof['attributes']['flaeche']) > minRoofSize and int(roof['attributes']['klasse']) >= minSuitability):
|
||||||
for month_count in range(12):
|
for month_count in range(12):
|
||||||
barChartData[month_count] = barChartData[month_count] + float(
|
barChartData[month_count] = barChartData[month_count] + float(
|
||||||
roof['attributes']['monats_ertrag'][month_count]) * float(
|
roof['attributes']['monats_ertrag'][month_count]) * float(
|
||||||
|
@ -203,8 +199,7 @@ 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 = "error"
|
existing_solar_panel_power = "none"
|
||||||
existing_solar_panel_begining_of_operation = "error"
|
|
||||||
roof_has_solarpanel = False # TODO check if roof has solar Panel
|
roof_has_solarpanel = False # TODO check if roof has solar Panel
|
||||||
|
|
||||||
#Check if there is solar panel existing
|
#Check if there is solar panel existing
|
||||||
|
@ -224,18 +219,13 @@ def search_adresses(adress_list, filename_adresslist, driver, mainText):
|
||||||
results = (repsonse_solar_panel_decoded['results'])
|
results = (repsonse_solar_panel_decoded['results'])
|
||||||
if(len(results) > 0):
|
if(len(results) > 0):
|
||||||
existing_solar_panel_power = results[0]['attributes']['total_power']
|
existing_solar_panel_power = results[0]['attributes']['total_power']
|
||||||
existing_solar_panel_begining_of_operation = results[0]['attributes']['beginning_of_operation']
|
|
||||||
else:
|
|
||||||
existing_solar_panel_power = "none"
|
|
||||||
existing_solar_panel_begining_of_operation = "none"
|
|
||||||
|
|
||||||
except:
|
except:
|
||||||
existing_solar_panel_power = "error"
|
existing_solar_panel_power = "not-found"
|
||||||
existing_solar_panel_begining_of_operation = "error"
|
|
||||||
roof_has_solarpanel = False
|
roof_has_solarpanel = False
|
||||||
|
|
||||||
if(found and createImages.get() > 0 and roof_is_suitable and (not roof_has_solarpanel)):
|
if(found and createImages.get() > 0 and roof_is_suitable and (not roof_has_solarpanel)):
|
||||||
image_filename = adress[columnIndexes[14]] + " " + address_string + ".png"
|
image_filename = address_string + ".png"
|
||||||
|
|
||||||
barchart_color = ""
|
barchart_color = ""
|
||||||
if(suitability == 1):
|
if(suitability == 1):
|
||||||
|
@ -249,44 +239,32 @@ def search_adresses(adress_list, filename_adresslist, driver, mainText):
|
||||||
elif(suitability == 5):
|
elif(suitability == 5):
|
||||||
barchart_color = "#a80000"
|
barchart_color = "#a80000"
|
||||||
|
|
||||||
qr_url = "https://nexs.ch/redirect?" + urlencode({
|
|
||||||
"id": adress[columnIndexes[14]],
|
|
||||||
"project": "PJ2505-0014",
|
|
||||||
"target": "https://www.solosolar.ch/de/kontakt?" + urlencode({
|
|
||||||
"firstname": adress[columnIndexes[15]],
|
|
||||||
"lastname": adress[columnIndexes[16]],
|
|
||||||
"adresse": f"{adress[columnIndexes[0]]} {adress[columnIndexes[1]]}",
|
|
||||||
"zip": adress[columnIndexes[2]],
|
|
||||||
"city": adress[columnIndexes[3]]
|
|
||||||
}, quote_via=quote_plus)
|
|
||||||
}, quote_via=quote_plus)
|
|
||||||
|
|
||||||
create_images(address_string, driver, image_filename, image_folder_map, image_folder_production, image_folder_qrcode, image_folder_barcharts,
|
create_images(address_string, driver, image_filename, image_folder_map, image_folder_production, image_folder_qrcode, image_folder_barcharts,
|
||||||
url, barChartMonth, barChartData, barchart_color, qr_url)
|
url, barChartMonth, barChartData, barchart_color)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
image_filename = "not-created"
|
image_filename = "not-created"
|
||||||
|
|
||||||
# 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, existing_solar_panel_begining_of_operation)
|
value_electricity_production, existing_solar_panel_power)
|
||||||
|
|
||||||
if(i % 100 == 0 or i + 1 == address_count):
|
|
||||||
save_addresslist_in_file(adress_list, filename_adresslist)
|
save_addresslist_in_file(adress_list, filename_adresslist)
|
||||||
|
|
||||||
|
|
||||||
|
if(found):
|
||||||
|
street = adress[columnIndexes[0]] + " " + adress[columnIndexes[1]]
|
||||||
|
plz = adress[columnIndexes[2]]
|
||||||
|
city = adress[columnIndexes[3]]
|
||||||
|
create_Partner_in_dolibarr(street, plz, city, coordinates, sumEnergyRoofs, sumRoofArea, suitability, featureId, url, response_all_roofs_decoded)
|
||||||
|
|
||||||
|
print("saved Address: " + address_string)
|
||||||
print("Address " + str(i) + " of " + str(address_count))
|
print("Address " + str(i) + " of " + str(address_count))
|
||||||
timediff = relativedelta(datetime.datetime.now(), startTime)
|
timediff = relativedelta(datetime.datetime.now(), startTime)
|
||||||
print("Process is running since %d years %d months %d days %d hours %d minutes %d seconds" % (
|
print("Process is running since %d years %d months %d days %d hours %d minutes %d seconds" % (
|
||||||
timediff.years, timediff.months, timediff.days, timediff.hours, timediff.minutes, timediff.seconds))
|
timediff.years, timediff.months, timediff.days, timediff.hours, timediff.minutes, timediff.seconds))
|
||||||
|
|
||||||
# if(found):
|
|
||||||
# street = adress[columnIndexes[0]] + " " + adress[columnIndexes[1]]
|
|
||||||
# plz = adress[columnIndexes[2]]
|
|
||||||
# city = adress[columnIndexes[3]]
|
|
||||||
# create_Partner_in_dolibarr(street, plz, city, coordinates, sumEnergyRoofs, sumRoofArea, suitability, featureId, url, response_all_roofs_decoded)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if(stopThread == True):
|
if(stopThread == True):
|
||||||
print("closing Thread")
|
print("closing Thread")
|
||||||
|
@ -300,7 +278,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, existing_solar_panel_begining_of_operation):
|
value_electricity_production, existing_solar_panel_power):
|
||||||
# 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])
|
||||||
|
@ -311,15 +289,20 @@ def save_information_to_addresslist(adress, adress_list, columnIndexes, coordina
|
||||||
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
|
adress[columnIndexes[12]] = existing_solar_panel_power
|
||||||
adress[columnIndexes[13]] = existing_solar_panel_begining_of_operation
|
new_line_string = ""
|
||||||
new_line_string = file_split_char.join(str(j) for j in adress)
|
for j in adress:
|
||||||
|
new_line_string = new_line_string + str(j) + file_split_char
|
||||||
adress_list[list_index] = new_line_string
|
adress_list[list_index] = new_line_string
|
||||||
|
|
||||||
|
|
||||||
def save_addresslist_in_file(address_list, filename_addresslist):
|
def save_addresslist_in_file(adress_list, filename_adresslist):
|
||||||
with open(filename_addresslist, "w", encoding="utf-8") as address_file:
|
new_adress_list = ""
|
||||||
for address in address_list:
|
for j in adress_list:
|
||||||
address_file.write(f"{address}\n")
|
new_adress_list = new_adress_list + (j) + "\n"
|
||||||
|
# save File
|
||||||
|
adress_file = open(filename_adresslist, "w", encoding="utf-8")
|
||||||
|
adress_file.write(new_adress_list)
|
||||||
|
adress_file.close()
|
||||||
|
|
||||||
def create_Partner_in_dolibarr(street, plz, city, coordinates, sumEnergyRoofs, sumRoofArea, suitability, featureId, url, roofs):
|
def create_Partner_in_dolibarr(street, plz, city, coordinates, sumEnergyRoofs, sumRoofArea, suitability, featureId, url, roofs):
|
||||||
global electricityPrice
|
global electricityPrice
|
||||||
|
@ -366,13 +349,13 @@ def create_roof_info(roofs):
|
||||||
info_text = info_text + str(i + 1) + ". Fläche\n" + "Potenzielle Energie: " + str(roofs[i]['attributes']['gstrahlung']*0.2*0.8) + "\nFläche: " + str(roofs[i]['attributes']['flaeche']) + "\nEignung: " + str(roofs[i]['attributes']['klasse']) + " (" + str(roofs[i]['attributes']['klasse_text']).split("##")[0] + ")\n\n"
|
info_text = info_text + str(i + 1) + ". Fläche\n" + "Potenzielle Energie: " + str(roofs[i]['attributes']['gstrahlung']*0.2*0.8) + "\nFläche: " + str(roofs[i]['attributes']['flaeche']) + "\nEignung: " + str(roofs[i]['attributes']['klasse']) + " (" + str(roofs[i]['attributes']['klasse_text']).split("##")[0] + ")\n\n"
|
||||||
return info_text
|
return info_text
|
||||||
|
|
||||||
def create_images(address_string, driver, image_filename, image_folder_map, image_folder_production, image_folder_qrcode, image_folder_barcharts, url, barChartMonth, barChartData, barchart_color, qr_url):
|
def create_images(address_string, driver, image_filename, image_folder_map, image_folder_production, image_folder_qrcode, image_folder_barcharts, url, barChartMonth, barChartData, barchart_color):
|
||||||
driver.get(url)
|
driver.get(url)
|
||||||
time.sleep(2)
|
time.sleep(2)
|
||||||
|
|
||||||
# Create QR-Code
|
# Create QR-Code
|
||||||
qr = qrcode.QRCode(version=1, box_size=10, border=5)
|
qr = qrcode.QRCode(version=1, box_size=10, border=5)
|
||||||
qr.add_data(qr_url)
|
qr.add_data(url)
|
||||||
qr.make(fit=True)
|
qr.make(fit=True)
|
||||||
qr.make_image(fill='black', back_color='white').save(image_folder_qrcode + image_filename)
|
qr.make_image(fill='black', back_color='white').save(image_folder_qrcode + image_filename)
|
||||||
|
|
||||||
|
@ -381,11 +364,6 @@ def create_images(address_string, driver, image_filename, image_folder_map, imag
|
||||||
try:
|
try:
|
||||||
driver.execute_script("""var l = document.getElementsByClassName("ol-zoom ol-unselectable ol-control")[0];
|
driver.execute_script("""var l = document.getElementsByClassName("ol-zoom ol-unselectable ol-control")[0];
|
||||||
l.parentNode.removeChild(l);""")
|
l.parentNode.removeChild(l);""")
|
||||||
|
|
||||||
# Marker entfernen
|
|
||||||
# driver.execute_script("""var l = document.getElementsByClassName("marker ga-crosshair")[0];
|
|
||||||
# l.parentNode.removeChild(l);""")
|
|
||||||
|
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
@ -398,13 +376,12 @@ def create_images(address_string, driver, image_filename, image_folder_map, imag
|
||||||
w = x + size["width"]
|
w = x + size["width"]
|
||||||
h = size["height"]
|
h = size["height"]
|
||||||
area = (x, 0, w, h)
|
area = (x, 0, w, h)
|
||||||
mapElement.screenshot(image_folder_map + image_filename)
|
driver.execute_script("window.scrollTo(0, " + str(y) + ")")
|
||||||
# driver.execute_script("window.scrollTo(0, " + str(y) + ")")
|
time.sleep(1)
|
||||||
# time.sleep(1)
|
driver.save_screenshot(image_folder_map + image_filename)
|
||||||
# driver.save_screenshot(image_folder_map + image_filename)
|
time.sleep(0.2)
|
||||||
# time.sleep(0.2)
|
Image.open(image_folder_map + image_filename).crop(area).save(
|
||||||
# Image.open(image_folder_map + image_filename).crop(area).save(
|
image_folder_map + image_filename)
|
||||||
# image_folder_map + image_filename)
|
|
||||||
|
|
||||||
# Create Screenshot of Chart
|
# Create Screenshot of Chart
|
||||||
# try:
|
# try:
|
||||||
|
@ -454,7 +431,7 @@ def create_images(address_string, driver, image_filename, image_folder_map, imag
|
||||||
# plt.xlim(barChartMonth[0], barChartMonth[-1])
|
# plt.xlim(barChartMonth[0], barChartMonth[-1])
|
||||||
|
|
||||||
plt.savefig(f"{image_folder_barcharts}{image_filename}", bbox_inches='tight')
|
plt.savefig(f"{image_folder_barcharts}{image_filename}", bbox_inches='tight')
|
||||||
plt.close('all')
|
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
Binary file not shown.
Binary file not shown.
|
@ -2,7 +2,7 @@
|
||||||
import json
|
import json
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
search_string = "Pelikanweg 51 3074 Muri b. Bern"
|
search_string = "Mattenweg 29 5600 Lenzburg"
|
||||||
|
|
||||||
#Address to coordinates
|
#Address to coordinates
|
||||||
params={
|
params={
|
||||||
|
@ -55,3 +55,5 @@ response_all_roofs_decoded = json.loads(response_all_roofs.content.decode())['re
|
||||||
for roof in response_all_roofs_decoded:
|
for roof in response_all_roofs_decoded:
|
||||||
# print(roof['attributes'].keys())
|
# print(roof['attributes'].keys())
|
||||||
print("URL:", "https://www.uvek-gis.admin.ch/BFE/sonnendach/index.html?featureId=" + str(roof['featureId']) + "&lang=de", "Fläche:", roof['attributes']['flaeche'], "Eignung(1-5):", roof['attributes']['klasse'], "PV100:", float(roof['attributes']['gstrahlung']*0.2*0.8))
|
print("URL:", "https://www.uvek-gis.admin.ch/BFE/sonnendach/index.html?featureId=" + str(roof['featureId']) + "&lang=de", "Fläche:", roof['attributes']['flaeche'], "Eignung(1-5):", roof['attributes']['klasse'], "PV100:", float(roof['attributes']['gstrahlung']*0.2*0.8))
|
||||||
|
|
||||||
|
print(roof)
|
Loading…
Reference in New Issue