You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

__init__.py 3.0KB

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