File size: 2,266 Bytes
9bc98d9 | 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 | import json
import pandas as pd
from pathlib import Path
# Paths
base_dir = Path("src/esdac")
output_dir = Path("src/fuse_esdac/outputs")
output_dir.mkdir(parents=True, exist_ok=True)
# Read JSON file
with open(base_dir / "status.json", "r", encoding="utf-8") as f:
data = json.load(f)
# Keep only items with status == "PROCESSED"
processed_items = [item for item in data if item.get("status") == "PROCESSED"]
# Convert to DataFrame
df = pd.DataFrame(processed_items)
# Rename url → dataset_url
df.rename(columns={"url": "dataset_url"}, inplace=True)
# Drop unwanted columns
cols_to_drop = [
"request_needed", "status", "notes",
"screened_by", "requested_downloaded_by", "processed_by"
]
df.drop(columns=cols_to_drop, inplace=True, errors="ignore")
# Determine fuse status and reason
fuse_statuses = []
reasons = []
for _, row in df.iterrows():
dataset_dir = base_dir / row["name"]
fuse_schema = dataset_dir / "fuse_schema.json"
fuse_skip = dataset_dir / "fuse_skip.txt"
if fuse_schema.exists():
fuse_statuses.append("FUSED")
reasons.append("")
elif fuse_skip.exists():
fuse_statuses.append("SKIPPED")
try:
text = fuse_skip.read_text(encoding="utf-8").strip()
except Exception as e:
text = f"[Error reading fuse_skip.txt: {e}]"
reasons.append(text)
else:
fuse_statuses.append("AWAIT")
reasons.append("")
df["fuse_status"] = fuse_statuses
df["reason"] = reasons
# Save to CSV
output_path = output_dir / "processed_datasets.csv"
df.to_csv(output_path, index=False, encoding="utf-8")
print(f"✅ Saved {len(df)} processed datasets to {output_path}")
# ---- existing code above stays unchanged ----
# Save to CSV (all processed)
output_path = output_dir / "processed_datasets.csv"
df.to_csv(output_path, index=False, encoding="utf-8")
print(f"✅ Saved {len(df)} processed datasets to {output_path}")
# ---- new feature: save only fused datasets ----
df_fused = df[df["fuse_status"] == "FUSED"].drop(columns=["fuse_status", "reason"])
fused_output_path = output_dir / "fused_datasets.csv"
df_fused.to_csv(fused_output_path, index=False, encoding="utf-8")
print(f"✅ Saved {len(df_fused)} fused datasets to {fused_output_path}")
|