public static Attempt GetAttempt(string id, int attemptN, DataSource source)
 {
     using(var repo = new AttemptRepository()) {
         var attempt = repo.Attempts.Where(att => att.ID == id && att.AttemptNumber == attemptN && att.Source == source);
         return attempt.Single();
     }
 }
 public static List<Attempt> GetAttempts(DataSource source, bool valid = true)
 {
     List<Attempt> attempts = null;
     using (var Repository = new AttemptRepository()) {
         attempts = Repository.Attempts
         .Where(x => x.Source == source && (x.Valid == valid || x.Valid == true)).ToList();
     }
     return attempts;
 }
        public static Test GetTest(string id, DataSource source, bool valid = true)
        {
            List<Attempt> attempts = null;
            using (var Repository = new AttemptRepository()) {
                attempts = Repository.Attempts
                    .Where(x => x.Source == source && x.ID == id && (x.Valid == valid || x.Valid == true))
                    .ToList();
            }

            return new Test(attempts);
        }
示例#4
0
        public static List <Attempt> GetMissedAttempts(DataSource source, bool valid = true)
        {
            List <Attempt> attempts = null;

            using (var Repository = new AttemptRepository())
            {
                attempts = Repository.Attempts
                           .Where(x => !x.Hit && x.Source == source && (x.Valid == valid || x.Valid == true))
                           .ToList()
                           .OrderByDescending(MathHelper.GetDistance)
                           .ToList();
            }
            return(attempts);
        }
        public static List<Attempt> GetMissedAttempts(DataSource source, bool valid = true)
        {
            List<Attempt> attempts = null;

            using (var Repository = new AttemptRepository())
            {
                attempts = Repository.Attempts
                    .Where(x => !x.Hit && x.Source == source && (x.Valid == valid || x.Valid == true))
                    .ToList()
                    .OrderByDescending(MathHelper.GetDistance)
                    .ToList();
            }
            return attempts;
        }
示例#6
0
 public static void InvalidateAttempts(Dictionary <string, List <int> > outliers, DataSource source)
 {
     using (var Repo = new AttemptRepository()) {
         foreach (var entry in outliers)
         {
             var attempts = Repo.Attempts.Where(attempt => attempt.ID == entry.Key && attempt.Source == source);
             foreach (var aNum in entry.Value)
             {
                 var attempt = attempts.Where(att => att.AttemptNumber == aNum).Single();
                 attempt.Valid             = false;
                 Repo.Entry(attempt).State = EntityState.Modified;
             }
         }
         Repo.SaveChanges();
     }
 }
示例#7
0
        public static void GetInvalidCounts(DataSource source)
        {
            var attempts = AttemptRepository.GetAttempts(source, false);

            Console.WriteLine($"Information for {source} experiment\n");
            foreach (var direction in AllDirections)
            {
                foreach (var technique in AllTechniques)
                {
                    var all     = attempts.Where(x => x.Type == technique && x.Direction == direction);
                    var invalid = attempts.Where(x => x.Type == technique && x.Direction == direction && x.Valid == false);
                    Console.WriteLine($"{technique},{direction} : \t All: {all.Count()} \t Invalid: {invalid.Count()}");
                }
            }
            Console.WriteLine("\n");
        }
示例#8
0
        public static List <Test> GetTests(DataSource source, bool valid = true)
        {
            List <Test> tests = new List <Test>();

            using (var Repository = new AttemptRepository()) {
                var allTests = Repository.Attempts
                               .Where(attempt => attempt.Source == source && (attempt.Valid == valid || attempt.Valid == true))
                               .GroupBy(attempt => attempt.ID, attempt => attempt);

                foreach (var testgrouping in allTests)
                {
                    tests.Add(new Test(testgrouping.ToList()));
                }
            }

            return(tests);
        }
示例#9
0
        public static void InvalidateTechniqueAttempts(DataSource source, int userId, GestureType type, GestureDirection direction)
        {
            var attempts = AttemptRepository.GetAttempts(source, false);
            var modified = from attempt in attempts
                           where    attempt.ID == userId.ToString() &&
                           attempt.Type == type &&
                           attempt.Direction == direction &&
                           attempt.Source == source
                           select attempt;


            foreach (var attempt in modified)
            {
                attempt.Valid = false;
            }
            AttemptRepository.UpdateAttempt(modified);
        }
示例#10
0
        public static List<Test> GetTests(DataSource source, bool valid = true)
        {
            List<Test> tests = new List<Test>();

            using (var Repository = new AttemptRepository()) {
                var allTests = Repository.Attempts
                    .Where(attempt => attempt.Source == source && (attempt.Valid == valid || attempt.Valid == true))
                    .GroupBy(attempt => attempt.ID, attempt => attempt);

                foreach (var testgrouping in allTests) {
                    tests.Add(new Test(testgrouping.ToList()));
                }
            }

            return tests;
        }
示例#11
0
 public static int GetTestCount(DataSource source)
 {
     int count = 0;
     using (var Repository = new AttemptRepository()) {
         count = (from attempt in Repository.Attempts
                  where attempt.Source == source
                  group attempt by attempt.ID into testsFound
                  select testsFound).Count();
     }
     return count;
 }
示例#12
0
        private static void SaveTest(Test test)
        {
            using (var Repository = new AttemptRepository()) {
                SaveStatus = DatabaseSaveStatus.Saving;
                DataSource source = test.Attempts.First().Value.First().Source;
                bool success = false;
                try {
                    Console.WriteLine($"Searching for {test.ID} in database...");
                    var testFound = Repository.Attempts.Where(z => z.ID == test.ID && z.Source == source).Count() > 0;
                    if (testFound) {
                        Console.WriteLine($"Test ID {test.ID} from {source} data source already exists in database");
                        SaveStatus = DatabaseSaveStatus.Failed;
                        return;
                    }
                    Console.WriteLine($"Test ID {test.ID} not found, saving...");
                    foreach (var technique in DataGenerator.AllTechniques) {
                        Repository.Attempts.AddRange(test.Attempts[technique]);
                    }

                    Repository.SaveChanges();
                    success = true;
                    Console.WriteLine($"Successfully saved test number {test.ID} to database");
                }
                catch (Exception e) {
                    Console.WriteLine("Failed saving to database");
                    Console.WriteLine("Message: " + e.Message);
                }
                SaveStatus = success ? DatabaseSaveStatus.Success : DatabaseSaveStatus.Failed;
            }
        }
示例#13
0
 public static void UpdateAttempt(IEnumerable<Attempt> attempts)
 {
     using (var Repository = new AttemptRepository()) {
         foreach (var attempt in attempts) {
             Repository.Entry(attempt).State = EntityState.Modified;
         }
         Repository.SaveChanges();
     }
 }
示例#14
0
 public static void InvalidateAttempts(Dictionary<string, List<int>> outliers, DataSource source)
 {
     using(var Repo = new AttemptRepository()) {
         foreach (var entry in outliers) {
             var attempts = Repo.Attempts.Where(attempt => attempt.ID == entry.Key && attempt.Source == source);
             foreach(var aNum in entry.Value) {
                 var attempt = attempts.Where(att => att.AttemptNumber == aNum).Single();
                 attempt.Valid = false;
                 Repo.Entry(attempt).State = EntityState.Modified;
             }
         }
         Repo.SaveChanges();
     }
 }