Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to python3.9 #274

Closed
wants to merge 12 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build_client_sdk_with_poetry.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.8'
python-version: '3.10'

- name: Install pipenv
run: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.8'
python-version: '3.10'

- name: Install pipenv
run: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.8'
python-version: '3.10'

- name: Install pipenv
run: |
Expand Down
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()
6 changes: 3 additions & 3 deletions boaviztapi/model/component/cpu.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,15 +131,15 @@ def _complete_from_name(self):

cpu_attributes = attributes_from_cpu_name(self.name.value)
name, manufacturer, family, model_range, tdp, cores, threads, die_size, die_size_source, source = cpu_attributes if (
cpu_attributes is not None) else (None, None, None, None, None, None, None, None, None)
cpu_attributes is not None) else (None, None, None, None, None, None, None, None, None, None)

if compute_min_max:
cpu_attributes_min = attributes_from_cpu_name(self.name.min)
cpu_attributes_max = attributes_from_cpu_name(self.name.max)
name_min, manufacturer_min, family_min, model_range_min, tdp_min, cores_min, threads_min, die_size_min, die_size_source_min, source_min = cpu_attributes_min if (
cpu_attributes_min is not None) else (None, None, None, None, None, None, None, None, None)
cpu_attributes_min is not None) else (None, None, None, None, None, None, None, None, None, None)
name_max, manufacturer_max, family_max, model_range_max, tdp_max, cores_max, threads_max, die_size_max, die_size_source_max, source_max = cpu_attributes_max if (
cpu_attributes_max is not None) else (None, None, None, None, None, None, None, None, None)
cpu_attributes_max is not None) else (None, None, None, None, None, None, None, None, None, None)
else:
name_min, manufacturer_min, family_min, model_range_min, tdp_min, cores_min, threads_min, die_size_min, die_size_source_min, source_min = name, manufacturer, family, model_range, tdp, cores, threads, die_size, die_size_source, source
name_max, manufacturer_max, family_max, model_range_max, tdp_max, cores_max, threads_max, die_size_max, die_size_source_max, source_max = name, manufacturer, family, model_range, tdp, cores, threads, die_size, die_size_source, source
Expand Down
4 changes: 2 additions & 2 deletions boaviztapi/model/device/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ def ram(self, value: List[ComponentRAM]) -> None:
@property
def disk(self) -> List[Union[ComponentSSD, ComponentHDD]]:
if not self._disk_list:
if get_arch_component(self.archetype, "SSD")["units"]["default"] != 0:
if get_arch_component(self.archetype, "SSD")["units"] not in [{}, {'default':0}]:
self._disk_list.append(ComponentSSD(archetype=get_arch_component(self.archetype, "SSD")))
if get_arch_component(self.archetype, "HDD")["units"]["default"] != 0:
if get_arch_component(self.archetype, "HDD")["units"] not in [{}, {'default':0}]:
self._disk_list.append(ComponentHDD(archetype=get_arch_component(self.archetype, "HDD")))

return self._disk_list
Expand Down
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
Loading