public static RetentionRow Get(DateTime datetime) { RetentionRow RetentionRow = new RetentionRow() { date = datetime.Date }; string query = String.Format(@"SELECT * FROM {1} where DATE(Date) = DATE('{0}')", datetime.ToString("yyyy/MM/dd HH:mm:ss"), "Retention"); try { DataTable singleRetentionRow = DBManager.Instance.Query(Datastore.Monitoring, query); if (singleRetentionRow.Rows.Count > 0) { DataRow c = singleRetentionRow.Rows[0]; foreach (DataColumn col in singleRetentionRow.Columns) { if (col.ColumnName.Contains("Day")) { int colIndex = Convert.ToInt32(Regex.Split(col.ColumnName, @"\D+")[1]); float perc = c.Field<float>(col.ColumnName); RetentionRow.SetDayPercent(colIndex, perc); } } } else { RetentionRow = new RetentionRow() { date = datetime.Date }; } } catch (Exception ex) { Logger.Instance.Error("Retention Get Problems" + datetime.ToString()); } return RetentionRow; }
//we're in a for loop when this is called, so we only want one row at a time public RetentionRow GetRetentionRow(DateTime datetime) { RetentionRow RetentionRow = new RetentionRow(); string query = String.Format(@"SELECT * FROM Retention where DATE(Date) = DATE('{0}')", datetime.ToString("yyyy/MM/dd HH:mm:ss")); try { DataTable singleRetentionRow = DBManager.Instance.Query(Datastore.Monitoring, query); if (singleRetentionRow.Rows.Count > 0) { DataRow c = singleRetentionRow.Rows[0]; RetentionRow.date = DateTime.Parse(c["Date"].ToString()); RetentionRow.installsOnThisDay = Convert.ToInt32(c["NewUsers"].ToString()); RetentionRow.loginsOnThisDay = Convert.ToInt32(c["Logins"].ToString()); int index = 0; foreach (object o in c.ItemArray) { if (o is float) { index++; RetentionRow.SetDayPercent(index, (float)o); } } } else { return null; } } catch (Exception ex) { Logger.Instance.Error("Do not have Retention Entry for date" + datetime.ToString()); } return RetentionRow; }