%%
%% This is file `lwarp-statistics.sty',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% lwarp.dtx  (with options: `statistics')
%% This is a generated file.
%% Copyright 2016-2020 Brian Dunn
%% 
%% This work may be distributed and/or modified under the
%% conditions of the LaTeX Project Public License, either version 1.3
%% of this license or (at your option) any later version.
%% The latest version of this license is in
%%   http://www.latex-project.org/lppl.txt
%% and version 1.3 or later is part of all distributions of LaTeX
%% version 2005/12/01 or later.

\LWR@ProvidesPackagePass{statistics}[2019/09/29]
\ExplSyntaxOn
\StartDefiningTabulars%     lwarp
\cs_set_protected_nopar:Nn \__statistics_table_make:nn {
    \int_compare:nT
            { 0 < \l__statistics_table_maxcols_int
                = \l__statistics_nbvals_int } {
        \__statistics_table_end:
        \tl_use:N \l__statistics_table_sep_tl
        \__statistics_table_start:
    }
    \int_incr:N \l__statistics_nbvals_int
    \int_incr:N \l__statistics_currange_int
    \fp_add:Nn \l__statistics_curtotal_fp { #2 }
    \__statistics_set_if_shown:N \l_tmpa_bool
    \tl_set:Nx \l_tmpa_tl {
        \exp_not:n { & \tl_set:Nn \currentcolumn } {
            \int_use:N \l__statistics_currange_int
        }
    }
    \bool_if:NTF \l_tmpa_bool {
        \tl_put_right:Nn \l_tmpa_tl
            {\__statistics_table_shown_format:n}
    }{
        \tl_put_right:Nn \l_tmpa_tl
            {\__statistics_table_hidden_format:n}
    }
    \seq_put_right:Nn \l__statistics_store_values_seq { #1 }
    \bool_if:NT \l__statistics_table_values_bool {
        \tl_put_right:Nx \l__statistics_table_values_tl {
            \exp_not:V \l_tmpa_tl {
                \exp_not:n {
                    \__statistics_table_values_format:n { #1 }
                }
            }
        }
    }
    \seq_put_right:Nx \l__statistics_store_counts_seq { \fp_eval:n {#2} }
    \bool_if:NT \l__statistics_table_counts_bool {
        \tl_put_right:Nx \l__statistics_table_counts_tl {
            \exp_not:V \l_tmpa_tl {
                \exp_not:n {
                    \__statistics_table_counts_format:n {
                        { \__statistics_table_allcounts_format:n { #2 } }
                    }
                }
            }
        }
    }
    \bool_if:NT \l__statistics_table_icc_bool {
        \tl_put_right:Nx \l__statistics_table_icc_tl {
            \exp_not:V \l_tmpa_tl {
                \exp_not:n { \__statistics_table_icc_format:n }
                {
                    \exp_not:n{ \__statistics_table_allcounts_format:n }
                        { \fp_use:N \l__statistics_curtotal_fp }
                }
            }
        }
    }
    \bool_if:NT \l__statistics_table_dcc_bool {
        \tl_put_right:Nx \l__statistics_table_dcc_tl {
            \exp_not:V \l_tmpa_tl {
                \exp_not:n { \__statistics_table_dcc_format:n }
                {
                    \exp_not:n{ \__statistics_table_allcounts_format:n }
                    {
                        \fp_eval:n {
                            \l__statistics_total_fp
                                - \l__statistics_curtotal_fp
                                + #2
                        }
                    }
                }
            }
        }
    }
    \fp_set:Nn \l__statistics_table_curICF_fp {
        round(\l__statistics_curtotal_fp
                / \l__statistics_total_fp,
              \l__statistics_table_round_int)
    }
    \bool_if:NT \l__statistics_table_frequencies_bool {
        \tl_put_right:Nx \l__statistics_table_frequencies_tl {
            \exp_not:V \l_tmpa_tl {
                \exp_not:n { \__statistics_table_frequencies_format:n }
                {
                    \exp_not:n{ \__statistics_table_allfreqs_format:n }
                    {
                        \fp_eval:n {
                            \l__statistics_table_curICF_fp
                                - \l__statistics_table_prevICF_fp
                        }
                    }
                }
            }
        }
    }
    \bool_if:NT \l__statistics_table_icf_bool {
        \tl_put_right:Nx \l__statistics_table_icf_tl {
            \exp_not:V \l_tmpa_tl {
                \exp_not:n { \__statistics_table_icf_format:n }
                {
                    \exp_not:n{ \__statistics_table_allfreqs_format:n }
                        { \fp_to_decimal:N \l__statistics_table_curICF_fp }
                }
            }
        }
    }
    \bool_if:NT \l__statistics_table_dcf_bool {
        \tl_put_right:Nx \l__statistics_table_dcf_tl {
            \exp_not:V \l_tmpa_tl {
                \exp_not:n { \__statistics_table_dcf_format:n }
                {
                    \exp_not:n{ \__statistics_table_allfreqs_format:n }
                    {
                        \fp_eval:n {
                            1 - \l__statistics_table_prevICF_fp
                        }
                    }
                }
            }
        }
    }
    \fp_set_eq:NN
        \l__statistics_table_prevICF_fp
        \l__statistics_table_curICF_fp
}
\StopDefiningTabulars%  lwarp

\cs_set_protected_nopar:Nn \__statistics_table_end: {
    \tl_set:Nx \l__statistics_table_preamble_tl {
        \exp_not:n {\begin{tabular}[ }%      lwarp
            \exp_not:V \l__statistics_table_valign_tl
        \exp_not:n { ] }
                { \exp_not:V \l__statistics_table_headcoltype_tl
                  \prg_replicate:nn { \l__statistics_nbvals_int }
                    { \exp_not:V \l__statistics_table_coltype_tl } }
    }
    \seq_clear:N \l__statistics_table_contents_seq
    \clist_map_inline:nn { values, counts, icc, dcc, frequencies, icf, dcf } {
        \bool_if:cT { l__statistics_table_##1_bool } {
            \seq_put_right:Nv
                    \l__statistics_table_contents_seq
                    { l__statistics_table_##1_tl }
        }
    }
    \tl_use:N \l__statistics_table_preamble_tl
        \hline%      lwarp
        \seq_use:Nn
                \l__statistics_table_contents_seq
                { \l__statistics_table_newline_tl }
        \\
        \hline%      lwarp
    \end{tabular}%      lwarp
}

\cs_set_protected_nopar:Nn \__statistics_table_start: {
    \int_zero:N \l__statistics_nbvals_int
    \clist_pop:NNT \l__statistics_table_maxcols_clist \l_tmpa_tl {
        \int_set:Nn \l__statistics_table_maxcols_int { \l_tmpa_tl }
    }
    \clist_map_inline:nn { values, counts, frequencies, icc, icf, dcc, dcf } {
        \tl_set:cx { l__statistics_table_##1_tl } {
                \exp_not:N \hbox {
                    \exp_not:c { l__statistics_table_##1_name_tl }
                }
        }
    }
}

\RenewDocumentCommand \__statistics_IN:w { m u{;} u{;} m } {
    #1 #2 ; #3 #4%      lwarp
}

\__statistics_setup:nn { table } {
    values/format = {#1},%      lwarp
}
\RenewDocumentCommand \StatsGraph { +O{} +m +O{} } {
    \group_begin:
    \int_gincr:N \g__statistics_graph_last_int
    \tl_set:Nx \l_tmpa_tl {
        \exp_not:n { g__statistics_graph_xstep_ }
        \int_use:N \g__statistics_graph_last_int
        \exp_not:n { _tl }
    }
    \tl_if_exist:cTF { \l_tmpa_tl } {
        \fp_gset:Nn \g__statistics_graph_xstep_fp
            { \tl_use:c {\l_tmpa_tl} }
    }{
        \fp_gset:Nn \g__statistics_graph_xstep_fp { \c_one_int }
    }
    \__statistics_setup:nn { graph } { #1, #3 }
    \tl_if_single:nTF { #2 } {
        \cs_if_exist:NF #2 { #2 }
        \tl_set_eq:NN \l__statistics_data_tl #2
    }{
        \tl_set:Nn \l__statistics_data_tl { #2 }
    }
    \fp_zero:N \l__statistics_graph_maxheight_fp
    \fp_set:Nn \l__statistics_graph_minvalue_fp {inf}
    \fp_set:Nn \l__statistics_graph_maxvalue_fp {-inf}
    \fp_zero:N \l__statistics_total_fp
    \int_zero:N \l__statistics_nbvals_int
    \bool_set_true:N \l__statistics_graph_allranges_bool
    \keyval_parse:NNV
            \__statistics_graph_prepare:n
            \__statistics_graph_prepare:nn
            \l__statistics_data_tl
    \tl_clear:N \l__statistics_graph_tikzdata_tl
    \tl_clear:N \l__statistics_graph_tikzinfo_tl
    \int_zero:N \l__statistics_currange_int
    \bool_if:NTF \l__statistics_graph_allranges_bool {
        \bool_if:NTF \l__statistics_graph_cumulative_bool {
 \ExplSyntaxOn%     lwarp
            \__statistics_graph_dopicture_cumulative:
 \ExplSyntaxOff%    lwarp
        }{
 \ExplSyntaxOn%     lwarp
            \__statistics_graph_dopicture_hist:
 \ExplSyntaxOff%    lwarp
        }
    }{
 \ExplSyntaxOn%    lwarp
        \__statistics_graph_dopicture_comb:
 \ExplSyntaxOff%    lwarp
    }
    \iow_now:Nx \@auxout {
        \exp_not:n {
            \ExplSyntaxOn
            \tl_gset:cn
        }
        {
            \exp_not:n {g__statistics_graph_xstep_}
            \int_use:N \g__statistics_graph_last_int
            \exp_not:n {_tl}
        }
        {
            \fp_to_decimal:N \g__statistics_graph_xstep_fp
        }
        \exp_not:n {
            \ExplSyntaxOff
        }
    }
    \group_end:
}

\ExplSyntaxOff
\endinput
%%
%% End of file `lwarp-statistics.sty'.
