|
5 | 5 |
|
6 | 6 | from .serialization import Deserializer
|
7 | 7 | from .utilities import get_auth
|
8 |
| -from .converters import to_dataframe |
| 8 | +from .converters import to_dataframe, metrics_to_dataframe |
9 | 9 |
|
10 | 10 | CONCURRENT_DOWNLOADS = 10
|
11 | 11 | DOWNLOAD_CHUNK_SIZE = 8192
|
@@ -293,3 +293,67 @@ def get_folders(self, filters, tags=False, metadata=False):
|
293 | 293 | return response.json()
|
294 | 294 |
|
295 | 295 | raise Exception(response.text)
|
| 296 | + |
| 297 | + def get_metrics_summaries(self, run, name): |
| 298 | + """ |
| 299 | + Get summary metrics for the specified run and metrics name |
| 300 | + """ |
| 301 | + params = {'runs': run, |
| 302 | + 'metrics': name, |
| 303 | + 'summary': True} |
| 304 | + |
| 305 | + response = requests.get(f"{self._url}/api/metrics", headers=self._headers, params=params) |
| 306 | + |
| 307 | + if response.status_code == 200: |
| 308 | + return response.json() |
| 309 | + |
| 310 | + raise Exception(response.text) |
| 311 | + |
| 312 | + def get_metrics(self, run, name, xaxis, format='list'): |
| 313 | + """ |
| 314 | + Get time series metrics for the specified run and metrics name |
| 315 | + """ |
| 316 | + params = {'runs': run, |
| 317 | + 'metrics': name, |
| 318 | + 'summary': False, |
| 319 | + 'xaxis': xaxis} |
| 320 | + |
| 321 | + if xaxis not in ('step', 'time', 'timestamp'): |
| 322 | + raise Exception('Invalid xaxis specified, should be either "step", "time", or "timestamp"') |
| 323 | + |
| 324 | + if format not in ('list', 'dataframe'): |
| 325 | + raise Exception('Invalid format specified, should be either "list" or "dataframe"') |
| 326 | + |
| 327 | + response = requests.get(f"{self._url}/api/metrics", headers=self._headers, params=params) |
| 328 | + |
| 329 | + if response.status_code == 200: |
| 330 | + if format == 'dataframe': |
| 331 | + return metrics_to_dataframe(response.json(), xaxis, name=name) |
| 332 | + return response.json() |
| 333 | + |
| 334 | + raise Exception(response.text) |
| 335 | + |
| 336 | + def get_metrics_multiple(self, runs, names, xaxis, sample_by, format='list'): |
| 337 | + """ |
| 338 | + Get time series metrics from multiple runs and/or metrics |
| 339 | + """ |
| 340 | + params = {'runs': ','.join(runs), |
| 341 | + 'metrics': ','.join(names), |
| 342 | + 'summary': False, |
| 343 | + 'sample_by': sample_by, |
| 344 | + 'xaxis': xaxis} |
| 345 | + |
| 346 | + if xaxis not in ('step', 'time'): |
| 347 | + raise Exception('Invalid xaxis specified, should be either "step" or "time"') |
| 348 | + |
| 349 | + if format not in ('list', 'dataframe'): |
| 350 | + raise Exception('Invalid format specified, should be either "list" or "dataframe"') |
| 351 | + |
| 352 | + response = requests.get(f"{self._url}/api/metrics", headers=self._headers, params=params) |
| 353 | + |
| 354 | + if response.status_code == 200: |
| 355 | + if format == 'dataframe': |
| 356 | + return metrics_to_dataframe(response.json(), xaxis) |
| 357 | + return response.json() |
| 358 | + |
| 359 | + raise Exception(response.text) |
0 commit comments