feat: add merge_images script, dataset module, and rename dr.rant_stats_all to dr.stats_all
Add new merge_images.py script that compiles all exported PNG graphs into a single composite image with 2-column layout and 480x320 per-image sizing. Introduce drstats/dataset.py with dump() function that outputs per-user contribution statistics and all rants/posts for LLM embedding. Rename the console script entry point from dr.rant_stats_all to dr.stats_all across setup.cfg, entry_points.txt, README.md, and PKG-INFO. Update Makefile to replace sync with sync_excempt target, add merge_images target, and add prerequisite reminders for export targets. Refactor db.py view creation queries to use compact string formatting. Redirect Duration class timing output and dataset.py printr calls to stderr.
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
from PIL import Image
|
||||
from pathlib import Path
|
||||
import functools
|
||||
import sys
|
||||
|
||||
printr = functools.partial(print,file=sys.stderr)
|
||||
|
||||
per_image_width = 480
|
||||
per_image_height = 320
|
||||
cols = 2
|
||||
|
||||
images = list(Path("./export/").glob("*.png"))
|
||||
image_count = len(images)
|
||||
total_image_height = (image_count / cols * per_image_height)
|
||||
if(image_count / cols * per_image_height > total_image_height):
|
||||
total_image_height += per_image_height
|
||||
total_image_width = image_count / cols * per_image_width
|
||||
|
||||
resized_images = []
|
||||
|
||||
for path in images:
|
||||
image = Image.open(path)
|
||||
image = image.resize((per_image_width, per_image_height))
|
||||
resized_images.append((path,image))
|
||||
|
||||
new_image = Image.new("RGB",(per_image_width * cols, int(per_image_height * image_count / cols)), (250,250,250))
|
||||
|
||||
current_col = 0
|
||||
current_row = 0
|
||||
current_image_number = 0
|
||||
for path, image in resized_images:
|
||||
printr("Merging image {}".format(path))
|
||||
current_row = int(current_image_number / cols)
|
||||
left = int((current_col) * per_image_width)
|
||||
top = int(per_image_height * current_row )
|
||||
new_image.paste(image,(left,top))
|
||||
new_image.save("export/1_graphs_compliation.png")
|
||||
|
||||
current_col += 1
|
||||
current_image_number += 1
|
||||
if current_col == cols:
|
||||
current_col = 0
|
||||
|
||||
new_image.show()
|
||||
Reference in New Issue
Block a user