|
|
|
@@ -46,13 +46,21 @@ Class StatsRepository_Class |
|
|
|
Set ActivityCounts = d |
|
|
|
End Function |
|
|
|
|
|
|
|
' Contacts per day for the last `days` days, oldest first: list of Array(date, count) including zero days |
|
|
|
' Contacts per day for the last `days` days, oldest first: list of Array(date, count, methods) including zero days. |
|
|
|
' methods is a Dictionary of method key -> count for that day. |
|
|
|
Public Function DailyActivity(days) |
|
|
|
Dim rs, counts, list, i, dt, key |
|
|
|
Dim rs, counts, byMethod, list, i, dt, key, m |
|
|
|
Set counts = CreateObject("Scripting.Dictionary") |
|
|
|
Set rs = Db_Query("SELECT contacted_at, COUNT(*) FROM interactions WHERE contacted_at >= DateAdd('d', " & CLng(1 - days) & ", Date()) GROUP BY contacted_at", Array()) |
|
|
|
Set byMethod = CreateObject("Scripting.Dictionary") |
|
|
|
Set rs = Db_Query("SELECT contacted_at, method, COUNT(*) FROM interactions WHERE contacted_at >= DateAdd('d', " & CLng(1 - days) & ", Date()) GROUP BY contacted_at, method", Array()) |
|
|
|
Do While Not rs.EOF |
|
|
|
If Not IsNull(rs(0)) Then counts(CStr(CLng(CDate(rs(0))))) = CLng(rs(1)) |
|
|
|
If Not IsNull(rs(0)) Then |
|
|
|
key = CStr(CLng(CDate(rs(0)))) |
|
|
|
counts(key) = N(counts(key)) + CLng(rs(2)) |
|
|
|
If Not byMethod.Exists(key) Then Set byMethod(key) = CreateObject("Scripting.Dictionary") |
|
|
|
m = rs(1) & "" |
|
|
|
byMethod(key)(m) = N(byMethod(key)(m)) + CLng(rs(2)) |
|
|
|
End If |
|
|
|
rs.MoveNext |
|
|
|
Loop |
|
|
|
rs.Close |
|
|
|
@@ -60,7 +68,11 @@ Class StatsRepository_Class |
|
|
|
For i = days - 1 To 0 Step -1 |
|
|
|
dt = Date - i |
|
|
|
key = CStr(CLng(dt)) |
|
|
|
If counts.Exists(key) Then list.Add list.Count, Array(dt, counts(key)) Else list.Add list.Count, Array(dt, 0) |
|
|
|
If counts.Exists(key) Then |
|
|
|
list.Add list.Count, Array(dt, counts(key), byMethod(key)) |
|
|
|
Else |
|
|
|
list.Add list.Count, Array(dt, 0, CreateObject("Scripting.Dictionary")) |
|
|
|
End If |
|
|
|
Next |
|
|
|
Set DailyActivity = list |
|
|
|
End Function |
|
|
|
|