second commit

This commit is contained in:
2026-04-13 23:14:05 +02:00
parent 1c031ebf63
commit e08597fc72
125 changed files with 26221 additions and 0 deletions
@@ -0,0 +1,36 @@
'''
Created on 19 janv. 2026
@author: denis
'''
from django.core.management.base import BaseCommand
#from django.conf import settings
from scanner.tasks import export_images
from scanner.models import Configuration
class Command(BaseCommand):
help = "Exporter les images jpg dans un fichier ZIP"
def add_arguments(self, parser):
super(Command, self).add_arguments(parser)
parser.add_argument("--uuid", type=str, help=f"Export video to jpg zip file with uuid")
def handle(self, *args, **options): # @UnusedVariable
try:
uuid = options.get('uuid')
conf = Configuration.objects.filter(active=True).first()
print(f"Export video to jpg zip file with uuid: {uuid}")
# Export images ZIP
job_zip = export_images(
uuid,
start_ts=None,
end_ts=None,
jpeg_quality=conf.video_jpeg_quality, # Qualité JPEG
)
print()
print(job_zip)
except Exception as e:
print("Export video to jpg zip file with uuid error", e)
@@ -0,0 +1,37 @@
'''
Created on 19 janv. 2026
@author: denis
'''
from django.core.management.base import BaseCommand
#from django.conf import settings
from scanner.tasks import export_videos
from scanner.models import Configuration
class Command(BaseCommand):
help = "Exporter les videos"
def add_arguments(self, parser):
super(Command, self).add_arguments(parser)
parser.add_argument("--uuid", type=str, help=f"Export video")
def handle(self, *args, **options): # @UnusedVariable
try:
uuid = options.get('uuid')
conf = Configuration.objects.filter(active=True).first()
print(f"Export video uuid: {uuid}", conf)
job = export_videos(
uuid,
start_ts=None,
end_ts=None,
frame_rate=conf.video_frame_rate, # Frame rate de la vidéo exportée
opencv_fourcc_format=conf.opencv_fourcc_format, # Format de compression vidéo (ex: 'mp4v' pour MP4),
opencv_video_type=conf.opencv_video_type, # Type de vidéo exportée (ex: 'mp4', 'avi', 'mkv'),
)
print()
print(f"Export video: {job.id}")
except Exception as e:
print("Export video uuid error", e)
@@ -0,0 +1,90 @@
#
# encoding: utf-8
#import re
#from django.utils.translation import gettext_lazy as _
from django.conf import settings
from django.core.management import BaseCommand
from django_celery_beat.models import IntervalSchedule, CrontabSchedule, SolarSchedule
from django.contrib.auth import get_user_model
from scanner.models import Well
def create_Well():
try:
if Well.objects.count() == 0:
for name in [
'A1', 'A2', 'A3', 'A4', 'A5', 'A6',
'B1', 'B2', 'B3', 'B4', 'B5', 'B6',
'C1', 'C2', 'C3', 'C4', 'C5', 'C6',
'D1', 'D2', 'D3', 'D4', 'D5', 'D6',
]:
Well.objects.create(name=name, user_id=1)
print('Creating Well')
except Exception as e:
print(f'Creating well error {e}')
def create_user():
try:
User = get_user_model()
if User.objects.count() == 0:
for email, username, password, is_superuser in settings.ADMINS:
if is_superuser:
User.objects.create_superuser(
email=email,
username=username,
password=password,
is_active=True,
is_superuser=is_superuser,
)
else:
User.objects.create_user(
email=email,
username=username,
password=password,
is_active=True,
)
print(f'Creating {username} user with {password} password and email: {email} superuser: {is_superuser}')
except Exception as e:
print(f'Creating user error {e}')
def create_schedule():
try:
for n in [1, 2, 5, 10, 15, 20, 30, 40, 45, 50]:
IntervalSchedule.objects.create(every=n, period='minutes')
print('Creating IntervalSchedule minutes')
for n in [1, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22]:
IntervalSchedule.objects.create(every=n, period='hours')
print('Creating IntervalSchedule hours')
for n in [1, 2, 3, 7, 15, 30, 60, 90, 180, 360]:
IntervalSchedule.objects.create(every=n, period='days')
print('Creating IntervalSchedule days')
CrontabSchedule.objects.create(minute='0', hour='4', day_of_week='*', timezone=settings.TIME_ZONE)
CrontabSchedule.objects.create(minute='0', hour='4', day_of_week='*/3', timezone=settings.TIME_ZONE)
CrontabSchedule.objects.create(minute='15', hour='4', day_of_week='*/3', timezone=settings.TIME_ZONE)
CrontabSchedule.objects.create(minute='30', hour='4', day_of_week='*/3', timezone=settings.TIME_ZONE)
CrontabSchedule.objects.create(minute='0', hour='18', day_of_week='*', timezone=settings.TIME_ZONE)
CrontabSchedule.objects.create(minute='15', hour='18', day_of_week='*/3', timezone=settings.TIME_ZONE)
CrontabSchedule.objects.create(minute='30', hour='18', day_of_week='*/3', timezone=settings.TIME_ZONE)
print('Creating CrontabSchedule')
SolarSchedule.objects.create(event='sunset', latitude=43.8, longitude=2.3)
SolarSchedule.objects.create(event='sunrise', latitude=43.8, longitude=2.3)
print('Creating SolarSchedule')
except Exception as e:
print(f'Creating schedule error {e}')
class Command(BaseCommand):
def handle(self, *args, **options):
try:
create_user()
create_schedule()
create_Well()
except Exception as e:
print(f'Creating monitor error {e}')
@@ -0,0 +1,20 @@
#
# encoding: utf-8
from django.core.management import BaseCommand
from django.urls import get_resolver
class Command(BaseCommand):
def handle(self, *args, **kwargs):
def show_urls(urllist, depth=0):
for entry in urllist:
print(entry.pattern)
if hasattr(entry, 'url_patterns'):
show_urls(entry.url_patterns, depth + 1)
show_urls(get_resolver().url_patterns)
@@ -0,0 +1,38 @@
'''
Created on 19 janv. 2026
@author: denis
'''
import asyncio
from django.core.management.base import BaseCommand
from scanner.export_tasks import remove_video_by_uuid
from scanner.models import MultiWell
async def remove_video(sid, multiwells):
for m in multiwells:
row_to_char = m.row_order.split(',')
for row in range(m.rows):
for col in range(m.cols):
uuid = f'{sid}-{m.position}-{row_to_char[row]}{col+1}'
filters = {"$and": [{"&session": { "$eq": sid} }]}
print(f"Delete video for {uuid} with filters {filters}")
await remove_video_by_uuid(uuid, when=filters)
class Command(BaseCommand):
help = "Démarre les tâches Celery."
def add_arguments(self, parser):
super(Command, self).add_arguments(parser)
parser.add_argument("--session", type=int, default=0, help=f"Delete all videos from Session id")
def handle(self, *args, **options): # @UnusedVariable
try:
sid = options.get('session')
multiwels = [m for m in MultiWell.objects.filter(active=True).all() ]
asyncio.run(remove_video(sid, multiwels))
except Exception as e:
print("Delete all videos from Session error", e)
@@ -0,0 +1,23 @@
#
# encoding: utf-8
from uuid import uuid4
from django.core.management import BaseCommand
from django.core.management.utils import get_random_string;
class Command(BaseCommand):
def add_arguments(self, parser):
super().add_arguments(parser)
parser.add_argument("--app", type=str, default='django', help=f"Default application django/reductstore")
parser.add_argument("--head", type=str, default='scanner', help=f"Default application django/reductstore")
def handle(self, *args, **options):
if options.get('app')=='django':
chars = "abcdefghijklmnopqrstuvwxyz0123456789!@#€%^&*(-_=+)"
sk = get_random_string(50, chars)
print(f'django-insecure-{sk}')
elif options.get('app')=='reductstore':
head = options.get('head')
print(f'{head}-{uuid4()}')
@@ -0,0 +1,26 @@
'''
Created on 19 janv. 2026
@author: denis
'''
from django.core.management.base import BaseCommand
from scanner import tasks as scanner_tasks
class Command(BaseCommand):
help = "Démarre les tâches Celery."
def add_arguments(self, parser):
super(Command, self).add_arguments(parser)
#parser.add_argument("--task", action="store", dest="task", default='start_all')
def handle(self, *args, **options): # @UnusedVariable
#task = options['task']
try:
scanner_tasks.scanner_start.delay() # @UndefinedVariable
scanner_tasks.replay_start.delay() # @UndefinedVariable
except Exception as e:
print(e)
@@ -0,0 +1,68 @@
'''
Created on 19 janv. 2026
@author: denis
'''
from django.core.management.base import BaseCommand
from modules.grbl import GRBLController, wait_for
import time
class Command(BaseCommand):
help = "Démarre les tâches Celery."
def add_arguments(self, parser):
super(Command, self).add_arguments(parser)
#parser.add_argument("--task", action="store", dest="task", default='start_all')
def handle(self, *args, **options): # @UnusedVariable
def check_limits(grbl):
grbl.send("$130=") # Limite max X
grbl.send("$131=") # Limite max Y
def check_speed_limits(grbl):
grbl.send("$110") # Vitesse max X
grbl.send("$111") # Vitesse max Y
grbl.send("$112") # Vitesse max Z
#task = options['task']
try:
grbl = GRBLController()
grbl.send("$$")
#print("clear_alarm")
#grbl.clear_alarm()
#print("home_machine")
#grbl.home_machine()
grbl.go_origin(feed=1000)
wait_for(4.0)
print("go_origin pos", grbl.get_mpos())
#grbl.go_origin(feed=1000)
#check_limits(grbl)
#print("home_machine")
#grbl.home_machine()
print("move_to 100, 100")
grbl.move_to(100, 100, feed=1500)
wait_for(4.0)
#print("halt")
#grbl.halt()
#wait_for(2.0)
#print("pos", grbl.get_mpos())
print("go_origin")
#grbl.go_origin(feed=2000)
grbl.move_to(0, 0, feed=3000)
wait_for(2.0)
print("pos", grbl.get_mpos())
except Exception as e:
print(e)