Boavizta / boaviztapi

🛠 Giving access to BOAVIZTA reference data and methodologies trough a RESTful API
GNU Affero General Public License v3.0
68 stars 23 forks source link

Complete_with_archetype won't complete embedded dictionary for usage component #48

Closed da-ekchajzer closed 2 years ago

da-ekchajzer commented 2 years ago

Problem

Complete_with_archetype won't complete workload data if workload exist but is not complete. It's an issue if I want to give a time per workload, but I don't have the power per load (case of cloud).

Example : since workload exist, the object will be used without replacing power

  "usage": {
    "hours_use_time": 1,
    "workload": {
     "10": {
        "time": 0.2,
      },
      "50": {
        "time": 0.3
      },
      "100": {
        "time":  0.5
      },
      "idle": {
        "time":  0
      }
    }
}

ERROR : hours_electrical_consumption += values["time"] * values["power"] * self.max_power KeyError: 'power'

Solution

complete_with_archetype for usage components should have a recursive way of treating attributes for usage only.

Additional context or elements

Such use case should be unit tested

da-ekchajzer commented 2 years ago

Example of how the API should behave

INPUT

  "model":{
     "archetype": "dellR740"
  }
  "usage": {
    "hours_use_time": 1,
    "workload": {
     "10": {
        "time": 0.2,
      },
      "50": {
        "time": 0.3
      },
      "100": {
        "time":  0.5
      },
      "idle": {
        "time":  0
      }
    }
}

complete_with_archetype should set power from dell r740

INPUT

  "model":{
     "archetype": "dellR740"
  }
  "usage": {
    "max_power": 510,
    "hours_use_time": 1,
    "workload": {
     "10": {
        "time": 0.2,
        "power": 0.5118
      },
      "50": {
        "time": 0.3,
        "power": 0.7235
      },
      "100": {
        "time":  0.5,
        "power": 1.0
      },
      "idle": {
        "time":  0,
        "power": 0.3941
      }
    }
}