crate_activity/
cli.rs

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