-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9d3cb9c
commit c526d00
Showing
8 changed files
with
383 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
from ..api import rule | ||
from ..api._endpoint import ApiEndpoint | ||
from ..entities._entity import NotFound | ||
from ..entities.history import get_history, HistorySerializer | ||
from ..entities.summary import Summary | ||
|
||
|
||
class HistoryEntityAPI(ApiEndpoint): | ||
serializer = HistorySerializer() | ||
|
||
def _get(self, benchmark_id): | ||
try: | ||
summary = Summary.one(id=benchmark_id) | ||
except NotFound: | ||
self.abort_404_not_found() | ||
return get_history( | ||
summary.case_id, | ||
summary.context_id, | ||
summary.run.machine.hash, | ||
) | ||
|
||
def get(self, benchmark_id): | ||
""" | ||
--- | ||
description: Get benchmark history. | ||
responses: | ||
"200": "HistoryList" | ||
"401": "401" | ||
"404": "404" | ||
parameters: | ||
- name: benchmark_id | ||
in: path | ||
schema: | ||
type: string | ||
tags: | ||
- History | ||
""" | ||
history = self._get(benchmark_id) | ||
return self.serializer.many.dump(history) | ||
|
||
|
||
history_entity_view = HistoryEntityAPI.as_view("history") | ||
|
||
rule( | ||
"/history/<benchmark_id>/", | ||
view_func=history_entity_view, | ||
methods=["GET"], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
from ..db import Session | ||
from ..entities._entity import EntitySerializer | ||
from ..entities.commit import Commit | ||
from ..entities.machine import Machine | ||
from ..entities.run import Run | ||
from ..entities.summary import Summary | ||
|
||
|
||
class _Serializer(EntitySerializer): | ||
decimal_fmt = "{:.6f}" | ||
|
||
def _dump(self, history): | ||
return { | ||
"benchmark_id": history.id, | ||
"case_id": history.case_id, | ||
"context_id": history.context_id, | ||
"mean": self.decimal_fmt.format(history.mean), | ||
"unit": history.unit, | ||
"machine_hash": history.hash, | ||
"sha": history.sha, | ||
"repository": history.repository, | ||
"message": history.message, | ||
"timestamp": history.timestamp.isoformat(), | ||
"run_name": history.name, | ||
} | ||
|
||
|
||
class HistorySerializer: | ||
one = _Serializer() | ||
many = _Serializer(many=True) | ||
|
||
|
||
def get_history(case_id, context_id, machine_hash): | ||
return ( | ||
Session.query( | ||
Summary.id, | ||
Summary.case_id, | ||
Summary.context_id, | ||
Summary.mean, | ||
Summary.unit, | ||
Machine.hash, | ||
Commit.sha, | ||
Commit.repository, | ||
Commit.message, | ||
Commit.timestamp, | ||
Run.name, | ||
) | ||
.join(Run, Run.id == Summary.run_id) | ||
.join(Machine, Machine.id == Run.machine_id) | ||
.join(Commit, Commit.id == Run.commit_id) | ||
.filter( | ||
Summary.case_id == case_id, | ||
Summary.context_id == context_id, | ||
Machine.hash == machine_hash, | ||
) | ||
.order_by(Commit.timestamp.asc()) | ||
.all() | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
from ...api._examples import _api_history_entity | ||
from ...tests.api import _asserts | ||
from ...tests.api import _fixtures | ||
|
||
|
||
def _expected_entity(summary): | ||
return _api_history_entity( | ||
summary.id, | ||
summary.case_id, | ||
summary.context_id, | ||
)[0] | ||
|
||
|
||
class TestHistoryGet(_asserts.GetEnforcer): | ||
url = "/api/history/{}/" | ||
public = True | ||
|
||
def _create(self): | ||
return _fixtures.create_benchmark_summary() | ||
|
||
def test_get_history(self, client): | ||
self.authenticate(client) | ||
summary = self._create() | ||
response = client.get(f"/api/history/{summary.id}/") | ||
self.assert_200_ok(response, contains=_expected_entity(summary)) |
Oops, something went wrong.