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

32 statements  

« prev     ^ index     » next       coverage.py v7.4.4, created at 2025-08-01 15:10 +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 

8class OfferStatus(Enum): 

9 not_accepted = "Not Accepted" 

10 accepted_positive = "Accepted Positive" 

11 accepted_negative = "Accepted Negative" 

12 

13 

14class FlexOffer(BaseModel): 

15 """Data class for the flexibility offer 

16 

17 """ 

18 base_power_profile: pd.Series = pydantic.Field( 

19 default=None, 

20 unit="W", 

21 scalar=False, 

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

23 ) 

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

25 default=None, 

26 unit="ct", 

27 scalar=True, 

28 description="Price for positive flexibility", 

29 ) 

30 pos_diff_profile: pd.Series = pydantic.Field( 

31 default=None, 

32 unit="W", 

33 scalar=False, 

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

35 ) 

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

37 default=None, 

38 unit="ct", 

39 scalar=True, 

40 description="Price for negative flexibility", 

41 ) 

42 neg_diff_profile: pd.Series = pydantic.Field( 

43 default=None, 

44 unit="W", 

45 scalar=False, 

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

47 ) 

48 status: OfferStatus = pydantic.Field( 

49 default=OfferStatus.not_accepted.value, 

50 scalar=True, 

51 description="Status of the FlexOffer", 

52 ) 

53 

54 class Config: 

55 arbitrary_types_allowed = True 

56 

57 def as_dataframe(self): 

58 """Returns the offer as a dataframe. Scalar values are written on the first timestep 

59 

60 """ 

61 data = [] 

62 cols = [] 

63 

64 # append scalar values 

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

66 if field.json_schema_extra["scalar"]: 

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

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

69 data.append(ser) 

70 cols.append(name) 

71 

72 df = pd.DataFrame(data).T 

73 df.columns = cols 

74 return df 

75 

76 

77# add the offer type to agent variables 

78_TYPE_MAP["FlexOffer"] = FlexOffer