refactor: move ifind pool helpers to feature service
This commit is contained in:
@@ -472,38 +472,6 @@ class DashboardService(
|
||||
**self.database.status(),
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@staticmethod
|
||||
def _ifind_field(row: dict[str, Any], tokens: tuple[str, ...]) -> Any:
|
||||
for key, value in row.items():
|
||||
label = str(key or "")
|
||||
if any(token.casefold() == label.casefold() for token in tokens):
|
||||
return value
|
||||
for key, value in row.items():
|
||||
label = str(key or "")
|
||||
if any(token in label for token in tokens):
|
||||
return value
|
||||
return None
|
||||
|
||||
@classmethod
|
||||
def _ifind_row_code(cls, row: dict[str, Any]) -> str:
|
||||
value = cls._ifind_field(row, ("股票代码", "证券代码", "代码", "thscode"))
|
||||
match = re.search(r"(?<!\d)(\d{6})(?!\d)", str(value or ""))
|
||||
if match:
|
||||
return match.group(1)
|
||||
for value in row.values():
|
||||
match = re.search(r"(?<!\d)(\d{6})\.(?:SH|SZ|BJ)(?![A-Z])", str(value or ""), re.I)
|
||||
if match:
|
||||
return match.group(1)
|
||||
return ""
|
||||
|
||||
|
||||
|
||||
|
||||
SERVICE = DashboardService()
|
||||
|
||||
|
||||
|
||||
@@ -117,6 +117,30 @@ class PoolServiceMixin:
|
||||
finally:
|
||||
self._ifind_event_lock.release()
|
||||
|
||||
@staticmethod
|
||||
def _ifind_field(row: dict[str, Any], tokens: tuple[str, ...]) -> Any:
|
||||
for key, value in row.items():
|
||||
label = str(key or "")
|
||||
if any(token.casefold() == label.casefold() for token in tokens):
|
||||
return value
|
||||
for key, value in row.items():
|
||||
label = str(key or "")
|
||||
if any(token in label for token in tokens):
|
||||
return value
|
||||
return None
|
||||
|
||||
@classmethod
|
||||
def _ifind_row_code(cls, row: dict[str, Any]) -> str:
|
||||
value = cls._ifind_field(row, ("股票代码", "证券代码", "代码", "thscode"))
|
||||
match = re.search(r"(?<!\d)(\d{6})(?!\d)", str(value or ""))
|
||||
if match:
|
||||
return match.group(1)
|
||||
for value in row.values():
|
||||
match = re.search(r"(?<!\d)(\d{6})\.(?:SH|SZ|BJ)(?![A-Z])", str(value or ""), re.I)
|
||||
if match:
|
||||
return match.group(1)
|
||||
return ""
|
||||
|
||||
@staticmethod
|
||||
def _normalize_ifind_event_time(value: Any) -> str:
|
||||
text = str(value or "").strip()
|
||||
|
||||
@@ -374,8 +374,8 @@
|
||||
},
|
||||
{
|
||||
"path": "backend/application.py",
|
||||
"bytes": 48513,
|
||||
"lines": 1119
|
||||
"bytes": 47552,
|
||||
"lines": 1087
|
||||
},
|
||||
{
|
||||
"path": "frontend/styles/theme.css",
|
||||
|
||||
@@ -29,6 +29,8 @@ POOL_METHODS = {
|
||||
"_apply_reason_overrides",
|
||||
"_schedule_ifind_event_enrichment",
|
||||
"_refresh_ifind_event_enrichment",
|
||||
"_ifind_field",
|
||||
"_ifind_row_code",
|
||||
"_normalize_ifind_event_time",
|
||||
"_merge_ifind_event_enrichment",
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user