refactor: Output analysis results to results/debug directory

- Update analyze_sma.py to save files to results/debug/
- Add timestamp to archived CSV and plot files
- Update .gitignore to exclude results/ directory
- Update ROLLINGSUM_GUIDE.md with new output locations
This commit is contained in:
yair 2025-11-14 14:34:58 +02:00
parent c783de425a
commit 44083222ee
3 changed files with 33 additions and 8 deletions

2
.gitignore vendored
View File

@ -38,3 +38,5 @@ ipch/
*.mkv *.mkv
*.raw *.raw
gst_plugs/
results/

View File

@ -157,7 +157,14 @@ uv run analyze_sma.py output.csv
- Statistical summary (min/max/mean/std) - Statistical summary (min/max/mean/std)
- Threshold recommendations based on percentiles - Threshold recommendations based on percentiles
- Standard deviation-based suggestions - Standard deviation-based suggestions
- Visualization plots (`output_analysis.png`) - Visualization plots saved to `results/debug/`
- Archived CSV with timestamp in `results/debug/`
**Output files are automatically organized:**
- `results/debug/output_YYYYMMDD_HHMMSS.csv` - Archived CSV
- `results/debug/output_analysis_YYYYMMDD_HHMMSS.png` - Analysis plots
The `results/` directory is gitignored to keep your repository clean.
### Interpreting Results ### Interpreting Results

View File

@ -18,11 +18,17 @@ import pandas as pd
import matplotlib.pyplot as plt import matplotlib.pyplot as plt
import numpy as np import numpy as np
from pathlib import Path from pathlib import Path
from datetime import datetime
import shutil
def analyze_csv(csv_file: str = "output.csv"): def analyze_csv(csv_file: str = "output.csv"):
"""Analyze the rolling sum CSV data and generate insights.""" """Analyze the rolling sum CSV data and generate insights."""
# Create output directory
output_dir = Path("results/debug")
output_dir.mkdir(parents=True, exist_ok=True)
# Read the CSV # Read the CSV
try: try:
df = pd.read_csv(csv_file) df = pd.read_csv(csv_file)
@ -30,6 +36,12 @@ def analyze_csv(csv_file: str = "output.csv"):
print(f"Error: CSV file '{csv_file}' not found.") print(f"Error: CSV file '{csv_file}' not found.")
sys.exit(1) sys.exit(1)
# Copy input CSV to results directory with timestamp
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
csv_name = Path(csv_file).stem
archived_csv = output_dir / f"{csv_name}_{timestamp}.csv"
shutil.copy(csv_file, archived_csv)
print("=" * 80) print("=" * 80)
print(f"ROLLING SUM ANALYSIS - {csv_file}") print(f"ROLLING SUM ANALYSIS - {csv_file}")
print("=" * 80) print("=" * 80)
@ -98,16 +110,17 @@ def analyze_csv(csv_file: str = "output.csv"):
print() print()
# Create visualizations # Create visualizations
create_plots(df, csv_file) plot_file = create_plots(df, csv_file, output_dir, timestamp)
print("=" * 80) print("=" * 80)
print("PLOTS SAVED:") print("OUTPUT FILES:")
print(f" - {csv_file.replace('.csv', '_analysis.png')}") print(f" CSV Archive: {archived_csv}")
print(f" Analysis Plot: {plot_file}")
print("=" * 80) print("=" * 80)
def create_plots(df: pd.DataFrame, csv_file: str): def create_plots(df: pd.DataFrame, csv_file: str, output_dir: Path, timestamp: str) -> Path:
"""Create analysis plots.""" """Create analysis plots and return the output file path."""
fig, axes = plt.subplots(2, 2, figsize=(14, 10)) fig, axes = plt.subplots(2, 2, figsize=(14, 10))
fig.suptitle(f'Rolling Sum Analysis - {csv_file}', fontsize=16, fontweight='bold') fig.suptitle(f'Rolling Sum Analysis - {csv_file}', fontsize=16, fontweight='bold')
@ -167,10 +180,13 @@ def create_plots(df: pd.DataFrame, csv_file: str):
plt.tight_layout() plt.tight_layout()
# Save the plot # Save the plot to results/debug
output_file = csv_file.replace('.csv', '_analysis.png') csv_name = Path(csv_file).stem
output_file = output_dir / f"{csv_name}_analysis_{timestamp}.png"
plt.savefig(output_file, dpi=150, bbox_inches='tight') plt.savefig(output_file, dpi=150, bbox_inches='tight')
print(f"\n✓ Saved analysis plot to: {output_file}\n") print(f"\n✓ Saved analysis plot to: {output_file}\n")
return output_file
if __name__ == "__main__": if __name__ == "__main__":