|
| 1 | +import datetime |
1 | 2 | import os
|
| 3 | +from pathlib import Path |
2 | 4 |
|
3 | 5 | import matplotlib.pyplot as plt
|
4 | 6 |
|
5 | 7 | from baec.measurements.io.basetime import BaseTimeBucket, Credentials
|
| 8 | +from baec.measurements.measured_settlement_series import MeasuredSettlementSeries |
6 | 9 |
|
7 | 10 | workdir = os.path.dirname(os.path.abspath(__file__))
|
8 | 11 |
|
|
12 | 15 | # create bucket manager
|
13 | 16 | manage_project = BaseTimeBucket(credentials)
|
14 | 17 |
|
| 18 | + |
15 | 19 | # get all the rod_id available to the user
|
16 | 20 | projects_ids = manage_project.get_users_projects_ids()
|
17 |
| -for key, items in projects_ids["Demo"].items(): |
18 |
| - for item in items: |
| 21 | +for project, rod_ids in projects_ids["Demo"].items(): |
| 22 | + # Create dirpath to store the figures for this project |
| 23 | + dirpath = Path(f"example/figs/{project}") |
| 24 | + if not dirpath.exists(): |
| 25 | + dirpath.mkdir(parents=True) |
| 26 | + |
| 27 | + for rod_id in rod_ids: |
19 | 28 | try:
|
20 | 29 | # create settlement rod measurement series
|
21 |
| - series = manage_project.make_settlement_rod_measurement_series( |
22 |
| - company="Demo", project=key, rod_id=item |
| 30 | + measurement_series = manage_project.make_settlement_rod_measurement_series( |
| 31 | + company="Demo", project=project, rod_id=rod_id |
| 32 | + ) |
| 33 | + |
| 34 | + # Visualize the measurements |
| 35 | + fig = measurement_series.plot_xyz_time() |
| 36 | + # fig.set_size_inches(18.75, 7.5) |
| 37 | + fig.set_size_inches(15, 10) |
| 38 | + plt.savefig(dirpath.joinpath(f"measurements_{rod_id}.png")) |
| 39 | + plt.close() |
| 40 | + |
| 41 | + # Create settlement series from measurements |
| 42 | + settlement_series = MeasuredSettlementSeries( |
| 43 | + series=measurement_series, |
| 44 | + # start_date_time=datetime.datetime(2015, 1, 18), |
23 | 45 | )
|
24 | 46 |
|
25 |
| - # create figures |
26 |
| - fig = series.plot_xyz_time() |
27 |
| - fig.savefig(f"{workdir}/figs/{key}-{item}.png") |
28 |
| - plt.show(block=False) |
29 |
| - plt.pause(3) |
30 |
| - plt.close(fig) |
| 47 | + # Visualize the settlements |
| 48 | + fig = settlement_series.plot_fill_settlement_time() |
| 49 | + fig.set_size_inches(15, 7.5) |
| 50 | + plt.savefig(dirpath.joinpath(f"settlements_{rod_id}.png")) |
| 51 | + plt.close() |
| 52 | + |
31 | 53 | # catch error and print it to console.
|
32 | 54 | except ValueError as e:
|
33 |
| - print(f"ERROR:{key}-{item};{e}") |
| 55 | + print(f"ERROR:{project}-{rod_id};{e}") |
0 commit comments