Skip to content

Classes

Lui-Instruct edited this page Jul 21, 2024 · 5 revisions

ARIAClient

Overview

AriaClient() is the entry point for fandanGO-aria

This class, and its methods, is used for the following:

  • Initiating EntityManager() classes, which retrieve data associated with ARIA entities

    • Entity is a vague word; it could be anything in ARIA’s project management system, such as a visit, proposal, or session
  • Initiating DataManager() classes, which interact with entity-related data. Each DataManger() is responsible for handling data for just one aria entity (ie. Visit #19), in the following ways:

    • Creating and/or displaying Bucket data

    • Creating and/or displaying Record data

    • Creating and/or displaying Field data

  • Handling login and token retrieval, dispersion and refreshing. This is done primarily through the OAuth() class

Example Usage

Initiation

Below is a simple demonstration on how to create a new DataManager() for a visit.

from fandango import AriaClient

client = AriaClient()
entity_id = 10
entity_type = 'visit'
# setting populate parameter to True so the manager for Visit_10 is updated
visit_10_data = client.new_data_manager(entity_id, entity_type, True)
print(visit_10_data.buckets)

Daemon

The daemon is a new concept that allows for the creation of x number of DataManger() classes for n number of ARIA entities.

Extra functionalities will be added in future releases to reduce input from the end user.

from fandango import AriaClient

cli = AriaClient()
  entities = {
      1 : 'visit',
      8 : 'proposal'
  }
  daemon = cli.new_data_managers(entities)
  for entity, data_manager in daemon.items() : 
      if len(data_manager.buckets.items()) :
          entity_buckets = entity_manager.buckets
          for id, bucket in entity_buckets.items() :
              print(json.dumps(bucket.__dict__, indent=4))
      else: 
          print(f'No Buckets for Entity_Manager: {entity}')

DataManager

Overview

DataManager is a class designed to manage entity data, including Buckets, Records, and Fields. It provides methods for creating and manipulating these data objects, as well as populating data from an API source.

Initialisation

To initialise a DataManager instance, you need to provide the following parameters:

token str

  • Authentication token required for accessing the DataManager instance

entity_id int

  • Unique identifier for the entity. If the DataManager is being used for Visit #19, the entity_id passed would be 19

entity_type str

  • Type of the entity. If the DataManager is being used for Visit #19, the entity_type passed would be ‘visit’

populate bool Default = False

  • Not essential for initialisation. If True passed, Bucket, Record and Field data will be imported into the class dictionaries.

Properties

  • ⬆️ entity_type

  • ⬆️ entity_id

  • buckets dict

    • A dictionary containing Bucket objects associated with the entity. Buckets are indexed by their IDs.
  • records dict

    • A dictionary containing Record objects associated with the entity. Records are indexed by their IDs.
  • fields dict

    • A dictionary containing Field objects associated with the entity. Fields are indexed by their IDs.
  • client DataManagerClient

    • An instance of DataManagerClient used for API communication. Token information is passed upon initiation

Methods

create_bucket(embargo: str) -> Bucket

Creates a new Bucket and adds it to the DataManager's Buckets dictionary. Returns the missing fields from the Bucket class required for database pushing and further population.

Parameters

  • embargo str <dd/mm/yyyy> : Embargo status for the bucket.

Returns

  • Bucket : The created Bucket object with missing fields for database pushing.

push(obj)

Pushes an object to the appropriate endpoint.

Parameters

  • obj
    • Object to be pushed.

Raises

  • ValueError: If the object type is not supported for pushing.

create_record(bucket_id: str, schema_type: str) -> Record

Creates a new Record and adds it to the DataManager's Records dictionary. Returns the missing fields from the Record class required for database pushing and further population.

Parameters

  • bucket_id str : ID of the bucket to which the record belongs.

  • schema_type str: Type of schema for the record.

Returns

  • Record: The created Record object with missing fields for database pushing.

create_field(record_id: str, type: str, content: str, options: dict = None) -> Field

Creates a new Field and adds it to the DataManager's Fields dictionary. Returns the missing fields from the Field class required for database pushing and further population.

Parameters

  • record_id str : ID of the record to which the field belongs

  • type str: Type of the field.

  • content str: Content of the field.

  • options dict, optional: Additional options for the field.

Returns

  • Field: The created Field object with missing fields for database pushing.

populate()

Populates new Bucket, Record, and Field instances based on API request. It fetches data from the API source and adds it to the DataManager's dictionaries.

Usage

  • Initialise a DataManager() instance with appropriate parameters.

  • Use methods like create_bucket, create_record, and create_field to add new data objects.

  • Utilise the populate method to fetch and populate data from an API source.

  • Handle data manipulation and interaction using DataManager methods.

Bucket


Definition

class Bucket(AbstractBucket)

Represents a bucket object for storing entity-related data.

Bucket Hierarchy

Requirements

The following arguments are needed to create a Bucket class instance. This will be enforced by it’s abstract class AbstractBucket:

  • entity_id : int

  • entity_type : str

  • embargo_date : str <dd/mm/yy>

Remaining properties are generated automatically once pushed to the database.

Attributes

  • entity_id : int

    • Unique identifier for the entity associated with the bucket.
  • entity_type : str

    • Type of the entity associated with the bucket.
  • embargo_date : str <dd/mm/yy>

    • Date indicating when the bucket's contents can be accessed.
  • id: int

    • optional Unique identifier for the bucket.
  • owner : str

    • optional Owner of the bucket.
  • created : str

    • optional Date indicating when the bucket was created.
  • updated : str

    • optional Date indicating when the bucket was last updated

Methods

__init__(self, entity_id: int, entity_type: str, embargo_date: str, **kwargs)

  • Initialises a Bucket object with the provided parameters.

populate(self, data)

  • Populates optional attributes of the Bucket object from a data dictionary.

  • Generally called when a bucket is returned from the database, post creation or otherwise.

Record


Definition

class Record(AbstractRecord)

Represents a Record object for storing (second-tiered) entity-related data.

Record Hierarchy

Requirements

The following arguments are needed to create a Record class instance. This will be enforced by it’s abstract class AbstractRecord:

  • bucket_id : str

  • schema_type : str

Please check for currently accepted Schema Types. If problems persist or more flexibility is needed for this, please get in contact with us via our Homepage

Remaining properties will be generated once pushed to the database

Attributes

  • bucket_id : str

    • Unique identifier for the bucket associated with the record.
  • schema_type : str

    • Type of schema associated with the record.
  • id : str, optional

    • Unique identifier for the record.
  • owner : str, optional

    • Owner of the record.
  • created : str, optional

    • Timestamp indicating when the record was created.
  • updated : str, optional

    • Timestamp indicating when the record was last updated.

Methods

init(self, bucket_id: str, schema: str)

Initialises a Record object with the provided parameters.

populate(self, data)

  • Populates optional attributes of the Record object from a data dictionary.

  • Generally used after pull from database

Field


Definition

class Field(AbstractField)

Represents a Field object for storing (third-tiered) entity-related data.

Field Hierarchy

Requirements

The following arguments are needed to create a Field class instance. This will be enforced by its abstract class AbstractField:

  • record_id : str

    • Unique identifier for the record associated with the field.
  • field_type : str

    • Type of the field.

    • This is currently a validated field. If a schema doesn’t exist and is necessary, get in contact via our homepage

  • content : str

    • Content of the field.
  • options : dict

    • Optional Additional options associated with the field (default is None).
  • order : int

    • Optional Order of the field (default is 0).

Methods

init(self, record_id: str, field_type: str, content: str, options: dict = None, order: int = 0, **kwargs)

Initialises a Field object with the provided parameters.

populate(self, data)

Populates optional attributes of the Field object from a data dictionary post database push.

CLI


Overview

DataManagerCLI is a command-line interface (CLI) extension of the DataManager() class. It offers a user-friendly terminal interface for managing entity data, including Buckets, Records, and Fields. This documentation provides detailed information on the DataManagerCLI class and its methods to assist users in effectively utilising its functionalities.

Initialisation

To initialise a DataManagerCLI instance, you need to provide the following parameters:

  • token str: Authentication token required for accessing the DataManagerCLI instance.

  • entity_id int: Unique identifier for the entity.

  • entity_type str: Type of the entity.

  • populate bool: Flag indicating whether to populate data upon initialisation.

Methods

menu()

Displays the main menu and handles user input for menu navigation. It allows users to choose actions like creating, printing, or exiting.

creator_cli(data)

Handles the creation process based on user input data. It prompts the user to create a Bucket, Record, or Field according to their selection.

create_bucket_cli(menu_return=True)

Guides the user through the process of creating a Bucket. It prompts the user to enter embargo details and creates the Bucket accordingly.

create_record_cli(menu_return=True)

Guides the user through the process of creating a Record. It prompts the user to create a new Record or select an existing Bucket to associate the Record with.

create_field_cli()

Guides the user through the process of creating a Field. It prompts the user to create a new Field or select an existing Record to associate the Field with.

select_bucket_cli() -> Union[str, None]

Allows the user to select a Bucket from existing options. It presents a list of available Buckets for the user to choose from.

select_record_cli(bucket_id: str) -> Union[str, None]

Allows the user to select a Record associated with a specific Bucket. It presents a list of Records associated with the selected Bucket for the user to choose from.

printer_cli(data)

Prints data (Buckets, Records, or Fields) in a user-friendly format. It displays the selected data in a structured manner for easy understanding.

Usage Tips

  • Start by using the menu() method to navigate through available actions.

  • Follow the prompts provided by each method to perform desired operations.

  • Utilise the selection methods (select_bucket_cli() and select_record_cli()) to choose specific items when required.

  • Make use of the printer_cli() method to view data in a structured format for better readability.

Clone this wiki locally