move more complex classes to their own module, keep imports helpers.py core python
This commit is contained in:
@@ -12,7 +12,8 @@ import inotify.adapters
|
|||||||
from inotify.constants import IN_CLOSE_WRITE
|
from inotify.constants import IN_CLOSE_WRITE
|
||||||
|
|
||||||
from server import load_global_model, run_analysis
|
from server import load_global_model, run_analysis
|
||||||
from utils.helpers import get_settings, ParseFileName, get_wav_files, ANALYZING_NOW
|
from utils.helpers import get_settings, get_wav_files, ANALYZING_NOW
|
||||||
|
from utils.classes import ParseFileName
|
||||||
from utils.reporting import extract_detection, summary, write_to_file, write_to_db, apprise, bird_weather, heartbeat, \
|
from utils.reporting import extract_detection, summary, write_to_file, write_to_db, apprise, bird_weather, heartbeat, \
|
||||||
update_json_file
|
update_json_file
|
||||||
|
|
||||||
|
|||||||
+3
-4
@@ -5,9 +5,9 @@ import time
|
|||||||
import librosa
|
import librosa
|
||||||
import numpy as np
|
import numpy as np
|
||||||
|
|
||||||
from utils.helpers import get_settings, Detection, get_language
|
from scripts.utils.classes import Detection, ParseFileName
|
||||||
from utils.models import get_model
|
from scripts.utils.helpers import get_settings, get_language
|
||||||
|
from scripts.utils.models import get_model
|
||||||
|
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
@@ -193,7 +193,6 @@ def run_analysis(file):
|
|||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
from utils.helpers import ParseFileName
|
|
||||||
conf = get_settings()
|
conf = get_settings()
|
||||||
model = conf['MODEL']
|
model = conf['MODEL']
|
||||||
test_files = ['../tests/testdata/2024-02-24-birdnet-16:19:37.wav']
|
test_files = ['../tests/testdata/2024-02-24-birdnet-16:19:37.wav']
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
import datetime
|
|
||||||
import glob
|
import glob
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
@@ -8,8 +7,6 @@ from collections import OrderedDict
|
|||||||
from configparser import ConfigParser
|
from configparser import ConfigParser
|
||||||
from itertools import chain
|
from itertools import chain
|
||||||
|
|
||||||
from tzlocal import get_localzone
|
|
||||||
|
|
||||||
_settings = None
|
_settings = None
|
||||||
|
|
||||||
DB_PATH = os.path.expanduser('~/BirdNET-Pi/scripts/birds.db')
|
DB_PATH = os.path.expanduser('~/BirdNET-Pi/scripts/birds.db')
|
||||||
@@ -60,47 +57,6 @@ def get_settings(settings_path='/etc/birdnet/birdnet.conf', force_reload=False):
|
|||||||
return settings
|
return settings
|
||||||
|
|
||||||
|
|
||||||
class Detection:
|
|
||||||
def __init__(self, file_date, start_time, stop_time, scientific_name, common_name, confidence):
|
|
||||||
self.start = float(start_time)
|
|
||||||
self.stop = float(stop_time)
|
|
||||||
self.datetime = file_date + datetime.timedelta(seconds=self.start)
|
|
||||||
self.date = self.datetime.strftime("%Y-%m-%d")
|
|
||||||
self.time = self.datetime.strftime("%H:%M:%S")
|
|
||||||
self.iso8601 = self.datetime.astimezone(get_localzone()).isoformat()
|
|
||||||
self.week = self.datetime.isocalendar()[1]
|
|
||||||
self.confidence = round(float(confidence), 4)
|
|
||||||
self.confidence_pct = round(self.confidence * 100)
|
|
||||||
self.species = scientific_name
|
|
||||||
self.scientific_name = scientific_name
|
|
||||||
self.common_name = common_name
|
|
||||||
self.common_name_safe = self.common_name.replace("'", "").replace(" ", "_")
|
|
||||||
self.file_name_extr = None
|
|
||||||
|
|
||||||
|
|
||||||
class ParseFileName:
|
|
||||||
def __init__(self, file_name):
|
|
||||||
self.file_name = file_name
|
|
||||||
name = os.path.splitext(os.path.basename(file_name))[0]
|
|
||||||
date_created = re.search('^[0-9]+-[0-9]+-[0-9]+', name).group()
|
|
||||||
time_created = re.search('[0-9]+:[0-9]+:[0-9]+$', name).group()
|
|
||||||
self.file_date = datetime.datetime.strptime(f'{date_created}T{time_created}', "%Y-%m-%dT%H:%M:%S")
|
|
||||||
self.root = name
|
|
||||||
|
|
||||||
ident_match = re.search("RTSP_[0-9]+-", file_name)
|
|
||||||
self.RTSP_id = ident_match.group() if ident_match is not None else ""
|
|
||||||
|
|
||||||
@property
|
|
||||||
def iso8601(self):
|
|
||||||
current_iso8601 = self.file_date.astimezone(get_localzone()).isoformat()
|
|
||||||
return current_iso8601
|
|
||||||
|
|
||||||
@property
|
|
||||||
def week(self):
|
|
||||||
week = self.file_date.isocalendar()[1]
|
|
||||||
return week
|
|
||||||
|
|
||||||
|
|
||||||
def get_open_files_in_dir(dir_name):
|
def get_open_files_in_dir(dir_name):
|
||||||
result = subprocess.run(['lsof', '-w', '-Fn', '+D', f'{dir_name}'], check=False, capture_output=True)
|
result = subprocess.run(['lsof', '-w', '-Fn', '+D', f'{dir_name}'], check=False, capture_output=True)
|
||||||
ret = result.stdout.decode('utf-8')
|
ret = result.stdout.decode('utf-8')
|
||||||
|
|||||||
@@ -12,7 +12,8 @@ from time import sleep
|
|||||||
import requests
|
import requests
|
||||||
from PIL import Image, ImageDraw, ImageFont
|
from PIL import Image, ImageDraw, ImageFont
|
||||||
|
|
||||||
from .helpers import get_settings, ParseFileName, Detection, get_font, DB_PATH
|
from .helpers import get_settings, get_font, DB_PATH
|
||||||
|
from .classes import Detection, ParseFileName
|
||||||
from .notifications import sendAppriseNotifications
|
from .notifications import sendAppriseNotifications
|
||||||
|
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
|
|||||||
Reference in New Issue
Block a user