lawkit_python/subcommands/
analyze.rs1use crate::common_options;
2use crate::subcommands::integration_common::{
3 get_dataset_name, get_numbers_from_input, output_integration_result,
4};
5use clap::{ArgMatches, Command};
6use lawkit_core::common::output::{create_output_writer, OutputConfig};
7use lawkit_core::error::Result;
8use lawkit_core::laws::integration::{
9 analyze_all_laws, analyze_selected_laws, apply_focus_analysis, compare_laws,
10};
11
12pub fn command() -> Command {
13 common_options::add_integration_options(common_options::add_common_options(
14 common_options::add_input_arg(
15 Command::new("analyze").about("複数の統計法則による基本分析"),
16 ),
17 ))
18}
19
20pub fn run(matches: &ArgMatches) -> Result<()> {
21 let numbers = get_numbers_from_input(matches)?;
22 let dataset_name = get_dataset_name(matches);
23
24 let result = if let Some(laws_str) = matches.get_one::<String>("laws") {
25 let selected_laws: Vec<String> =
26 laws_str.split(',').map(|s| s.trim().to_string()).collect();
27 let mut result = analyze_selected_laws(&numbers, &dataset_name, &selected_laws)?;
28
29 if let Some(focus) = matches.get_one::<String>("focus") {
31 apply_focus_analysis(&mut result, focus);
32 }
33
34 result
35 } else if let Some(focus) = matches.get_one::<String>("focus") {
36 compare_laws(&numbers, &dataset_name, Some(focus))?
37 } else {
38 analyze_all_laws(&numbers, &dataset_name)?
39 };
40
41 let mut writer = create_output_writer(matches)?;
42 let output_config = OutputConfig::from_matches(matches);
43
44 output_integration_result(&mut writer, &result, &output_config)?;
45
46 std::process::exit(result.risk_level.exit_code());
47}