Package: pbshm-core
PBSHM CorePBSHM Core is a minimal application built onFlaskto enable development of PBSHM modules that consumePBSHM Schemadata. It was designed to deal with all the basic requirements of a PBSHM system, allowing developers to focus on implementation of PBSHM modules.The application includes ainitialisationmodule to configure and set up the system, aauthenticationmodule to provide permission-based authorisation of controls, alayoutmodule to provide an app wide layout, atimekeepermodule to enable conversion between native pythondatetimeobjects and the PBSHM Schematimestampformat, and finally amechanicmodule to facilitate easy interaction between available PBSHM Schema versions and your local database. The minimum version of Python required to run the PBSHM Core is version 3.8.10.For more information on how to create a module for PBSHM Core, please see themodule templaterepository.InstallationInstall the package via pip:pip install pbshm-coreSetupSet the Flask application path and environment.For Linux/Mac:export FLASK_APP=pbshm
export FLASK_DEBUG=1For Windows:set FLASK_APP=pbshm
set FLASK_DEBUG=1Configure settings and initialise the database with a new root user:flask init config
flask init db new-root-userThe above steps will prompt you for all the required fields to set up the system.RunningThe application is run via the standard Flask command:flask runAccessing dataThe PBSHM Core operates under the premise of data silos: where each realm of confidential data has a corresponding silo (astructure collection) where it's data resides. A user will always have access to at least onestructure collection(thedefault collection), but there may be multiplestructure collections available to the user.The code below shows how to access data in thedefault collectionusing aMongoDB Aggregation Pipelineon thedefault_collection:frompbshm.dbimportdefault_collectionpopulations={}fordocumentindefault_collection().aggregate([{"$project":{"_id":1,"name":1,"population":1}},{"$group":{"_id":"$population","structures":{"$addToSet":"$name"}}},{"$project":{"_id":0,"population":"$_id","structures":1}}]):populations[document["population"]]=document["structures"]ToolsThe PBSHM Core comes with a few tools which are available via the mechanic and timekeeper modules. The mechanic module enables easy interaction with the PBSHM Schema and your local database. The timekeeper module enables conversions from native pythondatetimeobjects into thetimestampformat stored within the PBSHM Schema.To retrieve all versions of the PBSHM Schema available for installation, use the following command:flask mechanic versionsTo create a new collection with the latest version of the PBSHM Schema installed within the collection, use the following command:flask mechanic new-structure-collection collection-nameTo create a new collection with a specific version of the PBSHM Schema installed within the collection, use the following command:flask mechanic new-structure-collection collection-name --version=v1.0To convert a pythondatetimeobject into UTC nanoseconds since epoch, use the following code:fromdatetimeimportdatetimefrompbshm.timekeeperimportdatetime_to_nanoseconds_since_epochnow=datetime.now()nanoseconds=datetime_to_nanoseconds_since_epoch(now)To convert a UTC nanoseconds since epoch into a native pythondatetimeobject, use the following code:frompbshm.timekeeperimportnanoseconds_since_epoch_to_datetimenanoseconds=1706884924912888000date_time=nanoseconds_since_epoch_to_datetime(nanoseconds)Bug reportingIf you encounter any issues/bugs with the system or the instructions above, please raise an issue through theissues systemon GitHub.