NAME

Statistics::Covid::Analysis::Plot::Simple - Plots data

VERSION

Version 0.23

DESCRIPTION

This package contains routine(s) for plotting a number of Statistics::Covid::Datum objects using Chart::Clicker.

SYNOPSIS

        use Statistics::Covid;
        use Statistics::Covid::Datum;
        use Statistics::Covid::Utils;
        use Statistics::Covid::Analysis::Plot::Simple;
        
        # read data from db
        $covid = Statistics::Covid->new({   
                'config-file' => 't/config-for-t.json',
                'debug' => 2,
        }) or die "Statistics::Covid->new() failed";
        # retrieve data from DB for selected locations (in the UK)
        # data will come out as an array of Datum objects sorted wrt time
        # (the 'datetimeUnixEpoch' field)
        $objs = $covid->select_datums_from_db_for_specific_location_time_ascending(
                #{'like' => 'Ha%'}, # the location (wildcard)
                ['Halton', 'Havering'],
                #{'like' => 'Halton'}, # the location (wildcard)
                #{'like' => 'Havering'}, # the location (wildcard)
                'UK', # the belongsto (could have been wildcarded)
        );
        # create a dataframe
        $df = Statistics::Covid::Utils::datums2dataframe({
                'datum-objs' => $objs,
                # collect data from all those with same 'name' and same 'belongsto'
                # and plot this data as a single curve (or fit or whatever)
                'groupby' => ['name','belongsto'],
                # put only these values of the datum object into the dataframe
                # one of them will be X, another will be Y
                # if you want to plot multiple Y, then add here more dependent columns
                # like ('unconfirmed').
                'content' => ['confirmed', 'unconfirmed', 'datetimeUnixEpoch'],
        });

        # plot confirmed vs time
        $ret = Statistics::Covid::Analysis::Plot::Simple::plot({
                'dataframe' => $df,
                # saves to this file:
                'outfile' => 'confirmed-over-time.png',
                # plot this column against X
                # (which is not present and default is time ('datetimeUnixEpoch')
                'Y' => 'confirmed',
        });

        # plot confirmed vs unconfirmed
        # if you see a vertical line it means that your data has no 'unconfirmed'
        $ret = Statistics::Covid::Analysis::Plot::Simple::plot({
                'dataframe' => $df,
                # saves to this file:
                'outfile' => 'confirmed-vs-unconfirmed.png',
                'X' => 'unconfirmed',
                # plot this column against X
                'Y' => 'confirmed',
        });

        # plot using an array of datum objects as they came
        # out of the DB. A dataframe is created internally to the plot()
        # but this is not recommended if you are going to make several
        # plots because equally many dataframes must be created and destroyed
        # internally instead of recycling them like we do here...
        $ret = Statistics::Covid::Analysis::Plot::Simple::plot({
                'datum-objs' => $objs,
                # saves to this file:
                'outfile' => 'confirmed-over-time.png',
                # plot this column as Y
                'Y' => 'confirmed', 
                # X is not present so default is time ('datetimeUnixEpoch')
                # and make several plots, each group must have 'name' common
                'GroupBy' => ['name', 'belongsto'],
                'date-format-x' => {
                        # see Chart::Clicker::Axis::DateTime for all the options:
                        format => '%m', ##<<< specify timeformat for X axis, only months
                        position => 'bottom',
                        orientation => 'horizontal'
                },
        });


        # This is what the dataframe looks like (fictitious data):
        #  {
        #  Halton   => {
        #               confirmed => [0, 0, 3, 4, 4, 5, 7, 7, 7, 8, 8, 8],
        #               unconfirmed => [15, 15, 17, 17, 24, 29, 40, 45, 49, 54, 57, 80],
        #               datetimeUnixEpoch => [
        #                 1584262800,
        #                 1584349200,
        #                 1584435600,
        #                 1584522000,
        #                 1584637200,
        #                 1584694800,
        #                 1584781200,
        #                 1584867600,
        #                 1584954000,
        #                 1585040400,
        #                 1585126800,
        #                 1585213200,
        #               ],
        #             },
        #  Havering => {
        #               confirmed => [5, 5, 7, 7, 14, 19, 30, 35, 39, 44, 47, 70],
        #               unconfirmed => [15, 15, 17, 17, 24, 29, 40, 45, 49, 54, 57, 80],
        #               datetimeUnixEpoch => [
        #                 1584262800,
        #                 1584349200,
        #                 1584435600,
        #                 1584522000,
        #                 1584637200,
        #                 1584694800,
        #                 1584781200,
        #                 1584867600,
        #                 1584954000,
        #                 1585040400,
        #                 1585126800,
        #                 1585213200,
        #               ],
        #             },
        #  }

plot

Plots data to specified file using Chart::Clicker. The input data is either an array of Statistics::Covid::Datum objects or a dataframe (as created by Statistics::Covid::Utils::datums2dataframe (see the SYNOPSIS for examples). xxx

AUTHOR

Andreas Hadjiprocopis, <bliako at cpan.org>, <andreashad2 at gmail.com>

BUGS

This module has been put together very quickly and under pressure. There are must exist quite a few bugs.

Please report any bugs or feature requests to bug-statistics-Covid at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Statistics-Covid. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

SUPPORT

You can find documentation for this module with the perldoc command.

    perldoc Statistics::Covid::Analysis::Plot::Simple

You can also look for information at:

DEDICATIONS

Almaz

ACKNOWLEDGEMENTS

Perlmonks for supporting the world with answers and programming enlightment
DBIx::Class
the data providers:
John Hopkins University,
UK government,
https://www.bbc.co.uk (for disseminating official results)

LICENSE AND COPYRIGHT

Copyright 2020 Andreas Hadjiprocopis.

This program is free software; you can redistribute it and/or modify it under the terms of the the Artistic License (2.0). You may obtain a copy of the full license at:

http://www.perlfoundation.org/artistic_license_2_0

Any use, modification, and distribution of the Standard or Modified Versions is governed by this Artistic License. By using, modifying or distributing the Package, you accept this license. Do not use, modify, or distribute the Package, if you do not accept this license.

If your Modified Version has been derived from a Modified Version made by someone other than you, you are nevertheless required to ensure that your Modified Version complies with the requirements of this license.

This license does not grant you the right to use any trademark, service mark, tradename, or logo of the Copyright Holder.

This license includes the non-exclusive, worldwide, free-of-charge patent license to make, have made, use, offer to sell, sell, import and otherwise transfer the Package with respect to any patent claims licensable by the Copyright Holder that are necessarily infringed by the Package. If you institute patent litigation (including a cross-claim or counterclaim) against any party alleging that the Package constitutes direct or contributory patent infringement, then this Artistic License to you shall terminate on the date that such litigation is filed.

Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES. THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY YOUR LOCAL LAW. UNLESS REQUIRED BY LAW, NO COPYRIGHT HOLDER OR CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE OF THE PACKAGE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.