| 184 | } |
| 185 | |
| 186 | def plot_coverage_growth(project, statistics_dir): |
| 187 | json_path = os.path.join(statistics_dir, "coverage_growth.json") |
| 188 | if not os.path.isfile(json_path): |
| 189 | print(f"Error: Could not find coverage data at {json_path}") |
| 190 | return |
| 191 | |
| 192 | try: |
| 193 | with open(json_path, "r") as f: |
| 194 | data = json.load(f) |
| 195 | except Exception as e: |
| 196 | print(f"Error reading {json_path}: {e}") |
| 197 | return |
| 198 | |
| 199 | times_sec = data.get("times", []) |
| 200 | coverages = data.get("coverages", []) |
| 201 | |
| 202 | if not times_sec or not coverages: |
| 203 | print("Error: Empty or invalid data in coverage_growth.json") |
| 204 | return |
| 205 | |
| 206 | # Convert times from seconds to hours |
| 207 | times_hours = [t / 3600.0 for t in times_sec] |
| 208 | |
| 209 | # Configure Academic Style |
| 210 | plt.style.use('seaborn-v0_8-paper') |
| 211 | mpl.rcParams['font.family'] = 'serif' |
| 212 | mpl.rcParams['axes.labelsize'] = 12 |
| 213 | mpl.rcParams['xtick.labelsize'] = 10 |
| 214 | mpl.rcParams['ytick.labelsize'] = 10 |
| 215 | mpl.rcParams['axes.titlesize'] = 14 |
| 216 | mpl.rcParams['legend.fontsize'] = 10 |
| 217 | mpl.rcParams['figure.dpi'] = 300 |
| 218 | mpl.rcParams['savefig.dpi'] = 300 |
| 219 | |
| 220 | plt.figure(figsize=(8, 5)) |
| 221 | |
| 222 | # Plot data |
| 223 | plt.plot(times_hours, coverages, linestyle='-', marker='', color='#1f77b4', linewidth=2, label=project) |
| 224 | |
| 225 | # Configure axes |
| 226 | plt.xlabel('Time (Hours)') |
| 227 | plt.ylabel('Covered Branches') |
| 228 | |
| 229 | max_time = max(times_hours) if times_hours else 0 |
| 230 | plt.xlim(0, max(24.0, max_time + 0.5)) |
| 231 | |
| 232 | plt.grid(True, linestyle='--', alpha=0.7) |
| 233 | plt.title('Coverage Growth Over Time') |
| 234 | plt.legend(loc='lower right') |
| 235 | |
| 236 | plt.tight_layout() |
| 237 | |
| 238 | output_png = os.path.join(statistics_dir, "coverage_growth_24h_chart.png") |
| 239 | output_pdf = os.path.join(statistics_dir, "coverage_growth_24h_chart.pdf") |
| 240 | |
| 241 | plt.savefig(output_png, format='png', bbox_inches='tight') |
| 242 | plt.savefig(output_pdf, format='pdf', bbox_inches='tight') |
| 243 | plt.close() |