updated to utils th plot and convert to image solution

This commit is contained in:
2025-06-06 16:38:52 +03:00
parent 5627c790f5
commit 6240042901
11 changed files with 311 additions and 97 deletions

Binary file not shown.

View File

@@ -1 +1 @@
gAAAAABoQuJn-THhBcB9uQut4cng4vNqljWnzVOe-jvl4j8_nDzq1KiWNF5G2BKJCxy-u2Lf72PE9WMHOA7n2EMYsLzwmF0mi_2me3DnrckEE4kaC4reSowP0AiiKNdYqrZVFcemUf7w
gAAAAABoQu2h6f3qYomY4xLeBt21EA4y4D87mlBn31OUGEcEs3e3Pw0WXYnYHpRANYW291unV2egC2F1pGhuXelOi2N8xm-bEjlkhTMYZhxDLdZdPNNqNmk_HTom_JYZuqYEan3Oz7Xj

File diff suppressed because one or more lines are too long

Binary file not shown.

After

Width:  |  Height:  |  Size: 264 KiB

View File

@@ -17,10 +17,10 @@
<meta name="viewport" content="width=device-width,
initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<style>
#map_bf67b2d92a9afef5449c1b1b9845da94 {
#map_6173f842f324405630d110023c8c7322 {
position: relative;
width: 100.0%;
height: 100.0%;
width: 800.0px;
height: 600.0px;
left: 0.0%;
top: 0.0%;
}
@@ -54,14 +54,14 @@
<body>
<div class="folium-map" id="map_bf67b2d92a9afef5449c1b1b9845da94" ></div>
<div class="folium-map" id="map_6173f842f324405630d110023c8c7322" ></div>
</body>
<script>
var map_bf67b2d92a9afef5449c1b1b9845da94 = L.map(
"map_bf67b2d92a9afef5449c1b1b9845da94",
var map_6173f842f324405630d110023c8c7322 = L.map(
"map_6173f842f324405630d110023c8c7322",
{
center: [45.805146666666666, 24.126355555555556],
crs: L.CRS.EPSG3857,
@@ -78,7 +78,7 @@
var tile_layer_48f00dde609689cd95b3e5b1020d2d03 = L.tileLayer(
var tile_layer_0dca03e0dfb8bb283db80e7711192936 = L.tileLayer(
"https://tile.openstreetmap.org/{z}/{x}/{y}.png",
{
"minZoom": 0,
@@ -95,23 +95,23 @@
);
tile_layer_48f00dde609689cd95b3e5b1020d2d03.addTo(map_bf67b2d92a9afef5449c1b1b9845da94);
tile_layer_0dca03e0dfb8bb283db80e7711192936.addTo(map_6173f842f324405630d110023c8c7322);
var poly_line_ac2b74b1096aa06a1d4ab84860beacdc = L.polyline(
var poly_line_5185539b101b8eefa1da8150f47aa184 = L.polyline(
[[45.805146666666666, 24.126355555555556], [45.80562444444445, 24.123990555555554], [45.805820555555556, 24.122884444444445], [45.806001111111115, 24.121864444444444], [45.80658944444445, 24.118647777777777], [45.80706166666667, 24.11584], [45.80744277777778, 24.113130555555554], [45.80744444444444, 24.111027777777778], [45.807554999999994, 24.10904111111111], [45.80765388888889, 24.10791777777778], [45.80775722222222, 24.106204444444444], [45.80775722222222, 24.106204444444444], [45.807792777777784, 24.10529888888889], [45.80769222222222, 24.105220555555558], [45.807494444444444, 24.10537666666667], [45.80721722222222, 24.10552888888889], [45.80721722222222, 24.10552888888889], [45.80452833333334, 24.106312222222222], [45.80452833333334, 24.106312222222222], [45.802245000000006, 24.106793888888888], [45.802245000000006, 24.106793888888888], [45.80039166666667, 24.107621666666667], [45.80039166666667, 24.107621666666667], [45.79863111111111, 24.10826], [45.79706388888889, 24.109215], [45.796372222222224, 24.109560000000002], [45.79611444444444, 24.109526666666667], [45.79596611111111, 24.109244999999998], [45.79575722222222, 24.107441666666666], [45.79575722222222, 24.107441666666666], [45.79544, 24.105129444444444], [45.79544, 24.105129444444444], [45.795164444444445, 24.103232777777777], [45.794825555555555, 24.100786111111113], [45.79484444444444, 24.10045277777778], [45.79482, 24.100100555555557], [45.79452388888888, 24.098648333333333], [45.794362222222226, 24.097596666666668], [45.794362222222226, 24.097596666666668], [45.794362222222226, 24.097596666666668], [45.79418555555556, 24.09649111111111], [45.79419388888889, 24.096272777777777], [45.79433111111111, 24.095743333333335], [45.795445, 24.094136111111112], [45.796870000000006, 24.09261777777778], [45.797534444444445, 24.091910555555554], [45.79878277777778, 24.090588888888888], [45.79978833333333, 24.089429444444445], [45.799776111111115, 24.089080555555554], [45.79944055555555, 24.086607777777775], [45.79913277777778, 24.086008333333332], [45.79909722222222, 24.08582277777778], [45.79911555555555, 24.085697222222223], [45.79911555555555, 24.085697222222223], [45.79919388888889, 24.08558888888889], [45.79919388888889, 24.08558888888889], [45.79919388888889, 24.08558888888889], [45.79919388888889, 24.08558888888889], [45.79919388888889, 24.08558888888889], [45.79919388888889, 24.08558888888889], [45.79919388888889, 24.08558888888889], [45.79919388888889, 24.08558888888889], [45.79919388888889, 24.08558888888889], [45.79919388888889, 24.08558888888889], [45.79919388888889, 24.08558888888889], [45.79919388888889, 24.08558888888889], [45.79919388888889, 24.08558888888889], [45.79919388888889, 24.08558888888889], [45.79919388888889, 24.08558888888889], [45.79919388888889, 24.08558888888889], [45.79919388888889, 24.08558888888889], [45.79919388888889, 24.08558888888889], [45.79919388888889, 24.08558888888889], [45.79919388888889, 24.08558888888889], [45.79919388888889, 24.08558888888889], [45.79919388888889, 24.08558888888889], [45.79919388888889, 24.08558888888889], [45.79921, 24.085612222222224]],
{"bubblingMouseEvents": true, "color": "blue", "dashArray": null, "dashOffset": null, "fill": false, "fillColor": "blue", "fillOpacity": 0.2, "fillRule": "evenodd", "lineCap": "round", "lineJoin": "round", "noClip": false, "opacity": 1, "smoothFactor": 1.0, "stroke": true, "weight": 4.5}
).addTo(map_bf67b2d92a9afef5449c1b1b9845da94);
).addTo(map_6173f842f324405630d110023c8c7322);
var marker_508cb899cfad4984ec8c6bacbc7d4450 = L.marker(
var marker_5c3a847fd31760304779791ec443f473 = L.marker(
[45.805146666666666, 24.126355555555556],
{
}
).addTo(map_bf67b2d92a9afef5449c1b1b9845da94);
).addTo(map_6173f842f324405630d110023c8c7322);
var icon_27f251d0f4b490eac1364fdc7c0e4bcb = L.AwesomeMarkers.icon(
var icon_77c186d2e55fb8ae2e0070503fd0539c = L.AwesomeMarkers.icon(
{
"markerColor": "green",
"iconColor": "white",
@@ -122,7 +122,7 @@
);
marker_508cb899cfad4984ec8c6bacbc7d4450.bindTooltip(
marker_5c3a847fd31760304779791ec443f473.bindTooltip(
`<div>
Start
</div>`,
@@ -132,17 +132,17 @@
);
marker_508cb899cfad4984ec8c6bacbc7d4450.setIcon(icon_27f251d0f4b490eac1364fdc7c0e4bcb);
marker_5c3a847fd31760304779791ec443f473.setIcon(icon_77c186d2e55fb8ae2e0070503fd0539c);
var marker_fdc9ee2260616a462ff09a9869579e98 = L.marker(
var marker_0a30d487a2cda7756fd32b90acb9989b = L.marker(
[45.79921, 24.085612222222224],
{
}
).addTo(map_bf67b2d92a9afef5449c1b1b9845da94);
).addTo(map_6173f842f324405630d110023c8c7322);
var icon_5ab5f7e75df70e10f7a0380fd99ababf = L.AwesomeMarkers.icon(
var icon_cdb6bcef11f931e9bb82eb9c1a2e79bf = L.AwesomeMarkers.icon(
{
"markerColor": "red",
"iconColor": "white",
@@ -153,7 +153,7 @@
);
marker_fdc9ee2260616a462ff09a9869579e98.bindTooltip(
marker_0a30d487a2cda7756fd32b90acb9989b.bindTooltip(
`<div>
End
</div>`,
@@ -163,7 +163,7 @@
);
marker_fdc9ee2260616a462ff09a9869579e98.setIcon(icon_5ab5f7e75df70e10f7a0380fd99ababf);
marker_0a30d487a2cda7756fd32b90acb9989b.setIcon(icon_cdb6bcef11f931e9bb82eb9c1a2e79bf);
</script>
</html>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 352 KiB

After

Width:  |  Height:  |  Size: 291 KiB

File diff suppressed because one or more lines are too long

Binary file not shown.

Before

Width:  |  Height:  |  Size: 546 KiB

After

Width:  |  Height:  |  Size: 335 KiB

View File

@@ -8,7 +8,8 @@ from kivy.properties import StringProperty, ListProperty, AliasProperty
from utils import (
generate_key, load_key, encrypt_data, decrypt_data,
check_server_settings, save_server_settings,
test_connection, get_devices_from_server, save_route_to_file, fetch_positions_for_selected_day
test_connection, get_devices_from_server, save_route_to_file, fetch_positions_for_selected_day,
process_preview_util
)
from datetime import date
from kivy.uix.popup import Popup
@@ -32,7 +33,6 @@ from selenium.webdriver.chrome.options import Options
from PIL import Image
import time
import os
from utils import html_to_image
class CreateAnimationScreen(Screen):
project_name = StringProperty("")
@@ -43,8 +43,7 @@ class CreateAnimationScreen(Screen):
project_folder = os.path.join(RESOURCES_FOLDER, "projects", self.project_name)
img_path = os.path.join(project_folder, "preview.png")
if os.path.exists(img_path):
# Add a dummy query string to force reload
return f"{img_path}?{int(time.time())}"
return img_path
return "resources/images/track.png"
preview_image_source = AliasProperty(get_preview_image_source, None, bind=['project_name'])
@@ -211,54 +210,22 @@ class CreateAnimationScreen(Screen):
)
popup.open()
def process_preview(dt):
try:
import folium
project_folder = os.path.join(RESOURCES_FOLDER, "projects", self.project_name)
positions_path = os.path.join(project_folder, "positions.json")
html_path = os.path.join(project_folder, "preview.html")
img_path = os.path.join(project_folder, "preview.png")
if not os.path.exists(positions_path):
label.text = "positions.json not found!"
progress.value = 100
return
with open(positions_path, "r") as f:
positions = json.load(f)
if not positions:
label.text = "No positions to preview."
progress.value = 100
return
coords = [(pos['latitude'], pos['longitude']) for pos in positions]
m = folium.Map(location=coords[0], zoom_start=14)
folium.PolyLine(coords, color="blue", weight=4.5, opacity=1).add_to(m)
folium.Marker(coords[0], tooltip="Start", icon=folium.Icon(color="green")).add_to(m)
folium.Marker(coords[-1], tooltip="End", icon=folium.Icon(color="red")).add_to(m)
m.save(html_path)
# Convert HTML to image
html_to_image(html_path, img_path)
def set_preview_image_path(path):
self.preview_image_path = path
self.property('preview_image_source').dispatch(self)
# Set the image path for Kivy Image widget
self.preview_image_path = img_path
label.text = "Preview ready!"
progress.value = 100
def close_popup(dt):
popup.dismiss()
Clock.schedule_once(close_popup, 1)
except Exception as e:
label.text = f"Error: {e}"
progress.value = 100
def close_popup(dt):
popup.dismiss()
Clock.schedule_once(close_popup, 2)
Clock.schedule_once(process_preview, 0.5)
self.ids.preview_image.reload()
# Schedule the processing function
Clock.schedule_once(
lambda dt: process_preview_util(
self.project_name,
RESOURCES_FOLDER,
label,
progress,
popup,
self.ids.preview_image,
set_preview_image_path,
Clock
),
0.5
)

View File

@@ -209,3 +209,69 @@ def html_to_image(html_path, img_path, width=800, height=600, delay=2, driver_pa
except Exception as e:
print(f"Error converting HTML to image: {e}")
driver.quit()
def process_preview_util(
project_name,
RESOURCES_FOLDER,
label,
progress,
popup,
preview_image_widget,
set_preview_image_path,
Clock,
width=800,
height=600
):
import folium
import os
import json
from utils import html_to_image
try:
project_folder = os.path.join(RESOURCES_FOLDER, "projects", project_name)
positions_path = os.path.join(project_folder, "positions.json")
html_path = os.path.join(project_folder, "preview.html")
img_path = os.path.join(project_folder, "preview.png")
if not os.path.exists(positions_path):
label.text = "positions.json not found!"
progress.value = 100
return
with open(positions_path, "r") as f:
positions = json.load(f)
if not positions:
label.text = "No positions to preview."
progress.value = 100
return
coords = [(pos['latitude'], pos['longitude']) for pos in positions]
m = folium.Map(
location=coords[0],
width=width,
height=height
)
folium.PolyLine(coords, color="blue", weight=4.5, opacity=1).add_to(m)
folium.Marker(coords[0], tooltip="Start", icon=folium.Icon(color="green")).add_to(m)
folium.Marker(coords[-1], tooltip="End", icon=folium.Icon(color="red")).add_to(m)
m.fit_bounds(coords)
m.save(html_path)
html_to_image(html_path, img_path, width=width, height=height)
set_preview_image_path(img_path)
preview_image_widget.reload()
label.text = "Preview ready!"
progress.value = 100
def close_popup(dt):
popup.dismiss()
Clock.schedule_once(close_popup, 1)
except Exception as e:
label.text = f"Error: {e}"
progress.value = 100
def close_popup(dt):
popup.dismiss()
Clock.schedule_once(close_popup, 2)