Exemplo n.º 1
0
        private void panel1_MouseClick(object sender, MouseEventArgs e)
        {
            try
            {
                StatisticsResult sr = m_drawGraph.HitTest(e.Location);

                for (int i = lstDetails.SelectedItems.Count - 1; i >= 0; i--)
                {
                    lstDetails.SelectedItems[i].Selected = false;
                }

                if (sr != null)
                {
                    foreach (ListViewItem lvi in lstDetails.Items)
                    {
                        if (string.Equals(m_drawGraph.SelectedRegionKey, Convert.ToString(lvi.Tag), StringComparison.OrdinalIgnoreCase))
                        {
                            lvi.Selected = true;
                            break;
                        }
                    }
                }

                this.drawBoard1.Refresh();
            }
            catch (Exception ex)
            {
                MessageBox.Show("点击图标区域失败,错误消息为:" + ex.Message);
            }
        }
        public static StatisticsResult GenerateStatistics(List <Point> pixels, int[,] matrixWithContour,
                                                          int[,] image, int xmin, int xmax, int ymin, int ymax, double pixelAreaInMms,
                                                          double pixelLenghtInMms, Point startPoint)
        {
            StatisticsResult statisticsResult = new StatisticsResult();

            statisticsResult.CenterOfMass = Statistics.Barycentrum(pixels);
            try
            {
                statisticsResult.Histogram     = Statistics.HistogramOfContourFloodFill(matrixWithContour, image, xmin, xmax, ymin, ymax, startPoint);
                statisticsResult.HistogramMin  = Statistics.MinInHistogram(statisticsResult.Histogram);
                statisticsResult.HistogramMax  = Statistics.MaxInHistogram(statisticsResult.Histogram);
                statisticsResult.HistogramMean = Statistics.MeanInHistogram(statisticsResult.Histogram);
                statisticsResult.Area          = Statistics.AreaInMms(statisticsResult.Histogram, pixelAreaInMms);
                statisticsResult.NumberOfPixelsInsideContour = Statistics.AreaInPixels(statisticsResult.Histogram);
            }
            catch (Exception e)
            {
                e.ToString();
            }
            // statisticsResult.Permieter = Statistics.PerimeterInMmsSecondMethod(pixels, pixelLenghtInMms);
            statisticsResult.Permieter = Statistics.PerimeterInMms(pixels, pixelLenghtInMms);
            statisticsResult.NumberOfPixelsOfContour = Statistics.PerimeterInPixels(pixels);
            return(statisticsResult);
        }
Exemplo n.º 3
0
 public GetShipperResult(Int32 count, Int32 total, StatisticsResult statistics, IList <TasksResult> tasks)
 {
     this.Count      = count;
     this.Total      = total;
     this.Statistics = statistics;
     this.Tasks      = tasks;
 }
        private static List <VehicleSummaryData> MapStatisticsToVehicleData(StatisticsResult statistics)
        {
            var vehicleData = new List <VehicleSummaryData>()
            {
                new VehicleSummaryData
                {
                    Index       = 0,
                    Name        = "Avg Speed",
                    Value       = statistics.Driver.AvgSpeed.ToString("0.0"),
                    Unit        = "mph",
                    GlobalValue = statistics.Global.AvgSpeed.ToString("0.0")
                },
                new VehicleSummaryData
                {
                    Index       = 1,
                    Name        = "Miles Traveled",
                    Value       = statistics.Driver.Miles.ToString("0.0"),
                    Unit        = "",
                    GlobalValue = statistics.Global.Miles.ToString("0.0")
                },
                new VehicleSummaryData
                {
                    Index       = 2,
                    Name        = "Breakdowns",
                    Value       = statistics.Driver.Breakdowns.ToString("0"),
                    GlobalValue = statistics.Global.Breakdowns.ToString("0")
                }
            };

            return(vehicleData);
        }
Exemplo n.º 5
0
 private void siBOK_Click(object sender, EventArgs e)
 {
     if (string.IsNullOrEmpty(cBEResult.Text.Trim()))
     {
         MessageBox.Show("错误信息:n输入分类结果的值:是必需的");
     }
     else
     {
         frmWaitDialog frmWait = new frmWaitDialog("正在统计...", "提示信息");
         try
         {
             frmWait.Owner   = this;
             frmWait.TopMost = false;
             DataTable        table = new DataTable();
             StatisticsResult acc   = new StatisticsResult();
             if (acc.Statistics(cBEResult.Text, out table))
             {
                 frmWait.Close();
                 frmStatisticsTable frm = new frmStatisticsTable(table);
                 frm.ShowDialog();
             }
         }
         catch (Exception ex)
         {
             XtraMessageBox.Show(ex.Message, "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
             Log.WriteLog(typeof(frmStatisticsResult), ex);
         }
         finally
         {
             frmWait.Close();
             //this.Close();
         }
     }
 }
Exemplo n.º 6
0
 public GetShipperResult(int count, int total, StatisticsResult statistics, IList <TasksResult> tasks)
 {
     Count      = count;
     Total      = total;
     Statistics = statistics;
     Tasks      = tasks;
 }
Exemplo n.º 7
0
        protected override StatisticsResult Compare(StatisticsResult[] results)
        {
            if (results.Length != 2)
            {
                throw new ArgumentException(
                          "Should have 2 values, instead got " +
                          results.Length.ToString());
            }

            StatisticsResult denominator = results[0];
            StatisticsResult numerator   = results[1];

            StatisticsResult ret_r = (StatisticsResult)denominator.Clone();

            if (numerator == null)
            {
                return(null); // YM-625 / SUPPORT-5338

                /*
                 * ret_r.Value = 0;
                 * return ret_r;
                 */
            }

            if (denominator.Value == null || denominator.Value == 0)
            {
                ret_r.Value = 0;
                return(ret_r);
            }

            ret_r.Value = numerator.Value / denominator.Value;

            return(ret_r);
        }
        public async Task <IActionResult> Get()
        {
            Task <int> totalMedicationStrings = _uow.MedicationStringRepo.TotalCount();
            Task <int> totalDosageCounts      = _uow.MedicationStringRepo.TotalDosageCount();
            Task <List <CountByBottleSize> > totalNumberByBottleSize =
                _uow.MedicationStringRepo.TotalNumberByBottleSize();
            Task <List <CountByMedicationId> > distinctMedicationIdsWithCount =
                _uow.MedicationStringRepo.DistinctMedicationIds();

            Task.WaitAll(new Task[] {
                totalMedicationStrings,
                totalDosageCounts,
                totalNumberByBottleSize,
                distinctMedicationIdsWithCount
            });

            var result = new StatisticsResult
            {
                TotalCount       = totalMedicationStrings.Result,
                TotalDosageCount = totalDosageCounts.Result,
                PerBottleSize    = totalNumberByBottleSize.Result,
                PerMedicationId  = distinctMedicationIdsWithCount.Result
            };

            return(Ok(_mapper.Map <StatisticsDTO>(result)));
        }
Exemplo n.º 9
0
 public BenchmarkStatisticsCollection()
 {
     this.CollectionChanged += new NotifyCollectionChangedEventHandler(benchmarkStatisticsCollectionCollectionChanged);
     ArithmeticMean          = new StatisticsResult("Arithmetic Mean");
     GeometricMean           = new StatisticsResult("Geometric Mean");
     HarmonicMean            = new StatisticsResult("Harmonic Mean");
     FinalisationMessage     = new ResultListMessage("Finished", false);
 }
 private StatisticsResult SetDecimalCount(StatisticsResult obj)
 {
     if (obj.Value == null ||
         this.Details.DecimalCount == null)
     {
         return(obj);
     }
     obj.Value = decimal.Round((decimal)obj.Value,
                               (int)this.Details.DecimalCount);
     return(obj);
 }
Exemplo n.º 11
0
        private void ResetDetailList()
        {
            try
            {
                if (this.Cursor != Cursors.WaitCursor)
                {
                    this.Cursor = Cursors.WaitCursor;
                }

                this.lstDetails.SuspendLayout();
                this.lstDetails.Items.Clear();

                foreach (string key in m_analysisResult.Keys)
                {
                    StatisticsResult sr  = m_analysisResult[key];
                    ListViewItem     lvi = new ListViewItem(sr.Title);
                    lvi.SubItems.Add(sr.Percentage.ToString("P"));
                    lvi.SubItems.Add(sr.Count.ToString() + "条");
                    lvi.BackColor = sr.BackColor;
                    lvi.Tag       = key;

                    int index = 0;

                    foreach (ListViewItem lv in this.lstDetails.Items)
                    {
                        if (sr.Percentage > m_analysisResult[lv.Tag.ToString()].Percentage)
                        {
                            break;
                        }

                        index++;
                    }

                    this.lstDetails.Items.Insert(index, lvi);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("重新排列日志分析结果失败,错误消息为:" + ex.Message);
            }
            finally
            {
                this.lstDetails.ResumeLayout();

                if (this.Cursor != Cursors.Default)
                {
                    this.Cursor = Cursors.Default;
                }
            }
        }
Exemplo n.º 12
0
        public async Task <StatisticsResult> GetProfileDtoResults(string battleTag, string region)
        {
            battleTag = BattleTagQueryFormatConversion(battleTag);

            var requestUrl      = $"https://ow-api.com/v1/stats/pc/{region}/{battleTag}/complete";
            var responseMessage = await Client.GetAsync(requestUrl);

            var messageBody = await responseMessage.Content.ReadAsStringAsync();

            var completeDto = JsonConvert.DeserializeObject <OverWatchCompleteDTO>(messageBody);


            return(StatisticsResult.From(completeDto));
        }
Exemplo n.º 13
0
 public static List <User> Map(StatisticsResult model)
 {
     return(model.Results.Select(x => new User
     {
         Name = x.Name,
         Stats = new UserStats
         {
             Id = x.Stats.Id,
             Games = x.Stats.Games,
             Wins = x.Stats.Wins,
             Top5 = x.Stats.Top5,
             Kills = x.Stats.Kills
         }
     }).ToList());
 }
        public IEnumerable <StatisticsResult> FindAll()
        {
            if (this.Repositories == null)
            {
                throw new Exception("No repositories specified!");
            }

            var rstates = new List <RState>();

            foreach (IStatisticsRepository repo in this.Repositories)
            {
                rstates.Add(new RState()
                {
                    Enumerator = repo.FindAll().GetEnumerator()
                });
            }

            /* this loop should continue for as long as there is at least one
             * successfull .MoveNext() */
            while (this.MoveAll(rstates))
            {
                int min = rstates
                          .Where(x => x.Value != null)
                          .Min(x => x.Value.AreaId);

                var values = new List <StatisticsResult>();

                foreach (RState rstate in rstates)
                {
                    StatisticsResult val = null;
                    if (rstate.Value != null && // null = reached the end
                        rstate.Value.AreaId == min)
                    {
                        val = rstate.Value;
                    }
                    values.Add(val);
                }

                StatisticsResult ret_r = this.Compare(values.ToArray());
                yield return(ret_r);
            }

            foreach (RState rstate in rstates)
            {
                rstate.Enumerator.Dispose();
            }
        }
        public async Task <IActionResult> GetResultsAsync(QuestionFormInfoReq req)
        {
            CovidStatisticsList covidStatistics = await GetStatisticsAsync();

            TodayCases todayCases = await GetTodaysCasesAsync();

            StatisticsResult stats = await CovidTestAsync(req);

            TodayAndGeneralStatistics todayAndGeneralStatistics = new TodayAndGeneralStatistics
            {
                CovidGeneral  = covidStatistics,
                CovidToday    = todayCases,
                statisticsRes = stats
            };

            return(View(todayAndGeneralStatistics));
        }
Exemplo n.º 16
0
        public StatisticsResult Statistics()
        {
            var stats = _projectService.ProjectUserSummary();

            var result = new StatisticsResult
            {
                ProjectStatistics = stats.ToList()
            };

            if (stats.Any())
            {
                result.TotalEarnings = stats.Sum(p => p.UserTotalAmountEarned);
                result.TotalHours    = stats.Sum(p => p.UserTotalHoursReported);
            }

            return(result);
        }
        protected override StatisticsResult Compare(StatisticsResult[] results)
        {
            if (results.Length != 2)
            {
                throw new ArgumentException(
                          "Should have 2 values, instead got " +
                          results.Length.ToString());
            }

            StatisticsResult refval = results[0]; // value we compare against
            StatisticsResult val    = results[1]; // actual value

            StatisticsResult ret_r;

            /* we assume here that refval and val are never both null */

            if (refval == null)   // ref null, nothing to do
            {
                return((StatisticsResult)val.Clone());
            }

            if (val == null)   // val null, create a fake result from ref
            {
                ret_r       = (StatisticsResult)refval.Clone();
                ret_r.Value = 0;
            }
            else
            {
                ret_r = (StatisticsResult)val.Clone();
            }

            if (refval.Value <= this.Limit.GreaterThan)
            {
                ret_r.Value = null;
                ret_r.PrivacyLimitTriggered = true;
            }

            return(ret_r);
        }
Exemplo n.º 18
0
        public void AddToRepository(StatisticsDto statistics)
        {
            if (string.IsNullOrWhiteSpace(BluePrint))
            {
                throw new BllException("BluePrint not set.");
            }

            if (statistics == null)
            {
                throw new BllException("StatisticsDto can not be null.");
            }

            var statisticsResult = new StatisticsResult
            {
                BluePrint = BluePrint,
                C45Better = statistics.C45Better,
                C50Better = statistics.C50Better,
                Equal     = statistics.Equal
            };

            _statisticsResultsRepository.Add(statisticsResult);
        }
Exemplo n.º 19
0
        private void drawBoard1_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            try
            {
                StatisticsResult sr = m_drawGraph.HitTest(e.Location);

                if (sr == null)
                {
                    ClearData();
                }
                else
                {
                    ShowLogData(sr);
                }

                this.drawBoard1.Refresh();
            }
            catch (Exception ex)
            {
                MessageBox.Show("显示鼠标位置对应的日志内容失败,错误消息为:" + ex.Message);
            }
        }
        public static SemiAutomaticContourDTO TrivialContour(SemiAutomaticPointsDTO points)
        {
            List <Point> pixels = new List <Point>();
            int          count  = points.lines.First().points.Count;

            for (int i = 0; i < points.lines.First().points.Count; i++)
            {
                int          x1 = points.lines.First().points[i].x;
                int          y1 = points.lines.First().points[i].y;
                int          x2 = points.lines.First().points[(i + 1) % count].x;
                int          y2 = points.lines.First().points[(i + 1) % count].y;
                List <Point> pixelsBresenham = new List <Point>();
                BresenhamClass.Bresenham(pixelsBresenham, x1, y1, x2, y2);
                pixels = pixels.Concat(pixelsBresenham).ToList();
            }

            List <LinePointsAndPixels> lines = new List <LinePointsAndPixels>();
            LinePointsAndPixels        line  = new LinePointsAndPixels();

            line.points     = new List <Point>(points.lines.First().points);
            line.pixels     = new List <Point>(pixels);
            line.brushColor = points.lines.First().brushColor;

            lines.Add(line);

            System.Drawing.Bitmap bitmap = OrthancConnection.GetBitmapByInstanceId(points.dicomid);
            int[,] matrixWithContour = CannyAlgorithm.MakeMatrixFromPoints(bitmap.Width, bitmap.Height, pixels);
            int[,] image             = CannyAlgorithm.ReadMatrixFromBitmap(bitmap);

            StatisticsResult statisticsResult = Statistics.GenerateStatistics(pixels, matrixWithContour, image, 0, bitmap.Width, 0, bitmap.Height,
                                                                              0, 0, points.centralPoints.First());

            SemiAutomaticContourDTO contour = new SemiAutomaticContourDTO(points.guid,
                                                                          points.dicomid, points.tag, lines, points.width, points.height, statisticsResult, points.centralPoints, points.pixelSpacing);

            return(contour);
        }
Exemplo n.º 21
0
        public void AddToRepository_EverythingIsSetUp_ShouldFormCorrectObjectForRepository()
        {
            StatisticsResult result = null;
            var statistics          = new StatisticsDto
            {
                C45Better = 10,
                C50Better = 20,
                Equal     = 5
            };

            _statisticsResultsRepositoryMock
            .Setup(x => x.Add(It.IsAny <StatisticsResult>()))
            .Callback <StatisticsResult>(x => result = x);

            _service.BluePrint = "Test";

            _service.AddToRepository(statistics);

            Assert.IsNotNull(result);
            Assert.AreEqual("Test", result.BluePrint);
            Assert.AreEqual(10, result.C45Better);
            Assert.AreEqual(20, result.C50Better);
            Assert.AreEqual(5, result.Equal);
        }
Exemplo n.º 22
0
        public ActionResult GetData(string json)
        {
            var sReq = JsonConvert.DeserializeObject <StatisticsRequest>(json);

            var res = new StatisticsResult();

            try
            {
                IStatisticsManager statMngr = new DefaultStatMngr(_orderItemSearcher, new DefaultStatCalc());

                statMngr.CalculateAllData(sReq);

                res.Success        = true;
                res.Message        = "Succeessfully fetched statistics.";
                res.StatisticsData = sReq.StatisticsData;
            }
            catch (Exception e)
            {
                res.Success = false;
                res.Message = "Failed to import document from data: " + e.Message;
            }

            return(Json(res, JsonRequestBehavior.AllowGet));
        }
        private StatisticsResult MakeUnitConversions(StatisticsResult obj)
        {
            switch (this.Details.InternalUnitId)
            {
            case 12:     // osuus
                switch (this.Details.DisplayUnitId)
                {
                case 1:         // %
                    obj.Value = (decimal)(obj.Value * 100);
                    break;
                }
                break;

            case 10:     // m2
                switch (this.Details.DisplayUnitId)
                {
                case 14:         // ha
                    obj.Value = (decimal)(obj.Value / 10000);
                    break;

                case 4:         // km2
                    obj.Value = (decimal)(obj.Value / 1000000);
                    break;
                }
                break;

            case 4:     // km2
                switch (this.Details.DisplayUnitId)
                {
                case 10:         // m2
                    obj.Value = (decimal)(obj.Value * 1000000);
                    break;
                }
                break;

            case 21:     // as/m2 (Asukasta per neliömetri)
                switch (this.Details.DisplayUnitId)
                {
                case 16:         // as/km2
                    obj.Value = (decimal)(obj.Value * 1000000);
                    break;
                }
                break;

            case 16:     // as/km2
                switch (this.Details.DisplayUnitId)
                {
                case 21:          // as/m2 (Asukasta per neliömetri)
                    obj.Value = (decimal)(obj.Value / 1000000);
                    break;
                }
                break;

            case 17:     // km/maa-km2
                switch (this.Details.DisplayUnitId)
                {
                case 24:         // km/m2 (Kilometriä per neliömetri)
                    obj.Value = (decimal)(obj.Value / 1000000);
                    break;
                }
                break;

            case 22:     // lkm/as (Lukumäärä asukasta kohden)
                switch (this.Details.DisplayUnitId)
                {
                case 23:         // lkm / 1000 as (Lukumäärä tuhatta asukasta kohden)
                    obj.Value = (decimal)(obj.Value * 1000);
                    break;
                }
                break;

            case 23:     // lkm / 1000 as (Lukumäärä tuhatta asukasta kohden)
                switch (this.Details.DisplayUnitId)
                {
                case 22:         // lkm/as (Lukumäärä asukasta kohden)
                    obj.Value = (decimal)(obj.Value / 1000);
                    break;
                }
                break;

            case 24:     // km/m2 (Kilometriä per neliömetri)
                switch (this.Details.DisplayUnitId)
                {
                case 17:         // km/maa-km2
                    obj.Value = (decimal)(obj.Value * 1000000);
                    break;
                }
                break;

            case 25:     // €
                switch (this.Details.DisplayUnitId)
                {
                case 28:         // 1000 €
                    obj.Value = (decimal)(obj.Value / 1000);
                    break;
                }
                break;
            }

            return(obj);
        }
Exemplo n.º 24
0
 public StatisticsResponse()
 {
     Result = new StatisticsResult();
 }
Exemplo n.º 25
0
        public SemiAutomaticContourDTO Load(Guid guid)
        {
            using (var db = new ContourContext())
            {
                if (db.Contours.Where(c => c.ContourEntityId == guid).ToList().Count == 0)
                {
                    return(null);
                }
            }

            string DICOMid;
            string tag;
            List <LinePointsAndPixels> lines = new List <LinePointsAndPixels>();
            int width;
            int height;

            string buffor;

            string       filename = "../data/semiautomatic/" + guid.ToString() + ".csv";
            StreamReader sr       = null;

            try
            {
                sr = new StreamReader(filename);
            }
            catch (Exception)
            {
                return(null);
            }
            if (sr.EndOfStream)
            {
                throw new Exception($"Unexpected end of file {filename}");
            }

            buffor = sr.ReadLine();
            if (Guid.Parse(buffor) != guid)
            {
                throw new Exception($"Guid in file diffrent that in name of file {filename}");
            }
            if (sr.EndOfStream)
            {
                throw new Exception($"Unexpected end of file {filename}");
            }

            DICOMid = sr.ReadLine();
            if (sr.EndOfStream)
            {
                throw new Exception($"Unexpected end of file {filename}");
            }

            tag = sr.ReadLine();
            if (sr.EndOfStream)
            {
                throw new Exception($"Unexpected end of file {filename}");
            }

            LinePointsAndPixels line = new LinePointsAndPixels();

            line.pixels = new List <Point>();
            line.points = new List <Point>();

            buffor = sr.ReadLine();
            List <int> points = buffor.Split(',').Select(s => int.Parse(s)).ToList();
            int        i      = 0;

            while (i + 1 < points.Count)
            {
                line.points.Add(new Point(points[i++], points[i++]));
            }

            //It the same as:
            // while(i + 1 < points.Count)
            // {
            //     line.pixels.Add(new Point(points[i], points[i+1]));
            //     i += 2;
            // }
            // But it's look more funny

            buffor = sr.ReadLine();
            points = buffor.Split(',').Select(s => int.Parse(s)).ToList();

            while (i + 1 < points.Count)
            {
                line.pixels.Add(new Point(points[i++], points[i++]));
            }

            line.brushColor = sr.ReadLine();
            if (sr.EndOfStream)
            {
                throw new Exception($"Unexpected end of file {filename}");
            }

            lines.Add(line);

            buffor = sr.ReadLine();
            width  = int.Parse(buffor);
            if (sr.EndOfStream)
            {
                throw new Exception($"Unexpected end of file {filename}");
            }

            buffor = sr.ReadLine();
            height = int.Parse(buffor);

            if (sr.EndOfStream)
            {
                throw new Exception($"Unexpected end of file {filename}");
            }

            string pixelSpacing = sr.ReadLine();

            if (sr.EndOfStream)
            {
                throw new Exception($"Unexpected end of file {filename}");
            }

            StatisticsResult statisticsResult = new StatisticsResult();
            List <Point>     centralPoints    = new List <Point>();

            buffor = sr.ReadLine();
            if (buffor != "")
            {
                List <int> list = buffor.Split(',').Select(s => int.Parse(s)).ToList();
                statisticsResult.CenterOfMass = new Point(list[0], list[1]);
                if (sr.EndOfStream)
                {
                    throw new Exception($"Unexpected end of file {filename}");
                }

                buffor = sr.ReadLine();
                statisticsResult.Histogram = buffor.Split(',').Select(s => int.Parse(s)).ToArray();
                if (sr.EndOfStream)
                {
                    throw new Exception($"Unexpected end of file {filename}");
                }

                buffor = sr.ReadLine();
                statisticsResult.HistogramMin = int.Parse(buffor);
                if (sr.EndOfStream)
                {
                    throw new Exception($"Unexpected end of file {filename}");
                }

                buffor = sr.ReadLine();
                statisticsResult.HistogramMax = int.Parse(buffor);
                if (sr.EndOfStream)
                {
                    throw new Exception($"Unexpected end of file {filename}");
                }

                buffor = sr.ReadLine();
                statisticsResult.HistogramMean = double.Parse(buffor);
                if (sr.EndOfStream)
                {
                    throw new Exception($"Unexpected end of file {filename}");
                }

                buffor = sr.ReadLine();
                statisticsResult.Area = double.Parse(buffor);
                if (sr.EndOfStream)
                {
                    throw new Exception($"Unexpected end of file {filename}");
                }

                buffor = sr.ReadLine();
                statisticsResult.Permieter = double.Parse(buffor);
                if (sr.EndOfStream)
                {
                    throw new Exception($"Unexpected end of file {filename}");
                }

                buffor = sr.ReadLine();
                statisticsResult.NumberOfPixelsInsideContour = int.Parse(buffor);
                if (sr.EndOfStream)
                {
                    throw new Exception($"Unexpected end of file {filename}");
                }

                buffor = sr.ReadLine();
                statisticsResult.NumberOfPixelsOfContour = int.Parse(buffor);
                if (sr.EndOfStream)
                {
                    throw new Exception($"Unexpected end of file {filename}");
                }

                buffor = sr.ReadLine();
                points = buffor.Split(',').Select(s => int.Parse(s)).ToList();
                i      = 0;

                while (i + 1 < points.Count)
                {
                    centralPoints.Add(new Point(points[i++], points[i++]));
                }
            }

            sr.Close();

            SemiAutomaticContourDTO contour = new SemiAutomaticContourDTO(guid, DICOMid, tag, lines, width, height, statisticsResult, centralPoints, pixelSpacing);

            return(contour);
        }
        public static (List <Point>, StatisticsResult) Canny(string dicomId, List <Point> points, int canvasWidth, int canvasHeight,
                                                             List <Point> centralPoints, string pixelSpacing)
        {
            System.Drawing.Bitmap             bitmap  = OrthancConnection.GetBitmapByInstanceId(dicomId);
            System.Drawing.Rectangle          rect    = new System.Drawing.Rectangle(0, 0, bitmap.Width, bitmap.Height);
            System.Drawing.Imaging.BitmapData bmpData = bitmap.LockBits(rect, System.Drawing.Imaging.ImageLockMode.ReadOnly, bitmap.PixelFormat);
            IntPtr ptr   = bmpData.Scan0;
            int    bytes = Math.Abs(bmpData.Stride) * bitmap.Height;

            byte[] rgbValues = new byte[bytes];
            System.Runtime.InteropServices.Marshal.Copy(ptr, rgbValues, 0, bytes);

            double[, ][] sobel;
            int          width, height;

            width  = bitmap.Width;
            height = bitmap.Height;

            int xmin, xmax, ymin, ymax;

            (xmin, xmax, ymin, ymax) = FindPointsMinMaxPositions(points, width, height);

            sobel = SobelOperator(rgbValues, xmin, xmax, ymin, ymax, bmpData.Stride);
            bitmap.UnlockBits(bmpData);

            double[, ][] gradient = FindIntensityGradient(sobel, xmin, xmax, ymin, ymax);
            double[,] edges = NonMaximumSuppression(gradient, xmin, xmax, ymin, ymax);
            int[] distribution = DistributionFunction(edges, xmin, xmax, ymin, ymax);
            distribution = CumulativeDistributionFunction(distribution);

            int    min, max;
            double lowerThreshold = 0.70, higherThreshold = 0.95;

            (min, max)          = ChooseThreshold(distribution, lowerThreshold, higherThreshold);
            int[,] foundedEdges = HysteresisThreshold(edges, xmin, xmax, ymin, ymax, min, max);

            int[,] foundedEdges2 = Make4ConnectedMatrix(foundedEdges, xmin, xmax, ymin, ymax);

            double       weight = 2.5;
            List <Point> pixels = new List <Point>(Graph.FindShortestPath(foundedEdges2, xmin, xmax, ymin, ymax, weight, points));

            int[,] matrixWithContour = MakeMatrixFromPoints(width, height, pixels);
            int[,] matrix4Connected  = Make4ConnectedMatrix(matrixWithContour, 0, 0, width, height);
            List <Point> shortestPixels = new List <Point>(MakePointsFromMatrix(width, height, matrix4Connected));

            int[,] image = ReadMatrixFromBitmap(bitmap);

            StatisticsResult statisticsResult = null;

            double pixelSizeX = 0;
            double pixelSizeY = 0;

            if (pixelSpacing != null)
            {
                List <string> splitString = pixelSpacing.Split('\\').ToList();
                List <double> split       = new List <double>();
                foreach (var s in splitString)
                {
                    double d = 0;
                    if (double.TryParse(s, System.Globalization.NumberStyles.Number, System.Globalization.CultureInfo.InvariantCulture, out d))
                    {
                        split.Add(d);
                    }
                }
                if (split.Count >= 2)
                {
                    pixelSizeX = split[0];
                    pixelSizeY = split[1];
                }
            }

            double pixelAreaInMms   = pixelSizeX * pixelSizeY;
            double pixelLenghtInMms = pixelSizeX;

            statisticsResult = Statistics.GenerateStatistics(shortestPixels, matrixWithContour, image, 0, width, 0, height, pixelAreaInMms, pixelLenghtInMms, centralPoints.First());

            return(shortestPixels, statisticsResult);
        }
Exemplo n.º 27
0
        private void ShowLogData(StatisticsResult sr)
        {
            this.Cursor = Cursors.WaitCursor;

            try
            {
                myTabControl1.SuspendLayout();
                myTabControl1.TabPages.Clear();

                Dictionary <string, LogTmpInfo> dctInfos = new Dictionary <string, LogTmpInfo>();

                foreach (EvaluateResult er in sr.Results)
                {
                    string key = er.AppGuid + "@" + er.TableGuid;

                    if (dctInfos.ContainsKey(key))
                    {
                        dctInfos[key].lstRecordGuid.Add(er.LogGuid);
                    }
                    else
                    {
                        LogTmpInfo info = new LogTmpInfo();
                        info.AppGuid   = er.AppGuid;
                        info.TableGuid = er.TableGuid;
                        info.lstRecordGuid.Add(er.LogGuid);

                        dctInfos.Add(key, info);
                    }
                }

                foreach (LogTmpInfo ltInfo in dctInfos.Values)
                {
                    List <LogRecord> lstRecords = LogContentService.Instance.GetAppLogs(ltInfo.AppGuid, ltInfo.TableGuid, ltInfo.lstRecordGuid);

                    if (lstRecords == null || lstRecords.Count <= 0)
                    {
                        continue;
                    }

                    LogTable t = AppService.Instance.GetAppTable(ltInfo.AppGuid, ltInfo.TableGuid);

                    LogShowTabPage page = new LogShowTabPage(t.Name);
                    page.Tag = t.GUID;
                    page.ResetCloumns(t);
                    page.AppGuid   = ltInfo.AppGuid;
                    page.TableGuid = ltInfo.TableGuid;

                    this.myTabControl1.TabPages.Add(page);

                    page.SetLogs(lstRecords);
                }

                if (tplog.Parent == null)
                {
                    tplog.Parent = this.tabControl1;
                }

                tplog.Text = "\"" + sr.Title + "\"" + "的日志内容";
                this.tabControl1.SelectedTab = tplog;

                GC.Collect();
            }
            catch (Exception ex)
            {
                MessageBox.Show("显示日志内容失败,错误消息为:" + ex.Message);
            }
            finally
            {
                myTabControl1.ResumeLayout();
                this.Cursor = Cursors.Default;
            }
        }
        public async Task <StatisticsResult> CovidTestAsync(QuestionFormInfoReq req)
        {
            int[] simptomi = new int[14];
            for (int i = 0; i < req.Simptomi.Length; i++)
            {
                simptomi[req.Simptomi[i] - 1] = 1;
            }

            using (var client = new HttpClient())
            {
                var scoreRequest = new
                {
                    Inputs = new Dictionary <string, StringTable>()
                    {
                        {
                            "input1",
                            new StringTable()
                            {
                                ColumnNames = new string[] { "Age", "Gender", "Travel in previous 15 days", "Live in COVID affected area", "Contact with COVID positive person", "Wearing mask properly", "Already had COVID", "Is vaccinated", "Chronical illnesses", "Immune system weakening therapy", "Risk group", "Temperature", "Dry cough", "Weakness", "Muscle and bone pain", "Loss of taste", "Loss of smell", "Headache", "Difficulty breathing", "Short breath", "Diarrhea", "Chest pain", "Difficulty while moving", "Loss of consciousness", "Throat ache" },
                                Values      = new string[, ] {
                                    {
                                        req.Godine.ToString(),
                    req.Spol.ToString(),
                    req.Putovanje.ToString(),
                    req.Mjesto.ToString(),
                    req.Kontakt.ToString(),
                    req.Maska.ToString(),
                    req.Bolovanje.ToString(),
                    req.Vakcina.ToString(),
                    req.Hronicne.ToString(),
                    req.Terapija.ToString(),
                    req.Rizicno.ToString(),
                    simptomi[0].ToString(),
                    simptomi[1].ToString(),
                    simptomi[2].ToString(),
                    simptomi[3].ToString(),
                    simptomi[4].ToString(),
                    simptomi[5].ToString(),
                    simptomi[6].ToString(),
                    simptomi[7].ToString(),
                    simptomi[8].ToString(),
                    simptomi[9].ToString(),
                    simptomi[10].ToString(),
                    simptomi[11].ToString(),
                    simptomi[12].ToString(),
                    simptomi[13].ToString()
                                    }, { "0", "F", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0" },
                                }
                            }
                        },
                    },
                    GlobalParameters = new Dictionary <string, string>()
                    {
                    }
                };
                const string apiKey = "OP5UQHHwXqYWjrjJ3ZsrPXanE99DWnMi6Kmxa7z4uTULgwrNZSCLo4jtnTvNtQG4O17IZFdmqqKc+MyY6YUTHA=="; // Replace this with the API key for the web service
                client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", apiKey);

                client.BaseAddress = new Uri("https://ussouthcentral.services.azureml.net/workspaces/dfac26d08b5740aa9f52c2ee56a84c7d/services/19f09fb417c74779bee22a3db047c1a9/execute?api-version=2.0&details=true");



                HttpResponseMessage response = await client.PostAsJsonAsync("", scoreRequest);

                if (response.IsSuccessStatusCode)
                {
                    string result = await response.Content.ReadAsStringAsync();

                    string[] splitThis   = result.Split('"');
                    string   finalResult = splitThis[splitThis.Length - 56];


                    double statisticData = Convert.ToDouble(finalResult);
                    int    statDataRound = (int)Math.Round(statisticData * 100);

                    StatisticsResult statRes = new StatisticsResult
                    {
                        Result      = statisticData,
                        ResultRound = statDataRound
                    };

                    return(statRes);
                }
                else
                {
                    Console.WriteLine(string.Format("The request failed with status code: {0}", response.StatusCode));

                    // Print the headers - they include the requert ID and the timestamp, which are useful for debugging the failure
                    Console.WriteLine(response.Headers.ToString());

                    string responseContent = await response.Content.ReadAsStringAsync();

                    Console.WriteLine(responseContent);
                }

                return(null);
            }
        }
 public void Add(StatisticsResult statistics)
 {
     _results.Add(statistics);
 }