Skip to content

Commit

Permalink
Draft version of pydantic file v2
Browse files Browse the repository at this point in the history
  • Loading branch information
albertoabellagarcia committed Aug 14, 2024
1 parent d30ba86 commit 0a33503
Showing 1 changed file with 255 additions and 0 deletions.
255 changes: 255 additions & 0 deletions PhotovoltaicMeasurement/code/code_for_using_pydantic.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,255 @@
from __future__ import annotations

from enum import Enum
from typing import List, Optional, Union

from pydantic import (
AnyUrl,
AwareDatetime,
BaseModel,
Field,
RootModel,
confloat,
constr,
)


class Address(BaseModel):
addressCountry: Optional[str] = Field(
None, description='The country. For example, Spain'
)
addressLocality: Optional[str] = Field(
None,
description='The locality in which the street address is, and which is in the region',
)
addressRegion: Optional[str] = Field(
None,
description='The region in which the locality is, and which is in the country',
)
district: Optional[str] = Field(
None,
description='A district is a type of administrative division that, in some countries, is managed by the local government',
)
postOfficeBoxNumber: Optional[str] = Field(
None,
description='The post office box number for PO box addresses. For example, 03578',
)
postalCode: Optional[str] = Field(
None, description='The postal code. For example, 24004'
)
streetAddress: Optional[str] = Field(None, description='The street address')
streetNr: Optional[str] = Field(
None, description='Number identifying a specific property on a public street'
)


class InverterStatu(Enum):
field_00_On_sector = '00-On sector'
field_01_Power_failure___On_battery = '01-Power failure / On battery'
field_02_Loss_of_communication = '02-Loss of communication'
field_03_Battery_fault = '03-Battery fault'
field_04_System_shutdown = '04-System shutdown'
field_05_Tension_dip = '05-Tension dip'
field_06_Overvoltage = '06-Overvoltage'
field_07_Voltage_drop = '07-Voltage drop'
field_08_Voltage_increase = '08-Voltage increase'
field_09_Line_noise = '09-Line noise'
field_10_Frequency_variation = '10-Frequency variation'
field_11_Transient_distortion = '11-Transient distortion'
field_12_Harmonic_distortion = '12-Harmonic distortion'


class Type(Enum):
Point = 'Point'


class Location(BaseModel):
bbox: Optional[List[float]] = Field(None, min_length=4)
coordinates: List[float] = Field(..., min_length=2)
type: Type


class Coordinate(RootModel[List[float]]):
root: List[float]


class Type1(Enum):
LineString = 'LineString'


class Location1(BaseModel):
bbox: Optional[List[float]] = Field(None, min_length=4)
coordinates: List[Coordinate] = Field(..., min_length=2)
type: Type1


class Type2(Enum):
Polygon = 'Polygon'


class Location2(BaseModel):
bbox: Optional[List[float]] = Field(None, min_length=4)
coordinates: List[List[Coordinate]]
type: Type2


class Type3(Enum):
MultiPoint = 'MultiPoint'


class Location3(BaseModel):
bbox: Optional[List[float]] = Field(None, min_length=4)
coordinates: List[List[float]]
type: Type3


class Type4(Enum):
MultiLineString = 'MultiLineString'


class Location4(BaseModel):
bbox: Optional[List[float]] = Field(None, min_length=4)
coordinates: List[List[Coordinate]]
type: Type4


class Type5(Enum):
MultiPolygon = 'MultiPolygon'


class Location5(BaseModel):
bbox: Optional[List[float]] = Field(None, min_length=4)
coordinates: List[List[List[Coordinate]]]
type: Type5


class Type6(Enum):
PhotovoltaicMeasurement = 'PhotovoltaicMeasurement'


class PhotovoltaicMeasurement(BaseModel):
activePower: Optional[float] = Field(
None,
description='Active Power,where phi is the phase shift of the current compared to the voltage. The unit code (text) is given using the UN/CEFACT_Common_Codes (max 3 characters). For instance, For instance, **KWT** represents Kilowatt',
)
address: Optional[Address] = Field(None, description='The mailing address')
alternateName: Optional[str] = Field(
None, description='An alternative name for this item'
)
areaServed: Optional[str] = Field(
None,
description='The geographic area where a service or offered item is provided',
)
current: Optional[float] = Field(
None,
description='Electrical intensity of the current. The unit code (text) is given using the [UN/CEFACT Common Codes](http://wiki.goodrelations-vocabulary.org/Documentation/UN/CEFACT_Common_Codes). For instance, **AMP** represents Ampere',
)
dataProvider: Optional[str] = Field(
None,
description='A sequence of characters identifying the provider of the harmonised data entity',
)
dateCreated: Optional[AwareDatetime] = Field(
None,
description='Entity creation timestamp. This will usually be allocated by the storage platform',
)
dateEnergyMeteringStarted: Optional[AwareDatetime] = Field(
None,
description='The starting date for metering energy in an ISO8601 UTC format',
)
dateModified: Optional[AwareDatetime] = Field(
None,
description='Timestamp of the last modification of the entity. This will usually be allocated by the storage platform',
)
dateObserved: Optional[AwareDatetime] = Field(
None, description='Date of the observed entity defined by the user'
)
dateObservedFrom: Optional[AwareDatetime] = Field(
None,
description="Observation period: Start date and time in an ISO8601 UTC format. The attribute can be used in addition to the 'dateObserved attribute when it corresponds to a time interval to be highlighted",
)
dateObservedTo: Optional[AwareDatetime] = Field(
None,
description="Observation period: End date and time in an ISO8601 UTC format. The attribute can be used in addition to the 'dateObserved' attribute when it corresponds to a time interval to be highlighted",
)
description: Optional[str] = Field(None, description='A description of this item')
id: Optional[
Union[
constr(
pattern=r'^[\\w\\-\\.\\{\\}\\$\\+\\*\\[\\]`|~^@!, :\\\\]+$',
min_length=1,
max_length=256,
),
AnyUrl,
]
] = Field(None, description='Unique identifier of the entity')
inverterStatus: Optional[List[InverterStatu]] = Field(
None,
description="Active Power,where phi is the phase shift of the current compared to the voltage. The unit code (text) is given using the UN/CEFACT_Common_Codes (max 3 characters). For instance, For instance, **KWT** represents Kilowatt. Enum:'00-On sector, 01-Power failure / On battery, 02-Loss of communication, 03-Battery fault, 04-System shutdown, 05-Tension dip, 06-Overvoltage, 07-Voltage drop, 08-Voltage increase, 09-Line noise, 10-Frequency variation, 11-Transient distortion, 12-Harmonic distortion'",
)
location: Optional[
Union[Location, Location1, Location2, Location3, Location4, Location5]
] = Field(
None,
description='Geojson reference to the item. It can be Point, LineString, Polygon, MultiPoint, MultiLineString or MultiPolygon',
)
name: Optional[str] = Field(None, description='The name of this item')
nominalPeakPowerGeneration: Optional[float] = Field(
None,
description='nominalPeakPowerGeneration is a number. The unit code (text) is given using the [UN/CEFACT Common Codes](http://wiki.goodrelations-vocabulary.org/Documentation/UN/CEFACT_Common_Codes). For instance, **KWT** represents Kilowatt',
)
owner: Optional[
List[
Union[
constr(
pattern=r'^[\\w\\-\\.\\{\\}\\$\\+\\*\\[\\]`|~^@!,:\\\\]+$',
min_length=1,
max_length=256,
),
AnyUrl,
]
]
] = Field(
None,
description='A List containing a JSON encoded sequence of characters referencing the unique Ids of the owner(s)',
)
reactivePower: Optional[confloat(ge=0.0)] = Field(
None,
description='Reactive Power used by circuits. The unit code (text) is given using the [UN/CEFACT Common Codes](http://wiki.goodrelations-vocabulary.org/Documentation/UN/CEFACT_Common_Codes). For instance, **K5** represents kilovolt-ampere-reactive',
)
refPhotovoltaicDevice: Optional[
Union[
constr(
pattern=r'^[\w\-\.\{\}\$\+\*\[\]\'|~^@!, :\\]+$',
min_length=1,
max_length=256,
),
AnyUrl,
]
] = Field(None, description='')
refPointOfInterest: Optional[
Union[
constr(
pattern=r'^[\w\-\.\{\}\$\+\*\[\]\'|~^@!, :\\]+$',
min_length=1,
max_length=256,
),
AnyUrl,
]
] = Field(
None,
description='Reference to a [PointOfInterest](https://github.com/smart-data-models/dataModel.PointOfInterest/blob/master/PointOfInterest/doc/spec.md) linked with the Repository',
)
seeAlso: Optional[Union[List[AnyUrl], AnyUrl]] = Field(
None, description='list of uri pointing to additional resources about the item'
)
source: Optional[str] = Field(
None,
description='A sequence of characters giving the original source of the entity data as a URL. Recommended to be the fully qualified domain name of the source provider, or the URL to the source object',
)
temperature: Optional[confloat(ge=0.0)] = Field(
None,
description='Temperature recorded at the time of Observation compared to the nominal reference temperature of the device. The unit code (text) is given using the [UN/CEFACT Common Codes](http://wiki.goodrelations-vocabulary.org/Documentation/UN/CEFACT_Common_Codes). For instance, **CEL** represents Degree Celsius',
)
type: Optional[Type6] = Field(
None, description='NGSI Entity type. It has to be PhotovoltaicMeasurement'
)

0 comments on commit 0a33503

Please sign in to comment.