Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. #
  2. # Copyright 2025 The InfiniFlow Authors. All Rights Reserved.
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. #
  16. import datetime
  17. def refactor(cv):
  18. for n in [
  19. "raw_txt",
  20. "parser_name",
  21. "inference",
  22. "ori_text",
  23. "use_time",
  24. "time_stat",
  25. ]:
  26. if n in cv and cv[n] is not None:
  27. del cv[n]
  28. cv["is_deleted"] = 0
  29. if "basic" not in cv:
  30. cv["basic"] = {}
  31. if cv["basic"].get("photo2"):
  32. del cv["basic"]["photo2"]
  33. for n in [
  34. "education",
  35. "work",
  36. "certificate",
  37. "project",
  38. "language",
  39. "skill",
  40. "training",
  41. ]:
  42. if n not in cv or cv[n] is None:
  43. continue
  44. if isinstance(cv[n], dict):
  45. cv[n] = [v for _, v in cv[n].items()]
  46. if not isinstance(cv[n], list):
  47. del cv[n]
  48. continue
  49. vv = []
  50. for v in cv[n]:
  51. if "external" in v and v["external"] is not None:
  52. del v["external"]
  53. vv.append(v)
  54. cv[n] = {str(i): vv[i] for i in range(len(vv))}
  55. basics = [
  56. ("basic_salary_month", "salary_month"),
  57. ("expect_annual_salary_from", "expect_annual_salary"),
  58. ]
  59. for n, t in basics:
  60. if cv["basic"].get(n):
  61. cv["basic"][t] = cv["basic"][n]
  62. del cv["basic"][n]
  63. work = sorted(
  64. [v for _, v in cv.get("work", {}).items()],
  65. key=lambda x: x.get("start_time", ""),
  66. )
  67. edu = sorted(
  68. [v for _, v in cv.get("education", {}).items()],
  69. key=lambda x: x.get("start_time", ""),
  70. )
  71. if work:
  72. cv["basic"]["work_start_time"] = work[0].get("start_time", "")
  73. cv["basic"]["management_experience"] = (
  74. "Y"
  75. if any([w.get("management_experience", "") == "Y" for w in work])
  76. else "N"
  77. )
  78. cv["basic"]["annual_salary"] = work[-1].get("annual_salary_from", "0")
  79. for n in [
  80. "annual_salary_from",
  81. "annual_salary_to",
  82. "industry_name",
  83. "position_name",
  84. "responsibilities",
  85. "corporation_type",
  86. "scale",
  87. "corporation_name",
  88. ]:
  89. cv["basic"][n] = work[-1].get(n, "")
  90. if edu:
  91. for n in ["school_name", "discipline_name"]:
  92. if n in edu[-1]:
  93. cv["basic"][n] = edu[-1][n]
  94. cv["basic"]["updated_at"] = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
  95. if "contact" not in cv:
  96. cv["contact"] = {}
  97. if not cv["contact"].get("name"):
  98. cv["contact"]["name"] = cv["basic"].get("name", "")
  99. return cv