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

Create and populate tables with calculated data.
"""

import BTAnalysisPyInterface as bta


def main():
    bta.print("Creating power analysis table...")

    for source in bta.get_sources():
        # Create table
        table = bta.add_table(
            columns=["Time", "U", "I", "Power"],
            title="Power Analysis",
            units=["", "", "", "W"],
        )

        # Add computed data from measurements
        for point in source.data_points("Potentiostat measure", ["Time", "U", "I"]):
            power = point["U"] * point["I"]

            table.add_row(
                {
                    "Time": point["Time"],
                    "U": point["U"],
                    "I": point["I"],
                    "Power": power,
                }
            )

        bta.print(f"✓ Table created with {table.row_count} rows")

        # Export to CSV
        table.export_to_csv("power_analysis.csv")
        bta.print("✓ Exported to CSV")
