Translate

Using AI in Developing

Using AI in Developing Basic Functional Components


Using AI to assist in the development of various basic functional components may not necessarily be used in the final product, but it accumulates valuable practical experience. Having multiple solutions for various basic problems can help you tackle future challenges with greater confidence. To quickly move beyond the beginner stage, it's important to focus on problem-solving methods rather than struggling with simple, repetitive issues and unnecessary techniques. Writing code is not just about testing if it runs; it's also critical to verify that all functions operate as intended under normal circumstances. The testing workload might be significant, and discovering serious issues may require rewriting a lot of code and retesting until no problems are found. Although this can be troublesome, it is essential and serves as the final challenge in moving beyond the beginner stage.

Write a a Python class that implements reading, storage, and deletion operations for files using SQLite3 database. The class name is FileSQL3, and the constructor accepts a file path as a parameter. During initialization, it creates two database tables: one for storing metadata of files, and the other for storing the actual data of the files. The structure and fields of these database tables include:
1. files table: stores the metadata of files
- path: file path, used as primary key
- created: file creation time
- modified: file modification time
- length: file size
- encoding: file encoding (can be null)
- mimetype: MIME type of file (can be null)
- description: description of file (can be null)
- parts: the segmented data information of file in the database, stored as a JSON string
2. datas table: stores the actual data of files
- uuid: the UUID of file data
- data: binary data, stored as the BLOB data type of SQLite3
- path: file path
- start: start position of the file data segment (block)
- end: end position of the file data segment
The FileSQL3 class includes the following methods:
1. get(file_path): accepts a file path parameter and returns a FileS object
This method queries the metadata of the file from the files table, and then creates a FileS object. The FileS object has the following attributes:
- size: file size
- create: file creation time
- modified: file modification time
- mimetype: MIME type of file
- encoding: file encoding
- parts: segmented data information of file in the database
- conn: a connection object to the database, used for reading the file data
The FileS object has the following methods:
- read(size=-1): reads the specified amount of data, reads the entire file if the size exceeds the file size.
- seek(position): set the read-write pointer position.
- tell(): returns the current read-write pointer position.
2. put(file_path, p_path=None, description=None, block_size=DEFAULT_BLOCK_SIZE): stores the file in the database
This method reads data from the file path, saves the data into the datas table after segmentation, and adds a file metadata record into the files table. This metadata record includes the file path, creation time, modification time, size, description information, and segmented data information of the file. The path of the file can be modified by specifying p_path, and the description information of the file can be edited by specifying description.
3. search(search_string): searches all file paths that contain the specified string
This method queries all file paths in the files table that contain the specified string in their paths.
4. delete(file_path): deletes the specified file and file data from the database
This method deletes the specified file and file data from the files and datas tables in the database.

Testing phase:

Various files of different sizes and types were written into fileSQL3, and all kinds of operations were performed without issues. The ultimate test involved a 3.6GB t.mp4 file, which passed the random access test. Then, the file was simulated for web playback, allowing for regular file-like behavior such as pausing, resuming, and selecting playback positions.

Finally, store the 36GB of music videos in an SQLite3 database and create a simple web application so that all files can be played smoothly and without any issues.
Even with files counting in the terabytes(TB), it still works well.
videos with search, lazy loading and playing multi videos in same time.
generate a m3u8 from search result and can be played from vlc player like native files.
Hosted at home, the speed faster than my nas. To achieve this functionality, it is necessary to delve into the framework, take over the basic operations flow, customize the response flow using standards that comply with the HTTP protocol. AI cannot directly complete the task, but with its help, it quickly learned the basics of two frameworks, Face detection with opencv and FastAPI Multi detection on video Object Detection with yolov4.

沒有留言:

發佈留言