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); }
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; }
public static void ClearDatabase() { Console.WriteLine("Clearing database"); using (var db = new ResultContext()) { foreach (var result in db.SavedResults) { db.Remove(result); } db.SaveChanges(); } }
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); } }
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); }
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); }
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); } }