Repository

The Repository class allows to read and write to bb_binary data stores.

The bb_binary data is splitted into several files that are organized in subfolders via date and time. A Repository manages these bb_binary datafiles and provides methods to add new FrameContainer, or iterate through Frame.

This class provides performant access to a bb_binary data store but you will have to parse the data by yourself. You might use some helpers from Parsing.

load_frame_container(fname)[source]

Loads FrameContainer from this filename.

class Repository(root_dir, minute_step=None)[source]

Bases: object

The Repository class manages multiple bb_binary files. It creates a directory layout that enables fast access by the timestamp.

add(frame_container)[source]

Adds the frame_container of type FrameContainer to the repository.

open(timestamp, cam_id)[source]

Finds and load the FrameContainer that matches the timestamp and cam_id.

find(ts, cam=None)[source]

Returns all files that includes detections to the given timestamp ts.

Todo

UTC timestamps! Generall

iter_fnames(begin=None, end=None, cam=None, fname_filter=None)[source]

Returns a generator that yields filenames in sorted order.

From begin to end.

Parameters:
  • begin (Optional timestamp) – The first filename contains at least one frame with a timestamp greater or equal to begin. If begin is not set, it will start with the earliest file.
  • end (Optional timestamp) – The last filename contains at least one frame with a timestamp smaller then end. If not set, it will continue until the last file.
  • cam (Optional int) – Only yield filenames with this cam id.
  • fname_filter (Optional function) – only yield fnames for which the function returns true

Example:

Files:        A     B     C        D     E
Frames:    |-----|-----|-----|  |-----|-----|
                ⬆          ⬆
              begin       end

This should return the files A, B and C. If begin and end are None, then all will be yield.

iter_frames(begin=None, end=None, cam=None, frame_filter=None)[source]

Yields frames with their corresponding FrameContainers. The FrameContainers are ordered in time. Beware that individual frames may not be in order if cam is not set.

From begin to end.

Parameters:
  • begin (Optional timestamp) – select frames with begin <= timestamp.
  • with smallest timestamp in repository if not set. (Starts) –
  • end (Optional timestamp) – select frames with timestamp < end.
  • with biggest timestamp in repository if not set. (Ends) –
  • cam (Optional int) – only yield filenames with this cam id.
  • frame_filter (Optional function) – only yield frames for which the function returns true
Returns:

tuple containing:

iterator (iterable): iterator with Frames FrameContainer (FrameContainer): the corresponding FrameContainer for each frame.

Return type:

(tuple)

class TimeInterval(begin, end)[source]

Bases: object

Helper class to represent time intervals.

in_interval(dt)[source]