Database Sync Script
- class database_sync.CommandLogger[source]
CommandLogger is a class that implements the CommandListener abstract methods and uses that to log commands that are processed pymongo.
- failed(event: CommandFailedEvent)[source]
This function is called when the CommandListener detects a `CommandFailedEvent`_. It will log information related to the event. :param event: :return:
- started(event: CommandStartedEvent)[source]
This function is called when the CommandListener detects a CommandStartedEvent. This function will parse the command and log that in an easy-to-read format.
- Parameters:
event (CommandStartedEvent)
- succeeded(event: CommandSucceededEvent)[source]
This function is called when the CommandListener detects a `CommandSucceededEvent`_. It will log information related to the event.
- Parameters:
event
- Returns:
- class database_sync.DatabaseHandler[source]
A subclass of
FileSystemEventHandler
to pass watchdog information to a DatabaseSync object.- on_closed(event: DirCreatedEvent | FileCreatedEvent)[source]
Watchdog handler that, given an event, sends the relevant data to its DatabaseSync object.
- Parameters:
event (Union[
events.DirCreatedEvent
,events.FileCreatedEvent
]) – The file or directory created to use. Has asrc_path
field and anis_directory
field.
- class database_sync.DatabaseSync[source]
DatabaseSync is used as a way to get many methods that interact with the database. If run, this program will create a process called database_sync that continuously watches a directory (Currently usr/local/bee/appmais) for new incoming hives, audio files, or video files to insert into the database. See
UpdateDatabase
if you wish to insert many older files into the database rather than only the incoming files.- __weakref__
list of weak references to the object
- check_hive_audio(hive_name: str, date: str | None = '**')[source]
Checks one hive’s subtree in the filesystem for any audio files, and creates an entry for any that aren’t already in the database. Traverses through all the possible audio filepaths, checks if the filepaths are in the database, and if not then pass the filepaths to
insert_audio()
to insert into the database.
- check_hive_images(hive_name: str, date: str | None = '**')[source]
Checks one hive’s subtree in the filesystem for any images, and creates an entry for any that aren’t already in the database. Traverses through all the possible image filepaths, checks if the filepaths are in the database, and if not then pass the filepaths to
insert_image()
to insert into the database.
- check_hive_videos(hive_name: str, date: str | None = '**')[source]
Checks one hive’s subtree in the filesystem for any videos, and creates an entry for any that aren’t already in the database. Traverses through all the possible video filepaths, checks if the filepaths are in the database, and if not then pass the filepaths to
insert_video()
to insert into the database.
- find_new_audio()[source]
Iterates through each hive and checks if they have any new audio files to insert into the database. Can take a long time depending on the number of audio files. Uses
check_hive_audio()
to build the filepaths for each date and insert any audio file it finds.
- find_new_hives()[source]
Checks the directories at the given location for any new hives. If it finds one, pass it to
_insert_hive()
. Used byUpdateDatabase.update_hives()
.
- find_new_videos()[source]
Iterates through each hive and checks if they have any new videos or images to insert into the database. Can take a long time depending on the number of videos/images.Uses
check_hive_videos()
orcheck_hive_images()
to build the filepaths for each date and insert any video/image it finds.
- insert_airquality(airquality_path: str)[source]
Creates an entry for the air quality recording to put into the database. This indiscriminately inserts into the database (overwriting the values if they already exist), so be sure before you use it that it is certain that the values are not already in the database. This does not insert the whole file, just the last line of the .csv.
- Parameters:
airquality_path (str) – Full path to the airquality csv file.
- insert_audio(collection: Collection, audio_path: str)[source]
Creates an entry of an audio file to insert into the database. Audio file entries have the HiveName, TimeStamp, and FilePath as column headers. This indiscriminately inserts into the database, so be sure before you use it that it is certain that the file is not in the database. Used internally by
check_hive_audio()
whenever it finds an outstanding file, and externally by the watchdog methodDatabaseHandler.on_closed()
when the watchdog finds a new audio file.- Parameters:
collection (Collection) – The collection to insert the audio file item into.
audio_path (str) – The path to the audio file that was uploaded.
- insert_cpu(cpu_path: str)[source]
Creates an entry for cpu stats to put into the database. This indiscriminately inserts into the database, so be sure before you use it that it is certain that the values are not already in the database. This does not insert the whole file, just the last line of the .csv.
- Parameters:
cpu_path (str) – Full path to the cpu csv file.
- insert_hive(hive_name: str)[source]
Inserts one hive into the database, using the hive name and finding the earliest recordings sent from that hive.
- Parameters:
hive_name (str) – Name of hive to be inserted.
- insert_image(image_path: str)[source]
Creates an entry of a image file to insert into the database. image file entries have the HiveName, TimeStamp, FilePath, and FileSize as column headers. This indiscriminately inserts into the database, so be sure before you use it that it is certain that the file is not in the database. Used internally by
check_hive_images()
whenever it finds an outstanding file, and externally by the watchdog methodDatabaseHandler.on_closed()
when the watchdog finds a new image file.- Parameters:
image_path (str) – The path to the image that was uploaded.
- insert_scale(scale_path: str)[source]
Creates an entry for the scale recording to put into the database. This indiscriminately inserts into the database, so be sure before you use it that it is certain that the values are not already in the database. This does not insert the whole file, just the last line of the .csv.
- Parameters:
scale_path (str) – Full path to the scale csv file.
- insert_temp(temp_path: str)[source]
Creates an entry for both the temperature and humidity recording to put into the database. This indiscriminately inserts into the database, so be sure before you use it that it is certain that the values are not already in the database. This does not insert the whole file, just the last line of the .csv.
- Parameters:
temp_path (str) – Full path to the temperature and humidity csv file.
- insert_video(video_path: str)[source]
Creates an entry of a video file to insert into the database. Video file entries have the HiveName, TimeStamp, FilePath, and FileSize as column headers. This indiscriminately inserts into the database, so be sure before you use it that it is certain that the file is not in the database. Used internally by
check_hive_videos()
whenever it finds an outstanding file, and externally by the watchdog methodDatabaseHandler.on_closed()
when the watchdog finds a new video file.- Parameters:
video_path (str) – The path to the video that was uploaded.
- database_sync.already_exists(collection: Collection, key: str, value: str) bool [source]
Static method that checks whether an entry already exists in a database collection.
- Parameters:
collection (
pymongo.collection.Collection
) – A database collection to query, such as__hives_collection
.key (str) – Key column that you’re looking for, like “HiveName”.
value (str) – New value to check, like “AppMAIS1L” for “HiveName”.
- Returns:
True if the key and value are found in the given collection, false if not.
- Return type:
Todo
Port this method to utils.mongo