|
|
|
|
@ -52,24 +52,30 @@ async def get_master_by_assetnum(
|
|
|
|
|
yeardata_records = yeardata_result.scalars().all()
|
|
|
|
|
yeardata_dict = {y.year: y for y in yeardata_records}
|
|
|
|
|
|
|
|
|
|
# Get ens value from year data and calculate asset criticality per year
|
|
|
|
|
# Compute asset criticality per record/year and attach to each record.
|
|
|
|
|
# Use safe attribute access for Yeardata; if a value or attribute is missing,
|
|
|
|
|
# fall back to 0 so N/A data does not raise AttributeError.
|
|
|
|
|
for record in records:
|
|
|
|
|
year = record.tahun
|
|
|
|
|
if year in yeardata_dict:
|
|
|
|
|
asset_crit_ens_energy_not_served = yeardata_dict[year].asset_crit_ens_energy_not_served
|
|
|
|
|
asset_crit_bpp_system = yeardata_dict[year].asset_crit_bpp_system
|
|
|
|
|
asset_crit_bpp_pembangkit = yeardata_dict[year].asset_crit_bpp_pembangkit
|
|
|
|
|
asset_crit_marginal_cost = yeardata_dict[year].asset_crit_marginal_cost
|
|
|
|
|
asset_crit_dmn_daya_mampu_netto = yeardata_dict[year].asset_crit_dmn_daya_mampu_netto
|
|
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
asset_crit_ens_energy_not_served = 0 # Default value if year data not found
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# compute asset criticality per record/year and attach to each record
|
|
|
|
|
for record in records:
|
|
|
|
|
# use year-specific yeardata values already loaded above
|
|
|
|
|
y = yeardata_dict.get(year)
|
|
|
|
|
|
|
|
|
|
asset_crit_ens_energy_not_served = (
|
|
|
|
|
getattr(y, "asset_crit_ens_energy_not_served", 0) if y is not None else 0
|
|
|
|
|
)
|
|
|
|
|
asset_crit_bpp_system = (
|
|
|
|
|
getattr(y, "asset_crit_bpp_system", 0) if y is not None else 0
|
|
|
|
|
)
|
|
|
|
|
asset_crit_bpp_pembangkit = (
|
|
|
|
|
getattr(y, "asset_crit_bpp_pembangkit", 0) if y is not None else 0
|
|
|
|
|
)
|
|
|
|
|
asset_crit_marginal_cost = (
|
|
|
|
|
getattr(y, "asset_crit_marginal_cost", 0) if y is not None else 0
|
|
|
|
|
)
|
|
|
|
|
asset_crit_dmn_daya_mampu_netto = (
|
|
|
|
|
getattr(y, "asset_crit_dmn_daya_mampu_netto", 0) if y is not None else 0
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
# Convert to floats and compute criticality safely
|
|
|
|
|
ens = float(asset_crit_ens_energy_not_served or 0)
|
|
|
|
|
bpp_system = float(asset_crit_bpp_system or 0)
|
|
|
|
|
bpp_pembangkit = float(asset_crit_bpp_pembangkit or 0)
|
|
|
|
|
|