private void DeleterLoop() { var waitTime = TimeSpan.FromMinutes(5); while (!dispose) { var toDelete = new HashSet <string>(); foreach (var id in store.IDs) { var r = store.Get(id); if (DateTime.UtcNow > r.ExpiresAt) { toDelete.Add(id); } } foreach (var id in toDelete) { store.Delete(id); } waitMre.WaitOne(waitTime); } }
public IActionResult ViewReport(string id) { if (!reports.Exists(id)) { return(NotFound()); } //TODO: Cache this? var r = reports.Get(id); var sortableFields = new Dictionary <string, string>(); foreach (var field in r.Fields[0]) { if (r.Fields.All(x => { var f = x.Single(z => z.ID == field.ID); var value = f.Value; if (f.Type == Models.Type.Answers && value.ToUpperInvariant().StartsWith("A")) { value = value.Remove(0, 1); } return(float.TryParse(value, out var res)); })) { sortableFields[field.ID] = field.Name; } } ViewData["sha"] = ThisAssembly.Git.Sha; ViewData["sortableFields"] = sortableFields; return(View(r)); }
private Dictionary <string, AppStats> GetAppStats() { var appStats = new Dictionary <string, AppStats>(); var reports = new Dictionary <string, List <DateTime> >(); // Calculate total views and total reports foreach (var id in reportStore.IDs) { var r = reportStore.Get(id); if (!reports.ContainsKey(r.AppName)) { reports[r.AppName] = new List <DateTime>(); } reports[r.AppName].Add(r.CreatedAt.Date); if (!appStats.ContainsKey(r.AppName)) { appStats[r.AppName] = new AppStats { Name = r.AppName, AppURL = r.AppURL }; } appStats[r.AppName].LiveReports++; appStats[r.AppName].TotalViews += r.Views; } // Calculate views/report and reports/day foreach (var app in appStats.Keys) { if (appStats[app].TotalViews > 0) { var vpr = appStats[app].TotalViews * 1.0 / appStats[app].LiveReports; appStats[app].ViewsPerReport = vpr; } var days = reports[app].GroupBy(x => x); appStats[app].ReportsPerDay = days.Average(x => x.Count()); } return(appStats); }
public Task Invoke(HttpContext context, IReportStore reports) { var req = context.Request; var pathSplit = req.Path.ToString().Split("/"); if (req.Method == "GET" && reportBasePaths.Contains(pathSplit[1])) { Task.Run(() => { var id = pathSplit[2]; var r = reports.Get(id); r.Views++; reports.Save(r); }); } return(nextMiddleware(context)); }