Coverage for agentlib_flexquant/data_structures/flex_offer.py: 100%

32 statements  

« prev     ^ index     » next       coverage.py v7.4.4, created at 2025-08-15 15:25 +0000

1import pydantic 

2import pandas as pd 

3from enum import Enum 

4from pydantic import BaseModel 

5from typing import Optional 

6from agentlib.core.datamodels import _TYPE_MAP 

7 

8 

9class OfferStatus(Enum): 

10 not_accepted = "Not Accepted" 

11 accepted_positive = "Accepted Positive" 

12 accepted_negative = "Accepted Negative" 

13 

14 

15class FlexOffer(BaseModel): 

16 """Data class for the flexibility offer.""" 

17 base_power_profile: pd.Series = pydantic.Field( 

18 default=None, 

19 unit="W", 

20 scalar=False, 

21 description="Power profile of the baseline MPC", 

22 ) 

23 pos_price: Optional[float] = pydantic.Field( 

24 default=None, 

25 unit="ct", 

26 scalar=True, 

27 description="Price for positive flexibility", 

28 ) 

29 pos_diff_profile: pd.Series = pydantic.Field( 

30 default=None, 

31 unit="W", 

32 scalar=False, 

33 description="Power profile for the positive difference", 

34 ) 

35 neg_price: Optional[float] = pydantic.Field( 

36 default=None, 

37 unit="ct", 

38 scalar=True, 

39 description="Price for negative flexibility", 

40 ) 

41 neg_diff_profile: pd.Series = pydantic.Field( 

42 default=None, 

43 unit="W", 

44 scalar=False, 

45 description="Power profile for the negative difference", 

46 ) 

47 status: OfferStatus = pydantic.Field( 

48 default=OfferStatus.not_accepted.value, 

49 scalar=True, 

50 description="Status of the FlexOffer", 

51 ) 

52 

53 class Config: 

54 arbitrary_types_allowed = True 

55 

56 def as_dataframe(self) -> pd.DataFrame: 

57 """Store the flexibility offer in a pd.DataFrame 

58 

59 Returns: 

60 DataFrame containing the flexibility offer. 

61 Scalar values are written on the first timestep. 

62 

63 """ 

64 data = [] 

65 cols = [] 

66 

67 # append scalar values 

68 for name, field in self.model_fields.items(): 

69 if field.json_schema_extra["scalar"]: 

70 ser = pd.Series(getattr(self, name)) 

71 ser.index += self.base_power_profile.index[0] 

72 data.append(ser) 

73 cols.append(name) 

74 

75 df = pd.DataFrame(data).T 

76 df.columns = cols 

77 return df 

78 

79 

80# add the offer type to agent variables 

81_TYPE_MAP["FlexOffer"] = FlexOffer