NAME DateTime::Event::Predict - Predict new dates from a set of dates SYNOPSIS Given a set of dates this module will predict the next date or dates to follow. use DateTime::Event::Predict; my $dtp = DateTime::Event::Predict->new( profile => { buckets => ['day_of_week'], }, ); # Add today's date: 2009-12-17 my $date = new DateTime->today(); $dtp->add_date($date); # Add the previous 14 days for (1 .. 14) { my $new_date = $date->clone->add( days => ($_ * -1), ); $dtp->add_date($new_date); } # Predict the next date my $predicted_date = $dtp->predict; print $predicted_date->ymd; # 2009-12-18 Here we create a new "DateTime" object with today's date (it being December 17th, 2009 currently). We then use add_date to add it onto the list of dates that "DateTime::Event::Predict" (DTP) will use to make the prediction. Then we take the 14 previous days (December 16-2) and them on to same list one by one. This gives us a good set to make a prediction out of. Finally we call predict which returns a "DateTime" object representing the date that DTP has calculated will come next. HOW IT WORKS Predicting the future is not easy, as anyone except, perhaps, Nostradamus will tell you. Events can occur with perplexing randomness and discerning any pattern in the noise is nigh unpossible. However, if you have a set of data to work with that you know for certain contains some sort of regularity, and you have enough information to discover that regularity, then making predictions from that set can be possible. The main issue with our example above is the tuning we did with this sort of information. When you configure your instance of DTP, you will have to tell what sorts of date-parts to keep track of so that it has a good way of making a prediction. Date-parts can be things like "day of the week", "day of the year", "is a weekend day", "week on month", "month of year", differences between dates counted by "week", or "month", etc. Dtpredict will collect these identifiers from all the provided dates into "buckets" for processing later on. EXAMPLES Predicting Easter Predicting METHODS new Constructor my $dtp = DateTime::Event::Predict->new(); dates Arguments: none | \@dates Return value: \@dates Called with no argument this method will return an arrayref to the list of the dates currently in the instance. Called with an arrayref to a list of DateTime objects ("\@dates") this method will set the dates for this instance to "\@dates". add_date Arguments: $date Return value: Adds a date on to the list of dates in the instance, where $date is a DateTime object. profile Arguments: $profile Set the profile for which date-parts will be # Pass in preset profile by name $dtp->profile( profile => 'default' ); $dtp->profile( profile => 'holiday' ); # Create a new profile my $profile = new DateTime::Event::Predict::Profile( buckets => [qw/ minute hour day_of_week day_of_month /], ); $dtp->profile( profile => $profile ); Provided profiles The following profiles are provided for use by-name: predict Arguments: %options Return Value: $next_date | @next_dates Predict the next date(s) from the dates supplied. my $predicted_date = $dtp->predict(); If list context "predict" returns a list of all the predictions, sorted by their probability: my @predicted_dates = $dtp->predict(); The number of prediction can be limited with the "max_predictions" option. Possible options $dtp->predict( max_predictions => 4, # Once 4 predictions are found, return back callbacks => [ sub { return ($_->second % 4) ? 0 : 1 } # Only predict dates with second values that are divisible by four. ], ); max_predictions Maximum number of predictions to find. callbacks Arrayref of subroutine callbacks. If any of them return a false value the date will not be returned as a prediction. train Train this instance of DTP TODO * It would be be cool if you could pass your own buckets in with a certain type, so you could, say, look for recurrence based on intervals of 6 seconds, or 18 days, whatever. * We need to be able to handle recording more than one interval per diff. If the dates are all offset from each other by 1 day 6 hours (May 1, 3:00; May 2, 6:00), we can't be predicting a new date that's exactly 1 day after the most recent one. ^ The best way to do this is probably to record intervals as epoch seconds, so everything is taken into account. Maybe record epoch seconds in addition to whole regular intervals like days & hours. AUTHOR Brian Hann, "" BUGS Please report any bugs or feature requests to "bug-datetime-event-predict at rt.cpan.org", or through the web interface at . 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 DateTime::Event::Predict You can also look for information at: * RT: CPAN's request tracker * AnnoCPAN: Annotated CPAN documentation * CPAN Ratings * Search CPAN COPYRIGHT & LICENSE Copyright 2009 Brian Hann, all rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. SEE ALSO DateTime, DateTime::Event::Predict::Profile