public int StoreHeatMapAndInputs() //TODO: make this thing async or something { if (inputBuffer.Any()) { writeInProgress = true; List <InputObj> tempList = new List <InputObj>(inputBuffer); inputBuffer.Clear(); DBUtils.OpenConection(); string query; foreach (var item in tempList) { query = string.Format("INSERT INTO Heatmap (input,delay,date,program_id) " + "VALUES ('{0}', {1}, '{2}', '{3}')", item._inputKey, item._delay, item._dateStamp.ToString(), item._programID); DBUtils.ExecuteQueries(query); if (item._inputASCI == "'") { item._inputASCI = "''"; } query = string.Format("INSERT INTO Inputs ([input], [program_id], [datetime], [timestamp]) VALUES ('{0}', {1}, '{2}', {3})", item._inputASCI, item._programID, item._dateStamp, item._delay); DBUtils.ExecuteQueries(query); } DBUtils.CloseConnection(); } writeInProgress = false; return(1); }
private void Resutls() { SortList(); int mistakesCount = CompareArrays(); int percentage = Percentage(mistakesCount); int average = ListSum(); int ajustedAverage = CalculateAverage(mistakesCount, average, percentage); string userLevel = GetUserLevel(ajustedAverage); string message = ""; if (ajustedAverage == 0) { message = string.Format("You've made too many mistakes. {0} words were written with mistakes \n Which is {1}% of whole written text", mistakesCount, percentage); } else { DBUtils.OpenConection(); string query = string.Format("UPDATE User_level SET user_level = '{0}', user_speed = {1} WHERE Id=1", userLevel, ajustedAverage + 400); DBUtils.ExecuteQueries(query); DBUtils.CloseConnection(); message = string.Format("Your level has been assigned:{0} \n Your average typing speed is {1}", userLevel, ajustedAverage + 400); } mainForm.CheckForAutoCalibration(false); MessageBox.Show(message); }
private void materialFlatButton1_Click(object sender, EventArgs e) { if (numeric.Value < 200 || numeric.Value > 10000) { MessageBox.Show("Wrong values"); } else { DBUtils.OpenConection(); DBUtils.ExecuteQueries(string.Format("UPDATE User_level SET user_speed = {0} WHERE Id=1", numeric.Value)); DBUtils.CloseConnection(); cbMain.LoadTex(); mainForm.CheckForAutoCalibration(false); this.Close(); } }
public void CheckBoxFilter(DataGridView filterGrid) { List <ProgramExe> programList = new List <ProgramExe>(); try { foreach (DataGridViewRow row in filterGrid.Rows) { bool check = (bool)row.Cells["checkbox"].Value; int id = (int)row.Cells["id"].Value; ProgramExe program = new ProgramExe(id, check); programList.Add(program); } DBUtils.OpenConection(); foreach (var item in programList) { string query = string.Format("UPDATE Programs SET filter={0} WHERE Id={1} ", Convert.ToInt16(item._filter), item._id); DBUtils.ExecuteQueries(query); } DBUtils.CloseConnection(); // mistakes.MistakesHub(); JEIGU MISTAKES FILTRAS NEVEKIA BRING THIS BACK string connectionString = "Data Source=DatabaseLite.sqlite;Version=3;PRAGMA journal_mode=WAL;"; OrmLiteConnectionFactory dbFactory = new OrmLiteConnectionFactory(connectionString, SqliteDialect.Provider); //DateTime test = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); using (IDbConnection db = dbFactory.OpenDbConnection()) { //var filteredData = db.TABLE.Where(t => t.DATE > startDate && t.DATE < endDate); //var rows = db.From<Heatmap>().Where(x => x.date.CompareTo("2018-05-05 00:00:00") >= 0 && x.date.CompareTo("2018-06-21 23:59:59") <= 0); var rows = db.From <Heatmap>().Where <Heatmap>(x => x.program_id == 12); //db.From<Program>().Insert() } } catch (Exception xe) { MessageBox.Show(xe.ToString()); } }
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 ResetProgram(MainForm mf) { DBUtils.OpenConection(); string[] tables = { "Heatmap", "Inputs", "Mistakes", "Programs", }; foreach (var table in tables) { DBUtils.ExecuteQueries("delete from " + table); DBUtils.ExecuteQueries(string.Format("UPDATE sqlite_sequence SET seq = 1 WHERE name = '{0}'", table)); } DBUtils.ExecuteQueries(string.Format("UPDATE User_level SET user_speed = {0} WHERE Id=1", 0)); DBUtils.CloseConnection(); string path = Application.StartupPath + "\\AuCal.json"; File.WriteAllText(path, ""); MessageBox.Show("Please restart the aplication"); mf.Close(); }
public void SetUserLevel(int level) { DBUtils.OpenConection(); DBUtils.ExecuteQueries(string.Format("UPDATE User_level SET user_speed = {0} WHERE Id=1", level)); DBUtils.CloseConnection(); }
public void WriteToDB(string query) { DBUtils.OpenConection(); DBUtils.ExecuteQueries(query); DBUtils.CloseConnection(); }
private async void TestInsert() { string connectionString = "Data Source=DatabaseLite.sqlite;Version=3;PRAGMA journal_mode=WAL;"; OrmLiteConnectionFactory dbFactory = new OrmLiteConnectionFactory(connectionString, SqliteDialect.Provider); List <int> stList = new List <int>(); Stopwatch st = new Stopwatch(); Heatmap ht = new Heatmap(); ht.date = "2018-06-20 10:06:14"; ht.delay = 500; ht.program_id = 12; ht.input = "Return"; using (IDbConnection db = dbFactory.OpenDbConnection()) { using (IDbTransaction trans = db.OpenTransaction()) { st.Start(); // db.BeginTransaction(); for (int i = 0; i < 500000; i++) { db.Insert(ht); } trans.Commit(); st.Stop(); stList.Add((int)st.ElapsedMilliseconds); }; }; /* using (var db = dbFactory.Open()) * { * for (int i = 0; i < 100; i++) * { * db.ExecuteNonQuery("BEGIN"); * db.Insert(new Heatmap { input = "Return", delay = 500, date = "2018-06-20 10:06:14", program_id = 12 }); * db.ExecuteNonQuery("end"); * } * st.Stop(); * stList.Add((int)st.ElapsedMilliseconds); * }*/ DBUtils.OpenConection(); st.Restart(); for (int i = 0; i < 500000; i++) { query = "INSERT INTO Heatmap (input,delay,date,program_id) " + "VALUES ('Return', 500, '2018-06-20 10:06:1', '12')"; DBUtils.ExecuteQueries(query); } st.Stop(); stList.Add((int)st.ElapsedMilliseconds); DBUtils.CloseConnection(); string t = ""; using (var db = dbFactory.Open()) { } }