|
46 | 46 | from . import publish_to_experiment_log |
47 | 47 | from . import publish_to_log |
48 | 48 | from . import query_app_db |
| 49 | +from . import query_temp_local_metadata_db |
49 | 50 | from . import structs |
50 | 51 | from . import tasks |
51 | 52 | from .config import env |
|
59 | 60 | api = Blueprint("api", __name__, url_prefix="/api") |
60 | 61 |
|
61 | 62 |
|
62 | | -def to_json_response(json: str) -> ResponseReturnValue: |
| 63 | +def as_json_response(json: str) -> ResponseReturnValue: |
63 | 64 | return Response(json, mimetype="application/json") |
64 | 65 |
|
65 | 66 |
|
@@ -538,7 +539,7 @@ def get_growth_rates(experiment: str) -> ResponseReturnValue: |
538 | 539 | abort(400) |
539 | 540 |
|
540 | 541 | assert isinstance(growth_rates, dict) |
541 | | - return attach_cache_control(to_json_response(growth_rates["json"])) |
| 542 | + return attach_cache_control(as_json_response(growth_rates["json"])) |
542 | 543 |
|
543 | 544 |
|
544 | 545 | @api.route("/experiments/<experiment>/time_series/temperature_readings", methods=["GET"]) |
@@ -572,7 +573,7 @@ def get_temperature_readings(experiment: str) -> ResponseReturnValue: |
572 | 573 | abort(400) |
573 | 574 |
|
574 | 575 | assert isinstance(temperature_readings, dict) |
575 | | - return attach_cache_control(to_json_response(temperature_readings["json"])) |
| 576 | + return attach_cache_control(as_json_response(temperature_readings["json"])) |
576 | 577 |
|
577 | 578 |
|
578 | 579 | @api.route("/experiments/<experiment>/time_series/od_readings_filtered", methods=["GET"]) |
@@ -607,7 +608,7 @@ def get_od_readings_filtered(experiment: str) -> ResponseReturnValue: |
607 | 608 | abort(400) |
608 | 609 |
|
609 | 610 | assert isinstance(filtered_od_readings, dict) |
610 | | - return attach_cache_control(to_json_response(filtered_od_readings["json"])) |
| 611 | + return attach_cache_control(as_json_response(filtered_od_readings["json"])) |
611 | 612 |
|
612 | 613 |
|
613 | 614 | @api.route("/experiments/<experiment>/time_series/od_readings", methods=["GET"]) |
@@ -640,7 +641,7 @@ def get_od_readings(experiment: str) -> ResponseReturnValue: |
640 | 641 | abort(400) |
641 | 642 |
|
642 | 643 | assert isinstance(raw_od_readings, dict) |
643 | | - return attach_cache_control(to_json_response(raw_od_readings["json"])) |
| 644 | + return attach_cache_control(as_json_response(raw_od_readings["json"])) |
644 | 645 |
|
645 | 646 |
|
646 | 647 | @api.route("/experiments/<experiment>/time_series/<data_source>/<column>", methods=["GET"]) |
@@ -674,7 +675,7 @@ def get_fallback_time_series(data_source: str, experiment: str, column: str) -> |
674 | 675 | publish_to_error_log(str(e), "get_fallback_time_series") |
675 | 676 | abort(400) |
676 | 677 | assert isinstance(r, dict) |
677 | | - return attach_cache_control(to_json_response(r["json"])) |
| 678 | + return attach_cache_control(as_json_response(r["json"])) |
678 | 679 |
|
679 | 680 |
|
680 | 681 | @api.route("/experiments/<experiment>/media_rates", methods=["GET"]) |
@@ -1641,6 +1642,36 @@ def is_local_access_point_active() -> ResponseReturnValue: |
1641 | 1642 | ### experiment profiles |
1642 | 1643 |
|
1643 | 1644 |
|
| 1645 | +@api.route("/experiment_profiles/running/experiments/<experiment>", methods=["GET"]) |
| 1646 | +def get_running_profiles(experiment: str) -> ResponseReturnValue: |
| 1647 | + jobs = query_temp_local_metadata_db( |
| 1648 | + """ |
| 1649 | + SELECT |
| 1650 | + json_group_array(json_object( |
| 1651 | + 'job_name', m.job_name, |
| 1652 | + 'experiment', m.experiment, |
| 1653 | + 'job_id', m.id, |
| 1654 | + 'settings', ( |
| 1655 | + SELECT json_group_object(s.setting, s.value) |
| 1656 | + FROM pio_job_published_settings s |
| 1657 | + WHERE s.job_id = m.id |
| 1658 | + ) |
| 1659 | + )) as result |
| 1660 | + FROM |
| 1661 | + pio_job_metadata m |
| 1662 | + WHERE |
| 1663 | + m.is_running=1 and |
| 1664 | + m.experiment = (?) AND |
| 1665 | + m.job_name="experiment_profile" |
| 1666 | + """, |
| 1667 | + (experiment,), |
| 1668 | + one=True, |
| 1669 | + ) |
| 1670 | + assert isinstance(jobs, dict) |
| 1671 | + |
| 1672 | + return as_json_response(jobs["result"]) |
| 1673 | + |
| 1674 | + |
1644 | 1675 | @api.route("/contrib/experiment_profiles", methods=["POST"]) |
1645 | 1676 | def create_experiment_profile() -> ResponseReturnValue: |
1646 | 1677 | body = request.get_json() |
|
0 commit comments