public override void PerformFunction(MySqlDataManipulator manipulator)
        {
            //Ensure that all KeywordPredictor models are loaded
            //If one is not, then a company requesting that model through its settings will cause an error
            if (!GlobalModelHelper.LoadOrTrainGlobalModels(ReflectionHelper.GetAllKeywordPredictors()))
            {
                throw new NullReferenceException("One or more global models failed to load. Server cannot start.");
            }
            DatabaseQueryProcessor processor = new DatabaseQueryProcessor(DatabaseQueryProcessorSettings.RetrieveCompanySettings(manipulator, CompanyId));

            List <RepairJobEntry> validatedData = manipulator.GetDataEntriesWhere(CompanyId, "id > 0", validated: true);
            List <string>         sentences;

            if (Flag.ToLower().Equals("complaint"))
            {
                //train model
                sentences = validatedData.Select(entry => entry.Complaint).ToList();
                if (!processor.TrainClusteringModels(manipulator, CompanyId, sentences, false))
                {
                    Console.WriteLine("Failed to train problem prediction models for company " + CompanyId);
                    return;
                }
                //register the complaint groups that the clusterer predicts with the repair job entry in the database
                foreach (RepairJobEntry entry in validatedData)
                {
                    string groups = JsonDataObjectUtil <List <int> > .ConvertObject(processor.PredictGroupsInJobData(entry, CompanyId, manipulator));

                    entry.ComplaintGroups = groups;
                    manipulator.UpdateDataEntryGroups(CompanyId, entry, complaint: true);
                }
            }
            Console.WriteLine("Trained clustering models for company " + CompanyId);
        }
示例#2
0
        static void Main(string[] args)
        {
            Console.WriteLine(DateTime.Now.ToLocalTime().ToString());
            DatabaseConfigurationFileContents config;

            try
            {
                config = RetrieveConfiguration();
            } catch (ThreadInterruptedException)
            {
                return;
            }
            if (config == null)
            {
                Console.WriteLine("Failed to retrieve or restore database configuration file. Exiting");
                return;
            }
            bool res = MySqlDataManipulator.GlobalConfiguration.Connect(new MySqlConnectionString(config.Host, config.Database, config.User).ConstructConnectionString(config.Pass.ConvertToString()));

            if (!res && MySqlDataManipulator.GlobalConfiguration.LastException.Number != 1049 && MySqlDataManipulator.GlobalConfiguration.LastException.Number != 0)
            {
                Console.WriteLine("Encountered an error opening the global configuration connection");
                Console.WriteLine(MySqlDataManipulator.GlobalConfiguration.LastException.Message);
                return;
            }
            if (!MySqlDataManipulator.GlobalConfiguration.ValidateDatabaseIntegrity(new MySqlConnectionString(config.Host, null, config.User).ConstructConnectionString(config.Pass.ConvertToString()), config.Database))
            {
                Console.WriteLine("Encountered an error opening the global configuration connection");
                Console.WriteLine(MySqlDataManipulator.GlobalConfiguration.LastException.Message);
                return;
            }
            MySqlDataManipulator.GlobalConfiguration.Close();
            CommandLineArgumentParser parser = new CommandLineArgumentParser(args);

            MySqlDataManipulator.GlobalConfiguration.Connect(new MySqlConnectionString(config.Host, config.Database, config.User).ConstructConnectionString(config.Pass.ConvertToString()));
            config.Pass.Dispose();
            config = null;
            bool exit = DatabaseEntityCreationUtilities.PerformRequestedCreation(MySqlDataManipulator.GlobalConfiguration, parser);

            MySqlDataManipulator.GlobalConfiguration.Close();
            if (exit)
            {
                return;
            }
            if (!GlobalModelHelper.LoadOrTrainGlobalModels(ReflectionHelper.GetAllKeywordPredictors()))
            {
                throw new NullReferenceException("One or more global models failed to load. Server cannot start.");
            }
            else if (AveragedPerceptronTagger.GetTagger() == null)
            {
                throw new NullReferenceException("Failed to load the Averaged Perceptron Tagger");
            }
            Logger.GetLogger(Logger.LoggerDefaultFileLocations.DEFAULT).Log(Logger.LogLevel.INFO, "Server is starting up");
            using (Logger.Disposer)
            {
                Thread t = new Thread(RenewCertificate);
                t.Start();
                Thread train = new Thread(PerformTraining);
                train.Start();
                var server = ApiLoader.LoadApiAndListen(16384);
                while (server.IsAlive)
                {
                    Thread.Sleep(100);
                    if (Console.KeyAvailable)
                    {
                        ConsoleKeyInfo key = Console.ReadKey(true);
                        if (key.Key == ConsoleKey.Enter)
                        {
                            server.Close();
                        }
                    }
                }
                t.Interrupt();
                train.Interrupt();
            }
            //QueryProcessor processor = new QueryProcessor(QueryProcessorSettings.GenerateDefaultSettings());
            //processor.ProcessQuery(new Util.MechanicQuery("autocar", "xpeditor", null, null, "runs rough"));
        }
示例#3
0
        public static bool InitializeDatabaseSchema()
        {
            if (DatabaseInitialized)
            {
                return(true);
            }
            MySqlDataManipulator manipulator = new MySqlDataManipulator();

            using (manipulator)
            {
                if (!manipulator.Connect(TestingConstants.DatabaselessConnectionString))
                {
                    Console.WriteLine("Encountered an error opening the global configuration connection");
                    Console.WriteLine(manipulator.LastException.Message);
                    return(false);
                }
                if (!manipulator.ValidateDatabaseIntegrity(TestingConstants.DatabaselessConnectionString, "db_test"))
                {
                    Console.WriteLine("Encountered an error opening the global configuration connection");
                    Console.WriteLine(manipulator.LastException.Message);
                    return(false);
                }
                if (!manipulator.Connect(TestingConstants.ConnectionString))
                {
                    Console.WriteLine("Encountered an error opening the global configuration connection");
                    Console.WriteLine(manipulator.LastException.Message);
                    return(false);
                }
                if (manipulator.GetCompanyById(1) == null)
                {
                    if (!manipulator.AddCompany(TestingCompanyStorage.ValidCompany1))
                    {
                        Console.WriteLine("Encountered an error adding the first valid company");
                        Console.WriteLine(manipulator.LastException.Message);
                        return(false);
                    }
                }
                if (manipulator.GetCompanyById(2) == null)
                {
                    if (!manipulator.AddCompany(TestingCompanyStorage.ValidCompany2))
                    {
                        Console.WriteLine("Encountered an error adding the second valid company");
                        Console.WriteLine(manipulator.LastException.Message);
                        return(false);
                    }
                }
                DatabaseInitialized = true;
                if (!InitializeUsers())
                {
                    return(false);
                }
                if (!InitializeJoinRequests())
                {
                    return(false);
                }
                if (!InitializePartCatelogueEntries())
                {
                    return(false);
                }
                if (!InitializePartsRequests())
                {
                    return(false);
                }
                if (!GlobalModelHelper.LoadOrTrainGlobalModels(ReflectionHelper.GetAllKeywordPredictors()))
                {
                    return(false);
                }
            }
            MySqlDataManipulator.GlobalConfiguration.Connect(TestingConstants.ConnectionString);
            MySqlDataManipulator.GlobalConfiguration.Close();
            return(true);
        }