From 992787a8545ef912302629598a098c18d1b437a6 Mon Sep 17 00:00:00 2001 From: Joseph White Date: Tue, 9 Jul 2024 16:20:53 -0400 Subject: [PATCH] Add resource accessor function --- xdmod_data/warehouse.py | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/xdmod_data/warehouse.py b/xdmod_data/warehouse.py index 17cddef6..28622527 100644 --- a/xdmod_data/warehouse.py +++ b/xdmod_data/warehouse.py @@ -445,3 +445,40 @@ def __describe_metrics_or_dimensions(self, realm, m_or_d): ('id', 'label', 'description'), 'id', ) + + def __compliance(self, timeframe): + response = self.__http_requester._request_json( + '/controllers/compliance.php', + {'timeframe_mode': timeframe}, + ) + return response + + def resources(self): + """Get a data series describing the resources that are configured in + XDMoD and the type of each resource (High-performance computing, Disk storage, + etc). + + Returns + ------- + pandas.core.series.Series + + Raises + ------ + RuntimeError + If this method is called outside the runtime context or if + there is an error requesting data from the warehouse. + """ + _validator._assert_runtime_context(self.__in_runtime_context) + names = [] + types = [] + resource_ids = [] + cdata = self.__compliance('to_date') + for resource in cdata['metaData']['fields']: + if resource['name'] == 'requirement': + continue + names.append( + resource['header'][:-7].split('>')[1].replace('-', ' ') + ) + types.append(resource['status'].split('|')[0].strip()) + resource_ids.append(resource['resource_id']) + return pd.Series(data=types, index=names)