mindlogger_backend_dev (module)¶
Submodules¶
girder_connections¶
-
mindlogger_backend_dev.girder_connections.
configuration
(config_file=None, context_file=None, which_girder='dev')¶ Function to set configuration variables.
Parameters: - config_file: string, optional
path to configuration file default = “config.json”
- context_file: string, optional
path to context file default = “context.json”
- which_girder: string, optional
“dev” or “production” default = “dev”
Returns: - config: dictionary
- context: dictionary
- api_url: string
-
mindlogger_backend_dev.girder_connections.
connect_to_girder
(api_url='https://data.kitware.com/api/v1/', authentication=None)¶ Function to connect to a Girder DB.
Parameters: - api_url: string, optional
path to running Girder DB API endpoint. Default is Kitware Data API
- authentication: tuple or string, optional
(username, password) or APIkey (
username: string password: string
) default=None
- APIkey: string
default=None
Returns: - girder_connection: GirderClient
Examples
>>> import girder_client as gc >>> g = connect_to_girder() Connected to the Girder database 🏗🍃 but could not authenticate without username and password. >>> g.getItem( ... "58cb124c8d777f0aef5d79ff" ... )["name"] 'LARGE_PtCu_NanoParticles-stride-5.html' >>> g = connect_to_girder(authentication=("a", "b")) Connected to the Girder database 🏗🍃 but could not authenticate. >>> g = connect_to_girder(authentication="ab") Connected to the Girder database 🏗🍃 but could not authenticate. >>> import os >>> config_file = os.path.join( ... os.path.dirname(__file__), ... "config.json.template" ... ) >>> config, context, api_url = configuration( ... config_file=config_file ... ) >>> girder_connection = connect_to_girder( ... api_url=api_url, ... authentication=( ... config["girder-dev"]["user"], ... config["girder-dev"]["password"] ... ) ... ) Connected to the Girder database 🏗🍃 and authenticated. >>> connect_to_girder( ... api_url=config["girder-dev"]["password"], ... authentication=( ... config["girder-dev"]["user"], ... config["girder-dev"]["password"] ... ) ... ) I am unable to connect to the Girder database 🏗🍃
object_manipulation¶
-
mindlogger_backend_dev.object_manipulation.
drop_empty_keys
(d)¶ Function to iteratively drop empty keys from a given dictionary
Parameters: - d: dictionary
Returns: - d: dictionary
Examples
>>> drop_empty_keys( ... { ... "a": None, ... "b": { ... "a": None, ... "b": {} ... }, ... "c": [ ... "a", ... None, ... {"b": None}, ... ( ... "a", ... {"b": None}, ... "c" ... ), ... ("a", None, "c") ... ] ... } ... ) {'b': {'b': {}}, 'c': ['a', None, {}, ('a', {}, 'c'), ('a', None, 'c')]}
-
mindlogger_backend_dev.object_manipulation.
isiterable
(item)¶ Function to test if an item is an Iterable, ie a non-string object that can be iterated over
Parameters: - item: anything
Returns: - isterable: boolean
Is item iterable?
Examples
>>> isiterable(set()) True >>> isiterable(bool()) False
-
mindlogger_backend_dev.object_manipulation.
numeric
(s)¶ Function to test if a string is numeric and convert if so
Parameters: - s : string
Returns: - new_s: int, float, or string
Examples
>>> numeric("9") 9 >>> numeric("9s") '9s' >>> numeric("9.1") 9.1
-
mindlogger_backend_dev.object_manipulation.
test_format
(o)¶ Function to take long strings and format them for doctests.
Parameters: - o: string
original string
Returns: - new_o: string
docstring-formatted output string
Examples
>>> test_format( ... "test_this(set_of, params)" ... ) ' >>> test_this(\n ... set_of,\n ... params\n ... )' >>> test_format( ... 'test_format("test_this(set_of, params)")' ... ) ' >>> test_format(\n ... "test_this(set_of, params)"\n ... )'
postgres_to_girder¶
-
mindlogger_backend_dev.postgres_to_girder.postgres_to_girder.
assingments_from_postgres
(girder_connection, postgres_tables, context={}, timings={'1': 'Once', '12h': '2×Daily', '1d': 'Daily', '8h': '3×Daily'})¶ Function to build user activity schedules.
Parameters: - girder_connection: GirderClient
- postgres_tables: DataFrame
- context: dictionary, optional
- timings: dictionary, optional
Returns: - schedules: set
set of Girder Item _ids
-
mindlogger_backend_dev.postgres_to_girder.postgres_to_girder.
connect_to_postgres
(postgres_config)¶ Function to connect to a Girder DB.
Parameters: - postgres_config: dictionary
- “dbname”: string
Postgres DB name
- “user”: string
Postgres username
- “host”: string
active Postgres IP (no protocol, ie, without “https://”)
- “password”: string
password for Postgres user
Returns: - postgres_connection: connection
Examples
>>> config_file = os.path.join( ... os.path.dirname(__file__), ... os.pardir, ... "config.json.template" ... ) >>> connect_to_postgres( ... configuration( ... config_file=config_file ... )[0]["postgres"] ... ) I am unable to connect to the Postgres database 🐘
-
mindlogger_backend_dev.postgres_to_girder.postgres_to_girder.
get_abbreviation
(activity)¶ Function to extract abbreviation from activity name if one is present
Parameters: - activity: string
Returns: - activity_name: string
- abbreviation: string
Examples
>>> get_abbreviation( ... "Corresponding parts of congruent " ... "triangles are congruent (CPCTC)" ... )[1] 'CPCTC'
-
mindlogger_backend_dev.postgres_to_girder.postgres_to_girder.
get_postgres_item_version
(activity_name, abbreviation=None, activity_source=None, respondent=None, version=None)¶ Function to create an item version in Mindlogger Item format: [Source] — [Activity] — [Respondent] Report ([Version]).
Parameters: - activity_name: string
- abbreviation: string
- activity_source: string
- respondent: string
- version: string
Returns: - item_version: string
Examples
>>> activity_name, abbreviation = get_abbreviation( ... "EHQ (Edinburgh Handedness Questionnaire)" ... ) >>> get_postgres_item_version( ... activity_name=activity_name, ... abbreviation=abbreviation, ... activity_source="MATTER Lab", ... respondent="Coworker", ... version="v0.1" ... ) 'MATTER Lab ― Edinburgh Handedness Questionnaire (EHQ) ― Coworker Report (v0.1)'
-
mindlogger_backend_dev.postgres_to_girder.postgres_to_girder.
postgres_activities_to_girder_activities
(acts, gc, users, users_by_email, context)¶ Function to transfer users from Postgres table to Girder collection.
Parameters: - acts: DataFrame
activities table from Postgres DB
- gc: GirderClient
active GirderClient in which to add the users
- users: DataFrame
users table from Postgres DB
- users_by_email: dictionary
- key: string
email address
- value: string
Girder User_id
- context: dictionary
JSON-LD context
Returns: - activities: DataFrame
-
mindlogger_backend_dev.postgres_to_girder.postgres_to_girder.
postgres_answers_to_girder_answers
(girder_connection, postgres_tables, context)¶ Function to port User responses from Postgres to Girder
Parameters: - girder_connection: GirderClient
- postgres_tables: DataFrame
- context: dictionary
Returns: - response_folder_ids: set
-
mindlogger_backend_dev.postgres_to_girder.postgres_to_girder.
postgres_options_to_JSONLD_options
(gc, q, item_id, language='en-US')¶ Function to convert Postgres question options to JSON-LD options
Parameters: - gc: GirderClient
- q: dictionary
- item_id: string
- language: string, default en-US
Returns: - j_options: list of dictionaries
-
mindlogger_backend_dev.postgres_to_girder.postgres_to_girder.
postgres_question_to_girder_question
(q, question_text, variable_name, context, language='en-US')¶
-
mindlogger_backend_dev.postgres_to_girder.postgres_to_girder.
postgres_questions_to_girder_screens
(girder_connection, questions, short_name, screen_type, activity_version, context, language='en-US')¶ Function to convert Postgres questions to Girder screens
Parameters: - girder_connection: GirderClient
- questions: list of dictionaries
- short_name: string
- screen_type: string
- activity_version: string
Returns: - screens: list
list of Girder screen _ids
-
mindlogger_backend_dev.postgres_to_girder.postgres_to_girder.
postgres_user_assign_to_girder_groups
(postgres_user, girder_user, girder_connection)¶ Function to assign User to appropriate Girder Groups per permissions in PostgresDB.
Parameters: - postgres_user: Series
row from users DataFrame
- girder_user: string
Girder User “_id”
- girder_connection: GirderClient
active GirderClient
Returns: - groups: dictionary
- key: string
Group_id
- value: string
permissions level
groups and permissions levels assigned
-
mindlogger_backend_dev.postgres_to_girder.postgres_to_girder.
postgres_users_to_girder_users
(users, girder_connection, unknown_person={'first_name': '[Notname]', 'last_name': '[Anonymous]'})¶ Function to transfer users from Postgres table to Girder collection.
Parameters: - users: DataFrame
users table from Postgres DB
- girder_connection: GirderClient
active GirderClient in which to add the users
- unknown_person: dictionary
unknown_person[“first_name”]: string unknown_person[“last_name”]: string
Returns: - users_by_email: dictionary
- key: string
email address
- value: string
Girder User_id
-
mindlogger_backend_dev.postgres_to_girder.postgres_to_girder.
table_cells_from_postgres
(rows, columns, response_type)¶ Function to convert Postgres table options encoded as rows and columns to dictionaries with (row, column) keys where 0 represents a header in either dimension and internal cells are 1-indexed.
Parameters: - rows: list
- rows[]: dictionary
- key: string
“text” or “img_url”
- value: string
row header
- columns: list
- columns[] dictionary
- key: string
“text” or “img_url”
- value: string
internal cell option or column header
- response_type: string
Returns: - table: dictionary
- key: 2-tuple
(row_number, column_number) row_number: int
0 == header
- column_number: int
0 == header
- value: dictionary
- key: string
“text” or “img_url”
- value: string
internal cell option or column header
Examples
>>> [ ... key for key in table_cells_from_postgres( ... rows=[ ... {'text': 'Good question'}, ... {'text': 'Bad'} ... ], ... columns=[ ... {'text': '1'}, ... {'text': '2'} ... ], ... response_type="image_sel" ... ) ... ] [(1, 0), (2, 0), (1, 1), (1, 2), (2, 1), (2, 2)] >>> [ ... key for key in table_cells_from_postgres( ... rows=[ ... {'text': 'Good question'}, ... {'text': 'Bad'} ... ], ... columns=[ ... {'text': '1'}, ... {'text': '2'} ... ], ... response_type="single_sel" ... ) ... ] [(1, 0), (2, 0), (0, 1), (0, 2)]
-
mindlogger_backend_dev.postgres_to_girder.postgres_to_girder.
upload_applicable_files
(gc, act_data, item_id, item_name)¶ Function to find a File in a Girder Item if such File exists, otherwise to upload said File from Postgres pointer.
Parameters: - gc: GirderClient
active girder client
- act_data: dictionary
from JSON in Postgres
- item_id: string
Girder _id for Item
- item_name: string
name of Item
Returns: - file_ids: dictionary
- key: string
filename
- value: dictionary
- “@id”: string
“file/[Girder _id of File]”
Examples
>>> import girder_client >>> upload_applicable_files( ... gc=girder_client.GirderClient( ... apiUrl="https://data.kitware.com/api/v1/" ... ), ... act_data = { ... "image_url": "https://data.kitware.com/api/" ... "v1/file/596f64838d777f16d01e9c28/download/" ... "ensembl_vega_mart_88_drerio_gene_vega__" ... "gene__main.sql.gz" ... }, ... item_id="596f64838d777f16d01e9c27", ... item_name="ensembl_vega_mart_88_drerio_gene_" ... "vega__gene__main.sql" ... )[ ... "ensembl_vega_mart_88_drerio_gene_" ... "vega__gene__main.sql.gz" ... ]["@id"] 'file/596f64838d777f16d01e9c28'
update_schema¶
-
mindlogger_backend_dev.update_schema.
add_to_schedule
(girder_connection, frequency, schedules_id, activity_item_id, context={}, timings={'1': 'Once', '12h': '2×Daily', '1d': 'Daily', '8h': '3×Daily'}, schedule_folder_id=None, schedule_item_id=None)¶ Function to add Activities to a Schedule
Parameters: - girder_connection: GirderClient
- frequency: string
- schedules_id: string
- activity_item_id: string
- context: dictionary, optional
default: {}
- timings: dictionary, optional
- key: string
frequency
- value: string
schedule name
- default: {
“1d”: “Daily”, “1”: “Once”, “8h”: “3×Daily”, “12h”: “2×Daily”
}
- schedule_folder_id: string, optional
default: _id for public schedules
- schedule_item_id: string, optional
default: _id for “Version 0 [Frequency]”
Returns: - schedule_item_id: string
Examples
>>> from .. import girder_connections >>> import os >>> config_file = os.path.join( ... os.path.dirname(__file__), ... "config.json.template" ... ) >>> config, context, api_url = girder_connections.configuration( ... config_file=config_file ... ) >>> girder_connection = girder_connections.connect_to_girder( ... api_url=api_url, ... authentication=( ... config["girder-dev"]["user"], ... config["girder-dev"]["password"] ... ) ... ) Connected to the Girder database 🏗🍃 and authenticated. >>> collection_id = get_girder_id_by_name( ... girder_connection, ... "Collection", ... "Ancient One" ... ) >>> schedules_id = get_girder_id_by_name( ... girder_connection, ... "folder", ... "Schedules", ... ("Collection", collection_id) ... ) >>> girder_connection.get("item/{}".format( ... add_to_schedule( ... girder_connection=girder_connection, ... frequency="Centennially", ... schedules_id=schedules_id, ... activity_item_id=get_girder_id_by_name( ... girder_connection, ... "Item", ... "Fighting Dragon Raiders", ... ("Folder", get_girder_id_by_name( ... girder_connection, ... "Folder", ... "Fighting Dragon Raiders", ... ("Folder", get_girder_id_by_name( ... girder_connection, ... "Folder", ... "Activities", ... ("Collection", collection_id) ... )) ... )) ... ), ... timings={"Centennially": "Centennially"}, ... schedule_folder_id=schedules_id, ... schedule_item_id=get_girder_id_by_name( ... girder_connection, ... "Item", ... "Centennially", ... ("Folder", schedules_id) ... ) ... ) ... ))['name'] 'Centennially'
-
mindlogger_backend_dev.update_schema.
camelCase
(s)¶ Function to turn _-delimited strings to camelCase
Returns: - cc: string
Examples
>>> camelCase("bob_the_builder") 'bobTheBuilder' >>> camelCase(12) 12
-
mindlogger_backend_dev.update_schema.
camelCaseKeys
(d)¶ Function to CamelCase each _-delimited key in a nested dictionary
Returns: - d: dict
Examples
>>> camelCaseKeys({ ... 'response_type': None, ... 'rows': [ ... {'headers': [{'@value': ''}, {'@value': ''}]}, ... { ... 'index': {'@value': ''}, ... 'options': [ ... {'question_image': None, 'question_text': {'@value': ''}}, ... {'question_image': None, 'question_text': {'@value': ''}} ... ], ... 'select': {'max': 1, 'min': 1}}, ... { ... 'index': {'@value': ''}, ... 'options': [ ... {'question_image': None, 'question_text': {'@value': ''}}, ... {'question_image': None, 'question_text': {'@value': ''}} ... ], ... 'select': {'max': 1, 'min': 1} ... }, ... { ... 'index': {'@value': ''}, ... 'options': [ ... {'question_image': None, 'question_text': {'@value': ''}}, ... {'question_image': None, 'question_text': {'@value': ''}} ... ], ... 'select': {'max': 1, 'min': 1} ... } ... ] ... }) {'responseType': None, 'rows': [{'headers': [{'@value': ''}, {'@value': ''}]}, {'index': {'@value': ''}, 'options': [{'questionImage': None, 'questionText': {'@value': ''}}, {'questionImage': None, 'questionText': {'@value': ''}}], 'select': {'max': 1, 'min': 1}}, {'index': {'@value': ''}, 'options': [{'questionImage': None, 'questionText': {'@value': ''}}, {'questionImage': None, 'questionText': {'@value': ''}}], 'select': {'max': 1, 'min': 1}}, {'index': {'@value': ''}, 'options': [{'questionImage': None, 'questionText': {'@value': ''}}, {'questionImage': None, 'questionText': {'@value': ''}}], 'select': {'max': 1, 'min': 1}}]} >>> camelCaseKeys("test_this") 'testThis'
-
mindlogger_backend_dev.update_schema.
camelCaseMeta
(girderConnection, o)¶ Function to camelCase metadata keys on Girder
Parameters: - girderConnection: GirderClient
- o: dict
Returns: - None
-
mindlogger_backend_dev.update_schema.
find_or_create
(x, parent, girder_connection)¶ Function to find or create a Girder Folder or Item under a specific parent.
Parameters: - x: 2-tuple
- x[0]: string
“Folder”, “Item”, etc.
- x[1]: string
entity name
- parent: 2-tuple
- parent[0]: string
“Collection”, “Folder”, etc.
- parent[1]: string
Girder_id
- girder_connection: GirderClient
active GirderClient
Returns: - _id: string
Girder_id of found or created entity
Examples
>>> import os >>> from .. import girder_connections >>> which_girder = "dev" >>> config, context, api_url = girder_connections.configuration( ... config_file=os.path.join( ... os.path.dirname(__file__), ... "config.json.template" ... ), ... context_file=os.path.join( ... os.path.dirname(__file__), ... "context.json" ... ), ... which_girder=which_girder ... ) >>> which_girder = "girder-{}".format(which_girder) >>> girder_connection = girder_connections.connect_to_girder( ... api_url=api_url, ... authentication=( ... config[which_girder]["user"], ... config[which_girder]["password"], ... config[which_girder]["APIkey"] ... ) if "APIkey" in config[which_girder] else ( ... config[which_girder]["user"], ... config[which_girder]["password"] ... ) ... ) Connected to the Girder database 🏗🍃 and authenticated. >>> book = girder_connection.get("folder/{}".format(find_or_create( ... ("Folder", "Book of Cagliostro"), ... ("Collection", get_girder_id_by_name( ... girder_connection, ... "Collection", ... "Ancient One" ... )), ... girder_connection ... ))) >>> book['name'] 'Book of Cagliostro' >>> incantation = girder_connection.get("item/{}".format(find_or_create( ... ("Item", "draw energy from the Dark Dimension"), ... ("Folder", book["_id"]), ... girder_connection ... ))) >>> incantation['name'] 'draw energy from the Dark Dimension' >>> girder_connection.delete( ... "item/{}".format(incantation["_id"]) ... )['message'] 'Deleted item draw energy from the Dark Dimension.' >>> girder_connection.delete( ... "folder/{}".format(book["_id"]) ... )['message'] 'Deleted folder Book of Cagliostro.' >>> girder_connection.delete( ... 'collection/{}'.format( ... get_girder_id_by_name( ... girder_connection, ... "Collection", ... "Ancient One" ... ) ... ) ... )['message'] 'Deleted collection Ancient One.'
-
mindlogger_backend_dev.update_schema.
get_files_in_item
(girder_connection, item_id, sort='created', sortdir=-1)¶ Function to get a dictionary of Files in an Item in a Girder database.
Parameters: - girder_connection: GirderClient
an active GirderClient
- item_id: string
Girder _id of Item.
- sort: string, optional
Field to sort the result set by. default = “created”
- sortdir: int, optional
Sort order: 1 for ascending, -1 for descending. default = -1
Returns: - files: dictionary or None
metadata of files in Girder Item
Examples
>>> import girder_client as gc >>> get_files_in_item( ... girder_connection=gc.GirderClient( ... apiUrl="https://data.kitware.com/api/v1/" ... ), ... item_id="58a372f38d777f0721a64df3" ... )[0]["name"] 'Normal001-T1-Flash.mha'
-
mindlogger_backend_dev.update_schema.
get_folder_or_item_info
(girder_id, girder_type, girder_connection)¶ Function to collect all relevant info about a Folder or Item.
Parameters: - girder_id: string
Girder _id
- girder_type: string
“Folder” or “Item”
- girder_connection: GirderClient
active GirderClient
Returns: - info: dictionary
- Examples
- >>> import os
- >>> from .. import girder_connections
- >>> which_girder = “dev”
- >>> config, context, api_url = girder_connections.configuration(
- … config_file=os.path.join(
- … os.path.dirname(__file__),
- … “config.json.template”
- … ),
- … context_file=os.path.join(
- … os.path.dirname(__file__),
- … “context.json”
- … ),
- … which_girder=which_girder
- … )
- >>> which_girder = “girder-{}”.format(which_girder)
- >>> girder_connection = girder_connections.connect_to_girder(
- … api_url=api_url,
- … authentication=(
- … config[which_girder][“user”],
- … config[which_girder][“password”],
- … config[which_girder][“APIkey”]
- … ) if “APIkey” in config[which_girder] else (
- … config[which_girder][“user”],
- … config[which_girder][“password”]
- … )
- … )
- Connected to the Girder database 🏗🍃 and authenticated.
- >>> book = find_or_create(
- … (“Folder”, “Book of Cagliostro”),
- … (“Collection”, get_girder_id_by_name(
- … girder_connection,
- … “Collection”,
- … “Ancient One”
- … )),
- … girder_connection
- … )
- >>> get_folder_or_item_info(
- … book,
- … “Folder”,
- … girder_connection
- … )[‘name’]
- ‘Book of Cagliostro’
-
mindlogger_backend_dev.update_schema.
get_girder_id_by_name
(girder_connection, entity, name, parent=None, limit=1, sortdir=-1, index=0)¶ Function to get the _id of a single entity in a Girder database.
Parameters: - girder_connection: GirderClient
an active GirderClient
- entity: string
“collection”, “folder”, “item”, “file”, “user”
- name: string
name of entity
- parent: 2-tuple, optional, default=None
(parentType, parent_id) parentType: string
“Collection”, “Folder”, or “User”
- parendId: string
Girder _id for parent
- limit: int, optional, default=1
maximum number of query results
- sortdir: int, optional, default=-1
Sort order: 1 for ascending, -1 for descending.
- index: int, default=0
0-indexed index of named entity in given sort order.
Returns: - _id: string
Girder _id of requested entity
Examples
>>> import os >>> from .. import girder_connections >>> which_girder = "dev" >>> config, context, api_url = girder_connections.configuration( ... config_file=os.path.join( ... os.path.dirname(__file__), ... "config.json.template" ... ), ... context_file=os.path.join( ... os.path.dirname(__file__), ... "context.json" ... ), ... which_girder=which_girder ... ) >>> which_girder = "girder-{}".format(which_girder) >>> girder_connection = girder_connections.connect_to_girder( ... api_url=api_url, ... authentication=( ... config[which_girder]["user"], ... config[which_girder]["password"], ... config[which_girder]["APIkey"] ... ) if "APIkey" in config[which_girder] else ( ... config[which_girder]["user"], ... config[which_girder]["password"] ... ) ... ) Connected to the Girder database 🏗🍃 and authenticated. >>> girder_connection.get( ... "collection/{}".format( ... get_girder_id_by_name( ... girder_connection=girder_connection, ... entity="Collection", ... name="Ancient One" ... ) ... ) ... )["name"] 'Ancient One'
-
mindlogger_backend_dev.update_schema.
get_group_ids
(girder_connection, groups={'Viewers', 'Managers', 'Editors', 'Users'})¶ Function to collect Girder _ids, optionally creating any missing groups.
Parameters: - girder_connection: GirderClient
active Girder Client
- groups: set
set of Group names for which to get Girder _ids item: string
Group name
- default: {
“Editors”, “Managers”, “Users”, “Viewers”
}
Returns: - groups: dictionary
- key: string
name from original set
- value: string
Girder Group _id
Examples
>>> import girder_client as gc >>> get_group_ids( ... girder_connection=gc.GirderClient( ... apiUrl="https://data.kitware.com/api/v1/" ... ), ... groups={"VIGILANT"} ... ) {'VIGILANT': '58a354fe8d777f0721a6106a'} >>> import os >>> from .. import girder_connections >>> which_girder = "dev" >>> config, context, api_url = girder_connections.configuration( ... config_file=os.path.join( ... os.path.dirname(__file__), ... "config.json.template" ... ), ... context_file=os.path.join( ... os.path.dirname(__file__), ... "context.json" ... ), ... which_girder=which_girder ... ) >>> which_girder = "girder-{}".format(which_girder) >>> girder_connection = girder_connections.connect_to_girder( ... api_url=api_url, ... authentication=( ... config[which_girder]["user"], ... config[which_girder]["password"], ... config[which_girder]["APIkey"] ... ) if "APIkey" in config[which_girder] else ( ... config[which_girder]["user"], ... config[which_girder]["password"] ... ) ... ) Connected to the Girder database 🏗🍃 and authenticated. >>> groups = [k for k in get_group_ids( ... girder_connection, ... {"Masters of the Mystic Arts", "Sorcerers Supreme"} ... )] >>> groups.sort() >>> groups ['Masters of the Mystic Arts', 'Sorcerers Supreme']
-
mindlogger_backend_dev.update_schema.
get_user_id_by_email
(girder_connection, email)¶ Function to get the _id of a single User in a Girder database.
Parameters: - girder_connection: GirderClient
an active GirderClient
- email: string
email address
Returns: - _id: string or None
Girder _id of requested User, or None if not found
Examples
>>> import girder_client as gc >>> get_user_id_by_email( ... girder_connection=gc.GirderClient( ... apiUrl="https://data.kitware.com/api/v1/" ... ), ... email="test@example.com" ... )
-
mindlogger_backend_dev.update_schema.
ls_x_in_y
(x_type, y, girder_connection)¶ Function to list x in y.
Parameters: - x_type: string
“Folder”, “Item”, etc.
- y: 2-tuple
- y[0]: string
“Collection”, “Folder”, etc.
- y[1]: string
Girder_id
- girder_connection: GirderClient
active GirderClient
Returns: - x: list of dictionaries
≅ JSON array of objects
Examples
>>> import girder_client as gc >>> ls_x_in_y( ... "Folder", ... ("Collection", "58b5d21a8d777f0aef5d04b1"), ... girder_connection=gc.GirderClient( ... apiUrl="https://data.kitware.com/api/v1/" ... ) ... ) [{'_accessLevel': 0, '_id': '58b5d86c8d777f0aef5d04b4', '_modelType': 'folder', 'baseParentId': '58b5d21a8d777f0aef5d04b1', 'baseParentType': 'collection', 'created': '2017-02-28T20:07:08.074000+00:00', 'creatorId': '55a413168d777f649a9ba343', 'description': '', 'name': 'TestData', 'parentCollection': 'collection', 'parentId': '58b5d21a8d777f0aef5d04b1', 'public': True, 'publicFlags': [], 'size': 41319999, 'updated': '2017-02-28T20:07:08.074000+00:00'}, {'_accessLevel': 0, '_id': '58cb12048d777f0aef5d79fc', '_modelType': 'folder', 'baseParentId': '58b5d21a8d777f0aef5d04b1', 'baseParentType': 'collection', 'created': '2017-03-16T22:30:28.994000+00:00', 'creatorId': '55a413168d777f649a9ba343', 'description': '', 'name': 'TomvizData', 'parentCollection': 'collection', 'parentId': '58b5d21a8d777f0aef5d04b1', 'public': True, 'size': 0, 'updated': '2017-03-24T18:30:21.117000+00:00'}]
-
mindlogger_backend_dev.update_schema.
move_item_to_folder
(girder_id, girder_connection)¶ Function to collect all relevant info about a Folder or Item.
Parameters: - girder_id: string
Item’s Girder_id
- girder_connection: GirderClient
active GirderClient
Returns: - folder_id: string
Girder_id for new Folder replacing old Item
- Examples
- >>> import os
- >>> from .. import girder_connections
- >>> which_girder = “dev”
- >>> config, context, api_url = girder_connections.configuration(
- … config_file=os.path.join(
- … os.path.dirname(__file__),
- … “config.json.template”
- … ),
- … context_file=os.path.join(
- … os.path.dirname(__file__),
- … “context.json”
- … ),
- … which_girder=which_girder
- … )
- >>> which_girder = “girder-{}”.format(which_girder)
- >>> girder_connection = girder_connections.connect_to_girder(
- … api_url=api_url,
- … authentication=(
- … config[which_girder][“user”],
- … config[which_girder][“password”],
- … config[which_girder][“APIkey”]
- … ) if “APIkey” in config[which_girder] else (
- … config[which_girder][“user”],
- … config[which_girder][“password”]
- … )
- … )
- Connected to the Girder database 🏗🍃 and authenticated.
- >>> collection = get_girder_id_by_name(
- … girder_connection,
- … “Collection”,
- … “Ancient One”
- … )
- >>> item = get_girder_id_by_name(
- … girder_connection,
- … “Item”,
- … “Kaecilius”,
- … (“Folder”, get_girder_id_by_name(
- … girder_connection,
- … “Folder”,
- … “Masters of the Mystic Arts”,
- … (“Collection”, collection)
- … ))
- … )
- >>> from urllib.request import urlopen
- >>> image_stream = urlopen(
- … “/”.join([
- … “https://vignette.wikia.nocookie.net”,
- … “marvelcinematicuniverse/images/1/14/”,
- … “DS_Kaecilius_Poster_cropped.png”
- … ])
- … )
- >>> img_id = girder_connection.uploadFile(
- … parentId=item,
- … parentType=”item”,
- … stream=image_stream,
- … name=”Kaecilius.png”,
- … size=int(
- … image_stream.info()[“Content-Length”]
- … )
- … )[“_id”]
- >>> folder = move_item_to_folder(item, girder_connection)
- >>> girder_connection.get(
- … “folder/{}”.format(folder)
- … )[‘_modelType’]
- ‘folder’
-
mindlogger_backend_dev.update_schema.
mv
(x, new_parent, girder_connection)¶ Function to move a Girder entity to a new_parent.
Parameters: - x: 2-tuple
- x[0]: string
“Folder”, “Item”, etc.
- x[1]: string
Girder_id
- new_parent: 2-tuple
- new_parent[0]: string
“Collection”, “Folder”, etc.
- new_parent[1]: string
Girder_id
- girder_connection: GirderClient
active GirderClient
Returns: - x_object: dictionary
≅JSON representation of entity in new location
Examples
>>> import os >>> from .. import girder_connections >>> which_girder = "dev" >>> config, context, api_url = girder_connections.configuration( ... config_file=os.path.join( ... os.path.dirname(__file__), ... "config.json.template" ... ), ... context_file=os.path.join( ... os.path.dirname(__file__), ... "context.json" ... ), ... which_girder=which_girder ... ) >>> which_girder = "girder-{}".format(which_girder) >>> girder_connection = girder_connections.connect_to_girder( ... api_url=api_url, ... authentication=( ... config[which_girder]["user"], ... config[which_girder]["password"], ... config[which_girder]["APIkey"] ... ) if "APIkey" in config[which_girder] else ( ... config[which_girder]["user"], ... config[which_girder]["password"] ... ) ... ) Connected to the Girder database 🏗🍃 and authenticated. >>> book = find_or_create( ... ("Folder", "Book of Cagliostro"), ... ("Collection", get_girder_id_by_name( ... girder_connection, ... "Collection", ... "Ancient One" ... )), ... girder_connection ... ) >>> incantation = find_or_create( ... ("Item", "draw energy from the Dark Dimension"), ... ("Folder", book), ... girder_connection ... ) >>> girder_connection.get("folder/{}".format(mv( ... ("Item", incantation), ... ("Folder", get_girder_id_by_name( ... girder_connection, ... "Folder", ... "Incantations", ... ("User", get_user_id_by_email( ... girder_connection, ... "wong@wong.wong" ... )) ... )), ... girder_connection ... )['folderId']))['name'] 'Incantations'
-
mindlogger_backend_dev.update_schema.
rename
(x, new_name, girder_connection)¶ Function to rename a Girder entity.
Parameters: - x: 2-tuple
- x[0]: string
“Folder”, “Item”, etc.
- x[1]: string
Girder_id
- new_name: string
new name for entity
- girder_connection: GirderClient
active GirderClient
Returns: - x_object: dictionary
≅JSON representation of entity in new location
Examples
>>> import os >>> from .. import girder_connections >>> which_girder = "dev" >>> config, context, api_url = girder_connections.configuration( ... config_file=os.path.join( ... os.path.dirname(__file__), ... "config.json.template" ... ), ... context_file=os.path.join( ... os.path.dirname(__file__), ... "context.json" ... ), ... which_girder=which_girder ... ) >>> which_girder = "girder-{}".format(which_girder) >>> girder_connection = girder_connections.connect_to_girder( ... api_url=api_url, ... authentication=( ... config[which_girder]["user"], ... config[which_girder]["password"], ... config[which_girder]["APIkey"] ... ) if "APIkey" in config[which_girder] else ( ... config[which_girder]["user"], ... config[which_girder]["password"] ... ) ... ) Connected to the Girder database 🏗🍃 and authenticated. >>> book = find_or_create( ... ("Folder", "Book of Cagliostro"), ... ("Collection", get_girder_id_by_name( ... girder_connection, ... "Collection", ... "Ancient One" ... )), ... girder_connection ... ) >>> incantation = find_or_create( ... ("Item", "draw energy from the Dark Dimension"), ... ("Folder", book), ... girder_connection ... ) >>> rename( ... ("Item", incantation), ... "Draw Energy", ... girder_connection ... )['name'] 'Draw Energy'