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    #[structopt(long, help = "If true, we will print each individual crate per group")]
87    #[getset(get="pub")]
88    expand_groups: bool,
89
90    #[structopt(long, default_value = "2", help = "Minimum group size required to treat them as a group")]
91    #[getset(get="pub")]
92    min_group_size: usize,
93
94    #[structopt(long, short = "v", help = "Enable tracing")]
95    #[getset(get="pub")]
96    verbose: bool,
97}
98
99impl CrateActivityCli {
100
101    pub fn read_command_line() -> Self {
102        let mut cli = CrateActivityCli::from_args();
103        cli.apply_all_flag();
104        cli
105    }
106
107    pub fn disable_outlier_handling(&self) -> bool {
108
109        #[cfg(test)]
110        let disable_outliers_override = true; // Force no outliers in test
111
112        #[cfg(not(test))]
113        let disable_outliers_override = false;
114
115        let disable_outliers = self.disable_outlier_handling || disable_outliers_override;
116
117        disable_outliers
118    }
119
120    /// Apply the `--all` flag overrides if set.
121    pub fn apply_all_flag(&mut self) {
122        if self.all {
123            self.show_correlations = true;
124            self.perform_pca = true;
125            self.perform_hierarchical_clustering = true;
126            self.correlation_network = true;
127            self.compute_betweenness = true;
128            self.print_summary = true;
129            self.time_lag_correlations = true;
130            // You might leave outlier handling as is or also enable/disable it if desired.
131        }
132    }
133}