public async Task <ActionResult> GetAnomalyDetail(int AnomalyId) { var anomaly = await _prepareService.GetAnomaly(AnomalyId); var model = new AnomalyViewModel { AnomalyId = anomaly.Id, Category = anomaly.Category, Date = anomaly.Date, Description = anomaly.Description, HasPhoto = anomaly.Photo != null ? true : false, Photo = anomaly.Photo == null ? "" : string.Format("data:image/gif;base64,{0}", Convert.ToBase64String(anomaly.Photo)), Label = anomaly.Label, Line = anomaly.Line, Machine = anomaly.Machine, Priority = (int)anomaly.Priority.Value, Type = (int)anomaly.Type, TypeLabel = anomaly.Type.AnomalyTypeToString(), TypeColor = anomaly.Type == AnomalyType.Security ? "green" : anomaly.Type == AnomalyType.Maintenance ? "red" : anomaly.Type == AnomalyType.Operator ? "blue" : "gray" }; model.PriorityLists = new List <Tuple <int, string> > { new Tuple <int, string>(1, "A"), new Tuple <int, string>(2, "B"), new Tuple <int, string>(3, "C") }; model.KindItems = new List <IAnomalyKindItem>(); model.KindItems = Anomalies.GetPossibleAnomalies(anomaly.Type); return(PartialView("AnomalyDetail", model)); }
private static void ImportAnomalies() { var context = new MassDefectContext(); var json = File.ReadAllText(AnomaliesPath); var anomalies = JsonConvert.DeserializeObject <IEnumerable <AnomalyDTO> >(json); foreach (var anomaly in anomalies) { if (anomaly.OriginPlanet == null || anomaly.TeleportPlanet == null) { throw new ArgumentException("Error: Invalid data."); continue; } var anomalyEntity = new Anomalies() { //OriginPlanet = context.Anomalies.Select(orp => orp.OriginPlanet.Name), //TeleportPlanet = context.Anomalies.Select(tpl => tpl.TeleportPlanet.Name) }; context.Anomalies.Add(anomalyEntity); System.Console.WriteLine($"Successfully imported {anomalyEntity} {anomalyEntity.OriginPlanet} {anomalyEntity.TeleportPlanet}."); } context.SaveChanges(); }
/// <summary> /// Determines whether the given folder contains only the given files, and no others /// </summary> /// <returns></returns> protected bool FolderContainsExclusive(string relFolderPath, IEnumerable<string> filenames, Anomalies anomalies = null) { var dirPath = Path.Combine(this.TargetDir, relFolderPath); var exists = Directory.Exists(dirPath); if (!exists) { return false; } else { var folderFiles = new DirectoryInfo(dirPath).GetFiles(); var filesInFolder = folderFiles.Select(f => f.Name).Except(filenames).ToList(); var expectedFiles = filenames.Except(folderFiles.Select(f => f.Name)).ToList(); if (anomalies != null) { anomalies.ExpectedFiles.AddRange(expectedFiles); anomalies.UnexpectedFiles.AddRange(filesInFolder); } return !(filesInFolder.Any()) && !(expectedFiles.Any()); } }
private static void ImportAnomalies() { var context = new MassDefectContext(); var json = File.ReadAllText(AnomaliesPath); var anomalies = JsonConvert.DeserializeObject <IEnumerable <AnomaliesDTO> >(json); foreach (var anomaly in anomalies) { if (anomaly.OriginPlanet == null || anomaly.TeleportPlanet == null) { RaiseError(); continue; } var anomalyEntity = new Anomalies { OriginPlanet = GetOriginPlanet(anomaly.OriginPlanet, context), TeleportPlanet = GetTeleportPlanet(anomaly.TeleportPlanet, context) }; if (anomalyEntity.TeleportPlanet == null || anomalyEntity.OriginPlanet == null) { RaiseError(); continue; } context.Anomalies.Add(anomalyEntity); Console.WriteLine($"Successfully imported anomaly."); } context.SaveChanges(); }
private static void ImportAnomalyAndVictims(XElement anomalyNode, MassDefectContext context) { var originPlanetName = anomalyNode.Attribute("origin-planet"); var teleportPlanetName = anomalyNode.Attribute("teleport-planet"); if (originPlanetName == null || teleportPlanetName == null) { RaiseError(); return; } //might check the .values tho var anomalyEntity = new Anomalies { OriginPlanet = GetPlanetByName(originPlanetName.Value, context), TeleportPlanet = GetPlanetByName(teleportPlanetName.Value, context) }; if (anomalyEntity.OriginPlanet == null || anomalyEntity.TeleportPlanet == null) { RaiseError(); } var victims = anomalyNode.XPathSelectElements("victims/victim"); foreach (var victim in victims) { ImportVictim(victim, context, anomalyEntity); } context.SaveChanges(); }
// NOT USED public async Task <bool> CollectAndSendAnomaly() { var anomaly = await _prepareService.GetAnomaly(1023); if (anomaly == null) { return(false); } var model = new WebAdmin.Models.Inspection.AnomalyViewModel { AnomalyId = anomaly.Id, Category = anomaly.Category, Date = anomaly.Date, Description = anomaly.Description, HasPhoto = anomaly.Photo != null, Photo = anomaly.Photo == null ? string.Empty : string.Format("data:image/gif;base64,{0}", Convert.ToBase64String(anomaly.Photo)), Label = anomaly.Label, Line = anomaly.Line, Machine = anomaly.Machine, Priority = (int)anomaly.Priority.Value, Type = (int)anomaly.Type, TypeLabel = anomaly.Type.AnomalyTypeToString(), TypeColor = anomaly.Type == AnomalyType.Security ? "green" : anomaly.Type == AnomalyType.Maintenance ? "red" : anomaly.Type == AnomalyType.Operator ? "blue" : "gray" }; model.PriorityLists = new List <Tuple <int, string> > { new Tuple <int, string>(1, "A"), new Tuple <int, string>(2, "B"), new Tuple <int, string>(3, "C") }; model.KindItems = new List <IAnomalyKindItem>(); model.KindItems = Anomalies.GetPossibleAnomalies(anomaly.Type); model.Items = new List <WebAdmin.Models.Inspection.AnomalyKindItemViewModel>(); foreach (var item in model.KindItems) { if (item.GetType().Name == "AnomalyKindItem") { var tempItem = (AnomalyKindItem)item; model.Items.Add(new WebAdmin.Models.Inspection.AnomalyKindItemViewModel { Label = tempItem.Label, Category = tempItem.Category, Number = tempItem.Number }); } } string pdfString = _notificationService.RenderViewToString(model, pdfTemplatePath, "PdfAnomaly.cshtml"); _notificationService.RenderViewToPdf(pdfString, pdfBase, baseUrl); return(true); }
internal async Task <(Anomaly anomaly, Trigger trigger)> AddValue(TValue value) { var anomaly = Range.Validate(value); if (anomaly == Anomaly.None) { var referenceDate = await AddValueOnReferenceDate(value).ConfigureAwait(false); return(anomaly, TriggerSettings.DetermineTrigger(referenceDate, NextCalculationDate, Values.Count)); } Anomalies.Add(value); return(anomaly, TriggerSettings.DetermineAnomalyTrigger(Anomalies.Count)); }
public bool Read(Stream stream, MatchData matchData) { if (data == null) { data = new Anomalies(); } var buffer = string.Empty; AnomalousNode foundNode = null; var ifFound = false; var matchPos = stream.Position; int curByte; while ((curByte = stream.ReadByte()) >= 0) { buffer += (char)curByte; AnomalousNode node; var match = data.Parse(buffer, out node); if (match == MatchPrecision.None) { break; // No reason to continue reading stream, let's see what we have.. } if (match == MatchPrecision.Exact) { matchPos = stream.Position; foundNode = node; ifFound = true; } } if (foundNode != null) { // Initialize match data with values from this anomaly } matchData.Ingredient = foundNode.Ingredient; stream.Seek(matchPos, SeekOrigin.Begin); return ifFound; }
public bool Read(Stream stream, MatchData matchData) { if (data == null) { data = new Anomalies(); } var buffer = string.Empty; AnomalousNode foundNode = null; var matchFound = false; var matchPos = stream.Position; int curByte; while ((curByte = stream.ReadByte()) >= 0) { buffer += (char)curByte; AnomalousNode node; var match = data.Parse(buffer, out node); if (match == MatchPrecision.None) { break; } if (match == MatchPrecision.Exact) { matchPos = stream.Position; foundNode = node; matchFound = true; } } if (foundNode != null) { matchData.Ingredient = foundNode.Ingredient; } stream.Seek(matchPos, SeekOrigin.Begin); return matchFound; }
public bool Read(Stream stream, MatchData matchData) { if (data == null) { data = new Anomalies(); } var buffer = String.Empty; AnomalousNode foundNode = null; var fFound = false; var matchPos = stream.Position; int curByte; while ((curByte = stream.ReadByte()) >= 0) { buffer += (char)curByte; AnomalousNode node; var match = data.Parse(buffer, out node); if (match == MatchPrecision.None) { break; //No reason to continue reading stream, let's see what we have.. } if (match == MatchPrecision.Exact) { matchPos = stream.Position; foundNode = node; fFound = true; } } if (foundNode != null) //Initialize match data with values from this anomaly { matchData.Ingredient = foundNode.Ingredient; } stream.Seek(matchPos, SeekOrigin.Begin); return(fFound); }
/// <summary> /// Initializes the context and loads necessary data into memory through the configured database adapter. /// This must be done before the context is usable. /// </summary> public virtual void Initialize() { if (Adapter == null) { throw new InvalidConfigurationException("DBContext requires a configured database adapter. Please check your configuration."); } // Initiaze NHibernate session Adapter.Initialize(this); new Thread(delegate() { using (InitLock.WriteLock()) { // Initialize ingredient parser ingParser = new IngredientParser(); var ingredientIndex = Adapter.LoadIngredientsForIndex(); ingParser.CreateIndex(ingredientIndex); // Initialize modeler modeler = new ModelerProxy(this); modeler.LoadSnapshot(); // Initialize natural language parsing IngredientSynonyms.InitIndex(Adapter.IngredientLoader); UnitSynonyms.InitIndex(Adapter.UnitLoader); FormSynonyms.InitIndex(Adapter.FormLoader); PrepNotes.InitIndex(Adapter.PrepLoader); Anomalies.InitIndex(Adapter.AnomalyLoader); NumericVocab.InitIndex(); parser = new Parser(); LoadTemplates(); } }).Start(); Thread.Sleep(500); // Provides time for initialize thread to start and acquire InitLock }
private static void ImportVictim(XElement victimNode, MassDefectContext context, Anomalies anomaly) { var name = victimNode.Attribute("name"); if (name == null) { RaiseError(); } var perssonEntity = GetPersonName(name.Value, context); if (perssonEntity.Name == null) { RaiseError(); } anomaly.Person.Add(perssonEntity); }
public void Multimodal() { Anomalies.Multimodal(); }
/// <summary> /// Determines if the given file exists in the given folder /// </summary> /// <returns></returns> protected bool FolderNotEmpty(string relFolderPath, string fileTypes = "*.*", Anomalies anomalies = null) { var dirPath = Path.Combine(this.TargetDir, relFolderPath); var exists = Directory.Exists(dirPath); if (!exists) { if (anomalies != null) { anomalies.ExpectedFiles.Add(relFolderPath); } return false; } else { var filesInFolder = new DirectoryInfo(dirPath).GetFiles(fileTypes); if (!filesInFolder.Any()) { if (anomalies != null) { anomalies.ExpectedFiles.Add(fileTypes); } } return filesInFolder.Any(); } }
public void Changepoint2() { Anomalies.Changepoint2(); }
public void Bimodal() { Anomalies.Bimodal(); }
/// <summary> /// Asserts whether if the given file exists in the given folder, and reports the difference /// </summary> protected void AssertFolderNotEmpty(string relFolderPath, string fileTypes = "*.*") { var anomalies = new Anomalies(); Assert.IsTrue(FolderNotEmpty(relFolderPath, fileTypes, anomalies), anomalies.Format()); }
/// <summary> /// Determines if the given file exists in the given folder /// </summary> /// <returns></returns> protected bool FolderNotEmpty(string relFolderPath, string fileTypes = "*.*", Anomalies anomalies = null) { var dirPath = Path.Combine(this.TargetDir, relFolderPath); var exists = Directory.Exists(dirPath); if (!exists) { if (anomalies != null) { anomalies.ExpectedFiles.Add(relFolderPath); } return(false); } else { var filesInFolder = new DirectoryInfo(dirPath).GetFiles(fileTypes); if (!filesInFolder.Any()) { if (anomalies != null) { anomalies.ExpectedFiles.Add(fileTypes); } } return(filesInFolder.Any()); } }
public void Degradation() { Anomalies.Degradation(); }
internal void AddAnomaly(TValue value) { Anomalies.Add(value); }
/// <summary> /// Asserts whether the given folder contains only the given files, and no others, and reports the difference /// </summary> protected void AssertFolderContainsExclusive(string relFolderPath, IEnumerable<string> filenames) { var anomalies = new Anomalies(); Assert.IsTrue(FolderContainsExclusive(relFolderPath, filenames, anomalies), anomalies.Format()); }
/// <summary> /// Asserts whether the given folder contains only the given files, and no others, and reports the difference /// </summary> protected void AssertFolderContainsExclusive(string relFolderPath, IEnumerable <string> filenames) { var anomalies = new Anomalies(); Assert.IsTrue(FolderContainsExclusive(relFolderPath, filenames, anomalies), anomalies.Format()); }
/// <summary> /// Determines whether the given folder contains only the given files, and no others /// </summary> /// <returns></returns> protected bool FolderContainsExclusive(string relFolderPath, IEnumerable <string> filenames, Anomalies anomalies = null) { var dirPath = Path.Combine(this.TargetDir, relFolderPath); var exists = Directory.Exists(dirPath); if (!exists) { return(false); } else { var folderFiles = new DirectoryInfo(dirPath).GetFiles(); var filesInFolder = folderFiles.Select(f => f.Name).Except(filenames).ToList(); var expectedFiles = filenames.Except(folderFiles.Select(f => f.Name)).ToList(); if (anomalies != null) { anomalies.ExpectedFiles.AddRange(expectedFiles); anomalies.UnexpectedFiles.AddRange(filesInFolder); } return(!(filesInFolder.Any()) && !(expectedFiles.Any())); } }
public void Acceleration() { Anomalies.Acceleration(); }