public void Hub() { DBUtils.OpenConection(); try { //if ( DBUtils.ExecuteScalar("SELECT COUNT(ID) FROM InputsView" ) > 0 && !isOn) // { try { IsOn(); } catch (Exception) { } if (begginingID == 0) { if (!isOn) { File.WriteAllText(path, DBUtils.ExecuteScalar("SELECT ID FROM InputsView ORDER BY Id DESC LIMIT 1").ToString()); isOn = true; } } // } } catch (Exception) { } DBUtils.CloseConnection(); }
private void GetDailyHeatmap(string query) { highestHourValue = 0; Dictionary <string, int> dict = new Dictionary <string, int>(); for (int i = 0; i < 24; i++) { string from; string to; string zero = ""; if (i < 10) { zero = "0"; } from = zero + i.ToString() + ":00:00"; to = zero + i.ToString() + ":59:59"; string querySend = string.Format(query, from, to, where); int avg = DBUtils.ExecuteScalar(querySend); dict.Add(from, avg); if (avg > highestHourValue) { highestHourValue = avg; } } hourlyHeatmap = dict; }
private void AverageTimeItTakesToFixMistakes() { avgFixList.Clear(); int total = 0; int totalAccountedFor = 0; for (int i = 0; i < 10000; i += 50) { int typS = DBUtils.ExecuteScalar(string.Format("SELECT typing_speed FROM MistakesView WHERE typing_speed between {0} and {1} {2} ", i + 1, i + 50, whereAnd)); int trueTypS = DBUtils.ExecuteScalar(string.Format("SELECT true_typing_speed FROM MistakesView WHERE typing_speed between {0} and {1} {2} ", i + 1, i + 50, whereAnd)); int count = DBUtils.ExecuteScalar(string.Format("SELECT count(ID) FROM MistakesView WHERE typing_speed between {0} and {1} {2} ", i + 1, i + 50, whereAnd)); int avg = trueTypS - typS; if (avg > 0) { total += avg; totalAccountedFor += avg * count; TimeToFixMistakesObj ttf = new TimeToFixMistakesObj(i, count, trueTypS - typS); avgFixList.Add(ttf); } } List <TimeToFixMistakesObj> tempList = new List <TimeToFixMistakesObj>(); foreach (var item in avgFixList) { item.CalcPercentages(total, totalAccountedFor); } isLoadedFixed = true; }
public int UserLevelCheck() { try { DBUtils.OpenConection(); userLevel = DBUtils.ExecuteScalar("SELECT user_speed FROM user_level WHERE Id = 1"); DBUtils.CloseConnection(); if (userLevel < 500) { return(-100); } } catch (Exception a) { MessageBox.Show(a.ToString()); return(-500); } if (userLevel >= 500) { return(userLevel); } else { return(-100); } }
public int Validation(string view) { string valiadtioQuery = string.Format("SELECT COUNT(id) FROM {1} {0}", where, view); int validation = DBUtils.ExecuteScalar(valiadtioQuery); return(validation); }
public void AllInputsTypingSpeed() { string query = string.Format("SELECT SUM(timestamp) FROM InputsView {0}", where); int total_typing_speed = 0; total_typing_speed = DBUtils.ExecuteScalar(query); time = TimeSpan.FromMilliseconds(total_typing_speed); }
public void LoadTex() { DBUtils.OpenConection(); int userLevel = DBUtils.ExecuteScalar("SELECT user_speed FROM User_level WHERE id = 1"); DBUtils.CloseConnection(); if (userLevel > 200 && userLevel < 10000) { label_userLevel.Text = userLevel.ToString() + "ms"; } }
private void TypingSpeed_MistakesCount() { mistakesList.Clear(); for (int i = 0; i < 10000; i += 50) { string query = string.Format("SELECT COUNT(id) FROM MistakesView WHERE typing_speed between {0} and {1} {2}", i + 1, i + 50, whereAnd); int mistakes_count = DBUtils.ExecuteScalar(query); //double speed = (double)(i + 50) / (double)1000; if (mistakes_count != 0) { double speed = (double)1000 / (double)(i + 50); TypingSpeed_MistakesCount typS = new TypingSpeed_MistakesCount(Math.Round(speed, 2), mistakes_count); mistakesList.Add(typS); } } PercentageCalc(); isLoadedMistakes = true; }
public int CalculateUserLevel() { Dictionary <int, int> dict = new Dictionary <int, int>(); int totalVal = 0; for (int i = 0; i < 10000; i += 50) { string query = string.Format("SELECT COUNT(timestamp) FROM InputsView WHERE timestamp between {0} and {1} AND ID > {2}", i + 1, i + 50, begginingID); int count = DBUtils.ExecuteScalar(query); totalVal += count; dict.Add(i + 50, count); } double required = ((double)totalVal * 95) / 100; int current = 0; int userLevel = 0; if (dict.Count > 300) { foreach (var item in dict) { current += item.Value; if (current > required) { double ul = item.Key + (item.Key * 0.2); userLevel = (int)ul; break; } } DBUtils.ExecuteQueries(string.Format("DELETE FROM Inputs WHERE ID > {0} AND timestamp > {1} ", begginingID, userLevel)); DBUtils.ExecuteQueries(string.Format("DELETE FROM Heatmap WHERE ID > {0} AND delay > {1} ", begginingID, userLevel)); File.WriteAllText(path, ""); DBUtils.ExecuteQueries(string.Format("UPDATE User_level SET user_speed = {0} WHERE Id=1", userLevel)); MessageBox.Show("Automatic calibration is done \n" + "Your user level has been set to: " + userLevel.ToString() + "ms"); isOn = false; } return(userLevel); }
public void Typing_Speed() { doubleList.Clear(); string query; query = "SELECT COUNT(Id) FROM InputsView " + where; int sumOfRows = DBUtils.ExecuteScalar(query); double multiplier = Math.Floor((double)sumOfRows / 40); if (multiplier > 1) { doubleList = DBUtils.AllInputsTypingSpeed(("SELECT timestamp FROM InputsView " + where), (int)multiplier); } else { doubleList.Clear(); } SplitWhere(); isLoaderTypingSpeed = true; }
private void GetHeatmap(string query) { Dictionary <string, int> dict = new Dictionary <string, int>(); highestValue = 0; totalValue = 0; foreach (var item in heatDict) { string querySend = string.Format(query, item.Key, where); int avg = DBUtils.ExecuteScalar(querySend); dict.Add(item.Key, avg); totalValue += avg; if (avg > highestValue) { highestValue = avg; } } heatDict = dict; }
private static int GetExeID() { IntPtr hwnd = WindowsAPI.GetForegroundWindow(); uint pid; WindowsAPI.GetWindowThreadProcessId(hwnd, out pid); int processId = (int)pid; IntPtr hprocess = WindowsAPI.OpenProcess(ProcessAccessFlags.All, false, processId); var buffer = new StringBuilder(1024); int size = buffer.Capacity; if (WindowsAPI.QueryFullProcessImageName(hprocess, 0, buffer, out size)) { buffer.ToString(); } Process p = Process.GetProcessById((int)pid); DBUtils.OpenConection(); if (p != null) { try { exeID = DBUtils.GetExeID(p); } catch (Exception ex) { } } else { } isTrackable = Convert.ToBoolean(DBUtils.ExecuteScalar(string.Format("SELECT filter FROM Programs WHERE Id = {0} ", exeID))); DBUtils.CloseConnection(); return(1); }
private void GetWeeklyHeatmap(string query) { highestWeekValue = 0; Dictionary <string, int> dict = new Dictionary <string, int>(); int i = 1; foreach (var item in weeklyHeatmap) { if (i == 7) { i = 0; } string querySend = string.Format(query, i, where); int avg = DBUtils.ExecuteScalar(querySend); dict.Add(item.Key, avg); if (avg > highestWeekValue) { highestWeekValue = avg; } i++; } weeklyHeatmap = dict; }
private void userLevelTimer_Tick(object sender, EventArgs e) { AsyncStoreHeatnInput(); userLevelTimer.Enabled = false; sw.Reset(); inputStopWatch.Reset(); timer2.Stop(); normalInputSW.Reset(); if (autContrl.isOn) { DBUtils.OpenConection(); int test = DBUtils.ExecuteScalar(autContrl.lastRowIDQuery); int test2 = autContrl.begginingID; if (DBUtils.ExecuteScalar(autContrl.lastRowIDQuery) - autContrl.begginingID > 2500) { timer2.Interval = autContrl.CalculateUserLevel(); //autContrl.isOn = false; } DBUtils.CloseConnection(); } }
private void MistakesSpeed() { mistakesSpeedDict.Clear(); int average = DBUtils.ExecuteScalar(string.Format("SELECT AVG(timestamp) FROM InputsView WHERE timestamp > 5 {0}", whereAnd)); for (int i = 0; i < 10000; i += 50) { string query = string.Format("SELECT AVG(true_typing_speed) FROM MistakesView WHERE typing_speed between {0} and {1} {2}", i + 1, i + 50, whereAnd); int trueTypSpeedAvg = DBUtils.ExecuteScalar(query); if (trueTypSpeedAvg > 9) { mistakesSpeedDict.Add(Math.Round(1000 / (double)(i + 50), 2), Math.Round(1000 / (double)trueTypSpeedAvg, 2)); } } avgTypingSpeed = new double[mistakesSpeedDict.Count]; int k = 0; foreach (var item in mistakesSpeedDict) { avgTypingSpeed[k] = Math.Round(1000 / (double)average * 0.8, 2); k++; } isLoadedMistakesSpeed = true; }