Skip to content

Commit

Permalink
Merge pull request #21 from aaronweeden/fix-filters-10000
Browse files Browse the repository at this point in the history
Remove limit on number of results returned from `get_filter_values()`.
  • Loading branch information
aaronweeden authored Apr 5, 2024
2 parents 63141a0 + 068f338 commit a046f6e
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 9 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## Main development branch
- Update tests and testing instructions ([\#14](https://github.com/ubccr/xdmod-data/pull/14)).
- Remove limit on number of results returned from `get_filter_values()` ([\#21](https://github.com/ubccr/xdmod-data/pull/21)).

## v1.0.0 (2023-07-21)
- Initial release.
12 changes: 12 additions & 0 deletions tests/regression/test_datawarehouse_regression.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,3 +97,15 @@ def test_get_filter_values(valid_dw):
'jobs-fieldofscience-filter-values.csv',
valid_dw.get_filter_values('Jobs', 'Field of Science'),
)


def test_get_data_filter_user(valid_dw):
# Make sure the filter validation works for a user whose list position is
# greater than 10000 — this will raise an exception if it doesn't work.
valid_dw.get_data(
duration=('2023-01-01', '2023-01-01'),
realm='Jobs',
metric='CPU Hours: Total',
dataset_type='aggregate',
filters={'User': '10332'},
)
21 changes: 21 additions & 0 deletions xdmod_data/_http_requester.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,27 @@ def _request_raw_data(self, params):
print(progress_msg + 'DONE')
return (data, response['fields'])

def _request_filter_values(self, realm_id, dimension_id):
limit = 10000
data = []
num_rows = limit
offset = 0
while num_rows == limit:
response = self._request_json(
path='/controllers/metric_explorer.php',
post_fields={
'operation': 'get_dimension',
'realm': realm_id,
'dimension_id': dimension_id,
'start': offset,
'limit': limit,
},
)
data += response['data']
num_rows = len(response['data'])
offset += limit
return data

def _request_json(self, path, post_fields=None):
response = self.__request(path, post_fields)
return json.loads(response)
Expand Down
14 changes: 5 additions & 9 deletions xdmod_data/warehouse.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,15 +315,11 @@ def get_filter_values(self, realm, dimension):
realm_id,
dimension,
)
path = '/controllers/metric_explorer.php'
post_fields = {
'operation': 'get_dimension',
'dimension_id': dimension_id,
'realm': realm_id,
'limit': 10000,
}
response = self.__http_requester._request_json(path, post_fields)
data = [(datum['id'], datum['name']) for datum in response['data']]
response_data = self.__http_requester._request_filter_values(
realm_id,
dimension_id,
)
data = [(datum['id'], datum['name']) for datum in response_data]
result = self.__get_data_frame(data, ('id', 'label'), 'id')
return result

Expand Down

0 comments on commit a046f6e

Please sign in to comment.