public TrafficSessions(TrafficMinutes tMinutes) { TrafficSession currentSession = null; foreach (TrafficMinute tMin in tMinutes) { if (currentSession == null || currentSession.EndTime.AddMinutes(10) < tMin.Timestamp) //new session { if (currentSession != null && currentSession.EndTime > currentSession.StartTime.AddMinutes(10)) { this.Add(currentSession); } currentSession = new TrafficSession() { StartTime = tMin.Timestamp }; } currentSession.EndTime = tMin.Timestamp; currentSession.TrafficMinutes.Add(tMin); } if (currentSession != null && currentSession.EndTime > currentSession.StartTime.AddMinutes(10)) { this.Add(currentSession); } }
public static TrafficMinutes Load(DateTime startDate, DateTime endDate, string site) { TrafficMinutes result = new TrafficMinutes(); GoogleApis.AnalyticsReport report = GoogleApis.AnalyticsHelper.LoadStreamMinutes(startDate, endDate, site); foreach (GoogleApis.AnalyticsRow row in report) { string d = row.Dimensions[0]; DateTime ts = new DateTime(Convert.ToInt32(d.Substring(0, 4)), Convert.ToInt32(d.Substring(4, 2)), Convert.ToInt32(d.Substring(6, 2)), Convert.ToInt32(d.Substring(8, 2)), Convert.ToInt32(d.Substring(10, 2)), 0); TrafficMinute tm = new TrafficMinute() { Timestamp = ts, ViewerCount = row.Metrics[0] }; result.Add(tm); } return(result); }