-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmerge_file.py
More file actions
1409 lines (1245 loc) · 68.6 KB
/
merge_file.py
File metadata and controls
1409 lines (1245 loc) · 68.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import glob
import asyncio
import os
import re
from collections import Counter
from datetime import datetime
from functools import lru_cache
import pandas as pd
from rules.cohort27_rules import classify_27_cohort
from rules.location_normalizer import normalize_city
from utils.link_checker import check_links_batch
shixiseng_path = r"C:\jz_code\internship_finding\archive\history\shixiseng\实习僧公司要求大全"
bytedance_output_path = r"C:\jz_code\internship_finding\real-useful-resume\output"
official_raw_file = r"C:\jz_code\internship_finding\official_jobs_raw.csv"
BASE_DIR = r"C:\jz_code\internship_finding"
OUTPUT_REPORT_DIR = os.path.join(BASE_DIR, "outputs", "reports")
OUTPUT_DASHBOARD_DIR = os.path.join(BASE_DIR, "outputs", "dashboard")
OUTPUT_HEALTH_DIR = os.path.join(BASE_DIR, "outputs", "health")
big_company_keywords = [
"字节跳动", "阿里", "腾讯", "美团", "京东", "哔哩哔哩", "小红书", "拼多多", "快手", "华为", "米哈游",
"百度", "网易", "滴滴", "蚂蚁", "携程", "理想", "小米", "科大讯飞", "联想", "荣耀", "顺丰", "Shopee"
]
role_keywords = [
"数据分析", "商业分析", "策略分析", "经营分析", "bi", "产品经理", "数据产品", "产品运营",
"增长", "业务分析", "信息化", "数字化", "系统实施", "sql", "python", "ab测试", "实验", "用户增长"
]
grade_keywords = [
"27届", "2027届", "2027", "2026年9月-2027年8月", "26年9月-27年8月", "2027年毕业", "2027届毕业生",
"26-27届", "2026-2027", "2026/2027", "27届及以后", "2027届及以后", "27届毕业", "26届-27届",
"x-star", "xstar", "快star", "kstar", "redstar", "red star", "青锐计划", "北斗计划", "转正实习", "技术大咖", "跃动计划", "产培生", "大咖实习", "青云计划", "新星计划", "bilibili星", "珠峰计划", "新锐之星", "天才计划"
]
skill_keywords = [
"sql", "python", "excel", "tableau", "power bi", "统计", "机器学习", "a/b", "ab测试",
"产品思维", "增长", "数据建模", "数据仓库", "hive", "spark", "沟通协作", "项目管理"
]
dashboard_skill_keywords = [
"python", "sql", "spark", "hadoop", "tableau", "power bi", "hive", "数据分析", "机器学习", "统计"
]
priority_skill_keywords = ["python", "sql", "spark", "hadoop", "hive", "tableau", "power bi", "机器学习", "统计", "数据分析"]
TARGET_CITY = "上海"
TARGET_COMPANIES = ["快手", "腾讯", "字节跳动", "小红书", "美团", "阿里", "京东", "哔哩哔哩", "百度"]
OFFICIAL_PRIORITY_COMPANY_KEYWORDS = ["字节", "腾讯", "快手", "小红书", "美团", "阿里", "京东", "哔哩哔哩", "百度"]
SHANGHAI_VARIANTS = ["上海", "上海市", "浦东", "徐汇", "静安", "杨浦", "闵行", "虹口", "长宁", "普陀", "松江", "嘉定", "青浦", "奉贤", "金山", "崇明", "总部base上海", "base上海", "上海/北京", "上海/深圳", "上海/杭州"]
# 性能优化:全局预编译正则,避免热路径重复编译
RE_SPACES = re.compile(r"\s+")
RE_RESP = re.compile(r"(岗位职责|职位描述|工作职责)[::]?(.*?)(岗位要求|任职要求|职位要求|加分项|$)")
RE_REQ = re.compile(r"(岗位要求|任职要求|职位要求)[::]?(.*?)(加分项|工作地点|$)")
RE_DEGREE = re.compile(r"(本科及以上|硕士及以上|博士|本科|硕士|大专及以上|不限学历)")
RE_GRAD_BATCH = re.compile(r"(27届|2027届|2027年毕业|2026年9月-2027年8月)")
RE_INTERN_DAYS = re.compile(r"(每周.*?\d+天|\d+天/周|\d+天以上)")
RE_INTERN_MONTHS = re.compile(r"(\d+个月|实习.*?个月)")
RE_27_PAIR = re.compile(r"(26|2026).{0,8}(27|2027)")
RE_27_AFTER = re.compile(r"(27|2027).{0,8}(及以后|以后)")
RE_CITY_FALLBACK = re.compile(r"^(.{2,30})")
RE_NAME_CLEAN_COMPANY = re.compile(r"公司简介.*")
RE_NAME_CLEAN_LOCATION = re.compile(r"工作地点[::].*")
RE_NAME_CLEAN_MAP = re.compile(r"收起地图.*")
RE_TIME_YMD = re.compile(r"[年/月.]")
RE_MULTI_DELIMS = re.compile(r"[/、]|全国|多地|异地")
RE_ROLE_ANALYSIS = re.compile(r"(数据分析|商业分析|策略分析|经营分析|bi|tableau|power bi)")
RE_ROLE_ENGINEERING = re.compile(r"(数据开发|数据工程|数仓|数据仓库|hadoop|spark|hive|etl)")
RE_ROLE_ALGO = re.compile(r"(算法|机器学习|推荐|搜索|nlp|cv|深度学习)")
RE_DATA_JOB = re.compile(r"(数据|分析|策略|算法|商业分析|bi|python|sql)")
RE_FALSE_NEG = re.compile(r"2027|27届|暑期实习|留用|转正|2026.9|2027.8")
RE_SALARY_K_RANGE = re.compile(r"(\d+(?:\.\d+)?)\s*[-~至到]\s*(\d+(?:\.\d+)?)\s*k")
RE_SALARY_K_PLUS = re.compile(r"(\d+(?:\.\d+)?)\s*k\s*(?:以上|起)")
RE_SALARY_DAY_RANGE = re.compile(r"(\d+(?:\.\d+)?)\s*[-~至到]\s*(\d+(?:\.\d+)?)\s*元\s*/?\s*天")
RE_EXP_RANGE = re.compile(r"(\d+(?:\.\d+)?)\s*[-~至到]\s*(\d+(?:\.\d+)?)\s*年")
RE_EXP_PLUS = re.compile(r"(\d+(?:\.\d+)?)\s*年\s*(?:以上|及以上)")
RE_EXP_ANY = re.compile(r"(?:经验|工作年限|相关经历)[^0-9]{0,6}(\d+(?:\.\d+)?)\s*年")
RE_EXP_ZERO = re.compile(r"(应届|不限经验|无经验|无需经验|在校生|实习生)")
def ensure_output_dirs():
os.makedirs(OUTPUT_REPORT_DIR, exist_ok=True)
os.makedirs(OUTPUT_DASHBOARD_DIR, exist_ok=True)
os.makedirs(OUTPUT_HEALTH_DIR, exist_ok=True)
def report_path(file_name: str) -> str:
return os.path.join(OUTPUT_REPORT_DIR, file_name)
def dashboard_path(file_name: str) -> str:
return os.path.join(OUTPUT_DASHBOARD_DIR, file_name)
def health_path(file_name: str) -> str:
return os.path.join(OUTPUT_HEALTH_DIR, file_name)
# 性能优化:缓存归一化文本,避免同值多次处理
@lru_cache(maxsize=200000)
def _normalize_text_cached(x: str) -> str:
txt = str(x).replace("\u3000", " ").replace("\xa0", " ")
return RE_SPACES.sub(" ", txt).strip()
def normalize_text(x):
if pd.isna(x):
return ""
return _normalize_text_cached(str(x))
# 性能优化:向量化归一化,替代逐行 map(normalize_text)
def normalize_text_series(s: pd.Series) -> pd.Series:
if not isinstance(s, pd.Series):
s = pd.Series([s] * 0, dtype="string")
out = s.fillna("").astype("string")
out = out.str.replace("\u3000", " ", regex=False).str.replace("\xa0", " ", regex=False)
out = out.str.replace(RE_SPACES, " ", regex=True).str.strip()
return out.fillna("")
def split_jd(info):
text = normalize_text(info)
if not text:
return "", ""
resp = ""
req = ""
m_resp = RE_RESP.search(text)
if m_resp:
resp = normalize_text(m_resp.group(2))
m_req = RE_REQ.search(text)
if m_req:
req = normalize_text(m_req.group(2))
if resp and not req:
req = resp
if not resp and not req:
req = text
return resp, req
def extract_degree(text):
t = normalize_text(text)
m = RE_DEGREE.search(t)
return m.group(1) if m else ""
def extract_graduation_batch(text):
t = normalize_text(text)
m = RE_GRAD_BATCH.search(t)
if m:
return m.group(1)
return ""
def extract_intern_days(text):
t = normalize_text(text)
m = RE_INTERN_DAYS.search(t)
return m.group(1) if m else ""
def extract_intern_months(text):
t = normalize_text(text)
m = RE_INTERN_MONTHS.search(t)
return m.group(1) if m else ""
def normalize_salary(text):
t = normalize_text(text).lower()
if not t:
return ""
m = RE_SALARY_K_RANGE.search(t)
if m:
low = float(m.group(1))
high = float(m.group(2))
if low > high:
low, high = high, low
if low.is_integer() and high.is_integer():
return f"{int(low)}-{int(high)}K/月"
return f"{round(low, 1)}-{round(high, 1)}K/月"
m = RE_SALARY_K_PLUS.search(t)
if m:
v = float(m.group(1))
if v.is_integer():
return f"{int(v)}K+/月"
return f"{round(v, 1)}K+/月"
m = RE_SALARY_DAY_RANGE.search(t)
if m:
low = float(m.group(1)) * 21.75 / 1000
high = float(m.group(2)) * 21.75 / 1000
if low > high:
low, high = high, low
return f"{round(low, 1)}-{round(high, 1)}K/月"
return ""
def normalize_degree(text):
t = normalize_text(text)
if not t:
return ""
if re.search(r"(博士)", t):
return "博士"
if re.search(r"(硕士及以上|硕士|研究生)", t):
return "硕士"
if re.search(r"(本科及以上|本科)", t):
return "本科"
if re.search(r"(大专及以上|大专)", t):
return "大专"
if re.search(r"(不限学历|学历不限)", t):
return "不限"
return "其他"
def normalize_years_experience(text):
t = normalize_text(text)
if not t:
return ""
m = RE_EXP_RANGE.search(t)
if m:
low = int(float(m.group(1)))
high = int(float(m.group(2)))
if low > high:
low, high = high, low
return f"{low}-{high}年"
m = RE_EXP_PLUS.search(t)
if m:
return f"{int(float(m.group(1)))}年+"
m = RE_EXP_ANY.search(t)
if m:
return f"{int(float(m.group(1)))}年"
if RE_EXP_ZERO.search(t):
return "0年"
return ""
def vectorized_normalize_salary(text_s: pd.Series) -> pd.Series:
# 性能优化:薪资标准化向量化,替代逐行 map(normalize_salary)
t = text_s.fillna("").astype("string").str.lower()
out = pd.Series("", index=t.index, dtype="string")
m1 = t.str.extract(RE_SALARY_K_RANGE, expand=True)
has_m1 = m1[0].notna() & m1[1].notna()
if has_m1.any():
low = pd.to_numeric(m1[0], errors="coerce")
high = pd.to_numeric(m1[1], errors="coerce")
low2 = low.where(low <= high, high)
high2 = high.where(high >= low, low)
out.loc[has_m1] = low2.loc[has_m1].round(1).astype("string") + "-" + high2.loc[has_m1].round(1).astype("string") + "K/月"
out = out.str.replace(".0K/月", "K/月", regex=False)
m2 = t.str.extract(RE_SALARY_K_PLUS, expand=True)
has_m2 = m2[0].notna() & (out == "")
if has_m2.any():
v = pd.to_numeric(m2[0], errors="coerce").round(1).astype("string")
out.loc[has_m2] = v.loc[has_m2] + "K+/月"
out = out.str.replace(".0K+/月", "K+/月", regex=False)
m3 = t.str.extract(RE_SALARY_DAY_RANGE, expand=True)
has_m3 = m3[0].notna() & m3[1].notna() & (out == "")
if has_m3.any():
low = pd.to_numeric(m3[0], errors="coerce") * 21.75 / 1000
high = pd.to_numeric(m3[1], errors="coerce") * 21.75 / 1000
low2 = low.where(low <= high, high)
high2 = high.where(high >= low, low)
out.loc[has_m3] = low2.loc[has_m3].round(1).astype("string") + "-" + high2.loc[has_m3].round(1).astype("string") + "K/月"
return out.fillna("")
def vectorized_normalize_degree(text_s: pd.Series) -> pd.Series:
# 性能优化:学历标准化向量化,替代逐行 map(normalize_degree)
t = text_s.fillna("").astype("string")
out = pd.Series("其他", index=t.index, dtype="string")
out = out.where(~t.str.contains(r"(不限学历|学历不限)", regex=True, na=False), "不限")
out = out.where(~t.str.contains(r"(大专及以上|大专)", regex=True, na=False), "大专")
out = out.where(~t.str.contains(r"(本科及以上|本科)", regex=True, na=False), "本科")
out = out.where(~t.str.contains(r"(硕士及以上|硕士|研究生)", regex=True, na=False), "硕士")
out = out.where(~t.str.contains(r"(博士)", regex=True, na=False), "博士")
out = out.where(t.str.strip() != "", "")
return out
def vectorized_normalize_years_experience(text_s: pd.Series) -> pd.Series:
# 性能优化:年限提取向量化,替代逐行 map(normalize_years_experience)
t = text_s.fillna("").astype("string")
out = pd.Series("", index=t.index, dtype="string")
m1 = t.str.extract(RE_EXP_RANGE, expand=True)
has_m1 = m1[0].notna() & m1[1].notna()
if has_m1.any():
low = pd.to_numeric(m1[0], errors="coerce").fillna(0).astype(int)
high = pd.to_numeric(m1[1], errors="coerce").fillna(0).astype(int)
low2 = low.where(low <= high, high).astype("string")
high2 = high.where(high >= low, low).astype("string")
out.loc[has_m1] = low2.loc[has_m1] + "-" + high2.loc[has_m1] + "年"
m2 = t.str.extract(RE_EXP_PLUS, expand=True)
has_m2 = m2[0].notna() & (out == "")
out.loc[has_m2] = pd.to_numeric(m2.loc[has_m2, 0], errors="coerce").fillna(0).astype(int).astype("string") + "年+"
m3 = t.str.extract(RE_EXP_ANY, expand=True)
has_m3 = m3[0].notna() & (out == "")
out.loc[has_m3] = pd.to_numeric(m3.loc[has_m3, 0], errors="coerce").fillna(0).astype(int).astype("string") + "年"
zero_mask = t.str.contains(RE_EXP_ZERO, regex=True, na=False) & (out == "")
out.loc[zero_mask] = "0年"
return out
def vectorized_trust_score(df: pd.DataFrame) -> pd.Series:
# 性能优化:可信度计算向量化,替代 apply(trust_score_row, axis=1)
src = df.get("publish_time_source", pd.Series("", index=df.index)).fillna("").astype("string")
estimated = df.get("publish_time_estimated", pd.Series("", index=df.index)).fillna("").astype("string")
cached = df.get("cache_fallback_tag", pd.Series("", index=df.index)).fillna("").astype("string")
score = pd.Series(0.3, index=df.index, dtype="float64")
score = score.where(~estimated.str.strip().ne(""), 0.6)
score = score.where(~src.eq("official_update_proxy"), 0.8)
score = score.where(~src.str.startswith("real"), 1.0)
score = score.where(~cached.str.strip().ne(""), score.clip(upper=0.6))
return score
def parse_publish_time(value):
t = normalize_text(value)
if not t or t in {"不知道发布时间", "unknown", "nan", "none"}:
return pd.NaT
t = t.replace("年", "-").replace("月", "-").replace("日", "")
t = t.replace("/", "-").replace(".", "-")
t = re.sub(r"\s+", " ", t)
return pd.to_datetime(t, errors="coerce")
def is_publish_time_abnormal(value):
ts = parse_publish_time(value)
if pd.isna(ts):
return True
today = pd.Timestamp(datetime.now().date())
if ts > today + pd.Timedelta(days=1):
return True
if ts < pd.Timestamp("2010-01-01"):
return True
return False
def trust_score_row(row):
src = normalize_text(row.get("publish_time_source", ""))
estimated = normalize_text(row.get("publish_time_estimated", ""))
cached = normalize_text(row.get("cache_fallback_tag", ""))
if src.startswith("real"):
base = 1.0
elif src == "official_update_proxy":
base = 0.8
elif estimated:
base = 0.6
else:
base = 0.3
if cached:
base = min(base, 0.6)
return base
def map_shixiseng(df):
mapped = pd.DataFrame(
{
"url": df.get("url", ""),
"company": df.get("company", ""),
"name": df.get("name", ""),
"city": df.get("city", ""),
"jd_raw": df.get("info", ""),
"salary": df.get("salary", ""),
"company_size": df.get("company_size", ""),
"duration": df.get("duration", ""),
"academic": df.get("academic", ""),
"publish_time": "",
"deadline": "",
"collect_time": "",
"source": "shixiseng",
"publish_time_source": "unknown",
"deadline_source": "unknown",
}
)
return mapped
def map_bytedance(df):
duties = df.get("岗位职责")
if duties is None:
duties = pd.Series([""] * len(df))
reqs = df.get("岗位要求")
if reqs is None:
reqs = pd.Series([""] * len(df))
pub = df.get("岗位发布时间", "")
ddl = df.get("报名截止时间", "")
ctime = df.get("采集时间", "")
mapped = pd.DataFrame(
{
"url": df.get("投递链接", ""),
"company": df.get("公司名", ""),
"name": df.get("岗位名", ""),
"city": df.get("工作城市", ""),
"jd_raw": duties.fillna("").astype(str) + " 岗位要求:" + reqs.fillna("").astype(str),
"salary": "",
"company_size": "",
"duration": "",
"academic": "",
"publish_time": pub,
"publish_time_estimated": pub,
"publish_time_estimated_source": "real_import",
"deadline": ddl,
"collect_time": ctime,
"source": "bytedance",
"publish_time_source": "real_import",
"deadline_source": "real_import",
}
)
return mapped
def map_official(df):
mapped = pd.DataFrame(
{
"url": df.get("url", ""),
"company": df.get("company", ""),
"name": df.get("name", ""),
"city": df.get("city", ""),
"jd_raw": df.get("jd_raw", ""),
"salary": df.get("salary", ""),
"company_size": df.get("company_size", ""),
"duration": df.get("duration", ""),
"academic": df.get("academic", ""),
"publish_time": df.get("publish_time", ""),
"publish_time_estimated": df.get("publish_time_estimated", ""),
"publish_time_estimated_source": df.get("publish_time_estimated_source", ""),
"deadline": df.get("deadline", ""),
"collect_time": df.get("collect_time", ""),
"source": df.get("source", "official"),
"publish_time_source": df.get("publish_time_source", ""),
"deadline_source": df.get("deadline_source", ""),
"recruit_type": df.get("recruit_type", ""),
"raw_tags": df.get("raw_tags", ""),
"external_job_id": df.get("external_job_id", ""),
"update_time": df.get("update_time", ""),
"sync_status": df.get("sync_status", ""),
"cache_fallback_tag": df.get("cache_fallback_tag", ""),
"fetch_status": df.get("fetch_status", ""),
}
)
return mapped
def is_big_company(company):
c = normalize_text(company)
return any(k.lower() in c.lower() for k in big_company_keywords)
def vectorized_is_big_company(company_s: pd.Series) -> pd.Series:
# 性能优化:公司匹配向量化,替代逐行 map(is_big_company)
c = company_s.fillna("").astype("string").str.lower()
pattern = "|".join(re.escape(k.lower()) for k in big_company_keywords)
return c.str.contains(pattern, regex=True, na=False)
def is_official_priority_company(company):
c = normalize_text(company)
return any(k in c for k in OFFICIAL_PRIORITY_COMPANY_KEYWORDS)
def is_27_match(text):
t = normalize_text(text).lower()
if any(k.lower() in t for k in grade_keywords):
return True
if re.search(r"(26|2026).{0,8}(27|2027)", t):
return True
if re.search(r"(27|2027).{0,8}(及以后|以后)", t):
return True
return False
def vectorized_is_27_match(text_s: pd.Series) -> pd.Series:
# 性能优化:27届识别向量化,替代逐行 map(is_27_match)
t = text_s.fillna("").astype("string").str.lower()
base_pat = "|".join(re.escape(k.lower()) for k in grade_keywords)
m1 = t.str.contains(base_pat, regex=True, na=False)
m2 = t.str.contains(RE_27_PAIR, regex=True, na=False)
m3 = t.str.contains(RE_27_AFTER, regex=True, na=False)
return m1 | m2 | m3
def role_match_score(text):
t = normalize_text(text).lower()
hit = sum(1 for k in role_keywords if k.lower() in t)
return min(hit * 5, 30)
def vectorized_role_match_score(text_s: pd.Series) -> pd.Series:
# 性能优化:岗位关键词计分向量化,替代逐行 role_match_score
t = text_s.fillna("").astype("string").str.lower()
hits = pd.Series(0, index=t.index, dtype="int16")
for k in role_keywords:
hits = hits + t.str.contains(re.escape(k.lower()), regex=True, na=False).astype("int16")
return (hits * 5).clip(upper=30)
def jd_quality_score(resp, req):
fields = [normalize_text(resp), normalize_text(req)]
non_empty = sum(1 for x in fields if x)
length_score = min((len(fields[0]) + len(fields[1])) // 120, 10)
return non_empty * 5 + length_score
def vectorized_jd_quality_score(resp_s: pd.Series, req_s: pd.Series) -> pd.Series:
# 性能优化:JD质量分向量化,替代逐行 jd_quality_score
resp = resp_s.fillna("").astype("string")
req = req_s.fillna("").astype("string")
non_empty = (resp.str.len() > 0).astype("int16") + (req.str.len() > 0).astype("int16")
length_score = ((resp.str.len() + req.str.len()) // 120).clip(upper=10).astype("int16")
return non_empty * 5 + length_score
def score_row(row):
score = 0
company = normalize_text(row.get("company", ""))
city = normalize_text(row.get("city", ""))
jd = normalize_text(row.get("jd_raw", ""))
resp = normalize_text(row.get("responsibility", ""))
req = normalize_text(row.get("requirement", ""))
name = normalize_text(row.get("name", ""))
text = f"{name} {jd} {req}"
if is_big_company(company):
score += 20
if TARGET_CITY in city:
score += 20
if is_27_match(text):
score += 20
score += role_match_score(text)
score += jd_quality_score(resp, req)
if bool(row.get("is_dirty_data", False)):
score -= 10
return min(score, 100)
def extract_city_from_text(text):
t = normalize_text(text)
city_list = ["上海", "北京", "深圳", "广州", "杭州", "成都", "南京", "苏州", "武汉", "西安", "天津", "重庆", "青岛", "厦门", "大连"]
for c in city_list:
if c in t:
return c
return ""
def city_match_level(row):
city = normalize_text(row.get("city", ""))
location_text = normalize_text(f"{row.get('city', '')} {row.get('jd_raw', '')}")
if TARGET_CITY in city:
return "strict_shanghai"
if any(k in city for k in SHANGHAI_VARIANTS):
return "contains_shanghai"
if any(k in location_text for k in SHANGHAI_VARIANTS):
if any(x in location_text for x in ["/", "、", "全国", "多地", "异地"]):
return "multi_base_contains_shanghai"
return "contains_shanghai"
return "unknown"
def enrich_cohort27_fields(row):
signal = {
"title": row.get("name", ""),
"jd_raw": row.get("jd_raw", ""),
"source": row.get("source", ""),
"recruit_type": row.get("recruit_type", ""),
"collect_time": row.get("collect_time", ""),
"project_name": row.get("raw_tags", ""),
"year_text": row.get("graduation_batch", ""),
}
return classify_27_cohort(signal)
def infer_27_from_context(row):
text = normalize_text(f"{row.get('name', '')} {row.get('jd_raw', '')} {row.get('source', '')} {row.get('recruit_type', '')} {row.get('raw_tags', '')}").lower()
if is_27_match(text):
return True
src = normalize_text(row.get("source", ""))
if src in {"official_tencent_api", "official_jd_api", "official_baidu_api", "official_bilibili", "official_kuaishou_api", "official_meituan", "official_alibaba"}:
return True
if any(k in text for k in ["校园", "校招", "应届", "留用实习", "实习生", "暑期实习", "转正", "留用", "提前锁定", "x-star", "xstar", "快star", "kstar", "redstar", "red star", "青锐计划", "北斗计划", "技术大咖", "跃动计划", "产培生", "大咖实习", "青云计划", "新星计划", "bilibili星", "珠峰计划", "新锐之星", "天才计划"]):
return True
return False
def vectorized_infer_27(frame: pd.DataFrame) -> pd.Series:
# 性能优化:27届上下文推断向量化,替代 apply(infer_27_from_context, axis=1)
text = (
frame["name"].fillna("").astype("string")
+ " " + frame["jd_raw"].fillna("").astype("string")
+ " " + frame["source"].fillna("").astype("string")
+ " " + frame["recruit_type"].fillna("").astype("string")
+ " " + frame["raw_tags"].fillna("").astype("string")
).str.lower()
m27 = vectorized_is_27_match(text)
src = frame["source"].fillna("").astype("string")
src_hit = src.isin(
{
"official_tencent_api",
"official_jd_api",
"official_baidu_api",
"official_bilibili",
"official_kuaishou_api",
"official_meituan",
"official_alibaba",
}
)
ctx_hit = text.str.contains(r"校园|校招|应届|留用实习|实习生|暑期实习|转正|留用|提前锁定|x-star|xstar|快star|kstar|redstar|red star|青锐计划|北斗计划|技术大咖|跃动计划|产培生|大咖实习|青云计划|新星计划|bilibili星|珠峰计划|新锐之星|天才计划", regex=True, na=False)
return m27 | src_hit | ctx_hit
def vectorized_score(frame: pd.DataFrame) -> pd.Series:
# 性能优化:评分拆解为列级向量化,替代 apply(score_row, axis=1)
text = (
frame["name"].fillna("").astype("string")
+ " " + frame["jd_raw"].fillna("").astype("string")
+ " " + frame["requirement"].fillna("").astype("string")
)
company_score = frame["is_big_company"].astype("int16") * 20
city_score = frame["city"].fillna("").astype("string").str.contains(TARGET_CITY, regex=False, na=False).astype("int16") * 20
match27_score = vectorized_is_27_match(text).astype("int16") * 20
role_score = vectorized_role_match_score(text)
jd_score = vectorized_jd_quality_score(frame["responsibility"], frame["requirement"])
dirty_penalty = frame.get("is_dirty_data", pd.Series(False, index=frame.index)).astype(bool).astype("int16") * 10
return (company_score + city_score + match27_score + role_score + jd_score - dirty_penalty).clip(upper=100)
def build_quality_report(df):
rows = []
key_cols = ["company", "name", "city", "url", "jd_raw", "requirement"]
unknown_marker = "不知道发布时间"
for src, g in df.groupby("source"):
item = {"source": src, "rows": len(g)}
for col in key_cols:
item[f"{col}_完整率"] = round((g[col].astype(str).str.strip() != "").mean() * 100, 2)
p = g["publish_time"].fillna("").astype(str).str.strip()
pe = g.get("publish_time_estimated", pd.Series([""] * len(g))).fillna("").astype(str).str.strip()
ps = g.get("publish_time_source", pd.Series([""] * len(g))).fillna("").astype(str).str.strip()
item["publish_time_可用率"] = round(((p != "") & (p != unknown_marker)).mean() * 100, 2)
item["publish_time_估算可用率"] = round((pe != "").mean() * 100, 2)
item["publish_time_真实率"] = round(ps.str.startswith("real").mean() * 100, 2)
item["publish_time_代理率"] = round((ps == "official_update_proxy").mean() * 100, 2)
dirty = g.get("is_dirty_data", pd.Series([False] * len(g), index=g.index)).astype(bool)
dirty_jd = g.get("dirty_jd_short", pd.Series([False] * len(g), index=g.index)).astype(bool)
dirty_url = g.get("dirty_url_unreachable", pd.Series([False] * len(g), index=g.index)).astype(bool)
dirty_pub = g.get("dirty_publish_time_abnormal", pd.Series([False] * len(g), index=g.index)).astype(bool)
salary_norm = g.get("salary_normalized", pd.Series([""] * len(g), index=g.index)).fillna("").astype(str).str.strip()
degree_norm = g.get("degree_normalized", pd.Series([""] * len(g), index=g.index)).fillna("").astype(str).str.strip()
years_norm = g.get("years_experience_normalized", pd.Series([""] * len(g), index=g.index)).fillna("").astype(str).str.strip()
trust = vectorized_trust_score(g)
cache_ratio = g.get("cache_fallback_tag", pd.Series([""] * len(g), index=g.index)).fillna("").astype(str).str.strip()
item["脏数据占比"] = round(dirty.mean() * 100, 2)
item["JD短文本占比"] = round(dirty_jd.mean() * 100, 2)
item["URL异常占比"] = round(dirty_url.mean() * 100, 2)
item["发布时间异常占比"] = round(dirty_pub.mean() * 100, 2)
item["薪资标准化覆盖率"] = round((salary_norm != "").mean() * 100, 2)
item["学历标准化覆盖率"] = round((degree_norm != "").mean() * 100, 2)
item["年限标准化覆盖率"] = round((years_norm != "").mean() * 100, 2)
item["可信度均值"] = round(trust.mean() * 100, 2)
item["缓存补位占比"] = round((cache_ratio != "").mean() * 100, 2)
rows.append(item)
overall = {"source": "all", "rows": len(df)}
for col in key_cols:
overall[f"{col}_完整率"] = round((df[col].astype(str).str.strip() != "").mean() * 100, 2)
p = df["publish_time"].fillna("").astype(str).str.strip()
pe = df.get("publish_time_estimated", pd.Series([""] * len(df))).fillna("").astype(str).str.strip()
ps = df.get("publish_time_source", pd.Series([""] * len(df))).fillna("").astype(str).str.strip()
overall["publish_time_可用率"] = round(((p != "") & (p != unknown_marker)).mean() * 100, 2)
overall["publish_time_估算可用率"] = round((pe != "").mean() * 100, 2)
overall["publish_time_真实率"] = round(ps.str.startswith("real").mean() * 100, 2)
overall["publish_time_代理率"] = round((ps == "official_update_proxy").mean() * 100, 2)
dirty = df.get("is_dirty_data", pd.Series([False] * len(df), index=df.index)).astype(bool)
dirty_jd = df.get("dirty_jd_short", pd.Series([False] * len(df), index=df.index)).astype(bool)
dirty_url = df.get("dirty_url_unreachable", pd.Series([False] * len(df), index=df.index)).astype(bool)
dirty_pub = df.get("dirty_publish_time_abnormal", pd.Series([False] * len(df), index=df.index)).astype(bool)
salary_norm = df.get("salary_normalized", pd.Series([""] * len(df), index=df.index)).fillna("").astype(str).str.strip()
degree_norm = df.get("degree_normalized", pd.Series([""] * len(df), index=df.index)).fillna("").astype(str).str.strip()
years_norm = df.get("years_experience_normalized", pd.Series([""] * len(df), index=df.index)).fillna("").astype(str).str.strip()
trust = vectorized_trust_score(df)
cache_ratio = df.get("cache_fallback_tag", pd.Series([""] * len(df), index=df.index)).fillna("").astype(str).str.strip()
overall["脏数据占比"] = round(dirty.mean() * 100, 2)
overall["JD短文本占比"] = round(dirty_jd.mean() * 100, 2)
overall["URL异常占比"] = round(dirty_url.mean() * 100, 2)
overall["发布时间异常占比"] = round(dirty_pub.mean() * 100, 2)
overall["薪资标准化覆盖率"] = round((salary_norm != "").mean() * 100, 2)
overall["学历标准化覆盖率"] = round((degree_norm != "").mean() * 100, 2)
overall["年限标准化覆盖率"] = round((years_norm != "").mean() * 100, 2)
overall["可信度均值"] = round(trust.mean() * 100, 2)
overall["缓存补位占比"] = round((cache_ratio != "").mean() * 100, 2)
official_scope = df[df["source"].astype(str).str.contains("official|bytedance", case=False, regex=True)]
if not official_scope.empty:
osp = official_scope.get("publish_time_source", pd.Series([""] * len(official_scope))).fillna("").astype(str).str.strip()
ope = official_scope.get("publish_time_estimated", pd.Series([""] * len(official_scope))).fillna("").astype(str).str.strip()
overall["大厂发布时间真实覆盖率"] = round(osp.str.startswith("real").mean() * 100, 2)
overall["大厂发布时间有效覆盖率"] = round((osp.str.startswith("real") | (osp == "official_update_proxy")).mean() * 100, 2)
overall["大厂发布时间估算可用率"] = round((ope != "").mean() * 100, 2)
rows.append(overall)
return pd.DataFrame(rows)
def build_skill_gap_report(target_df):
text_series = (target_df["name"].fillna("") + " " + target_df["jd_raw"].fillna("") + " " + target_df["requirement"].fillna("")).str.lower()
counter = Counter()
for text in text_series.tolist():
for k in skill_keywords:
if k.lower() in text:
counter[k] += 1
report = pd.DataFrame({"skill": list(counter.keys()), "count": list(counter.values())}).sort_values("count", ascending=False)
if report.empty:
report = pd.DataFrame({"skill": skill_keywords, "count": [0] * len(skill_keywords)})
report["coverage_pct"] = (report["count"] / max(len(target_df), 1) * 100).round(2)
return report
def classify_role_type(row):
text = normalize_text(f"{row.get('name', '')} {row.get('jd_raw', '')}").lower()
if re.search(r"(数据分析|商业分析|策略分析|经营分析|bi|tableau|power bi)", text):
return "数据分析"
if re.search(r"(数据开发|数据工程|数仓|数据仓库|hadoop|spark|hive|etl)", text):
return "数据开发"
if re.search(r"(算法|机器学习|推荐|搜索|nlp|cv|深度学习)", text):
return "算法"
return "其他"
def is_data_job(row):
text = normalize_text(f"{row.get('name', '')} {row.get('jd_raw', '')}").lower()
return bool(re.search(r"(数据|分析|策略|算法|商业分析|bi|python|sql)", text))
def count_priority_skill_hits(row):
text = normalize_text(f"{row.get('name', '')} {row.get('jd_raw', '')} {row.get('requirement', '')}").lower()
return sum(1 for k in priority_skill_keywords if k.lower() in text)
def _load_csv_if_exists(path):
if os.path.exists(path):
try:
return pd.read_csv(path, dtype="string", keep_default_na=False)
except Exception:
return pd.DataFrame()
return pd.DataFrame()
# 性能优化:读取CSV时指定dtype,降低类型推断和内存开销
READ_DTYPE = {
"url": "string",
"company": "string",
"name": "string",
"city": "string",
"info": "string",
"salary": "string",
"company_size": "string",
"duration": "string",
"academic": "string",
"source": "string",
"jd_raw": "string",
"publish_time": "string",
"deadline": "string",
"collect_time": "string",
"recruit_type": "string",
"raw_tags": "string",
"external_job_id": "string",
"update_time": "string",
}
def read_csv_fast(path: str) -> pd.DataFrame:
return pd.read_csv(path, dtype=READ_DTYPE, keep_default_na=False)
def compute_priority_score(row):
if normalize_text(row.get("cohort27_confidence", "")) != "high":
return 0
text = normalize_text(f"{row.get('name', '')} {row.get('jd_raw', '')} {row.get('requirement', '')}").lower()
score = 0
if "python" in text and "sql" in text:
score += 20
if "spark" in text or "hadoop" in text:
score += 15
if TARGET_CITY in normalize_text(row.get("city", "")):
score += 10
if normalize_text(row.get("company", "")) in {"快手", "腾讯"}:
score += 10
return score
def attach_link_health(frame, companies=None, max_concurrent=12, timeout=6):
if companies is None:
companies = ["快手", "腾讯"]
check_df = frame[frame["company"].isin(companies)][["company", "name", "url"]].copy()
check_df["url"] = normalize_text_series(check_df["url"])
check_df = check_df[check_df["url"] != ""]
check_df = check_df.drop_duplicates(subset=["url"], keep="first")
if check_df.empty:
frame["link_status"] = frame.get("link_status", "UNKNOWN")
frame["link_reason"] = frame.get("link_reason", "")
return frame, pd.DataFrame(columns=["company", "url", "status", "reason"])
urls = check_df["url"].tolist()
results = asyncio.run(check_links_batch(urls, max_concurrent=max_concurrent, timeout=timeout))
result_df = pd.DataFrame(results)
if result_df.empty:
frame["link_status"] = frame.get("link_status", "UNKNOWN")
frame["link_reason"] = frame.get("link_reason", "")
return frame, pd.DataFrame(columns=["company", "url", "status", "reason"])
link_health_file = health_path("link_health_latest.csv")
broken_report_file = health_path("broken_links_report.csv")
if os.path.exists(link_health_file):
prev = _load_csv_if_exists(link_health_file)
if not prev.empty and {"url", "status"}.issubset(set(prev.columns)):
prev = prev[["url", "status"]].rename(columns={"status": "prev_status"})
result_df = result_df.merge(prev, on="url", how="left")
result_df.loc[(result_df["status"] == "RISKY") & (result_df["prev_status"] == "RISKY"), "status"] = "BROKEN"
result_df.loc[(result_df["reason"] == "") & (result_df["status"] == "BROKEN"), "reason"] = "RISKY two days"
result_df.to_csv(link_health_file, index=False, encoding="utf-8-sig")
report_df = check_df.merge(result_df, on="url", how="left")
report_df["status"] = report_df["status"].fillna("UNKNOWN")
report_df["reason"] = report_df["reason"].fillna("")
report_df = report_df.sort_values(["status", "company", "name"], ascending=[True, True, True])
report_df.to_csv(broken_report_file, index=False, encoding="utf-8-sig")
link_map = result_df[["url", "status", "reason"]].rename(columns={"status": "link_status", "reason": "link_reason"})
frame = frame.merge(link_map, on="url", how="left")
frame["link_status"] = frame["link_status"].fillna("UNKNOWN")
frame["link_reason"] = frame["link_reason"].fillna("")
return frame, report_df
def generate_company_dashboard(df_all, company_name):
df_ks = df_all[df_all["company"] == company_name].copy()
if df_ks.empty:
print(f"[Dashboard] {company_name}看板跳过:当前无数据")
return {}
company_slug_map = {
"快手": "kuaishou",
"腾讯": "tencent",
"字节跳动": "bytedance",
"小红书": "xiaohongshu",
"美团": "meituan",
"阿里": "alibaba",
"京东": "jd",
"哔哩哔哩": "bilibili",
"百度": "baidu",
}
slug = company_slug_map.get(company_name, normalize_text(company_name).lower())
today = datetime.now().strftime("%Y-%m-%d")
dashboard_latest_path = dashboard_path(f"dashboard_{slug}_latest.csv")
summary_path = dashboard_path(f"dashboard_{slug}_summary.csv")
role_path = dashboard_path(f"dashboard_{slug}_role_distribution.csv")
keyword_path = dashboard_path(f"dashboard_{slug}_keyword_top10.csv")
new_high_path = dashboard_path(f"dashboard_{slug}_new_high_sh_data.csv")
close_warn_path = dashboard_path(f"dashboard_{slug}_close_warning.csv")
daily_trend_path = dashboard_path(f"dashboard_{slug}_daily_trend.csv")
history_path = dashboard_path(f"dashboard_{slug}_history.csv")
strict_snap_prev = dashboard_path(f"dashboard_{slug}_strict27_snapshot_prev.csv")
strict_snap_latest = dashboard_path(f"dashboard_{slug}_strict27_snapshot_latest.csv")
core_snap_prev = dashboard_path(f"dashboard_{slug}_core_snapshot_prev.csv")
core_snap_latest = dashboard_path(f"dashboard_{slug}_core_snapshot_latest.csv")
df_ks["collect_date"] = pd.to_datetime(df_ks["collect_time"], errors="coerce").dt.strftime("%Y-%m-%d")
role_text = (df_ks["name"].fillna("") + " " + df_ks["jd_raw"].fillna("")).astype("string").str.lower()
df_ks["role_type"] = "其他"
df_ks.loc[role_text.str.contains(RE_ROLE_ANALYSIS, regex=True, na=False), "role_type"] = "数据分析"
df_ks.loc[role_text.str.contains(RE_ROLE_ENGINEERING, regex=True, na=False), "role_type"] = "数据开发"
df_ks.loc[role_text.str.contains(RE_ROLE_ALGO, regex=True, na=False), "role_type"] = "算法"
df_ks["is_data_job"] = role_text.str.contains(RE_DATA_JOB, regex=True, na=False)
df_ks["is_shanghai_city"] = df_ks["city"].astype(str).str.contains(TARGET_CITY, na=False)
score_text = (df_ks["name"].fillna("") + " " + df_ks["jd_raw"].fillna("") + " " + df_ks["requirement"].fillna("")).astype("string").str.lower()
df_ks["priority_skill_hit_count"] = 0
for k in priority_skill_keywords:
df_ks["priority_skill_hit_count"] += score_text.str.contains(re.escape(k.lower()), regex=True, na=False).astype("int16")
df_ks["priority_label"] = ""
df_ks.loc[
(df_ks["cohort27_confidence"] == "high")
& (df_ks["is_shanghai_city"])
& (df_ks["is_data_job"])
& (df_ks["priority_skill_hit_count"] >= 3),
"priority_label",
] = "PRIORITY_A"
df_ks["priority_score"] = 0
cond_high = df_ks["cohort27_confidence"].eq("high")
cond_py_sql = score_text.str.contains("python", na=False) & score_text.str.contains("sql", na=False)
cond_spark = score_text.str.contains("spark|hadoop", regex=True, na=False)
cond_city = df_ks["city"].astype("string").str.contains(TARGET_CITY, regex=False, na=False)
cond_company = df_ks["company"].isin(["快手", "腾讯"])
df_ks.loc[cond_high & cond_py_sql, "priority_score"] += 20
df_ks.loc[cond_high & cond_spark, "priority_score"] += 15
df_ks.loc[cond_high & cond_city, "priority_score"] += 10
df_ks.loc[cond_high & cond_company, "priority_score"] += 10
df_ks["is_core_target"] = (df_ks["cohort27_confidence"] == "high") & df_ks["is_shanghai_city"] & df_ks["is_data_job"]
strict_now = df_ks[df_ks["cohort27_confidence"] == "high"].copy()
strict_now_ids = set(strict_now["external_job_id"].astype(str).tolist()) if "external_job_id" in strict_now.columns else set()
strict_prev_df = _load_csv_if_exists(strict_snap_latest)
strict_prev_ids = set(strict_prev_df.get("external_job_id", pd.Series(dtype=str)).astype(str).tolist())
strict_net_increase = len(strict_now_ids - strict_prev_ids)
if os.path.exists(strict_snap_latest):
try:
if os.path.exists(strict_snap_prev):
os.remove(strict_snap_prev)
os.replace(strict_snap_latest, strict_snap_prev)
except Exception:
pass
strict_now[["external_job_id", "name", "city", "collect_time", "update_time", "cohort27_confidence"]].to_csv(
strict_snap_latest, index=False, encoding="utf-8-sig"
)
core_now = df_ks[df_ks["is_core_target"]].copy()
core_now_ids = set(core_now["external_job_id"].astype(str).tolist()) if "external_job_id" in core_now.columns else set()
core_prev_df = _load_csv_if_exists(core_snap_latest)
core_prev_ids = set(core_prev_df.get("external_job_id", pd.Series(dtype=str)).astype(str).tolist())
new_core_ids = core_now_ids - core_prev_ids
new_core_today = core_now[core_now["external_job_id"].astype(str).isin(new_core_ids)].copy()
if os.path.exists(core_snap_latest):
try:
if os.path.exists(core_snap_prev):
os.remove(core_snap_prev)
os.replace(core_snap_latest, core_snap_prev)
except Exception:
pass
core_now[["external_job_id", "name", "city", "collect_time", "update_time", "cohort27_confidence", "url"]].to_csv(
core_snap_latest, index=False, encoding="utf-8-sig"
)
city_dist = df_ks["city"].value_counts(dropna=False)
shanghai_ratio = round((df_ks["city"].astype(str).str.contains(TARGET_CITY, na=False).mean()) * 100, 2)
role_dist = df_ks["role_type"].value_counts().reset_index()
role_dist.columns = ["role_type", "count"]
role_dist["pct"] = (role_dist["count"] / max(len(df_ks), 1) * 100).round(2)
text_series = (df_ks["name"].fillna("") + " " + df_ks["jd_raw"].fillna("")).str.lower()
keyword_rows = []
for k in dashboard_skill_keywords:
hit = int(text_series.str.contains(re.escape(k.lower()), na=False).sum())
keyword_rows.append({"keyword": k, "count": hit, "hit_rate_pct": round(hit / max(len(df_ks), 1) * 100, 2)})
keyword_df = pd.DataFrame(keyword_rows).sort_values(["count", "keyword"], ascending=[False, True]).head(10)
today_high_df = new_core_today[
[
"external_job_id",
"name",
"city",
"cohort27_confidence",
"priority_label",
"priority_score",
"priority_skill_hit_count",
"recruit_type",
"raw_tags",
"link_status",
"link_reason",
"update_time",
"url",
"jd_raw",
]
].copy()
today_high_df = today_high_df.sort_values(["update_time", "name"], ascending=[False, True])
hist_today = core_now[["external_job_id", "name", "city", "update_time", "collect_time", "source"]].copy()
hist_today["date"] = today
hist_df = _load_csv_if_exists(history_path)
hist_df = pd.concat([hist_df, hist_today], ignore_index=True)
hist_df = hist_df.drop_duplicates(subset=["date", "external_job_id"], keep="last")
hist_df.to_csv(history_path, index=False, encoding="utf-8-sig")
recent = hist_df.copy()
recent = recent[recent["date"] >= (datetime.now() - pd.Timedelta(days=3)).strftime("%Y-%m-%d")]
warn_rows = []
if not recent.empty:
for job_id, g in recent.groupby("external_job_id"):
g = g.sort_values("date")
dates = g["date"].dropna().unique().tolist()
if len(dates) >= 3:
upd = g["update_time"].fillna("").astype(str).str.strip().unique().tolist()
if len([x for x in upd if x]) <= 1:
row = g.iloc[-1].to_dict()
row["warning_reason"] = "连续3天在榜且更新时间未变化"
warn_rows.append(row)
warn_df = pd.DataFrame(warn_rows)
if not warn_df.empty:
warn_df = warn_df.sort_values(["date", "name"], ascending=[False, True])
daily_trend = hist_df.groupby("date", as_index=False).agg(核心岗位数=("external_job_id", "nunique"))
daily_trend = daily_trend.sort_values("date")
summary = pd.DataFrame(
[
{
"date": today,
"company": company_name,
"total_jobs": len(df_ks),
"confidence_high": int((df_ks["cohort27_confidence"] == "high").sum()),
"confidence_medium": int((df_ks["cohort27_confidence"] == "medium").sum()),
"confidence_low": int((df_ks["cohort27_confidence"] == "low").sum()),
"confidence_none": int((df_ks["cohort27_confidence"] == "none").sum()),
"strict27_net_increase_dod": int(strict_net_increase),
"shanghai_ratio_pct": shanghai_ratio,
"core_target_new_today": int(len(today_high_df)),
"priority_a_new_today": int((today_high_df["priority_label"] == "PRIORITY_A").sum()),
"broken_link_count": int((df_ks["link_status"] == "BROKEN").sum()),
"risky_link_count": int((df_ks["link_status"] == "RISKY").sum()),