# coding: utf-8

"""
    Mixpeek API

    This is the Mixpeek API, providing access to various endpoints for data processing and retrieval.

    The version of the OpenAPI document: 1.3.0
    Contact: info@mixpeek.com
    Generated by OpenAPI Generator (https://openapi-generator.tech)

    Do not edit the class manually.
"""  # noqa: E501


from __future__ import annotations
import pprint
import re  # noqa: F401
import json

from pydantic import BaseModel, ConfigDict, Field, StrictFloat, StrictInt
from typing import Any, ClassVar, Dict, List, Union
from typing import Optional, Set
from typing_extensions import Self

class DurationStats(BaseModel):
    """
    Statistical distribution of durations for successful step transitions.  Provides comprehensive percentile analysis to understand timing patterns.  Attributes:     mean: Average duration (seconds)     median: Middle value (50th percentile)     p50: 50th percentile (same as median, included for consistency)     p90: 90th percentile (90% complete faster)     p95: 95th percentile (95% complete faster)     std_dev: Standard deviation (measure of spread)     min: Fastest observed duration     max: Slowest observed duration  Example:     ```python     DurationStats(         mean=432000.0,     # 5 days average         median=345600.0,   # 4 days median         p50=345600.0,         p90=691200.0,      # 8 days (90th percentile)         p95=864000.0,      # 10 days (95th percentile)         std_dev=172800.0,  # 2 days std dev         min=86400.0,       # 1 day minimum         max=1209600.0      # 14 days maximum     )     ```
    """ # noqa: E501
    mean: Union[StrictFloat, StrictInt] = Field(description="Average duration in seconds")
    median: Union[StrictFloat, StrictInt] = Field(description="Median duration in seconds")
    p50: Union[StrictFloat, StrictInt] = Field(description="50th percentile (same as median)")
    p90: Union[StrictFloat, StrictInt] = Field(description="90th percentile duration in seconds")
    p95: Union[StrictFloat, StrictInt] = Field(description="95th percentile duration in seconds")
    std_dev: Union[StrictFloat, StrictInt] = Field(description="Standard deviation in seconds")
    min: Union[StrictFloat, StrictInt] = Field(description="Minimum duration observed in seconds")
    max: Union[StrictFloat, StrictInt] = Field(description="Maximum duration observed in seconds")
    __properties: ClassVar[List[str]] = ["mean", "median", "p50", "p90", "p95", "std_dev", "min", "max"]

    model_config = ConfigDict(
        populate_by_name=True,
        validate_assignment=True,
        protected_namespaces=(),
    )


    def to_str(self) -> str:
        """Returns the string representation of the model using alias"""
        return pprint.pformat(self.model_dump(by_alias=True))

    def to_json(self) -> str:
        """Returns the JSON representation of the model using alias"""
        # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
        return json.dumps(self.to_dict())

    @classmethod
    def from_json(cls, json_str: str) -> Optional[Self]:
        """Create an instance of DurationStats from a JSON string"""
        return cls.from_dict(json.loads(json_str))

    def to_dict(self) -> Dict[str, Any]:
        """Return the dictionary representation of the model using alias.

        This has the following differences from calling pydantic's
        `self.model_dump(by_alias=True)`:

        * `None` is only added to the output dict for nullable fields that
          were set at model initialization. Other fields with value `None`
          are ignored.
        """
        excluded_fields: Set[str] = set([
        ])

        _dict = self.model_dump(
            by_alias=True,
            exclude=excluded_fields,
            exclude_none=True,
        )
        return _dict

    @classmethod
    def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
        """Create an instance of DurationStats from a dict"""
        if obj is None:
            return None

        if not isinstance(obj, dict):
            return cls.model_validate(obj)

        _obj = cls.model_validate({
            "mean": obj.get("mean"),
            "median": obj.get("median"),
            "p50": obj.get("p50"),
            "p90": obj.get("p90"),
            "p95": obj.get("p95"),
            "std_dev": obj.get("std_dev"),
            "min": obj.get("min"),
            "max": obj.get("max")
        })
        return _obj


