Example #1
0
        public void ProcessCorona()
        {
            using (var cc = CC.GetCorona())
            {
                // Pobranie listy rekordów z bazy
                var dataList = cc.Cnn.Query <corona>("SELECT * FROM corona").ToList();

                // Pobranie pojedynczego rekordu
                var dataItem = cc.Cnn.Query <corona>("SELECT * FROM corona WHERE id = :id")
                               .Bind("id", 1, typeof(Int64))
                               .FetchItem();

                // Dodanie nowego rekordu
                var img  = File.ReadAllBytes(@"d:\indeks.jpg");
                var img2 = File.ReadAllBytes(@"d:\csdb.png");

                var newItem = new corona
                {
                    imie     = "Jan",
                    nazwisko = "Kowalski",
                    pesel    = "123456",
                    opis     = "Dobry gość",
                    data_po  = new DateTime(1978, 1, 1),
                    foto     = img,
                };
                newItem.Save(cc.Cnn);
            }
        }
Example #2
0
        public async Task <IActionResult> MakePredictionRequest(HomeViewModel model)
        {
            if (model.AttachedFile == null)
            {
                return(View("Index", model));
            }



            var client = new HttpClient();

            client.DefaultRequestHeaders.Add("Prediction-Key", _config.Value.Key);

            string url = _config.Value.Url;

            HttpResponseMessage response;

            var combinedPath = Path.Combine(_hostingEnvironment.WebRootPath, "temp");
            var fileName     = "org" + DateTime.Now.ToString("yyyyMMddhhmmss") + model.AttachedFile.FileName;
            var fileNameNew  = DateTime.Now.ToString("yyyyMMddhhmmss") + model.AttachedFile.FileName;
            var filePath     = Path.Combine(combinedPath, fileName);
            var filePathNew  = Path.Combine(combinedPath, fileNameNew);

            using (var stream = new FileStream(filePath, FileMode.Create))
            {
                model.AttachedFile.CopyTo(stream);
            }

            byte[] byteData = GetImageAsByteArray(filePath);

            JsonObj result = null;

            using (var content = new ByteArrayContent(byteData))
            {
                content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");
                response = await client.PostAsync(url, content);

                var res = await response.Content.ReadAsStringAsync();

                result = JsonConvert.DeserializeObject <JsonObj>(res);
            }

            var probability = result.Predictions.Where(x => x.TagName == "Pneumonia_Covid19").Select(x => x.Probability).FirstOrDefault();

            var czyWykryto = false;

            if (probability > _config.Value.Probability)
            {
                await SecondScan(filePath, filePathNew);

                czyWykryto   = true;
                model.Result = $"<p class=\"text-danger info\">Additional patient health verification required </p>";
                model.Src    = $"/temp/{fileNameNew}";
                model.Class  = "zdjecie";
            }
            else
            {
                model.Src   = $"/temp/{fileName}";
                model.Class = "";
            }

            using (var cc = CC.GetCorona())
            {
                var    img  = System.IO.File.ReadAllBytes(filePath);
                byte[] img2 = null;
                if (czyWykryto)
                {
                    img2 = System.IO.File.ReadAllBytes(filePathNew);
                }

                var newItem = new corona
                {
                    imie        = model.Imie,
                    nazwisko    = model.Nazwisko,
                    pesel       = model.Pesel,
                    opis        = model.Opis,
                    data_po     = model.Data_po,
                    foto        = img,
                    foto_marked = img2,
                };
                newItem.Save(cc.Cnn);
            }

            model.Procent = Math.Round(((decimal)probability * 100m) / 1m, 2);

            return(View("Index", model));
        }