crate_activity/
cli.rs

1crate::ix!();
2
3/// Crate Activity Analyzer
4#[derive(Getters,StructOpt, Debug)]
5#[structopt(name = "crate-activity")]
6pub struct CrateActivityCli {
7
8    /// Enable all analyses: correlations, PCA, hierarchical clustering, network analysis, etc.
9    #[structopt(long, help = "Enable all analyses at once")]
10    #[getset(get = "pub")]
11    all: bool,
12
13    /// Toggle to enable or disable correlation analysis
14    #[structopt(long, short = "c", help = "Display correlation analysis")]
15    #[getset(get = "pub")]
16    show_correlations: bool,
17
18    /// Toggle to enable or disable PCA analysis
19    #[structopt(long, short = "p", help = "Perform PCA analysis")]
20    #[getset(get = "pub")]
21    perform_pca: bool,
22
23    /// Toggle to enable hierarchical clustering
24    #[structopt(long, short = "h", help = "Perform hierarchical clustering")]
25    #[getset(get = "pub")]
26    perform_hierarchical_clustering: bool,
27
28    /// Toggle to enable correlation network analysis
29    #[structopt(long, short = "n", help = "Perform correlation network analysis")]
30    #[getset(get = "pub")]
31    correlation_network: bool,
32
33    /// Threshold for including edges in the correlation network graph
34    #[structopt(long, default_value = "0.7", help = "Correlation threshold for network edges")]
35    #[getset(get = "pub")]
36    network_threshold: f64,
37
38    /// Use Girvan–Newman algorithm to find a specified number of communities
39    #[structopt(long, short = "g", help = "Target number of communities for Girvan–Newman")]
40    #[getset(get = "pub")]
41    girvan_newman: Option<usize>,
42
43    /// Compute betweenness centrality for nodes (and edges) and display top nodes
44    #[structopt(long, short = "b", help = "Compute betweenness centrality and display top nodes")]
45    #[getset(get = "pub")]
46    compute_betweenness: bool,
47
48    /// Print a summary of the network graph
49    #[structopt(long, short = "s", help = "Print a summary of the network graph")]
50    #[getset(get = "pub")]
51    print_summary: bool,
52
53    /// Toggle to enable time-lagged correlation analysis
54    #[structopt(long, short = "t", help = "Compute time-lagged correlations")]
55    #[getset(get = "pub")]
56    time_lag_correlations: bool,
57
58    /// Maximum lag in days for time-lagged correlations
59    #[structopt(long, default_value = "7", help = "Maximum lag (in days) to consider for time-lag correlations")]
60    #[getset(get = "pub")]
61    max_lag: i32,
62
63    /// Z-score threshold for outlier detection (MAD-based)
64    #[structopt(long, default_value = "24.0", help = "Z-score threshold for outlier detection")]
65    #[getset(get = "pub")]
66    outlier_z_threshold: f64,
67
68    /// Downweight outliers instead of removing them
69    #[structopt(long, help = "Downweight outliers instead of removing them")]
70    #[getset(get = "pub")]
71    downweight_outliers: bool,
72
73    /// Factor by which to downweight outliers if --downweight-outliers is used
74    #[structopt(long, default_value = "0.1", help = "Downweight factor for outliers")]
75    #[getset(get = "pub")]
76    outlier_weight: f64,
77
78    /// Disable outlier handling altogether
79    #[structopt(long, help = "Disable outlier detection and handling")]
80    disable_outlier_handling: bool,
81}
82
83impl CrateActivityCli {
84
85    pub fn read_command_line() -> Self {
86        let mut cli = CrateActivityCli::from_args();
87        cli.apply_all_flag();
88        cli
89    }
90
91    pub fn disable_outlier_handling(&self) -> bool {
92
93        #[cfg(test)]
94        let disable_outliers_override = true; // Force no outliers in test
95
96        #[cfg(not(test))]
97        let disable_outliers_override = false;
98
99        let disable_outliers = self.disable_outlier_handling || disable_outliers_override;
100
101        disable_outliers
102    }
103
104    /// Apply the `--all` flag overrides if set.
105    pub fn apply_all_flag(&mut self) {
106        if self.all {
107            self.show_correlations = true;
108            self.perform_pca = true;
109            self.perform_hierarchical_clustering = true;
110            self.correlation_network = true;
111            self.compute_betweenness = true;
112            self.print_summary = true;
113            self.time_lag_correlations = true;
114            // You might leave outlier handling as is or also enable/disable it if desired.
115        }
116    }
117}