# flake8: noqa T001, E501
# -*- coding: utf-8 -*-
"""
Summary Basics Example

Use pre-calculated summaries for instant per-cycle statistics.
"""

import BTAnalysisPyInterface as bta


def main():
    bta.print("Getting cycle summaries...")

    for source in bta.get_sources():
        # Get per-cycle summary (instant!)
        summary = source.get_summary(bta.SummaryType.PER_CYCLE)

        bta.print(f"Found {summary.row_count} cycles")

        # Access summary columns (returns Series)
        cycles = summary.get_column("Cycle number")
        q_discharge = summary.get_column("Q discharge")
        efficiency = summary.get_column("Efficiency")

        # Calculate statistics
        bta.print(f"Average capacity: {q_discharge.mean() / 3.6:.2f} mA.h")
        bta.print(f"Min capacity: {q_discharge.min() / 3.6:.2f} mA.h")
        bta.print(f"Max capacity: {q_discharge.max() / 3.6:.2f} mA.h")
        bta.print(f"Average efficiency: {efficiency.mean() * 100:.2f} %")

        # Create graph from summary
        graph = bta.add_graph(
            title="Q discharge vs Cycle", xAxis="Cycle number", y1Axis="Q discharge"
        )

        graph.add_series("Discharge Capacity", cycles, q_discharge)

        bta.print("✓ Summary graph created")
