Spaces:
Running
Running
优化时间戳处理逻辑,确保时间范围过滤条件正确
Browse files- logging_helper.py +13 -9
logging_helper.py
CHANGED
|
@@ -167,9 +167,11 @@ class LoggingHelper:
|
|
| 167 |
parts = remotepath.split("/")
|
| 168 |
year, month, day = parts[0], parts[1], parts[2]
|
| 169 |
date_obj = date(int(year), int(month), int(day))
|
| 170 |
-
timestamp =
|
| 171 |
-
date_obj, datetime.min.time()
|
| 172 |
-
|
|
|
|
|
|
|
| 173 |
self.timestamps[remotepath] = timestamp
|
| 174 |
except Exception as e:
|
| 175 |
print(f"[pull] Error parsing timestamp of {remotepath}: {e}")
|
|
@@ -208,8 +210,8 @@ class LoggingHelper:
|
|
| 208 |
|
| 209 |
start_timestamp = self.cutoff_timestamp()
|
| 210 |
end_timestamp = (
|
| 211 |
-
|
| 212 |
-
.replace(hour=
|
| 213 |
.isoformat(timespec="microseconds")
|
| 214 |
)
|
| 215 |
from_timestamp = from_timestamp or start_timestamp
|
|
@@ -343,9 +345,11 @@ class LoggingHelper:
|
|
| 343 |
from_timestamp = from_datetime.isoformat(timespec="microseconds")
|
| 344 |
to_timestamp = None
|
| 345 |
if to_date is not None:
|
| 346 |
-
to_datetime =
|
| 347 |
-
|
| 348 |
-
|
|
|
|
|
|
|
| 349 |
to_timestamp = to_datetime.isoformat(timespec="microseconds")
|
| 350 |
|
| 351 |
print(
|
|
@@ -362,7 +366,7 @@ class LoggingHelper:
|
|
| 362 |
if from_timestamp is not None:
|
| 363 |
filter_condition = filter_condition & (df["timestamp"] >= from_timestamp)
|
| 364 |
if to_timestamp is not None:
|
| 365 |
-
filter_condition = filter_condition & (df["timestamp"]
|
| 366 |
df = df[filter_condition]
|
| 367 |
# 按timestamp降序排序(最新日志在前)
|
| 368 |
df = df.sort_values(by="timestamp", ascending=False)
|
|
|
|
| 167 |
parts = remotepath.split("/")
|
| 168 |
year, month, day = parts[0], parts[1], parts[2]
|
| 169 |
date_obj = date(int(year), int(month), int(day))
|
| 170 |
+
timestamp = (
|
| 171 |
+
datetime.combine(date_obj, datetime.min.time())
|
| 172 |
+
.astimezone(TIMEZONE)
|
| 173 |
+
.isoformat(timespec="microseconds")
|
| 174 |
+
)
|
| 175 |
self.timestamps[remotepath] = timestamp
|
| 176 |
except Exception as e:
|
| 177 |
print(f"[pull] Error parsing timestamp of {remotepath}: {e}")
|
|
|
|
| 210 |
|
| 211 |
start_timestamp = self.cutoff_timestamp()
|
| 212 |
end_timestamp = (
|
| 213 |
+
beijing()
|
| 214 |
+
.replace(hour=23, minute=59, second=59, microsecond=999999)
|
| 215 |
.isoformat(timespec="microseconds")
|
| 216 |
)
|
| 217 |
from_timestamp = from_timestamp or start_timestamp
|
|
|
|
| 345 |
from_timestamp = from_datetime.isoformat(timespec="microseconds")
|
| 346 |
to_timestamp = None
|
| 347 |
if to_date is not None:
|
| 348 |
+
to_datetime = (
|
| 349 |
+
datetime.strptime(to_date, "%Y-%m-%d")
|
| 350 |
+
.astimezone(TIMEZONE)
|
| 351 |
+
.replace(hour=23, minute=59, second=59, microsecond=999999)
|
| 352 |
+
)
|
| 353 |
to_timestamp = to_datetime.isoformat(timespec="microseconds")
|
| 354 |
|
| 355 |
print(
|
|
|
|
| 366 |
if from_timestamp is not None:
|
| 367 |
filter_condition = filter_condition & (df["timestamp"] >= from_timestamp)
|
| 368 |
if to_timestamp is not None:
|
| 369 |
+
filter_condition = filter_condition & (df["timestamp"] <= to_timestamp)
|
| 370 |
df = df[filter_condition]
|
| 371 |
# 按timestamp降序排序(最新日志在前)
|
| 372 |
df = df.sort_values(by="timestamp", ascending=False)
|