GIScience / ohsome-quality-api

Data quality estimations for OpenStreetMap
https://api.quality.ohsome.org
GNU Affero General Public License v3.0
35 stars 7 forks source link

Label should reflect quality estimation #585

Open matthiasschaub opened 1 year ago

matthiasschaub commented 1 year ago

Currently, labels are either red, yellow or green.

Suggestion: Labels should describe quality dimension. E.g. for quality dimension "completeness" label should be either low, medium or high.

matthiasschaub commented 12 months ago

Could look like

class Result(BaseModel):
    """The result of the Indicator.

    Attributes:
        timestamp (datetime): Timestamp of the creation of the indicator
        timestamp_osm (datetime): Timestamp of the used OSM data
            (e.g. Latest timestamp of the ohsome API results)
        label (str): Traffic lights like quality label: `green`, `yellow` or `red`. The
            value is determined by the result classes
        value (float): The result value
        class_ (int): The result class. An integer between 1 and 5. It maps to the
            result labels. This value is used by the reports to determine an overall
            result.
        description (str): The result description.
    """

    description: str
    timestamp: datetime = Field(default=datetime.now(timezone.utc))
    timestamp_osm: datetime | None = Field(default=None, alias="timestampOSM")
    value: float | None = None
    class_: Literal[1, 2, 3, 4, 5] | None = None
    figure: dict | None = None
    labels: dict = {1: "red", 2: "yellow", 3: "yellow", 4: "green", 5: "green"}
    model_config = ConfigDict(
        alias_generator=snake_to_lower_camel,
        extra="forbid",
        populate_by_name=True,
    )

    @computed_field
    @property
    def label(self) -> Literal["green", "yellow", "red", "undefined"]:
        return self.labels.get(self.class_, "undefined")