增加web_api
This commit is contained in:
@ -66,47 +66,52 @@ def generate_reports(name: str, processor, config: dict):
|
||||
Generates reports, configuration files, and processed output variables for gasflux processing runs.
|
||||
|
||||
Parameters:
|
||||
name (str): The name identifier for the current processing run.
|
||||
name (str): The name identifier for the current processing run (task_id).
|
||||
processor (object): The processing object containing report data and output variables.
|
||||
config (dict): Configuration dictionary used for processing.
|
||||
"""
|
||||
output_dir = Path(config["output_dir"]).expanduser()
|
||||
processing_time = datetime.now()
|
||||
output_path = output_dir / name / processing_time.strftime("%Y-%m-%d_%H-%M-%S-%f_processing_run")
|
||||
# Save directly to outputs/{task_id} directory
|
||||
output_path = output_dir / "outputs" / name
|
||||
output_path.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
# Save reports
|
||||
for gas, report in processor.reports.items():
|
||||
report_path = output_path / f"{name}_{gas}_report.html"
|
||||
timestamp_str = processing_time.strftime("%Y%m%d_%H%M%S")
|
||||
report_path = output_path / f"{gas}_report_{timestamp_str}.html"
|
||||
with open(report_path, "w", encoding="utf-8") as file:
|
||||
file.write(report)
|
||||
|
||||
# Save config
|
||||
header = f"# Gasflux output config for file {name} from processing run at {processing_time}\n"
|
||||
config_path = output_path / f"{name}_config.yaml"
|
||||
header = f"# Gasflux output config for task {name} from processing run at {processing_time}\n"
|
||||
timestamp_str = processing_time.strftime("%Y%m%d_%H%M%S")
|
||||
config_path = output_path / f"config_{timestamp_str}.yaml"
|
||||
with open(config_path, "w") as file:
|
||||
file.write(header)
|
||||
yaml.safe_dump(config, file)
|
||||
|
||||
# Save DataFrame to CSV
|
||||
# Save DataFrame to Excel
|
||||
if hasattr(processor, 'df') and processor.df is not None:
|
||||
csv_path = output_path / f"{name}_data.csv"
|
||||
processor.df.to_csv(csv_path, index=False)
|
||||
logger.info(f"DataFrame saved to {csv_path}")
|
||||
timestamp_str = processing_time.strftime("%Y%m%d_%H%M%S")
|
||||
excel_path = output_path / f"processed_data_{timestamp_str}.xlsx"
|
||||
processor.df.to_excel(excel_path, index=False, engine='openpyxl')
|
||||
logger.info(f"DataFrame saved to {excel_path}")
|
||||
|
||||
# Save output variables
|
||||
output_vars = processor.output_vars
|
||||
# output_vars = delete_large_arrays(output_vars, threshold_size=50)
|
||||
header = (
|
||||
f"# Gasflux output variables for file {name} from processing run at {processing_time}\n"
|
||||
f"# Gasflux output variables for task {name} from processing run at {processing_time}\n"
|
||||
)
|
||||
filename = output_path / f"{name}_output_vars.json"
|
||||
timestamp_str = processing_time.strftime("%Y%m%d_%H%M%S")
|
||||
filename = output_path / f"output_vars_{timestamp_str}.json"
|
||||
with open(filename, "w") as file:
|
||||
file.write(header)
|
||||
json.dump(
|
||||
output_vars, file, default=lambda item: item.tolist() if isinstance(item, np.ndarray) else item, indent=4
|
||||
)
|
||||
logger.info(f"Processing run saved to {output_path}")
|
||||
logger.info(f"Task {name} results saved to {output_path}")
|
||||
|
||||
|
||||
def delete_large_arrays(output_vars: dict, threshold_size: int) -> dict:
|
||||
|
||||
Reference in New Issue
Block a user