File size: 3,778 Bytes
0988432
 
6d12201
0988432
 
 
 
cf751fb
 
 
 
 
 
 
fdb689f
 
 
0cc9ead
 
 
 
0988432
 
 
 
 
6d12201
0988432
6d12201
8c69abd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0cc9ead
 
 
 
0988432
 
6d12201
 
 
8c69abd
 
 
6d12201
 
 
8c69abd
 
 
0988432
8c69abd
 
 
0988432
 
8c69abd
 
 
 
 
 
 
 
 
 
0988432
 
8c69abd
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
"""This module manages plugins for the AI Dashboard application."""

from typing import Any, List, Optional
from .plot_plugin.bar_plot import BarPlotPlugin
from .plot_plugin.histogram_plot import HistogramPlotPlugin
from .plot_plugin.scatter_plot import ScatterPlotPlugin
from .table_plugin.table_sample import SampleTablePlugin
from .plot_plugin.line_plot import LinePlotPlugin
from .plot_plugin.box_plot import BoxPlotPlugin
from .plot_plugin.violin_plot import ViolinPlotPlugin
from .plot_plugin.scatter_matrix import ScatterMatrixPlugin
from .plot_plugin.heatmap_plot import CorrelationHeatmapPlugin
from .plot_plugin.grouped_bar_plot import GroupedBarPlotPlugin
from .plot_plugin.hexbin_plot import HexbinPlotPlugin
from .plot_plugin.tsne import PCATSNEPlotPlugin
from .plot_plugin.scatter_3d import Scatter3DPlotPlugin
from .plot_plugin.geo_scatter import GeoPlotPlugin
from .plot_plugin.word_cloud import WordCloudPlotPlugin
from .plot_plugin.regression_line import RegressionPlotPlugin
from .table_plugin.correlation_matrix import CorrelationMatrixTablePlugin
from .table_plugin.summary_table import SummaryStatisticsTablePlugin


class PluginManager:
    """Manages plot and table plugins for the AI Dashboard."""

    def __init__(self, dataframe: Optional[Any] = None) -> None:
        """Initialize the PluginManager with available plot and table plugins."""
        self.df = dataframe
        self.plot_groups = {
            "Basic Plots": [
                ScatterPlotPlugin(dataframe),
                BarPlotPlugin(dataframe),
                LinePlotPlugin(dataframe),
                GroupedBarPlotPlugin(dataframe),
            ],
            "Statistical": [
                HistogramPlotPlugin(dataframe),
                BoxPlotPlugin(dataframe),
                ViolinPlotPlugin(dataframe),
                CorrelationHeatmapPlugin(dataframe),
            ],
            "Dimensionality Reduction": [
                ScatterMatrixPlugin(dataframe),
                PCATSNEPlotPlugin(dataframe),
            ],
            "Geospatial": [
                GeoPlotPlugin(dataframe),
            ],
            "Advanced Visualizations": [
                HexbinPlotPlugin(dataframe),
                Scatter3DPlotPlugin(dataframe),
                RegressionPlotPlugin(dataframe),
                WordCloudPlotPlugin(dataframe),
            ],
        }
        self.tables = [
            SampleTablePlugin(dataframe),
            CorrelationMatrixTablePlugin(dataframe),
            SummaryStatisticsTablePlugin(dataframe),
        ]

    def set_dataframe(self, df: Any) -> None:
        """Set the dataframe for all plugins."""
        self.df = df
        for group in self.plot_groups.values():
            for p in group:  # type: ignore
                p.dataframe = df
        for t in self.tables:
            t.dataframe = df

    def get_categories(self) -> List[str]:
        """Get the list of plot categories."""
        return list(self.plot_groups.keys())

    def get_plots_in_category(self, category: str) -> List[str]:
        """Get the list of plot names in a given category."""
        return [p.name for p in self.plot_groups[category]]  # type: ignore

    def get_plot(self, name: str) -> Any:
        """Get a plot plugin by its name."""
        for group in self.plot_groups.values():
            for p in group:  # type: ignore
                if p.name == name:
                    return p
        raise KeyError(f"Plot {name} not found.")

    def get_table_names(self) -> List[str]:
        """Get the list of table names."""
        return [t.name for t in self.tables]

    def get_table(self, name: str) -> Any:
        """Get a table plugin by its name."""
        return next(t for t in self.tables if t.name == name)