DownloadStats GetDownloadStats(TimePeriod period, DateTime startDate, DateTime endDate, string from, string filter, object arg) { string sql = null; filter += " AND R.Date >= {1} AND R.Date < {2} "; switch (period) { case TimePeriod.Day: sql = "SELECT sum(Downloads), Platform, Date, Date FROM ReleasePackage R " + from + " where " + filter + " GROUP BY Platform, Date"; break; case TimePeriod.Week: sql = "SELECT sum(Downloads), Platform, MIN(Date), DATE_FORMAT(R.Date,'%u/%Y') FROM ReleasePackage R " + from + " where " + filter + " GROUP BY Platform, DATE_FORMAT(R.Date,'%u/%Y')"; break; case TimePeriod.Month: sql = "SELECT sum(Downloads), Platform, MIN(Date), DATE_FORMAT(R.Date,'%m/%Y') FROM ReleasePackage R " + from + " where " + filter + " GROUP BY Platform, DATE_FORMAT(R.Date,'%m/%Y')"; break; case TimePeriod.Year: sql = "SELECT sum(Downloads), Platform, MIN(Date), YEAR(Date) FROM ReleasePackage R " + from + " where " + filter + " GROUP BY Platform, YEAR(Date)"; break; case TimePeriod.All: sql = "SELECT sum(Downloads), Platform, MIN(Date), 'Total' FROM ReleasePackage R " + from + " where " + filter + " GROUP BY Platform"; break; } DownloadStats stats = new DownloadStats(); using (DbDataReader r = db.ExecuteSelect(sql, arg, startDate, endDate)) { while (r.Read()) { int count = r.IsDBNull(0) ? 0 : r.GetInt32(0); string plat = r.GetString(1); DateTime date = r.GetDateTime(2); string label = r[3].ToString(); DateTime start, end; GetPeriod(period, date, out start, out end); stats.AddValue(plat, label, count, start, end); } } stats.GenerateTotals(); stats.FillGaps(period, startDate, endDate); return(stats); }
DownloadStats GetDownloadStats(TimePeriod period, DateTime startDate, DateTime endDate, string from, string filter, object arg) { string sql = null; filter += " AND R.Date >= {1} AND R.Date < {2} "; switch (period) { case TimePeriod.Day: sql = "SELECT sum(Downloads), Platform, Date, Date FROM ReleasePackage R " + from + " where " + filter + " GROUP BY Platform, Date"; break; case TimePeriod.Week: sql = "SELECT sum(Downloads), Platform, MIN(Date), DATE_FORMAT(R.Date,'%u/%Y') FROM ReleasePackage R " + from + " where " + filter + " GROUP BY Platform, DATE_FORMAT(R.Date,'%u/%Y')"; break; case TimePeriod.Month: sql = "SELECT sum(Downloads), Platform, MIN(Date), DATE_FORMAT(R.Date,'%m/%Y') FROM ReleasePackage R " + from + " where " + filter + " GROUP BY Platform, DATE_FORMAT(R.Date,'%m/%Y')"; break; case TimePeriod.Year: sql = "SELECT sum(Downloads), Platform, MIN(Date), YEAR(Date) FROM ReleasePackage R " + from + " where " + filter + " GROUP BY Platform, YEAR(Date)"; break; case TimePeriod.All: sql = "SELECT sum(Downloads), Platform, MIN(Date), 'Total' FROM ReleasePackage R " + from + " where " + filter + " GROUP BY Platform"; break; } DownloadStats stats = new DownloadStats (); using (DbDataReader r = db.ExecuteSelect (sql, arg, startDate, endDate)) { while (r.Read ()) { int count = r.IsDBNull (0) ? 0 : r.GetInt32 (0); string plat = r.GetString (1); DateTime date = r.GetDateTime (2); string label = r[3].ToString (); DateTime start, end; GetPeriod (period, date, out start, out end); stats.AddValue (plat, label, count, start, end); } } stats.GenerateTotals (); stats.FillGaps (period, startDate, endDate); return stats; }