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

feature/add metrics schema generator #112

Merged
merged 6 commits into from
Dec 18, 2023
Merged
Show file tree
Hide file tree
Changes from 5 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
25 changes: 17 additions & 8 deletions exasol/toolbox/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,26 @@


class Rating(Enum):
A = auto()
B = auto()
C = auto()
D = auto()
E = auto()
F = auto()
NotAvailable = auto()
"""
A = Excellent
B = Good
C = Satisfactory (Ok, could be better though)
D = Poor (Improvement necessary)
E = Bad (Need for action)
F = Broken (Get it fixed!)
N/A = Rating is not available
"""
A = "A"
B = "B"
C = "C"
D = "D"
E = "E"
F = "F"
NotAvailable = "N/A"

def __format__(self, format_spec: str) -> str:
if format_spec == "n":
return f"{self.name}" if not self == Rating.NotAvailable else "N/A"
return f"{self.value}"
return str(self)

@staticmethod
Expand Down
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/project-metrics-0.1.0.json",
}
schema.update(Metrics.model_json_schema())
print(json.dumps(schema, indent=2))
Loading
Loading