Advertisement
Guest User

Untitled

a guest
Jun 20th, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. [
  2. {
  3. "group": { "id": "01234" },
  4. "measures": {
  5. "measures": {
  6. "...device 1 uuid...": {
  7. "metric.name.here": {
  8. "mean": [
  9. ["2019-04-17T14:30:00+00:00", 300, 1],
  10. ["2019-04-17T14:35:00+00:00", 300, 2],
  11. ...
  12. ]
  13. }
  14. },
  15. "...device 2 uuid...": {
  16. "metric.name.here": {
  17. "mean": [
  18. ["2019-04-17T14:30:00+00:00", 300, 0],
  19. ["2019-04-17T14:35:00+00:00", 300, 1],
  20. ...
  21. ]
  22. }
  23. }
  24. }
  25. }
  26. }
  27. ]
  28.  
  29. ["2019-04-17T14:30:00+00:00", 300, 1],
  30. ["2019-04-17T14:35:00+00:00", 300, 3],
  31.  
  32. with open('data.json') as fd:
  33. data = pd.read_json(fd)
  34.  
  35. for i, group in enumerate(data.group):
  36. project = group['project_id']
  37. instances = data.measures[i]['measures']
  38. series_for_group = []
  39. for instance in instances.keys():
  40. measures = instances[instance][metric][aggregate]
  41.  
  42. # build an index from the timestamps
  43. index = pd.DatetimeIndex(measure[0] for measure in measures)
  44.  
  45. # extract values from the data and link it to the index
  46. series = pd.Series((measure[2] for measure in measures),
  47. index=index)
  48.  
  49. series_for_group.append(series)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement