summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSteve Manuel <nilslice@gmail.com>2016-11-03 23:51:41 -0700
committerSteve Manuel <nilslice@gmail.com>2016-11-03 23:51:41 -0700
commit594bb855814b198a3a8c337fc0788753d921b39e (patch)
tree5d8538f8d2bdca3a8d1052d82f1a9ca7413150b8
parentcb8abfefc88b82e12be8b5b370573e3648da9c03 (diff)
testing simplified fix for template interpolation with analytics data
-rw-r--r--system/admin/admin.go2
-rw-r--r--system/api/analytics/init.go17
2 files changed, 10 insertions, 9 deletions
diff --git a/system/admin/admin.go b/system/admin/admin.go
index 37332ba..a0c2889 100644
--- a/system/admin/admin.go
+++ b/system/admin/admin.go
@@ -383,7 +383,7 @@ var analyticsHTML = `
var chart = new Chart(target, {
type: 'bar',
data: {
- labels: {{ .dates }},
+ labels: [{{ .dates }}],
datasets: [{
type: 'line',
label: 'Unique Clients',
diff --git a/system/api/analytics/init.go b/system/api/analytics/init.go
index d6735fb..6fb43a4 100644
--- a/system/api/analytics/init.go
+++ b/system/api/analytics/init.go
@@ -151,7 +151,7 @@ func Week() (map[string]string, error) {
return nil, err
}
- dates := [7]json.RawMessage{}
+ dates := []string{}
ips := [7]map[string]struct{}{}
total := [7]int{}
unique := [7]int{}
@@ -162,12 +162,12 @@ CHECK_REQUEST:
for j := range times {
// format times[j] (time.Time) into a MM/DD format for dates
- dates[j] = json.RawMessage(times[j].Format("01/02"))
+ dates = append(dates, times[j].Format("01/02"))
// if on today, there will be no next iteration to set values for
// day prior so all valid requests belong to today
if j == len(times) {
- if ts.After(times[j]) || ts.Equal(times[j]) {
+ if ts.After(times[j-1]) || ts.Equal(times[j]) {
// do all record keeping
total[j]++
@@ -175,6 +175,8 @@ CHECK_REQUEST:
unique[j-1]++
ips[j][requests[i].RemoteAddr] = struct{}{}
}
+
+ continue CHECK_REQUEST
}
}
@@ -187,6 +189,8 @@ CHECK_REQUEST:
unique[j]++
ips[j][requests[i].RemoteAddr] = struct{}{}
}
+
+ continue CHECK_REQUEST
}
if ts.Before(times[j]) {
@@ -217,13 +221,10 @@ CHECK_REQUEST:
return nil, err
}
- jsDates, err := json.Marshal(dates)
- if err != nil {
- return nil, err
- }
+ jsDates := strings.Join(dates, ",")
return map[string]string{
- "dates": string(jsDates),
+ "dates": jsDates,
"unique": string(jsUnique),
"total": string(jsTotal),
}, nil