generate and load weeks
This commit is contained in:
parent
988c2fe898
commit
36a3400e5d
70
index.html
70
index.html
|
|
@ -9,7 +9,7 @@
|
|||
|
||||
<style>
|
||||
#map {
|
||||
height: 100vh;
|
||||
height: 90vh;
|
||||
}
|
||||
#slider {
|
||||
position: relative;
|
||||
|
|
@ -47,50 +47,21 @@
|
|||
zoomOffset: -1
|
||||
}).addTo(map);
|
||||
|
||||
const locations = [
|
||||
{
|
||||
"city": "Hamburg",
|
||||
"lat": "53.64286",
|
||||
"lng": "9.9753",
|
||||
"icon": "test5.png",
|
||||
"anchor": [101,101]
|
||||
},
|
||||
// {
|
||||
// "city": "Kiel",
|
||||
// "lat": "54.3297",
|
||||
// "lng": "10.1435"
|
||||
// },
|
||||
// {
|
||||
// "city": "München",
|
||||
// "lat": "48.1341",
|
||||
// "lng": "11.5674",
|
||||
// "icon": "test8.png",
|
||||
// "anchor": [144,144]
|
||||
// },
|
||||
{
|
||||
"city": "La Spezia",
|
||||
"lat": "44.1064",
|
||||
"lng": "9.8439",
|
||||
"icon": "test8.png",
|
||||
"anchor": [144,144]
|
||||
},
|
||||
{
|
||||
"city": "Teisnach",
|
||||
"lat": "49.0301",
|
||||
"lng": "12.998",
|
||||
"icon": "test13.png",
|
||||
"anchor": [144,144]
|
||||
}
|
||||
];
|
||||
var markerLayer = L.layerGroup();
|
||||
|
||||
|
||||
const markers = locations.map(location => {
|
||||
function loadWeek(locations){
|
||||
locations.map(location => {
|
||||
return L.marker([location.lat, location.lng], {icon: L.icon({
|
||||
|
||||
iconUrl: location.icon,
|
||||
iconAnchor: location.anchor
|
||||
})}).addTo(map);
|
||||
});
|
||||
iconUrl: location.icon,
|
||||
iconAnchor: location.anchor
|
||||
})})
|
||||
.bindPopup(location.popup)
|
||||
.addTo(markerLayer);
|
||||
});
|
||||
map.addLayer(markerLayer)
|
||||
}
|
||||
|
||||
</script>
|
||||
<script src="external/jquery/jquery.js"></script>
|
||||
<script src="jquery-ui.js"></script>
|
||||
|
|
@ -113,14 +84,25 @@ console.log(`The current week of ${year} is ${week}`);
|
|||
max: week + 12,
|
||||
step: 1,
|
||||
|
||||
create: function() {
|
||||
create: function() {
|
||||
handle.text( `KW ${week}/${year}`);
|
||||
$.ajaxSetup({ cache: false });
|
||||
$.getJSON(`cw_${week}_${year}.json`, function( data ) {
|
||||
loadWeek(data);
|
||||
});
|
||||
},
|
||||
slide: function( event, ui ) {
|
||||
// ToDo: handle year change
|
||||
var curweek = ui.value;
|
||||
var curyear = year;
|
||||
|
||||
if (map.hasLayer(markerLayer)) {
|
||||
markerLayer.clearLayers();
|
||||
}
|
||||
handle.text( `KW ${curweek}/${curyear}`);
|
||||
$.ajaxSetup({ cache: false });
|
||||
$.getJSON(`cw_${curweek}_${curyear}.json`, function( data ) {
|
||||
loadWeek(data);
|
||||
});
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
|
||||
import math
|
||||
import json
|
||||
import yaml
|
||||
from PIL import Image, ImageDraw, ImageFilter
|
||||
from pathlib import Path
|
||||
import numpy as np
|
||||
import math
|
||||
|
||||
def circular_mask(img):
|
||||
center_x = int(img.width / 2)
|
||||
|
|
@ -17,7 +17,7 @@ def circular_mask(img):
|
|||
return img
|
||||
|
||||
|
||||
def arrange_imager_in_circle(images, spacing=5, min_radius=0):
|
||||
def arrange_images_in_circle(images, spacing=5, min_radius=0):
|
||||
|
||||
d = images[0].size[0]
|
||||
dis = d + spacing
|
||||
|
|
@ -51,7 +51,7 @@ def arrange_imager_in_circle(images, spacing=5, min_radius=0):
|
|||
return masterImage
|
||||
|
||||
|
||||
def create_circle(image_paths, output_path):
|
||||
def create_circle(image_paths):
|
||||
# Resize all images to 64x64 pixels
|
||||
shrunk_images = [Image.open(path).resize((64, 64)) for path in image_paths]
|
||||
|
||||
|
|
@ -63,26 +63,72 @@ def create_circle(image_paths, output_path):
|
|||
return
|
||||
|
||||
if len(circular_images) < 7:
|
||||
output_img = arrange_imager_in_circle(circular_images)
|
||||
output_img = arrange_images_in_circle(circular_images)
|
||||
ow, oh = output_img.size
|
||||
else:
|
||||
inner_img = arrange_imager_in_circle(circular_images[:4])
|
||||
inner_img = arrange_images_in_circle(circular_images[:4])
|
||||
iw, ih = inner_img.size
|
||||
mask = inner_img.split()[-1]
|
||||
dr = circular_images[0].size[0]//2 + iw//2
|
||||
output_img = arrange_imager_in_circle(circular_images[4:],min_radius=dr)
|
||||
output_img = arrange_images_in_circle(circular_images[4:],min_radius=dr)
|
||||
ow, oh = output_img.size
|
||||
output_img.paste(inner_img,((ow-iw)//2,(oh-ih)//2),mask)
|
||||
|
||||
draw = ImageDraw.Draw(output_img)
|
||||
dr = 3
|
||||
draw.ellipse((ow//2-dr, oh//2-dr, ow//2+dr, oh//2+dr),fill=(255,0,0),outline=False)
|
||||
output_path = output_img.save(output_path)
|
||||
return output_img
|
||||
|
||||
def generateWeek(week, persons, locations, output_path=Path('.')):
|
||||
loc = {}
|
||||
for person in persons:
|
||||
print(person)
|
||||
if week in person['weeks'].keys():
|
||||
cur_name = person['name']
|
||||
cur_image = person['image']
|
||||
for task in person['weeks'][week]:
|
||||
cur_loc = task['location']
|
||||
cur_tasks = task['tasks']
|
||||
if cur_loc not in loc.keys():
|
||||
loc[cur_loc] = {}
|
||||
if cur_name not in loc[cur_loc].keys():
|
||||
loc[cur_loc][cur_name] = {
|
||||
'image': cur_image,
|
||||
'tasks': []
|
||||
}
|
||||
loc[cur_loc][cur_name]['tasks'] += cur_tasks
|
||||
week_json = []
|
||||
w,y = week.split('/')
|
||||
json_file = "cw_%s_%s.json" % (w,y)
|
||||
for cur_loc, cur_persons in loc.items():
|
||||
print(cur_loc)
|
||||
print(cur_persons)
|
||||
png_file = "%s_%s_%s.png" % (cur_loc.lower(),w,y)
|
||||
[print(x) for x in cur_persons]
|
||||
image_paths = [("persons/%s" % x['image']) for n,x in cur_persons.items()]
|
||||
img = create_circle(image_paths)
|
||||
img.save(output_path / Path(png_file))
|
||||
popup = "<h2>%s</h2>" % cur_loc
|
||||
for cur_per, cur_info in cur_persons.items():
|
||||
popup += "<h3>%s</h3>" % cur_per
|
||||
popup += "</br>".join(cur_info['tasks'])
|
||||
l = [x for x in locations if x['name'] == cur_loc][0]
|
||||
week_json.append({
|
||||
"city": cur_loc,
|
||||
"lat": l['lat'],
|
||||
"lng": l['lng'],
|
||||
"icon": png_file,
|
||||
"anchor": [x//2 for x in img.size],
|
||||
"popup": popup
|
||||
})
|
||||
print()
|
||||
with open(output_path / Path(json_file),"w") as j:
|
||||
json.dump(week_json, j)
|
||||
|
||||
if __name__ == "__main__":
|
||||
p = Path("test_images")
|
||||
image_paths = [str(x) for x in p.glob("*.jpg")]*2
|
||||
for i in range(len(image_paths)):
|
||||
output_path = "test%i.png" % i
|
||||
create_circle(image_paths[:i+1], output_path)
|
||||
with open("persons.yml","r") as fp:
|
||||
persons = yaml.safe_load(fp)
|
||||
with open("locations.yml","r") as fp:
|
||||
locations = yaml.safe_load(fp)
|
||||
generateWeek('21/2023', persons, locations)
|
||||
generateWeek('22/2023', persons, locations)
|
||||
|
|
|
|||
Loading…
Reference in a new issue