RUFAS.data_collection_app_updater module#

RUFAS.data_collection_app_updater.SCHEMA_DIRECTORY_PATH: Path = PosixPath('DataCollectionApp/schema')#

Path to the home page of the Data Collection App.

RUFAS.data_collection_app_updater.INDEX_PATH: Path = PosixPath('DataCollectionApp/index.html')#

Path to the template for regenerating the Data Collection App’s home page.

RUFAS.data_collection_app_updater.TEMPLATE_PATH: Path = PosixPath('DataCollectionApp/template')#

Directory to the available user feed inputs.

RUFAS.data_collection_app_updater.USER_FEED_PATH: Path = PosixPath('input/data/feed/user_feeds.csv')#

Path to the feed_schema.js schema file.

RUFAS.data_collection_app_updater.FEED_SCHEMA_PATH: Path = PosixPath('DataCollectionApp/schema/feed_schema.js')#

Placeholder for inserting schema import scripts in index.html.

RUFAS.data_collection_app_updater.SCHEMA_SCRIPT_TAG_PLACEHOLDER: str = '    <!-- Schema imports go here-->'#

Placeholder for listing newly available schemas in the rewritten index.html.

RUFAS.data_collection_app_updater.AVAILABLE_SCHEMAS_LIST_PLACEHOLDER: str = '// List of available schema goes here'#

Fallback placeholder in a DCA input field if no value has been entered into it.

class RUFAS.data_collection_app_updater.DataCollectionAppUpdater#

Bases: object

This class provides a suite of methods for automatically updating the JSON schemas for the Data Collection App based on the properties contained in the metadata.

Attributes#

_imInputManager

Instance of the Input Manager.

_omOutputManager

Instance of the Output Manager.

_type_to_schema_mapdict[str, Callable[[str, dict[str, Any]], dict[str, Any]]]

Maps types in the metadata properties to methods used to generate schema for those types.

Methods#

update_data_collection_app

Orchestrates updates to the schemas and index page of the Data Collection App.

__init__() None#
update_data_collection_app(task_manager_metadata_properties: dict[str, Any]) None#

Updates schemas for collection of RuFaS inputs in the Data Collection App.

Parameters#

task_manager_metadata_propertiesdict[str, Any]

Properties Task Manager inputs.

_rewrite_schemas(task_manager_metadata_properties: dict[str, Any]) list[Path]#

Rewrites schemas in the Data Collection App using the input properties found in the Input Manager.

Parameters#

task_manager_metadata_propertiesdict[str, Any]

Properties Task Manager inputs.

Returns#

list[str]

List of file names of the rewritten schema.

_rewrite_index_page(schema_paths: list[Path]) None#

Rewrites the index.html page of the Data Collection App to use the newly written schema.

Parameters#

schema_pathslist[Path]

List of path instances which will be used to link the index page to the input schemas.

_create_number_schema(var_name: str, input_properties: dict[str, Any]) dict[str, Any]#

Creates an input schema for a numerical input.

Parameters#

var_namestr

The name of the variable for which this schema is being created.

input_propertiesdict[str, Any]

The properties of the input variable.

Returns#

dict[str, Any]

Dictionary containing the input schema for this variable.

_create_bool_schema(var_name: str, input_properties: dict[str, Any]) dict[str, Any]#

Creates an input schema for a boolean input.

Parameters#

var_namestr

The name of the variable for which this schema is being created.

input_propertiesdict[str, Any]

The properties of the input variable.

Returns#

dict[str, Any]

Dictionary containing the input schema for this variable.

_create_string_schema(var_name: str, input_properties: dict[str, Any]) dict[str, Any]#

Creates an input schema for a string input.

Parameters#

var_namestr

The name of the variable for which this schema is being created.

input_propertiesdict[str, Any]

The properties of the input variable.

Returns#

dict[str, Any]

Dictionary containing the input schema for this variable.

_get_list_of_options(input_pattern: str) list[str]#

Gets a list of acceptable string inputs based on the Regex pattern that is used to validate the input.

Parameters#

input_patternstr

The Regex pattern that is used to determine if a string input is valid or not.

Returns#

list[str]

List of strings that would be valid when checked against the input pattern.

Raises#

ValueError

If the Regex pattern used for validation does not adhere to the format “^(<option 1>|<option 2>|…)$”.

Notes#

When a string input is taken, often it is to select from a preset group of options. This method is designed to derive those options from the Regex pattern that is used to validate it.

The Regex pattern used to check input_pattern ensures there no special characters in-between “^(” and “)$” unless they are a bar (“|”), hyphen (“-“), whitespace (” “), or slash (“/”).

Examples#

>>> DataCollectionAppUpdater._get_list_of_options("^(kg)$")
["kg"]
>>> DataCollectionAppUpdater._get_list_of_options("^(default|no_kill)$")
["default", "no_kill"]
>>> DataCollectionAppUpdater._get_list_of_options("^(TAI|ED|Synch-ED)$")
["TAI", "ED", "Synch-ED"]
_create_array_schema(var_name: str, input_properties: dict[str, Any]) dict[str, Any]#

Creates an input schema for an array input.

Parameters#

var_namestr

The name of the variable for which this schema is being created.

input_propertiesdict[str, Any]

The properties of the input variable.

Returns#

dict[str, Any]

Dictionary containing the input schema for this variable.

_create_object_schema(var_name: str, input_properties: dict[str, Any]) dict[str, Any]#

Creates an input schema for an object input.

Parameters#

var_namestr

The name of the variable for which this schema is being created.

input_propertiesdict[str, Any]

The properties of the input variable.

Returns#

dict[str, Any]

Dictionary containing the input schema for this variable.

_parse_variable_name_into_title(variable_name: str) str#

Converts a variable name written all or partially in snake case to a more readable name.

Parameters#

variable_namestr

The variable name to be converted into a more readable title.

Returns#

str

The variable name with spaces between all words and the first letter of each word capitalized.

_add_filename_input_field(schema: dict[str, Any]) dict[str, Any]#

Adds field to schema for collecting filename that data will be saved as.

static gather_feed_data() dict[str, Any]#

Gather the user feed data to update.

update_feed_schema(user_feed: dict[str, list[Any]]) None#

Main routine to update the structure of feed schema.

Parameters#

user_feeddict[str, list]

The user feeds input data parsed so that it can be used to setup dropdowns.

modify_items_schema(data: dict[str, Any], dropdown_data: dict[str, list[Any]], skip_first: bool = True) dict[str, Any]#

Modify the schema with dropdowns by updating the corresponding field with updated feed data.

Parameters#

datadict[str, Any]

The schema structure.

dropdown_datadict[str, list]

The updated content in the dropdown.

skip_firstbool, default=True

Boolean indicators to help skip the first “properties” field

Returns#

dict[str, Any]

Input schema with updated dropdowns.

static update_first_property_with_enum(properties: dict[Any, Any], dropdown_data: dict[str, Any]) dict[Any, Any]#

Create a new properties dictionary with the first dictionary property.

Parameters#

propertiesdict[Any, Any]

The target properties to update with dropdown menu data.

dropdown_datadict[str, Any]

The data containing the dropdown values to insert.

Returns#

dict[Any, Any]

A new dictionary with the update applied.