-
Notifications
You must be signed in to change notification settings - Fork 0
/
stats.go
674 lines (617 loc) · 21.3 KB
/
stats.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
package main
/*
imports
*/
import (
"database/sql"
"flag"
"fmt"
"github.com/go-echarts/go-echarts/v2/charts"
"github.com/go-echarts/go-echarts/v2/opts"
_ "github.com/mattn/go-sqlite3"
"github.com/wcharczuk/go-chart"
"gopkg.in/ini.v1"
"html/template"
//"math/rand"
"os"
"regexp"
"runtime"
"strconv"
"time"
//"reflect"
)
/*
html templates
*/
const timeseriesplot_tmpl = `
<html>
<h1>{{.Title}}</h1>
<p>{{.Description}}</p>
<img src="{{.Img}}">
</html>
`
const table_tmpl = `<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>{{.Pagetitle}}</title>
<!-- choose a theme file -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jquery.tablesorter/2.31.3/css/theme.default.min.css">
<!-- load jQuery and tablesorter scripts -->
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.3/jquery.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery.tablesorter/2.31.3/js/jquery.tablesorter.js"></script>
<!-- tablesorter widgets (optional) -->
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery.tablesorter/2.31.3/js/jquery.tablesorter.widgets.js"></script>
</head>
<body>
<h1>{{.Pagetitle}}</h1>
<p>{{.Pagedescription}}</p>
<p>
<table id="myTable" class="tablesorter" border = "1">
<thead>
<tr>
{{range .Headers}}
<th>{{.}}</th>
{{end}}
</tr>
</thead>
<tbody>
{{range .Data}}
<tr>
{{range .}}
<td>{{.}}</td>
{{end}}
</tr>
{{end}}
</tbody>
</table>
</p>
<script>
$(function() {
$("#myTable").tablesorter();
});
</script>
</body>
</html>`
const html_index = `<!DOCTYPE html>
<html>
<body>
{{range .}}
<p>{{.Textpre}}<a href="{{.Url}}">{{.Title}}</a>{{.Textpost}}</p>
{{end}}
</body>
</html>`
/*
structs
*/
type Table struct {
Pagetitle string
Pagedescription string
Headers map[string]string
Data []map[string]string
}
type Visit struct {
id int
referrer string
request string
timestamp int
statuscode int
httpsize int
}
type Visitor struct {
visitor_id int
ip string
useragent string
visit []Visit
}
type timeseriesplot_html struct {
Title string
Img string
Description string
}
type args struct {
outputpad string
dbpad string
max_rows_in_table int
number_of_days_detailed int
number_of_days_per_hour int
number_of_days_per_day int
number_of_days_per_week int
number_of_days_per_month int
ignoredips []string
ignoredhostagents []string
ignoredreferrers []string
ignoredrequests []string
mydomain string
nodetailedstats bool
assethost string
}
type page_forindex struct {
Title string
Url string
Textpre string
Textpost string
}
/*
globals
*/
var indexpages []page_forindex
/*
functions
*/
func parseargs() args {
var output args
padPtr := flag.String("outputpath", `./output`, "the output path")
dbnamePtr := flag.String("dbname", `apachelog.db`, "name of the database to use")
mydomainPtr := flag.String("mydomain", `localhost.local`, "your domain name, so it doesn't show up as refferer")
number_of_days_detailed := flag.Int("number_of_days_detailed", 31, "number of days you want to show detailed info about")
number_of_days_per_hour := flag.Int("number_of_days_per_hour", 31, "number of days you want to show hourly statistics about")
number_of_days_per_day := flag.Int("number_of_days_per_day", 31, "number of days you want to show dayly statistics about")
number_of_days_per_week := flag.Int("number_of_days_per_week", 31, "number of days you want to show weekly statistics about")
number_of_days_per_month := flag.Int("number_of_days_per_month", 31, "number of days you want to show monthly statistics about")
max_rows_in_tablePtr := flag.Int("max_rows_in_table", 10000, "maximum number of rows in a html table")
ignorehostagents := flag.String("ignore_hostagents", `.*google.*`, "ignore this hostagent. If you want to ignore multipe hostagents: use a configfile!")
ignoredreferrers := flag.String("ignore_referrers", `.*localhost.*`, "ignore this referrer. If you want to ignore multipe referrers: use a configfile!")
ignorevisitorips := flag.String("ignore_visitor_ips", `^127\.0\.0\1$`, "ignore this ip. If you want to ignore multipe ips: use a configfile!")
ignoredrequests := flag.String("ignore_requests", `robots\.txt$`, "ignore this request. If you want to ignore multipe requests: use a configfile!")
assethostPtr := flag.String("assethost", `https://go-echarts.github.io/go-echarts-assets/assets/`, "By default, some dynamic graphs will pull the javascript for dynamic graphing from here...")
configfilePtr := flag.String("config", `none`, "complete path to the config file")
nodetailedstatsPtr := flag.Bool("nodetailedstats", false, "if you set this boolean parameter, the detailed stats table will be skipped... This stat takes up most of the time and memory consumption. Skipping this will dramatically speed up the stats process!")
flag.Parse()
flag_configfile := *configfilePtr
var ignorevisitorips_list []string
var ignorehostagents_list []string
var ignoredreferrers_list []string
var ignoredrequests_list []string
if flag_configfile == `none` {
if _, err := os.Stat("config.ini"); err == nil {
fmt.Printf("config file was not entered, but i found a config.ini file in the current path... using that one\n")
flag_configfile = "config.ini"
}
if _, err := os.Stat("/etc/CLFtoSQLite/config.ini"); err == nil {
fmt.Printf("config file was not entered, but i found a config.ini file: /etc/CLFtoSQLite/config.ini... using that one\n")
flag_configfile = "/etc/CLFtoSQLite/config.ini"
}
}
if flag_configfile != `none` {
cfg, err := ini.Load(flag_configfile)
if err != nil {
fmt.Printf("Fail to read file: %v", err)
os.Exit(1)
}
output.outputpad = cfg.Section("output").Key("pad").String()
output.number_of_days_detailed, _ = cfg.Section("output").Key("number_of_days_detailed").Int()
output.max_rows_in_table, _ = cfg.Section("output").Key("max_rows_in_table").Int()
output.dbpad = cfg.Section("general").Key("dbfilepath").String()
output.mydomain = cfg.Section("general").Key("mydomain").String()
output.number_of_days_per_hour, _ = cfg.Section("output").Key("number_of_days_per_hour").Int()
output.number_of_days_per_day, _ = cfg.Section("output").Key("number_of_days_per_day").Int()
output.number_of_days_per_week, _ = cfg.Section("output").Key("number_of_days_per_week").Int()
output.number_of_days_per_month, _ = cfg.Section("output").Key("number_of_days_per_month").Int()
output.assethost = cfg.Section("output").Key("assethost").String()
output.nodetailedstats, _ = cfg.Section("output").Key("nodetailedstats").Bool()
for _, ignoredip := range cfg.Section("ignorevisitorips").Keys() {
ignorevisitorips_list = append(ignorevisitorips_list, ignoredip.String())
}
output.ignoredips = ignorevisitorips_list
for _, ignoredhostagent := range cfg.Section("ignorehostagents").Keys() {
ignorehostagents_list = append(ignorehostagents_list, ignoredhostagent.String())
}
output.ignoredhostagents = ignorehostagents_list
for _, ignoredreferrer := range cfg.Section("ignorereferrers").Keys() {
ignoredreferrers_list = append(ignoredreferrers_list, ignoredreferrer.String())
}
output.ignoredreferrers = ignoredreferrers_list
for _, ignoredrequest := range cfg.Section("ignoredrequests").Keys() {
ignoredrequests_list = append(ignoredrequests_list, ignoredrequest.String())
}
output.ignoredrequests = ignoredrequests_list
} else {
output.outputpad = *padPtr
output.dbpad = *dbnamePtr
output.max_rows_in_table = *max_rows_in_tablePtr
output.number_of_days_detailed = *number_of_days_detailed
output.number_of_days_per_hour = *number_of_days_per_hour
output.number_of_days_per_day = *number_of_days_per_day
output.number_of_days_per_week = *number_of_days_per_week
output.number_of_days_per_month = *number_of_days_per_month
output.mydomain = *mydomainPtr
ignorevisitorips_list = append(ignorevisitorips_list, *ignorevisitorips)
output.ignoredips = ignorevisitorips_list
ignorehostagents_list = append(ignorehostagents_list, *ignorehostagents)
output.ignoredhostagents = ignorehostagents_list
ignoredreferrers_list = append(ignoredreferrers_list, *ignoredreferrers)
output.ignoredreferrers = ignoredreferrers_list
ignoredrequests_list = append(ignoredrequests_list, *ignoredrequests)
output.ignoredrequests = ignoredrequests_list
output.nodetailedstats = *nodetailedstatsPtr
output.assethost = *assethostPtr
}
return output
}
func createdb(dbnaam string) *sql.DB {
db, err := sql.Open("sqlite3", dbnaam)
if err != nil {
fmt.Printf("%s\n", err.Error())
os.Exit(1)
}
return db
}
func initialisedb(db *sql.DB) *sql.Tx {
tx, err := db.Begin()
if err != nil {
fmt.Printf("%s\n", err.Error())
os.Exit(1)
}
return tx
}
func prepstatements(tx *sql.Tx, args args) map[string]*sql.Stmt {
listitems := make(map[string]*sql.Stmt)
/*
detailed info about all visits
*/
query_allvisits_detailed := " select visit.id as visit_id, referrer.referrer as referrer, request.request as request, visit.visit_timestamp as visit_timestamp, user.ip as user_ip, user.useragent as user_agent, visit.statuscode as visit_statuscode, visit.httpsize as visit_httpsize, user.id as user_id "
query_allvisits_detailed += " from visit, user, request, referrer "
query_allvisits_detailed += " where visit.referrer = referrer.id and visit.request = request.id and visit.user = user.id "
query_allvisits_detailed += " and visit_timestamp > ? "
query_allvisits_detailed += " order by visit_timestamp desc "
stmt_allvisits_detailed, err := tx.Prepare(query_allvisits_detailed)
if err != nil {
fmt.Printf("%s\n", err.Error())
os.Exit(1)
}
listitems["stmt_allvisits_detailed"] = stmt_allvisits_detailed
/*
number of raw visitors per day
*/
query_nbhitsperday := "select count(*), date(visit_timestamp, 'unixepoch'), max(visit_timestamp) from visit group by date(visit_timestamp, 'unixepoch') order by visit_timestamp desc"
stmt_nbhitsperday, err := tx.Prepare(query_nbhitsperday)
if err != nil {
fmt.Printf("%s\n", err.Error())
os.Exit(1)
}
listitems["stmt_nbhitsperday"] = stmt_nbhitsperday
query_nbuniquesperday := "select count(distinct(user)), date(visit_timestamp, 'unixepoch'), max(visit_timestamp) from visit group by date(visit_timestamp, 'unixepoch') order by visit_timestamp desc"
stmt_nbuniquesperday, err := tx.Prepare(query_nbuniquesperday)
if err != nil {
fmt.Printf("%s\n", err.Error())
os.Exit(1)
}
listitems["stmt_nbuniquesperday"] = stmt_nbuniquesperday
return listitems
}
func getdetailedstats_andfillstructs(args args, prepdb map[string]*sql.Stmt) map[int]Visitor {
visitorlog := make(map[int]Visitor)
nu := int(time.Now().Unix())
vanaf := nu - (args.number_of_days_detailed * 86400)
MyHeaders := map[string]string{
"Title_0": "nb",
"Title_1": "timestamp",
"Title_1b": "request",
"Title_2": "referrer",
"Title_3": "user_ip",
"Title_4": "user_agent",
"Title_5": "visit_statuscode",
"Title_6": "visit_httpsize",
}
myTable := Table{
Pagetitle: "detailed visitor log",
Pagedescription: "this page shows a detailed log of all visits over the last " + strconv.Itoa(args.number_of_days_detailed) + " days",
Headers: MyHeaders,
Data: []map[string]string{},
}
stmt_allvisits_detailed := prepdb["stmt_allvisits_detailed"]
rows, err := stmt_allvisits_detailed.Query(vanaf)
if err != nil {
fmt.Printf("%s\n", err.Error())
}
defer rows.Close()
rownum := 0
for rows.Next() {
rownum = rownum + 1
var visit_id, visit_timestamp, visit_statuscode, visit_httpsize, user_id int
var referrer, request, user_ip, user_agent string
if err := rows.Scan(&visit_id, &referrer, &request, &visit_timestamp, &user_ip, &user_agent, &visit_statuscode, &visit_httpsize, &user_id); err != nil {
fmt.Printf("%s\n", err.Error())
}
ignore := false
for _, ignoredhostagent := range args.ignoredhostagents {
r, err := regexp.MatchString(ignoredhostagent, user_agent)
if err == nil && r {
ignore = true
}
}
for _, ignoredip := range args.ignoredips {
r, err := regexp.MatchString(ignoredip, user_ip)
if err == nil && r {
ignore = true
}
}
for _, ignoredreferrer := range args.ignoredreferrers {
r, err := regexp.MatchString(ignoredreferrer, referrer)
if err == nil && r {
ignore = true
}
}
for _, ignoredrequest := range args.ignoredrequests {
r, err := regexp.MatchString(ignoredrequest, request)
if err == nil && r {
ignore = true
}
}
if ignore == false {
visitstruct, exits := visitorlog[user_id]
MyVisit := Visit{id: visit_id, referrer: referrer, request: request, timestamp: visit_timestamp, statuscode: visit_statuscode, httpsize: visit_httpsize}
if exits {
visitstruct.visit = append(visitstruct.visit, MyVisit)
visitorlog[user_id] = visitstruct
} else {
MyVisitor := Visitor{visitor_id: user_id, ip: user_ip, useragent: user_agent}
MyVisitor.visit = append(MyVisitor.visit)
visitorlog[user_id] = MyVisitor
}
if rownum <= args.max_rows_in_table {
MyData := map[string]string{
"Value_0": strconv.Itoa(rownum),
"Value_1": strconv.Itoa(visit_timestamp),
"Value_1b": request,
"Value_2": referrer,
"Value_3": user_ip,
"Value_4": user_agent,
"Value_5": strconv.Itoa(visit_statuscode),
"Value_6": strconv.Itoa(visit_httpsize),
}
myTable.Data = append(myTable.Data, MyData)
}
}
}
if err := rows.Err(); err != nil {
fmt.Printf("%s\n", err.Error())
}
createtable(args, "detailed_visitor_log.html", "Detailed visitor Log", myTable)
return visitorlog
}
func createtable(args args, htmlfile string, htmltitle string, myTable Table) {
t, err := template.New("mytemplate").Parse(table_tmpl)
if err != nil {
panic(err)
}
var outputHTMLFile *os.File
if outputHTMLFile, err = os.Create(args.outputpad + htmlfile); err != nil {
panic(err)
}
if err = t.Execute(outputHTMLFile, myTable); err != nil {
panic(err)
}
defer outputHTMLFile.Close()
MyPageForIndex := page_forindex{
Title: htmltitle,
Url: htmlfile,
}
indexpages = append(indexpages, MyPageForIndex)
}
func overview_nbhits_total_last4weeks(args args, prepdb map[string]*sql.Stmt) bool {
MyHeaders := map[string]string{
"Title_1": "date",
"Title_2": "number of hits",
}
myTable := Table{
Pagetitle: "number of hits per day",
Pagedescription: "this table show the total raw hits per day",
Headers: MyHeaders,
Data: []map[string]string{},
}
var XValues_ts []time.Time
var YValues_ts []float64
var XValues_bs []string
YValues_bs := make(map[string][]int)
stmt_nbhitsperday := prepdb["stmt_nbhitsperday"]
rows, err := stmt_nbhitsperday.Query()
if err != nil {
fmt.Printf("%s\n", err.Error())
}
defer rows.Close()
rownum := 0
weeknum := 0
for rows.Next() {
rownum = rownum + 1
if rownum > 6 {
rownum = 0
weeknum++
}
if weeknum > 4 {
continue
}
var aantalhits int
var datum string
var avgepoch int
if err := rows.Scan(&aantalhits, &datum, &avgepoch); err != nil {
fmt.Printf("%s\n", err.Error())
}
golangtime := time.Unix(int64(avgepoch), 0)
XValues_ts = append(XValues_ts, golangtime)
YValues_ts = append(YValues_ts, float64(aantalhits))
YValues_bs[strconv.Itoa(weeknum)+"weeks ago"] = append(YValues_bs[strconv.Itoa(weeknum)+"weeks ago"], aantalhits)
MyData := map[string]string{
"Value_1": golangtime.Format("2006-01-02"),
"Value_2": strconv.Itoa(aantalhits),
}
myTable.Data = append(myTable.Data, MyData)
}
for i := 1; i < 8; i++ {
XValues_bs = append(XValues_bs, strconv.Itoa(i))
}
gochart_drawtimeseries(XValues_ts, YValues_ts, args, "Date", "Number of hits", "NbHitsPerDay.png", "NbHitsPerDay.html", "Number of hits per day", "The number of raw hits per day")
createBarChart_XString_Yint(XValues_bs, YValues_bs, "hits per day over the last 4 weeks", "day by day comparison of the number of hits for the last 4 weeks", args, "nb_hits_comparison_4_weeks.html")
createtable(args, "NbRawHitsPerDay.html", "Number of Raw hits per day", myTable)
return true
}
func createBarChart_XString_Yint(XValues []string, YValues map[string][]int, title string, subtitle string, args args, filename string) {
//fmt.Printf("X values:%+v\nY Values:%+v\n", XValues, YValues)
bar := charts.NewBar()
bar.SetGlobalOptions(charts.WithTitleOpts(opts.Title{
Title: title,
Subtitle: subtitle,
Top: "5%",
}))
for serienaam, serievalues := range YValues {
items := make([]opts.BarData, 0)
for _, serievalue := range serievalues {
items = append(items, opts.BarData{Value: serievalue})
}
bar.SetXAxis(XValues).AddSeries(serienaam, items)
}
bar.SetGlobalOptions(
charts.WithInitializationOpts(opts.Initialization{
PageTitle: title,
Width: `95vw`,
Height: `95vh`,
AssetsHost: args.assethost,
}),
charts.WithLegendOpts(opts.Legend{
Show: true,
Top: "10%",
Right: "5%",
}),
)
f, _ := os.Create(args.outputpad + filename)
_ = bar.Render(f)
MyPageForIndex := page_forindex{
Title: title,
Url: filename,
}
indexpages = append(indexpages, MyPageForIndex)
}
func gochart_drawtimeseries(XValues []time.Time, YValues []float64, args args, xtitle string, ytitle string, outputfilename_image string, outputfilename_html string, htmltitle string, description string) {
graph := chart.Chart{
Series: []chart.Series{
chart.TimeSeries{
XValues: XValues,
YValues: YValues,
},
},
XAxis: chart.XAxis{
Name: xtitle,
NameStyle: chart.StyleShow(),
Style: chart.StyleShow(),
},
YAxis: chart.YAxis{
Name: ytitle,
NameStyle: chart.StyleShow(),
Style: chart.StyleShow(),
},
}
f, _ := os.Create(args.outputpad + outputfilename_image)
defer f.Close()
graph.Render(chart.PNG, f)
myHtmlInput := timeseriesplot_html{
Title: htmltitle,
Img: outputfilename_image,
Description: description,
}
t, err := template.New("mytemplate").Parse(timeseriesplot_tmpl)
if err != nil {
panic(err)
}
var outputHTMLFile *os.File
if outputHTMLFile, err = os.Create(args.outputpad + outputfilename_html); err != nil {
panic(err)
}
if err = t.Execute(outputHTMLFile, myHtmlInput); err != nil {
panic(err)
}
defer outputHTMLFile.Close()
MyPageForIndex := page_forindex{
Title: htmltitle,
Url: outputfilename_html,
}
indexpages = append(indexpages, MyPageForIndex)
}
func createindex(args args) {
t, err := template.New("mytemplate").Parse(html_index)
if err != nil {
panic(err)
}
var outputHTMLFile *os.File
if outputHTMLFile, err = os.Create(args.outputpad + "index.html"); err != nil {
panic(err)
}
if err = t.Execute(outputHTMLFile, indexpages); err != nil {
panic(err)
}
defer outputHTMLFile.Close()
}
func overview_nbuniques_total_last4weeks(args args, prepdb map[string]*sql.Stmt) bool {
MyHeaders := map[string]string{
"Title_1": "date",
"Title_2": "number of uniques per day",
}
myTable := Table{
Pagetitle: "number of unique visitors per day",
Pagedescription: "this table show the total of unique visitors per day",
Headers: MyHeaders,
Data: []map[string]string{},
}
var XValues_ts []time.Time
var YValues_ts []float64
var XValues_bs []string
YValues_bs := make(map[string][]int)
stmt_nbuniquesperday := prepdb["stmt_nbuniquesperday"]
rows, err := stmt_nbuniquesperday.Query()
if err != nil {
fmt.Printf("%s\n", err.Error())
}
defer rows.Close()
rownum := 0
weeknum := 0
for rows.Next() {
rownum = rownum + 1
if rownum > 6 {
rownum = 0
weeknum++
}
if weeknum > 4 {
continue
}
var aantalhits int
var datum string
var avgepoch int
if err := rows.Scan(&aantalhits, &datum, &avgepoch); err != nil {
fmt.Printf("%s\n", err.Error())
}
golangtime := time.Unix(int64(avgepoch), 0)
XValues_ts = append(XValues_ts, golangtime)
YValues_ts = append(YValues_ts, float64(aantalhits))
YValues_bs[strconv.Itoa(weeknum)+" weeks ago"] = append(YValues_bs[strconv.Itoa(weeknum)+" weeks ago"], aantalhits)
MyData := map[string]string{
"Value_1": golangtime.Format("2006-01-02"),
"Value_2": strconv.Itoa(aantalhits),
}
myTable.Data = append(myTable.Data, MyData)
}
for i := 1; i < 8; i++ {
XValues_bs = append(XValues_bs, strconv.Itoa(i))
}
gochart_drawtimeseries(XValues_ts, YValues_ts, args, "Date", "Number of uniques", "NbUniquesPerDay.png", "NbUniquesPerDay.html", "Number of uniques per day", "The number of unique visitors per day")
createBarChart_XString_Yint(XValues_bs, YValues_bs, "unique visitors per day over the last 4 weeks", "day by day comparison of the number of unique visitors for the last 4 weeks", args, "nb_unique_visitors_comparison_4_weeks.html")
createtable(args, "NbUniquehitsHitsPerDay.html", "Number of Unique visitors per day", myTable)
return true
}
func main() {
var memStats runtime.MemStats
args := parseargs()
db := createdb(args.dbpad)
defer db.Close()
tx := initialisedb(db)
prepdb := prepstatements(tx, args)
//visitors := getdetailedstats_andfillstructs(args, prepdb)
if !args.nodetailedstats {
_ = getdetailedstats_andfillstructs(args, prepdb)
}
overview_nbhits_total_last4weeks(args, prepdb)
overview_nbuniques_total_last4weeks(args, prepdb)
tx.Commit()
runtime.ReadMemStats(&memStats)
fmt.Printf("runtime memstats begin of proces %+v\n", memStats.Alloc)
createindex(args)
}