public ClassificationCounts GetCountsBySubjectId(string id) { string query = GetCurrentClassificationCount(id); ClassificationCounts counts = new ClassificationCounts(); using (SQLiteConnection connection = new SQLiteConnection($"Data Source={App.DatabasePath}")) { try { connection.Open(); SQLiteCommand command = new SQLiteCommand(query, connection); SQLiteDataReader reader = command.ExecuteReader(); while (reader.Read()) { int total = Convert.ToInt32(reader["classifications_count"]); int smooth = Convert.ToInt32(reader["smooth"]); int features = Convert.ToInt32(reader["features"]); int star = Convert.ToInt32(reader["star"]); counts = new ClassificationCounts(total, smooth, features, star); } } catch (SQLiteException exception) { string ErrorMessage = $"Error Connecting to Database. Error: {exception.Message}"; Messenger.Default.Send(ErrorMessage, "DatabaseError"); } return(counts); } }
public async Task UpdateDBFromGraphQL(string id) { ClassificationCounts counts = await _graphQLService.GetReductionAsync(id); if (counts.Total > 0) { UpdateSubject(id, counts); } }
public void UpdateSubject(string id, ClassificationCounts counts) { string query = UpdateSubjectCounts(id, counts); using (SQLiteConnection connection = new SQLiteConnection($"Data Source={App.DatabasePath}")) { try { connection.Open(); SQLiteCommand command = new SQLiteCommand(query, connection); command.ExecuteNonQuery(); } catch (SQLiteException exception) { string ErrorMessage = $"Error Connecting to Database. Error: {exception.Message}"; Messenger.Default.Send(ErrorMessage, "DatabaseError"); } } }
string UpdateSubjectCounts(string id, ClassificationCounts counts) { return($"update Subjects set classifications_count = {counts.Total}, smooth = {counts.Smooth}, features = {counts.Features}, star = {counts.Star} where subject_id = {id}"); }
public ClassificationCounts IncrementAndUpdateCounts(Classification classification, ClassificationCounts counts) { switch (classification.Annotations[0].Value) { case 0: counts.Smooth += 1; break; case 1: counts.Features += 1; break; case 2: counts.Star += 1; break; } counts.Total += 1; UpdateSubject(classification.Links.Subjects[0], counts); return(counts); }
public ClassificationCounts IncrementClassificationCount(Classification classification) { ClassificationCounts counts = GetCountsBySubjectId(classification.Links.Subjects[0]); return(IncrementAndUpdateCounts(classification, counts)); }