private void SaveTaskResults(string taskName, int datasetId, int taskId)
        {
            var resultsFile           = _lmConnector.GetTaskResultsFile(taskName);
            var pmmlService           = new PmmlService(_configuration, resultsFile);
            var dimensionValues       = _data.GetAllDimensionValues(datasetId);
            var measures              = _data.GetAllMeasures(datasetId);
            var rules                 = pmmlService.GetRules(dimensionValues, measures);
            var postprocessedRules    = _pruner.PruneRules(rules);
            var taskDuration          = pmmlService.GetTaskDuration();
            var numberOfVerifications = pmmlService.GetNumberOfVerifications();

            _data.SaveTaskResults(taskId, postprocessedRules, numberOfVerifications, taskDuration);
        }
예제 #2
0
 public bool SendPreprocessing(string userId, MiningTask task, XmlDocument preprocessingPmml, HttpClient client = null)
 {
     if (client == null)
     {
         client = new HttpClient();
     }
     using (client)
     {
         client.Timeout = TimeSpan.FromMinutes(10);
         var method        = new HttpMethod("PATCH");
         var stringContent = new StringContent(preprocessingPmml.OuterXml);
         var request       = new HttpRequestMessage(method, GetSendPreprocessingAddress(task.DataSet.MinerId))
         {
             Content = stringContent
         };
         try
         {
             var response       = client.SendAsync(request).Result;
             var responseString = response.Content.ReadAsStringAsync().Result;
             if (response.StatusCode == HttpStatusCode.InternalServerError || response.StatusCode == HttpStatusCode.NotFound)
             {
                 if (responseString.Contains("Requested LISpMiner with ID") && responseString.Contains("does not exists"))
                 {
                     var minerId = PmmlService.GetMinerId(GetMinerId(userId, task));
                     _data.SetMinerId(userId, task.DataSet.Id, minerId);
                     task.DataSet.MinerId = minerId;
                     return(SendPreprocessing(userId, task, preprocessingPmml, null));
                 }
                 _data.SetTaskState(userId, task.Id, (int)TaskState.Failed, responseString);
                 return(false);
             }
         }
         catch (TaskCanceledException e)
         {
             _data.SetTaskState(userId, task.Id, (int)TaskState.Failed, "Connection to Lisp Miner timed out after 10 minutes.");
             return(false);
         }
     }
     _data.SetPreprocessed(task.DataSet.Id);
     return(true);
 }
예제 #3
0
 public bool SendTask(string userId, MiningTask task, XmlDocument taskPmml, XmlDocument preprocessingPmml)
 {
     using (var client = new HttpClient())
     {
         client.Timeout = TimeSpan.FromMinutes(10);
         var stringContent = new StringContent(taskPmml.OuterXml);
         try
         {
             var response       = client.PostAsync(GetSendTaskAddress(task.DataSet.MinerId), stringContent).Result;
             var responseString = response.Content.ReadAsStringAsync().Result;
             if (response.StatusCode != HttpStatusCode.OK)
             {
                 if (responseString.Contains("Requested LISpMiner with ID") && responseString.Contains("does not exists"))
                 {
                     var minerId = PmmlService.GetMinerId(GetMinerId(userId, task));
                     _data.SetMinerId(userId, task.DataSet.Id, minerId);
                     task.DataSet.MinerId = minerId;
                     var preprocessed = SendPreprocessing(userId, task, preprocessingPmml);
                     return(preprocessed && SendTask(userId, task, taskPmml, preprocessingPmml));
                 }
                 _data.SetTaskState(userId, task.Id, (int)TaskState.Failed, responseString);
                 return(false);
             }
             else
             {
                 File.WriteAllText(GetTaskResultsFileName(task.Name), responseString);
                 return(true);
             }
         }
         catch (TaskCanceledException e)
         {
             _data.SetTaskState(userId, task.Id, (int)TaskState.Failed, "Connection to Lisp Miner timed out after 10 minutes.");
             return(false);
         }
     }
 }
        private void SendToLispMinerAsync(string userId, MiningTask task,
                                          List <Discretization> discretizations, int rowCount, List <EquivalencyClass> eqClasses)
        {
            var  service      = new PmmlService(_configuration);
            var  minerId      = task.DataSet.MinerId;
            bool?preprocessed = null;

            if (minerId == null)
            {
                preprocessed = false;
                var minerIdResponse = _lmConnector.GetMinerId(userId, task);
                var newMinerId      = PmmlService.GetMinerId(minerIdResponse);
                if (newMinerId == null)
                {
                    _data.SetTaskState(userId, task.Id, (int)TaskState.Failed,
                                       "OLAP Recommender was unable to obtain miner id from LISP Miner. Response: " + minerIdResponse);
                    return;
                }
                else
                {
                    task.DataSet.MinerId = newMinerId;
                    _data.SetMinerId(userId, task.DataSet.Id, newMinerId);
                }
            }
            if (preprocessed == null)
            {
                preprocessed = task.DataSet.Preprocessed;
            }
            var preprocessingPmml = service.GetPreprocessingPmml(task, discretizations, rowCount);

            if ((bool)!preprocessed)
            {
                preprocessed = _lmConnector.SendPreprocessing(userId, task, preprocessingPmml);
            }
            if ((bool)preprocessed)
            {
                var taskPmml = service.GetTaskPmml(task, eqClasses, rowCount);
                while (true)
                {
                    var responseOk = _lmConnector.SendTask(userId, task, taskPmml, preprocessingPmml);
                    if (responseOk)
                    {
                        var resultsFile   = _lmConnector.GetTaskResultsFile(task.Name);
                        var resultService = new PmmlService(_configuration, resultsFile);
                        var taskState     = resultService.GetTaskState();
                        if (taskState == TaskState.Started)
                        {
                            Thread.Sleep(TimeSpan.FromMinutes(2));
                        }
                        else if (taskState == TaskState.Finished)
                        {
                            _data.SetTaskState(userId, task.Id, (int)TaskState.Finished);
                            SaveTaskResults(task.Name, task.DataSet.Id, task.Id);
                            break;
                        }
                        else if (taskState == TaskState.Interrupted)
                        {
                            _data.SetTaskState(userId, task.Id, (int)TaskState.Interrupted, "Hypotheses count too high, define higher Lift or Base to obtain less rules.");
                            SaveTaskResults(task.Name, task.DataSet.Id, task.Id);
                            break;
                        }
                        else
                        {
                            _data.SetTaskState(userId, task.Id, (int)TaskState.Failed, "Task failed due to an unknown reason in Lisp Miner.");
                            break;
                        }
                    }
                    else
                    {
                        break;
                    }
                }
            }
        }