maint_views.py 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. # -*- coding: utf-8 -*-
  2. r"""维护面视图适配(P12):把详情层 `serve.py` 的两段维护面逻辑**搬到算法服务**(目标栈内,逐字保留)。
  3. 来源:`app_backEnd/app_backEnd_guanlan/serve.py` 的 `maint_framework_view()`(361-394)
  4. 与 `/api/maint_std` 分支内联逻辑(2079-2110 一带)。
  5. """
  6. from __future__ import annotations
  7. import json
  8. import pathlib
  9. from typing import Any
  10. def _objects() -> dict[str, Any]:
  11. from app_common.app_common_guanlan.api import paths as P
  12. return json.loads(P.objects_json().read_text(encoding='utf-8'))
  13. def maint_framework(lang: str = 'zh') -> dict[str, Any]:
  14. """运维管理体系三维骨架 —— 与详情层 `maint_framework_view()` **逐字一致**。"""
  15. from src.windscada.maint import framework as _fw
  16. db = _objects()
  17. wo = [(v.get('props') or {}) for k, v in db.items() if k.startswith('workorder/')]
  18. r = dict(systems=_fw.system_load(wo)['rows'], tiers=_fw.systems_by_tier(),
  19. stages=_fw.stage_matrix(), records=_fw.RECORDS,
  20. gaps=_fw.capability_gaps(wo), coverage=_fw.coverage(wo))
  21. # unmapped_top = 未映射到系统码的现场手写部件名(不是枚举,码表投影对它无效)⇒ 走 part_en 自由文本解析
  22. if lang and lang != 'zh' and (r.get('gaps') or {}).get('unmapped_top'):
  23. try:
  24. from src.windscada import en_text as _et
  25. out = []
  26. for it in r['gaps']['unmapped_top']:
  27. if isinstance(it, (list, tuple)) and len(it) == 2:
  28. e = _et.part_en(it[0]) or it[0]
  29. out.append(['(not recorded)' if e == '\u2014' else e, it[1]])
  30. else:
  31. out.append(it)
  32. r['gaps'] = dict(r['gaps'], unmapped_top=out)
  33. except Exception: # noqa: BLE001
  34. pass
  35. return r
  36. def maint_std() -> dict[str, Any]:
  37. """运维标准四判据 + 成熟度评分 —— 与详情层 `/api/maint_std` 分支**逐字一致**。"""
  38. try:
  39. from src.windscada.maint import standards as _st
  40. db = _objects()
  41. wo = [(v.get('props') or {}) for k, v in db.items() if k.startswith('workorder/')]
  42. r = _st.run_all(wo)
  43. r['score'] = _st.score(wo, r)
  44. return r
  45. except Exception as e: # noqa: BLE001
  46. return dict(err=('运维标准判据失败: %s' % e)[:200])