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); }
/// <summary> /// <para>Uses the supplied <see cref="MySqlDataManipulator"/> to add the setting to all of the specified targets</para> /// </summary> /// <param name="manipulator"></param> public override void PerformFunction(MySqlDataManipulator manipulator) { if (Target.Equals("user")) { var users = manipulator.GetUsersWhere("id > 0"); foreach (OverallUser user in users) { //Add the setting to the user if they do not already have a setting with the same key List <UserSettingsEntry> settings = JsonDataObjectUtil <List <UserSettingsEntry> > .ParseObject(user.Settings); bool found = false; foreach (UserSettingsEntry entry in settings) { if (entry.Key.Equals(Key)) { found = true; break; } } if (!found) { settings.Add(new UserSettingsEntry() { Key = Key, Value = Value }); user.Settings = JsonDataObjectUtil <List <UserSettingsEntry> > .ConvertObject(settings); if (!manipulator.UpdateUsersSettings(user)) { Console.WriteLine("Failed to update settings for user " + user.UserId); continue; } Console.WriteLine("Updated settings for user " + user.UserId); continue; } Console.WriteLine("User " + user.UserId + " already had a setting with key " + Key); } } else if (Target.Equals("company")) { var companies = manipulator.GetCompaniesWithNamePortion(""); foreach (CompanyId company in companies) { //Add the setting to the company if it does not already have one with the same key int companyId = company.Id; bool found = manipulator.GetCompanySettingsWhere(companyId, "SettingKey = \"" + Key + "\"").Count == 1; if (!found) { if (!manipulator.AddCompanySetting(companyId, new CompanySettingsEntry(Key, Value))) { Console.WriteLine("Company " + company.LegalName + " failed to have the setting added"); continue; } Console.WriteLine("Successfully added setting for company " + company.LegalName); continue; } Console.WriteLine("Company " + company.LegalName + " already had a setting with key " + Key); } } }
public override void PerformFunction(MySqlDataManipulator manipulator) { StreamReader fileReader = new StreamReader(FilePath); string jsonString = fileReader.ReadToEnd(); fileReader.Close(); List <RepairJobEntry> loadedData = JsonDataObjectUtil <List <RepairJobEntry> > .ParseObject(jsonString); foreach (RepairJobEntry entry in loadedData) { entry.Make = entry.Make.ToLower(); entry.Model = entry.Model.ToLower(); entry.Complaint = entry.Complaint.ToLower(); entry.Problem = entry.Problem.ToLower(); if (!manipulator.AddDataEntry(CompanyId, entry, validated: true)) { Console.WriteLine(JsonDataObjectUtil <RepairJobEntry> .ConvertObject(entry) + " was not added to the database"); } } }
public override void PerformFunction(MySqlDataManipulator manipulator) { //Convert all MechanicQueries to RepairJobEntries FileSystemDataSource dataSource = new FileSystemDataSource(); List <MechanicQuery> queries = dataSource.LoadMechanicQueries(); List <RepairJobEntry> toWrite = new List <RepairJobEntry>(); foreach (MechanicQuery query in queries) { RepairJobEntry toAdd = new RepairJobEntry() { Make = query.Make, Model = query.Model, Complaint = query.Complaint, Problem = query.Problem, JobId = "Unknown", Year = -1 }; toWrite.Add(toAdd); } //Write all RepairJobEntries to the specified file StreamWriter fileWriter = new StreamWriter(FilePath); //This is a CLI for devs, so no worries if this goes wonky fileWriter.WriteLine('['); foreach (RepairJobEntry entry in toWrite) { string entryJson = JsonDataObjectUtil <RepairJobEntry> .ConvertObject(entry); fileWriter.WriteLine(entryJson); } fileWriter.WriteLine(']'); fileWriter.Close(); }