logbook

This module consists of two classes, LogEntry and Logbook, which are used to create a digital logbook.

class pype_schema.logbook.LogCode(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Enum to represent codes associated with logbook entries

class pype_schema.logbook.LogEntry(timestamp, text, code=LogCode.Info)[source]

A single text log entry in the digital Logbook with associated timestamp and code (e.g., info or error)

Parameters:
  • timestamp (datetime.datetime) – The timestamp for the entry

  • text (str) – The text portion of the entry

  • code (LogCode) – The code associated with the entry. Default is Info

Variables:
  • timestamp (datetime.datetime) – The timestamp for the entry

  • text (str) – The text portion of the entry

  • code (LogCode) – The code associated with the entry. Default is Info

pprint()[source]

Pretty print this entry

class pype_schema.logbook.Logbook(entries=None)[source]

A digital logbook with built-in querying.

Parameters:

entries (dict) – Dictionary of the form { int : LogEntry }. Default is an empty dictionary

Variables:

entries (dict) – Dictionary of the form { int : LogEntry }

add_entry(timestamp, text, code=LogCode.Info)[source]

Modifies self.entries to add the desired text with associated timestamp and code (e.g., info or error). Entries are saved with an automatically incremented counter as their ID.

Parameters:
  • timestamp (datetime.datetime) – The timestamp for the entry to be added

  • text (str) – Plaintext logbook entry

  • code (LogCode) – Code associated with the entry. Default is Info

load_entries(filepath)[source]

Adds all the logbook entries from the given filepath. Supports both JSON and CSV file formats.

Parameters:

filpath (str) – The path to the file to load logbook entries from

Raises:

ValueError – When file extension is not json or csv

next_entry_id()[source]

Gets the next entry ID by checking the current maximum ID

Returns:

ID for the next logbook entry

Return type:

int

print_query(start_dt, end_dt=None, keyword=None, code=None)[source]

Queries logbook entries based on timestamp, keywords, and code. Pretty prints the queried entries, and then also returns them

Parameters:
  • start_dt (datetime.datetime) – First datetime to include in the timestamps of log entries to return.

  • end_dt (datetime.datetime) – Final datetime to include in the timestamps of log entries to return. None by default, meaning that all entries after start_dt will be returned

  • keyword (str) – Keyword to find in the log entry. None by default

  • code (LogCode) – The code associated with desired logbook entries. None by default, meaning all codes will be included

Returns:

Dictionary of logbook entries between start_dt and end_dt that contain keyword and have a matching code

Return type:

dict

query(start_dt, end_dt=None, keyword=None, code=None)[source]

Queries logbook entries based on timestamp, keywords, and code.

Parameters:
  • start_dt (datetime.datetime) – First datetime to include in the timestamps of log entries to return.

  • end_dt (datetime.datetime) – Final datetime to include in the timestamps of log entries to return. None by default, meaning that all entries after start_dt will be returned

  • keyword (str) – Keyword to find in the log entry. None by default

  • code (LogCode) – The code associated with desired logbook entries. None by default, meaning all codes will be included

Returns:

Dictionary of logbook entries between start_dt and end_dt that contain keyword and have a matching code

Return type:

dict

remove_entry(entry_id)[source]

Modifies self.entries

Parameters:

timestamp (datetime.datetime) – The timestamp for the entry to be removed

save_query(start_dt, end_dt=None, keyword=None, code=None, outpath='')[source]

Queries logbook entries based on timestamp, keywords, and code. Saves the queried entries, and then also returns them

Parameters:
  • start_dt (datetime.datetime) – First datetime to include in the timestamps of log entries to return.

  • end_dt (datetime.datetime) – Final datetime to include in the timestamps of log entries to return. None by default, meaning that all entries after start_dt will be returned

  • keyword (str) – Keyword to find in the log entry. None by default

  • code (LogCode) – The code associated with desired logbook entries. None by default, meaning all codes will be included

  • outpath (str) – Path where logbook will be saved. Supported filetypes are JSON and CSV. Default path is “”, meaning that no file will be written

Returns:

Dictionary of logbook entries between start_dt and end_dt that contain keyword and have a matching code

Return type:

dict

to_csv(outpath='')[source]

Save the current Logbook as a CSV file

Parameters:

outpath (str) – Path where logbook will be saved. Default is “”, meaning no file will be saved

Returns:

csv in DataFrame format

Return type:

pandas.DataFrame

to_json(outpath='', indent=4)[source]

Save the current Logbook as a JSON file

Parameters:
  • outpath (str) – Path where logbook will be saved. Default is “”, meaning that no file will be written

  • indent (int) – number of spaces to indent the JSON file. Default is 4

Returns:

json in dictionary format

Return type:

dict