Skip to content

Commit

Permalink
Add metrics-schema generator script
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicoretti committed Dec 12, 2023
1 parent ec65754 commit 1d5bb4a
Show file tree
Hide file tree
Showing 6 changed files with 446 additions and 0 deletions.
29 changes: 29 additions & 0 deletions metrics-schema/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Metrics Schema

This project contains a small script to generate the JSON schema for Exasol metrics.
It has been intentionally separated and should not be used as a dependency.
Its sole purpose is to generate the schema for the metrics statistics.

## How to Generate a Schema

**Note:** Ensure that the script is run from the directory where this README is located.

### 1. Create a new poetry shell

```shell
poetry shell
```

### 2. Install all necessary dependencies

```shell
poetry install
```

### 3. Generate the schema

**Note:** Please make sure to replace `MAJOR`, `MINOR` and `PATCH` with the appropriate version numbers.

```shell
python metrics_schema.py > metrics-MAJOR-MINOR-PATCH.json
```
53 changes: 53 additions & 0 deletions metrics-schema/metrics_schema.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import sys
from pathlib import Path
import json
from datetime import datetime
from inspect import cleandoc

from pydantic import (
BaseModel,
Field,
)

_TOOLBOX_PATH = Path(__file__).parent / ".."
sys.path.append(f'{_TOOLBOX_PATH}')

from exasol.toolbox.metrics import Rating


class Metrics(BaseModel):
"""This schema defines the structure and values for reporting Q/A metrics for projects."""

commit: str = Field(
description=(
"Commit-Hash pointing to the state of the codebase used for generating the metrics."
)
)
date: datetime = Field(
description="The date and time when the metrics were recorded."
)
coverage: float = Field(
description="Represents the percentage of the codebase that is covered by automated tests.",
ge=0, le=100
)
maintainability: Rating = Field(
description="Rating of how easily the codebase can be understood, adapted, and extended.",
)
reliability: Rating = Field(
description="Stability and dependability of the software. "
)
security: Rating = Field(
description="Resilience against security threats and vulnerabilities."
)
technical_debt: Rating = Field(
description="Amount of 'technical debt' in the project."
)


if __name__ == "__main__":
schema = {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://schemas.exasol.com/metrics-0.1.0.json",
}
schema.update(Metrics.model_json_schema())
print(json.dumps(schema, indent=2))
Loading

0 comments on commit 1d5bb4a

Please sign in to comment.