public static string GetDescription(this AnomalyInfo ai)
        {
            var _context = DissertationDbList.getInstance();
            {
                var sb = new StringBuilder();
                sb.AppendLine("Ситуации:");
                var situations = ai.SetSituations.Split(',');
                BaseClassStatisticBy statistic = null;
                foreach (var sit in situations)
                {
                    int number = Convert.ToInt32(sit);
                    switch (ai.TypeSituation)
                    {
                    case TypeSituation.ПоНечеткости:
                        statistic = _context.StatisticsByFuzzys
                                    //.Include(stf => stf.EndStateFuzzyLabel)
                                    //.Include(stf => stf.EndStateFuzzyTrend)
                                    //.Include(stf => stf.StartStateFuzzyLabel)
                                    //.Include(stf => stf.StartStateFuzzyTrend)
                                    .FirstOrDefault(stf => stf.NumberSituation == number &&
                                                    stf.SeriesDiscriptionId == ai.SeriesDiscriptionId);
                        break;

                    case TypeSituation.ПоЭнтропии:
                        statistic = _context.StatisticsByEntropys.FirstOrDefault(ste => ste.NumberSituation == number &&
                                                                                 ste.SeriesDiscriptionId == ai.SeriesDiscriptionId);
                        break;
                    }
                    sb.AppendLine(string.Format("{0} -> {1}", statistic.StartState, statistic.EndState));
                }
                sb.AppendLine("Аномалия:");
                switch (ai.TypeSituation)
                {
                case TypeSituation.ПоНечеткости:
                    statistic = _context.StatisticsByFuzzys
                                //.Include(stf => stf.EndStateFuzzyLabel)
                                //.Include(stf => stf.EndStateFuzzyTrend)
                                //.Include(stf => stf.StartStateFuzzyLabel)
                                //.Include(stf => stf.StartStateFuzzyTrend)
                                .FirstOrDefault(stf => stf.NumberSituation == ai.AnomalySituation &&
                                                stf.SeriesDiscriptionId == ai.SeriesDiscriptionId);
                    break;

                case TypeSituation.ПоЭнтропии:
                    statistic = _context.StatisticsByEntropys.FirstOrDefault(stf => stf.NumberSituation == ai.AnomalySituation &&
                                                                             stf.SeriesDiscriptionId == ai.SeriesDiscriptionId);
                    break;
                }
                sb.AppendLine(string.Format("{0} -> {1}", statistic.StartState, statistic.EndState));

                return(sb.ToString());
            }
        }
Example #2
0
 public static AnomalyInfo ToAnomalyInfo(AnomalyInfoBindingModel model, AnomalyInfo elem = null)
 {
     if (elem == null)
     {
         elem = new AnomalyInfo();
     }
     elem.SeriesDiscriptionId = model.SeriesDiscriptionId;
     elem.AnomalyName         = model.AnomalyName;
     elem.Description         = model.Description;
     elem.AnomalySituation    = model.AnomalySituation;
     elem.SetSituations       = model.SetSituations;
     elem.SetValues           = model.SetValues;
     elem.TypeMemoryValue     = Converter.ToTypeMemoryValue(model.TypeMemoryValue);
     elem.TypeSituation       = Converter.ToTypeSituation(model.TypeSituation);
     elem.NotAnomaly          = model.NotAnomaly;
     elem.NotDetected         = model.NotDetected;
     elem.CountMeet           = model.CountMeet;
     return(elem);
 }
Example #3
0
 public static AnomalyInfoViewModel ToAnomalyInfo(AnomalyInfo elem)
 {
     return(new AnomalyInfoViewModel
     {
         Id = elem.Id,
         SeriesDiscriptionId = elem.SeriesDiscriptionId,
         TypeSituation = elem.TypeSituation,
         AnomalyName = elem.AnomalyName,
         AnomalySituation = elem.AnomalySituation,
         SetSituations = elem.SetSituations,
         TypeMemoryValue = elem.TypeMemoryValue,
         SetValues = elem.SetValues,
         Description = elem.Description,
         CountMeet = elem.CountMeet,
         NotAnomaly = elem.NotAnomaly,
         NotDetected = elem.NotDetected,
         Rashifrovka = elem.GetDescription()
     });
 }
 public void AnomalyGraphButton(int indexOfCosenAnomaly)
 {
     ButtonChosenAnomalyGraphPressed = true;
     Anomaly = model.GetSpecificAnomaly(indexOfCosenAnomaly);
     //for display we need the names of the features
     if (Anomaly == null)
     {
         PlotAnomaliesGraph.Axes[1].Title = "null";
         PlotAnomaliesGraph.Axes[0].Title = "null";
         LineSerieAnomalyLine.Points.Clear();
         LineSerieAnomalyGraphAllPoints.Points.Clear();
         LineSerieAnomalyPoints.Points.Clear();
         PlotAnomaliesGraph.InvalidatePlot(true);
         ButtonChosenAnomalyGraphPressed = false;
         return;
     }
     else
     {
         PlotAnomaliesGraph.Axes[0].Title = Anomaly.Feature1;
         PlotAnomaliesGraph.Axes[1].Title = Anomaly.Feature2;
         UpdateModelAnomaliesGraph();
     }
 }
Example #5
0
        public async Task <List <AnomalyInfo> > GetAnomalyInfos(List <AnomalyIdentity> anomalyIdentities)
        {
            var anomalyGuids = anomalyIdentities.Select(x => x.Value).ToList();
            var output       = await this.ExecuteInContextAsync(async dbContext =>
            {
                // Get all the info, in rows.
                var query =
                    from anomaly in dbContext.Anomalies
                    where anomaly.GUID != null
                    where anomalyGuids.Contains(anomaly.GUID)
                    join anomalyCatchment in dbContext.AnomalyToCatchmentMappings
                    on anomaly.ID equals anomalyCatchment.AnomalyID into catchmentGroup
                    from c in catchmentGroup.DefaultIfEmpty()
                    join anomalyText in dbContext.AnomalyToTextItemMappings
                    on anomaly.ID equals anomalyText.AnomalyID into textGroup
                    from t in textGroup.DefaultIfEmpty()
                    join anomalyImage in dbContext.AnomalyToImageFileMappings
                    on anomaly.ID equals anomalyImage.AnomalyID into imageGroup
                    from i in imageGroup.DefaultIfEmpty()
                    select new
                {
                    anomaly.ID,
                    anomaly.GUID,
                    anomaly.ReportedUTC,
                    anomaly.ReportedLocationGUID,
                    anomaly.ReporterLocationGUID,
                    CatchmentIdentity = c == default ? Guid.Empty : c.CatchmentIdentity,
                    TextItemIdentity  = t == default ? Guid.Empty : t.TextItemGUID,
                    ImageIdentity     = i == default ? Guid.Empty : i.ImageFileGUID,
                };
                // Group it by anomaly (since we need an AnomalyInfo per AnomalyIdentity passed in)
                var result  = await query.ToListAsync();
                var grouped = result.GroupBy(group =>
                                             new {
                    group.ID,
                    group.GUID,
                    group.ReportedUTC,
                    group.ReportedLocationGUID,
                    group.ReporterLocationGUID
                }, group => group);

                // Use the grouping to put together anomaly infos.
                var anomalyInfos = new List <AnomalyInfo>();
                foreach (var entry in grouped)
                {
                    // Console.WriteLine(entry.Key);
                    var images      = new HashSet <Guid>();
                    var catchments  = new HashSet <Guid>();
                    var textItemSet = new HashSet <Guid>();
                    foreach (var thing in entry)
                    {
                        images.Add(thing.ImageIdentity);
                        catchments.Add(thing.CatchmentIdentity);
                        textItemSet.Add(thing.TextItemIdentity);
                    }

                    var imagesList     = images.ToList();
                    var catchmentsList = catchments.ToList();
                    var textItemsList  = textItemSet.ToList();

                    // Console.WriteLine($"    Images ({images.Count}):     {string.Join(',',images.ToList())}");
                    // Console.WriteLine($"    Catchments ({catchments.Count}): {string.Join(',', catchments.ToList())}");
                    // Console.WriteLine($"    Text items ({textItemSet.Count}): {string.Join(',', textItemSet.ToList())}");

                    if (entry.Key.GUID == default)
                    {
                        // Unfortunately this also catches anomalies added with an all-zeros guid...
                        // and we have at least one of those (ID 228 as of 2020-07-17)
                        // throw new Exception("Got an anomaly without a GUID");
                    }
                    var anomalyIdentity     = new AnomalyIdentity(entry.Key.GUID);
                    var reportedUTC         = entry.Key.ReportedUTC;
                    var reportedLocation    = entry.Key.ReportedLocationGUID.HasValue ? LocationIdentity.From(entry.Key.ReportedLocationGUID.Value) : null;
                    var reporterLocation    = entry.Key.ReporterLocationGUID.HasValue ? LocationIdentity.From(entry.Key.ReporterLocationGUID.Value) : null;
                    var catchmentIdentities = catchmentsList.Select(x => CatchmentIdentity.From(x)).ToList();
                    var imageFileIdentities = imagesList
                                              .Where(x => x != Guid.Empty)
                                              .Select(x => ImageFileIdentity.From(x))
                                              .ToList();
                    var textItems = textItemsList.Select(x => TextItemIdentity.From(x)).ToList();
                    var info      = new AnomalyInfo
                    {
                        AnomalyIdentity          = anomalyIdentity,
                        ReportedUTC              = reportedUTC,
                        ReportedLocationIdentity = reportedLocation,
                        ReporterLocationIdentity = reporterLocation,
                        CatchmentIdentities      = catchmentIdentities,
                        ImageFileIdentities      = imageFileIdentities,
                        TextItemsIdentities      = textItems
                    };
                    anomalyInfos.Add(info);
                }
                return(anomalyInfos);
            });

            return(output);
        }
Example #6
0
        public async Task <AnomalyInfo> GetAnomalyInfo(AnomalyIdentity anomalyIdentity)
        {
            var anomalyInfo = await this.ExecuteInContextAsync(async dbContext =>
            {
                var gettingAnomalyDetails = dbContext.GetAnomaly(anomalyIdentity)
                                            .Select(x => new
                {
                    x.ReportedUTC,
                    x.ReportedLocationGUID,
                    x.ReporterLocationGUID,
                    x.UpvotesCount,
                })
                                            .SingleAsync();

                var gettingImageFileIdentityValues = dbContext.GetAnomaly(anomalyIdentity)
                                                     .Join(dbContext.AnomalyToImageFileMappings,
                                                           anomaly => anomaly.ID,
                                                           mapping => mapping.AnomalyID,
                                                           (_, mapping) => mapping.ImageFileGUID)
                                                     .ToListAsync();

                var gettingTextItemIdentityValues = dbContext.GetAnomaly(anomalyIdentity)
                                                    .Join(dbContext.AnomalyToTextItemMappings,
                                                          anomaly => anomaly.ID,
                                                          mapping => mapping.AnomalyID,
                                                          (_, mapping) => mapping.TextItemGUID)
                                                    .ToListAsync();

                var gettingCatchmentMapping = dbContext.GetAnomaly(anomalyIdentity)
                                              .Join(dbContext.AnomalyToCatchmentMappings,
                                                    anomaly => anomaly.ID,
                                                    mapping => mapping.AnomalyID,
                                                    (_, mapping) => mapping)
                                              .ToListAsync();


                var anomalyDetails          = await gettingAnomalyDetails;
                var imageFileIdentityValues = await gettingImageFileIdentityValues;
                var textItemIdentityValues  = await gettingTextItemIdentityValues;
                var catchmentMapping        = await gettingCatchmentMapping;

                var catchmentIdentities = catchmentMapping.Select(x => CatchmentIdentity.From(x.CatchmentIdentity)).ToList();
                var imageFileIdentities = imageFileIdentityValues.Select(x => ImageFileIdentity.From(x)).ToList();
                var reportedLocation    = anomalyDetails.ReportedLocationGUID.HasValue ? LocationIdentity.From(anomalyDetails.ReportedLocationGUID.Value) : null;
                var reporterLocation    = anomalyDetails.ReporterLocationGUID.HasValue ? LocationIdentity.From(anomalyDetails.ReporterLocationGUID.Value) : null;
                var reportedUTC         = anomalyDetails.ReportedUTC;
                var textItems           = textItemIdentityValues.Select(x => TextItemIdentity.From(x)).ToList();
                var upvotesCount        = anomalyDetails.UpvotesCount;

                var output = new AnomalyInfo()
                {
                    AnomalyIdentity          = anomalyIdentity,
                    CatchmentIdentities      = catchmentIdentities,
                    ImageFileIdentities      = imageFileIdentities,
                    ReportedLocationIdentity = reportedLocation,
                    ReporterLocationIdentity = reporterLocation,
                    ReportedUTC         = reportedUTC,
                    TextItemsIdentities = textItems,
                    UpvotesCount        = upvotesCount,
                };
                return(output);
            });

            return(anomalyInfo);
        }