|
|
@@ -54,7 +54,7 @@ def sample_per_day(rows, per_day):
|
|
|
|
|
|
|
|
|
def spans(connection, file_ids):
|
|
|
- """Median pressure span of wave_sample_one per file_id."""
|
|
|
+ """Return {file_id: (median_span, has_samples)} from wave_sample_one."""
|
|
|
result = {}
|
|
|
with connection.cursor() as cursor:
|
|
|
for start in range(0, len(file_ids), 200):
|
|
|
@@ -67,7 +67,8 @@ def spans(connection, file_ids):
|
|
|
)
|
|
|
for row in cursor.fetchall():
|
|
|
mn, mx = row["mn"], row["mx"]
|
|
|
- result[int(row["wave_file_id"])] = float(mx) - float(mn) if mn is not None and mx is not None else 0.0
|
|
|
+ span = float(mx) - float(mn) if mn is not None and mx is not None else 0.0
|
|
|
+ result[int(row["wave_file_id"])] = (span, True)
|
|
|
return result
|
|
|
|
|
|
|
|
|
@@ -97,13 +98,15 @@ def main():
|
|
|
span_by_id = spans(connection, [int(r["id"]) for r in picked])
|
|
|
by_day = defaultdict(list)
|
|
|
for row in picked:
|
|
|
- by_day[row["sample_time"].date()].append(span_by_id.get(int(row["id"]), 0.0))
|
|
|
- valid_days = [d for d, v in sorted(by_day.items()) if np.median(v) >= MIN_SPAN and len(span_by_id)]
|
|
|
+ by_day[row["sample_time"].date()].append(span_by_id.get(int(row["id"])))
|
|
|
all_days = sorted(by_day)
|
|
|
- print(f"{point}: 文件 {len(files)},抽样日 {len(all_days)},其中有效日 {len(valid_days)}")
|
|
|
- if valid_days:
|
|
|
- print(f" 有效数据段: {valid_days[0]} ~ {valid_days[-1]} 共 {len(valid_days)} 天")
|
|
|
- print(" 有效日:", ", ".join(str(d) for d in valid_days))
|
|
|
+ has_days = [d for d in all_days if any(v is not None for v in by_day[d])]
|
|
|
+ valid_days = [d for d in all_days
|
|
|
+ if np.median([v[0] for v in by_day[d] if v is not None] or [0.0]) >= MIN_SPAN]
|
|
|
+ print(f"{point}: 文件 {len(files)},抽样日 {len(all_days)},"
|
|
|
+ f"有 wave_sample_one 的日 {len(has_days)},其中有效周期日 {len(valid_days)}")
|
|
|
+ if has_days:
|
|
|
+ print(f" 有样本数据段: {has_days[0]} ~ {has_days[-1]} 共 {len(has_days)} 天")
|
|
|
finally:
|
|
|
connection.close()
|
|
|
|