Skip to content

Commit

Permalink
Merge pull request #267 from Boavizta/Orange-OpenSource-2-automate-th…
Browse files Browse the repository at this point in the history
…e-generation-of-the-tutorial-output-in-the-documentation

Changed docs files to avoid displaying long json, and added execution of the instance of the API when executing the script or unit test.
  • Loading branch information
valentinchaud authored Jan 24, 2024
2 parents c973a48 + d2ab209 commit 5604bc3
Show file tree
Hide file tree
Showing 7 changed files with 2,200 additions and 1,235 deletions.
27 changes: 25 additions & 2 deletions boaviztapi/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,11 @@
from mangum import Mangum
from starlette.requests import Request
from starlette.responses import Response
import contextlib
import time
import threading
import uvicorn

from boaviztapi.routers import iot_router
from boaviztapi.routers.component_router import component_router
from boaviztapi.routers.consumption_profile_router import consumption_profile
from boaviztapi.routers.iot_router import iot
Expand All @@ -29,7 +32,8 @@
stage = os.environ.get('STAGE', None)
openapi_prefix = f"/{stage}" if stage else "/"
app = FastAPI(root_path=openapi_prefix) # Here is the magic
version = toml.loads(open(os.path.join(os.path.dirname(__file__), '../pyproject.toml'), 'r').read())['tool']['poetry']['version']
version = toml.loads(open(os.path.join(os.path.dirname(__file__), '../pyproject.toml'), 'r').read())['tool']['poetry'][
'version']
_logger = logging.getLogger(__name__)

origins = json.loads(os.getenv("ALLOWED_ORIGINS", '["*"]'))
Expand Down Expand Up @@ -123,3 +127,22 @@ async def welcome_page():
</html>
""" % os.getenv('SPECIAL_MESSAGE', '')
return HTMLResponse(content=html_content, status_code=200)


# # A uvicorn server that can be run in a thread. Taken from @florimondmanca @
# https://github.com/encode/uvicorn/issues/742#issuecomment-674411676
class UvicornServerThreaded(uvicorn.Server):
def install_signal_handlers(self):
pass

@contextlib.contextmanager
def run_in_thread(self):
thread = threading.Thread(target=self.run)
thread.start()
try:
while not self.started:
time.sleep(1e-3)
yield
finally:
self.should_exit = True
thread.join()
75 changes: 46 additions & 29 deletions docs/docs/getting_started/cpu_component.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,8 @@ curl -X 'POST' \
"name": "intel xeon gold 6134"
}'
```

This query returns :

- The impacts for the default criteria (gwp, pe, adp) since no impact is specified
- The total embedded impacts of the CPU
- The usage impacts of the CPU during the life duration, since no duration is given
- Error margins are provided in the form of min & max values for both embedded and usage impacts
- Significant figures are provided for each value

Result :
<details>
<summary>Results</summary>

```json
{
Expand Down Expand Up @@ -93,6 +85,16 @@ Result :
}
```

</details>

This query returns :

- The impacts for the default criteria (gwp, pe, adp) since no impact is specified
- The total embedded impacts of the CPU
- The usage impacts of the CPU during the life duration, since no duration is given
- Error margins are provided in the form of min & max values for both embedded and usage impacts
- Significant figures are provided for each value

## Get the values used to assess the impacts of the cpu

This is the same query as before. However, you add the `verbose=true` flag to get the value of the attributes used for the calculation.
Expand All @@ -106,13 +108,8 @@ curl -X 'POST' \
"name": "intel xeon gold 6134"
}'
```

Result :

* This query returns will only compute the gwp impact since we add the `criteria=gwp` flag.
* You can see that the API has completed the needed value from the cpu name. We parse and fuzzymatch the cpu ```name``` with our dataset of cpu to identify ```tdp```, ```cores_unit```, ```family```...
* The ```die_size``` is completed from the cpu family.
* The usage impact has been assessed using a default level of workload of 50% with the consumption profile of a xeon gold (completed from cpu ```name```).
<details>
<summary>Results</summary>

```json
{
Expand Down Expand Up @@ -268,6 +265,16 @@ Result :
}
```

</details>

Result :

* This query returns will only compute the gwp impact since we add the `criteria=gwp` flag.
* You can see that the API has completed the needed value from the cpu name. We parse and fuzzymatch the cpu ```name``` with our dataset of cpu to identify ```tdp```, ```cores_unit```, ```family```...
* The ```die_size``` is completed from the cpu family.
* The usage impact has been assessed using a default level of workload of 50% with the consumption profile of a xeon gold (completed from cpu ```name```).


## Get the impacts from custom cpu characteristics

In this query, we give some characteristics to describe the CPU.
Expand All @@ -282,10 +289,9 @@ curl -X 'POST' \
"family": "skylake"
}'
```
Result :

* This query returns will compute the gwp and adp impacts since we add the `criteria=gwp&criteria=adp` flags.
* The API will correct skylake to Skylake (CHANGED) and complete the missing attributes from the given attributes (COMPLETED) or by default ones (ARCHETYPE).
<details>
<summary>Results</summary>

```json
{
Expand Down Expand Up @@ -456,6 +462,12 @@ Result :
}
```

</details>

* This query returns will compute the gwp and adp impacts since we add the `criteria=gwp&criteria=adp` flags.
* The API will correct skylake to Skylake (CHANGED) and complete the missing attributes from the given attributes (COMPLETED) or by default ones (ARCHETYPE).


## Get the impacts from custom cpu usage using an electrical consumption

In this query we set a custom usage to an ```intel xeon gold 6134```. The average electrical consumption is given.
Expand All @@ -473,12 +485,8 @@ curl -X 'POST' \
}}'
```

Result :

* The API will use an electrical consumption of 120 Watt/hours for 2 hours (since duration is set at 2)
* Usage impacts will be assessed for the French electrical mix impacts
* Embedded impacts will be allocated on 2 hours

<details>
<summary>Results</summary>

```json
{
Expand All @@ -504,6 +512,12 @@ Result :
}
```

</details>

* The API will use an electrical consumption of 120 Watt/hours for 2 hours (since duration is set at 2)
* Usage impacts will be assessed for the French electrical mix impacts
* Embedded impacts will be allocated on 2 hours


## Get the impacts from custom cpu usage using a workload

Expand All @@ -524,9 +538,8 @@ curl -X 'POST' \
}}'
```

Result :

* The API will use the ```xeon gold``` consumption profile adapted for a TDP of 130 Watt with a level of workload of 30% for 2 hours to retrieve the electrical consumption of the CPU.
<details>
<summary>Results</summary>

```json
{
Expand All @@ -552,4 +565,8 @@ Result :
}
```

</details>

* The API will use the ```xeon gold``` consumption profile adapted for a TDP of 130 Watt with a level of workload of 30% for 2 hours to retrieve the electrical consumption of the CPU.

For further information see : [The explanation page on cpu](../Explanations/components/cpu.md)
42 changes: 26 additions & 16 deletions docs/docs/getting_started/end_user_devices.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,8 @@ curl -X 'GET' \
-H 'accept: application/json'
```

This query returns :

- The impacts for the default criteria (gwp, pe, adp) since no impact is specified
- The total embedded impacts of the laptop since no duration is given
- The usage impacts of the laptop during its life duration, since no duration is given
- Error margins are provided in the form of min & max values for both embedded and usage impacts
- Significant figures are provided for each value

Result :
<details>
<summary>Results</summary>

```json
{
Expand Down Expand Up @@ -60,6 +53,17 @@ Result :
}
```

</details>

This query returns :

- The impacts for the default criteria (gwp, pe, adp) since no impact is specified
- The total embedded impacts of the laptop since no duration is given
- The usage impacts of the laptop during its life duration, since no duration is given
- Error margins are provided in the form of min & max values for both embedded and usage impacts
- Significant figures are provided for each value


## Get the impact of a desktop with a custom usage

In this query, we compute the impact of a desktop with a custom usage. Since ```verbose=true``` the api will return the values used during the computation.
Expand All @@ -77,13 +81,8 @@ curl -X 'POST' \
}
}'
```

This query returns :

* The impacts for both gwp and adp criteria since ```criteria=gwp&criteria=adp```
* The API will use an average electrical consumption of 70 Watt/hours 30% of the time (since ```use_time_ratio=0.3```) for one year (since duration is set at 8760 hours).
* Usage impacts will be assessed for the French electrical mix impacts since ```usage_location='FRA'```
* Embedded impacts will be allocated on one year (since duration is set at 8760 hours).
<details>
<summary>Results</summary>

```json
{
Expand Down Expand Up @@ -165,4 +164,15 @@ This query returns :
}
}
```

</details>

This query returns :

* The impacts for both gwp and adp criteria since ```criteria=gwp&criteria=adp```
* The API will use an average electrical consumption of 70 Watt/hours 30% of the time (since ```use_time_ratio=0.3```) for one year (since duration is set at 8760 hours).
* Usage impacts will be assessed for the French electrical mix impacts since ```usage_location='FRA'```
* Embedded impacts will be allocated on one year (since duration is set at 8760 hours).


For further information see : [The explanation page on terminal and peripherals](../Explanations/devices/terminals_&_peripherals.md)
Loading

0 comments on commit 5604bc3

Please sign in to comment.