예제 #1
0
        private bool check_if_in_db(byte[] blob, string path, out Result info)
        {
            info         = null;
            using var db = new ResultContext();
            var query = db.SavedResults.Where(a => a.Path == path);

            if (query.Count() == 0)
            {
                return(false);
            }
            foreach (var result in query)
            {
                info = new Result {
                    Class = result.Class, Confidence = result.Confidence, Path = result.Path, Blob = new ImageData {
                        Data = blob
                    }
                };
                if (result.Blob.Data.Length != blob.Length)
                {
                    return(false);
                }
                for (int i = 0; i < blob.Length; ++i)
                {
                    if (blob[i] != result.Blob.Data[i])
                    {
                        return(false);
                    }
                }
            }
            return(true);
        }
예제 #2
0
        private void post_process(Result result)
        {
            counter += 1;
            using (var db = new ResultContext())
            {
                Console.WriteLine("Added new entity");
                db.Add(result);
                db.SaveChanges();
            }

            tmpResult = result;
        }
예제 #3
0
        public static void ClearDatabase()
        {
            Console.WriteLine("Clearing database");
            using (var db = new ResultContext())
            {
                foreach (var result in db.SavedResults)
                {
                    db.Remove(result);
                }

                db.SaveChanges();
            }
        }
예제 #4
0
        public static Result[] ExtractDatabase()
        {
            Console.WriteLine("Extracting Database");

            using (var db = new ResultContext())
            {
                Result[] ret = new Result[db.SavedResults.Count()];
                int      i   = 0;
                foreach (var result in db.SavedResults.Include(a => a.Blob))
                {
                    ret[i] = result;
                    i     += 1;
                }

                return(ret);
            }
        }
예제 #5
0
        public static List <Result> GetDatabaseDir(string dir)
        {
            List <Result> ret = new List <Result>();

            using (var db = new ResultContext())
            {
                foreach (var path in Directory.GetFiles(dir, "*.jpeg"))
                {
                    Result saved = (from item in db.SavedResults.Include(a => a.Blob)
                                    where item.Path == path
                                    select item).First();
                    ret.Add(saved);
                }
            }
            Console.WriteLine("Returning from predictor");
            return(ret);
        }
예제 #6
0
        public static string DatabaseStats()
        {
            string ret = "";

            using (var db = new ResultContext())
            {
                foreach (var classLabel in classLabels)
                {
                    int count = db.SavedResults.Count(a => a.Class == classLabel);
                    if (count > 0)
                    {
                        ret += $"{classLabel}: {count}\r\n";
                    }
                }
            }

            return(ret);
        }
예제 #7
0
        public static Result[] ExtractByClass(string classname)
        {
            Console.WriteLine("Extracting " + classname);

            using (var db = new ResultContext())
            {
                Result[] ret   = new Result[db.SavedResults.Count(a => a.Class == classname)];
                var      items = from item in db.SavedResults.Include(a => a.Blob)
                                 where item.Class == classname
                                 select item;
                int i = 0;
                foreach (Result res in items)
                {
                    ret[i] = res;
                    i++;
                }
                return(ret);
            }
        }