예제 #1
0
파일: Program.cs 프로젝트: oswaldor/Plume
        /// <summary>
        /// Copy model files from current model repository to remote model repository (file share).
        /// </summary>
        private static void CopyModels(object needDeleteModel)
        {
            bool needDeleteFromLocal;

            if (!bool.TryParse(needDeleteModel.ToString(), out needDeleteFromLocal))
            {
                throw new Exception("Invalid value for boolean flag\"needDeleteModel\".");
            }

            string currentConfigFileForTest = "";

            while (IsRunning())
            {
                string configFileForTest;

                if (configFileQueue.TryPeek(out configFileForTest))
                {
                    // Make sure model files are ready.
                    while (!LDAModelStatusChecker.AreModelFilesReady(configFileForTest))
                    {
                        Thread.Sleep(5);
                        if (configFileForTest != currentConfigFileForTest)
                        {
                            StatusMessage.Write("Waiting for model under\r\n\t" + Path.GetDirectoryName(configFileForTest));
                            currentConfigFileForTest = configFileForTest;
                        }
                    }

                    if (configFileQueue.TryDequeue(out configFileForTest))
                    {
                        string sourceDir = Path.GetDirectoryName(configFileForTest);

                        string destinationDir = GetDestinationPathFromSourcePath(sourceDir, RemoteModelRepositoryPath);

                        StatusMessage.Write(string.Format("Copying model under\r\n\t{0}-->{1}", sourceDir, RemoteModelRepositoryPath), ConsoleColor.DarkGreen);
                        string message = FileManager.CopyDirectoryOrFile(sourceDir, destinationDir);
                        StatusMessage.Write(message, ConsoleColor.Green);
                        int retVal = int.Parse(message.Split('\t')[0]);

                        if (retVal == 0 && needDeleteFromLocal)
                        {
                            StatusMessage.Write(string.Format("Deleting directory\r\n\t{0}", sourceDir), ConsoleColor.DarkGreen);
                            ConsoleColor color;
                            message = FileManager.DeleteDirectory(sourceDir, out color);
                            StatusMessage.Write(message, color);
                        }
                    }
                }
            }

            // Tell main thread that all models listed in the queue have been copied.
            Interlocked.Decrement(ref flag);
        }
예제 #2
0
파일: Program.cs 프로젝트: oswaldor/Plume
        private static void ComputeMetrics(string commonParentOfModelDirs, int numOfThreads, ModelMetricTypes metricsType)
        {
            long i                   = 0;
            long oneHour             = 60 * 60 * 1000L;
            long numOfModelsMeasured = 0;

            while (true)
            {
                int numOfModelsDemanded = 0;
                // Find all LDAConfig files (.json)
                List <string> listOfLDAConfigFilesForTest = FileManager.SearchFileInDir(commonParentOfModelDirs, "*.LDAConfig.json");
                do
                {
                    // Find the models that are ready and need to compute metrics.
                    var configFilesReady = listOfLDAConfigFilesForTest.Where(configFile =>
                                                                             LDAModelStatusChecker.AreModelFilesReady(configFile) &&
                                                                             !LDAModelStatusChecker.HaveMetricsBeenComputed(configFile, TestSampleName, metricsType)).ToList();

                    if (configFilesReady.Count() == 0)
                    {
                        Thread.Sleep(1);
                        continue;
                    }

                    ComputeMetrics(configFilesReady, numOfThreads, metricsType, ref numOfModelsMeasured);

                    Thread.Sleep(1);

                    // Find the number of models that demand computation of metrics.
                    numOfModelsDemanded = listOfLDAConfigFilesForTest.Count(configFile => !LDAModelStatusChecker.HaveMetricsBeenComputed(configFile, TestSampleName, metricsType));
                } while (numOfModelsDemanded > 0);

                Thread.Sleep(1);
                if (i++ % oneHour == 0)
                {
                    // Display the message when the metrics thread has been idle for every hour.
                    StatusMessage.Write("Waiting for models to be ready...");
                }
            }
        }