-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrebuild_method_corrected_datasets.py
More file actions
85 lines (68 loc) · 2.45 KB
/
Copy pathrebuild_method_corrected_datasets.py
File metadata and controls
85 lines (68 loc) · 2.45 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
"""Reconstrói os oito datasets após as correções metodológicas.
Os datasets FULL são sempre construídos antes dos CASEONLY correspondentes,
pois estes últimos são filtrados pelo suporte de datas e unidades do FULL.
"""
from __future__ import annotations
import os
import subprocess
import sys
from pathlib import Path
PROJECT_ROOT = Path(__file__).resolve().parent
LOG_DIRECTORY = PROJECT_ROOT / "runs" / "dataset_build_method_corrected_v2"
CONFIGS = [
"config/config_rj_daily.yaml",
"config/config_rj_daily_casesonly.yaml",
"config/config_natal_daily.yaml",
"config/config_natal_daily_casesonly.yaml",
"config/config_rj_weekly.yaml",
"config/config_rj_weekly_casesonly.yaml",
"config/config_natal_weekly.yaml",
"config/config_natal_weekly_casesonly.yaml",
]
def run_build(config: str) -> None:
config_path = PROJECT_ROOT / config
log_path = LOG_DIRECTORY / f"{config_path.stem}.log"
command = [
sys.executable,
str(PROJECT_ROOT / "src" / "data_handling" / "build_dataset.py"),
"--config",
str(config_path),
]
environment = os.environ.copy()
environment["PYTHONIOENCODING"] = "utf-8"
environment["PYTHONUTF8"] = "1"
print(f"\n=== Construindo {config} ===", flush=True)
with log_path.open("w", encoding="utf-8") as log_file:
process = subprocess.Popen(
command,
cwd=PROJECT_ROOT,
env=environment,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
text=True,
encoding="utf-8",
errors="replace",
bufsize=1,
)
assert process.stdout is not None
for line in process.stdout:
print(line, end="", flush=True)
log_file.write(line)
log_file.flush()
return_code = process.wait()
if return_code != 0:
raise SystemExit(
f"Falha ao construir {config}. Consulte o log: {log_path}"
)
def main() -> None:
if hasattr(sys.stdout, "reconfigure"):
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
if hasattr(sys.stderr, "reconfigure"):
sys.stderr.reconfigure(encoding="utf-8", errors="replace")
LOG_DIRECTORY.mkdir(parents=True, exist_ok=True)
for config in CONFIGS:
run_build(config)
print(f"\nConstrução corrigida concluída para os {len(CONFIGS)} datasets.")
print(f"Logs: {LOG_DIRECTORY}")
if __name__ == "__main__":
main()