#!/usr/bin/perl
use strict;
use warnings;
use Digest::MD5 qw(md5 md5_hex md5_base64);
use MIME::Parser;
use MIME::Entity;
use MIME::Body;
use Getopt::Long;
use lib qw(Core);
use lib qw(Classes);
use Configuration;
use LocalConfiguration;
use Submission;
use Logger;
use StatusManager;

my $SCRIPTNAME = 'generate_cleaned_predictions.pl';

#my $logger = new Logger();
my $status_manager = new StatusManager();
my $submission = new Submission();
my $groups_manager = new GroupsManager();

#1 Do select from prediction_status_log for all wher recalculate status is 0 and group_id <> 0
#my @predictions_log = $status_manager->all_predictions_log('','','',1,'','','accepted', '','','');

my @predictions_log = $status_manager->all_predictions_log('','','',19,'1bf92b64bdcad8141ec1d1d51e49b66b','','accepted', '','','');

#2 Calculate prediction just for new submissions
for(my $count = 0; $count < scalar(@predictions_log); $count++) {


	$submission->{_groups_name} =  $groups_manager->name($predictions_log[$count]->{GROUP_ID});
print "GROUPNAME is:" . $submission->{_groups_name} . "\n";	
$submission->{_pfrmat} = $predictions_log[$count]->{PFRMAT};
	$submission->{_target} = $predictions_log[$count]->{TARGET_NAME};
	#$self->calculate_satus($predictions_log[$count]->{GROUP_ID}, $predictions_log[$count]->{TARGET_NAME}, $predictions_log[$count]->{TARGET_ID});
	my $accepted_file = sprintf("%s/%s", $LOCAL_CONFIG->{ACCEPTED_PREDICTIONS_DIR}, $predictions_log[$count]->{FILE_NAME});
	$submission->create_clean_model($predictions_log[$count]->{MODEL}, $accepted_file);
	print $accepted_file . "\n";
}
