}
);
+__PACKAGE__->register_method(
+ method => 'make_prediction_values',
+ api_name => 'open-ils.serial.make_prediction_values',
+ api_level => 1,
+ argc => 1,
+ signature => {
+ desc => 'Receives an ssub id and returns objects that can be used to populate the issuance and item tables',
+ 'params' => [ {
+ name => 'ssub_id',
+ desc => 'Serial Subscription ID',
+ type => 'int'
+ }
+ ]
+ }
+);
+
sub make_predictions {
my ($self, $conn, $authtoken, $args) = @_;
- my $editor = OpenILS::Utils::CStoreEditor->new();
my $ssub_id = $args->{ssub_id};
- my $mfhd = MFHD->new(MARC::Record->new());
+ my $editor = OpenILS::Utils::CStoreEditor->new();
my $ssub = $editor->retrieve_serial_subscription([$ssub_id]);
- my $scaps = $editor->search_serial_caption_and_pattern({ subscription => $ssub_id, active => 't'});
my $sdists = $editor->search_serial_distribution( [{ subscription => $ssub->id }, { flesh => 1, flesh_fields => {sdist => [ qw/ streams / ]} }] ); #TODO: 'deleted' support?
+ return store_predictions(
+ $self, $conn, $authtoken, $args, $ssub, $sdists,
+ make_prediction_values($self, $conn, $authtoken, $args, $ssub, $sdists, $editor)
+ );
+}
+
+sub make_prediction_values {
+ my ($self, $conn, $authtoken, $args, $ssub, $sdists, $editor) = @_;
+
+ my $ssub_id = $args->{ssub_id};
+
+ $editor ||= OpenILS::Utils::CStoreEditor->new();
+ $ssub ||= $editor->retrieve_serial_subscription([$ssub_id]);
+ $sdists ||= $editor->search_serial_distribution( [{ subscription => $ssub->id }, { flesh => 1, flesh_fields => {sdist => [ qw/ streams / ]} }] ); #TODO: 'deleted' support?
+
+ my $scaps = $editor->search_serial_caption_and_pattern({ subscription => $ssub_id, active => 't'});
+ my $mfhd = MFHD->new(MARC::Record->new());
+
my $total_streams = 0;
foreach (@$sdists) {
$total_streams += scalar(@{$_->streams});
my $options = {
'caption' => $caption_field,
'scap_id' => $scap->id,
+ 'include_base_issuance' => $args->{include_base_issuance},
'num_to_predict' => $args->{num_to_predict},
'end_date' => defined $args->{end_date} ?
$_strp_date->parse_datetime($args->{end_date}) : undef
$link_id++;
}
+ return @predictions;
+}
+
+sub store_predictions {
+ my ($self, $conn, $authtoken, $args, $ssub, $sdists, @predictions) = @_;
+
my @issuances;
foreach my $prediction (@predictions) {
my $issuance = new Fieldmapper::serial::issuance;
my ($mfhd, $options) = @_;
my $caption = $options->{caption};
my $scap_id = $options->{scap_id};
+ my $include_base_issuance = $options->{include_base_issuance};
my $num_to_predict = $options->{num_to_predict};
my $end_date = $options->{end_date};
my $predict_from = $options->{predict_from}; # MFHD::Holding to predict from
$predict_from = new MFHD::Holding($predict_from->seqno, new MARC::Field($predict_from->tag, $predict_from->indicator(1), $predict_from->indicator(2), $predict_from->subfields_list), $faked_caption);
}
- my @predictions = $mfhd->generate_predictions({'base_holding' => $predict_from, 'num_to_predict' => $num_to_predict, 'end_date' => $end_date});
+ my @predictions = $mfhd->generate_predictions({
+ 'include_base_issuance' => $include_base_issuance,
+ 'base_holding' => $predict_from,
+ 'num_to_predict' => $num_to_predict,
+ 'end_date' => $end_date
+ });
my $pub_date;
my @issuance_values;
# generate_predictions()
# Accepts a hash ref of options initially defined as:
# base_holding : reference to the holding field to predict from
+# include_base_issuance : whether to "predict" the startting holding, so as to generate a label for it
# num_to_predict : the number of issues you wish to predict
# OR
# end_holding : holding field ref, keep predicting until you meet or exceed it
my $end_holding = $options->{end_holding};
my $end_date = $options->{end_date};
my $max_to_predict = $options->{max_to_predict} || 10000; # fail-safe
+ my $include_base_issuance = $options->{include_base_issuance};
if (!defined($base_holding)) {
carp("Base holding not defined in generate_predictions, returning empty set");
my $curr_holding = $base_holding->clone; # prevent side-effects
my @predictions;
+ push(@predictions, $curr_holding) if ($include_base_issuance);
if ($num_to_predict) {
for (my $i = 0; $i < $num_to_predict; $i++) {