aggregation.py 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. from marshmallow import fields, validate
  2. from flexmeasures.data.schemas.reporting import (
  3. ReporterConfigSchema,
  4. ReporterParametersSchema,
  5. )
  6. from flexmeasures.data.schemas.io import Output
  7. class AggregatorConfigSchema(ReporterConfigSchema):
  8. """Schema for the AggregatorReporter configuration
  9. Example:
  10. .. code-block:: json
  11. {
  12. "method" : "sum",
  13. "weights" : {
  14. "pv" : 1.0,
  15. "consumption" : -1.0
  16. }
  17. }
  18. """
  19. method = fields.Str(required=False, dump_default="sum", load_default="sum")
  20. weights = fields.Dict(fields.Str(), fields.Float(), required=False)
  21. class AggregatorParametersSchema(ReporterParametersSchema):
  22. """Schema for the AggregatorReporter parameters
  23. Example:
  24. .. code-block:: json
  25. {
  26. "input": [
  27. {
  28. "name" : "pv",
  29. "sensor": 1,
  30. "source" : 1,
  31. },
  32. {
  33. "name" : "consumption",
  34. "sensor": 1,
  35. "source" : 2,
  36. }
  37. ],
  38. "output": [
  39. {
  40. "sensor": 3,
  41. }
  42. ],
  43. "start" : "2023-01-01T00:00:00+00:00",
  44. "end" : "2023-01-03T00:00:00+00:00",
  45. }
  46. """
  47. # redefining output to restrict the output length to 1
  48. output = fields.List(
  49. fields.Nested(Output()), validate=validate.Length(min=1, max=1)
  50. )