public EmailScoreEntry(EmailData data, bool from_me) { this.Email = data.Email; if (from_me) { this.EmailCount = data.MyReplyTimesCount; this.MeanReplyTime = data.MyReplyTimesAverage; } else { this.EmailCount = data.ReplyTimesCount; this.MeanReplyTime = data.ReplyTimesAverage; } }
public static Dictionary <string, EmailData> CalculateStatistics(int daysAgo) { var myEmailAddress = App.GoogleUser.Email; var minDate = (DateTimeOffset)DateTime.Now.AddDays(-daysAgo); var emails = Database.Main.Table <Email> ().Where(x => x.Date > minDate).ToList(); var emailsById = new Dictionary <string, Email> (); foreach (var email in emails) { emailsById [email.Id] = email; } var emailData = new Dictionary <string, EmailData> (); foreach (var email in emails) { if (email.Date < DateTime.Now.AddDays(-daysAgo)) { continue; } bool isMyEmail = false; if (email.From.IndexOf(myEmailAddress, StringComparison.CurrentCultureIgnoreCase) > -1) { isMyEmail = true; } Email origEmail = null; if (!emailsById.TryGetValue(email.InReplyTo ?? "", out origEmail)) { continue; } // Ignore exchanges between other people if (origEmail.From.IndexOf(myEmailAddress, StringComparison.CurrentCultureIgnoreCase) == -1 && email.From.IndexOf(myEmailAddress, StringComparison.CurrentCultureIgnoreCase) == -1) { continue; } // Ignore emails which are not replies to the original email; they are probably forwards if (email.To.IndexOf(EmailScoreEntry.ParseEmailAddress(origEmail.From), StringComparison.CurrentCultureIgnoreCase) == -1) { continue; } // Ignore emails that are replies to myself if (isMyEmail && email.To.IndexOf(myEmailAddress, StringComparison.CurrentCultureIgnoreCase) > -1) { continue; } var key = isMyEmail ? origEmail.From : email.From; EmailData data; if (!emailData.TryGetValue(key, out data)) { emailData [key] = data = new EmailData { Email = key, }; } var replyTime = (int)(email.Date - origEmail.Date).TotalMinutes; if (isMyEmail) { data.MyReplyTimes [email.Id] = replyTime; } else { if (origEmail.From.IndexOf(myEmailAddress, StringComparison.CurrentCultureIgnoreCase) > -1) { data.ReplyTimesMinutes [email.Id] = replyTime; } else { data.OtherReplyTimesMinutes [email.Id] = replyTime; } } } return(emailData); }