public ActionResult PingCSV() { var model = new CsvModel() {Filename = "ping.csv"}; var bydate = _repository.GetAll().OrderBy(p => p.Time); var urls = bydate.Select(p => p.Url).Distinct(); var i = 0; bydate.Where(p=>p.Url == urls.First()).ToList().ForEach(p=> { var cols = new List<CsvColumn>(); cols.Add(new CsvColumn("Time",p.Time.ToString("u"))); cols.Add(new CsvColumn(p.Url,p.Duration.TotalMilliseconds.ToString())); urls.Skip(1).ToList().ForEach(u=> { var pForUrl = bydate.Where(pi => pi.Url == u).ElementAt(i); cols.Add(new CsvColumn(pForUrl.Url, pForUrl.Duration.TotalMilliseconds.ToString())); }); model.Rows.Add(new CsvRow() { Columns = cols }); i++; }); return View("csv", model); }
public ActionResult S3Hits() { var model = new CsvModel(){Filename = "s3Hits.csv"}; var date = DateTime.Parse("2012-08-08T00:58:05.000Z").ToUniversalTime(); var go = true; int i = 0; do { DateTime today = date.AddDays(i); DateTime tomorrow = today.AddDays(1); DateTime yesterday = today.AddDays(-1); var dayLogs = _parsedLogRepo.Search(l => l.Time < tomorrow && l.Time > yesterday).ToList(); i++; if(dayLogs.Any()) { var cols = new[] { new CsvColumn("Date",today.Date.ToString("yyyy-MM-dd")), new CsvColumn("200Hits",dayLogs.Count(l => l.HttpResponseCode == 200).ToString()), new CsvColumn("PartialHits",dayLogs.Count(l => l.HttpResponseCode == 206).ToString()), new CsvColumn("OtherHits",dayLogs.Count(l => l.HttpResponseCode != 206 && l.HttpResponseCode != 200).ToString()), new CsvColumn("TotalHits",dayLogs.Count().ToString()), new CsvColumn("TotalData",dayLogs.Sum(l=>l.BytesSent).ToString()) }; model.Rows.Add(new CsvRow() { Columns = cols.ToList() }); } else { go = false; } } while (go); return View("csv",model); }