|
@@ -1,58 +1,63 @@
|
1
|
1
|
package events
|
2
|
2
|
|
3
|
3
|
import (
|
4
|
|
- "fmt"
|
5
|
|
- "os"
|
6
|
4
|
"bufio"
|
|
5
|
+ "fmt"
|
7
|
6
|
"io"
|
8
|
|
- "strings"
|
9
|
7
|
"math"
|
|
8
|
+ "os"
|
|
9
|
+ "strings"
|
10
|
10
|
|
11
|
11
|
"box-gm/utils"
|
12
|
12
|
"time"
|
|
13
|
+
|
13
|
14
|
// "log"
|
14
|
|
- "github.com/tealeg/xlsx"
|
15
|
15
|
"github.com/astaxie/beego"
|
|
16
|
+ "github.com/tealeg/xlsx"
|
16
|
17
|
)
|
17
|
18
|
|
18
|
19
|
// 注册分布
|
19
|
|
-func Register_get_day_time_count(date string, serverId string) (map[int]int, int) {
|
|
20
|
+func Register_get_day_time_count(date string, shareCode string) (map[int]int, int) {
|
20
|
21
|
var timeCount = make(map[int]int)
|
21
|
|
-
|
22
|
|
- f, err := os.Open(fmt.Sprintf("%s/register-%s.log", utils.GetKeyConf("events", "path"), date))
|
|
22
|
+
|
|
23
|
+ filename := fmt.Sprintf("%s/register-%s.log", utils.GetKeyConf("events", "path"), date)
|
|
24
|
+ f, err := os.Open(filename)
|
23
|
25
|
if err != nil {
|
24
|
26
|
return timeCount, 0
|
25
|
27
|
}
|
26
|
28
|
defer f.Close()
|
27
|
29
|
|
28
|
|
-
|
29
|
|
- startTime := utils.GetTime(date+" 00:00:00")
|
|
30
|
+ startTime := utils.GetTime(date + " 00:00:00")
|
30
|
31
|
totalCount := 0
|
31
|
|
-
|
|
32
|
+
|
32
|
33
|
buff := bufio.NewReader(f)
|
33
|
34
|
for {
|
34
|
35
|
line, err := buff.ReadString('\n')
|
35
|
36
|
|
36
|
|
- if err != nil || io.EOF == err {
|
|
37
|
+ if (err != nil || io.EOF == err) && line == "" {
|
37
|
38
|
break
|
38
|
39
|
}
|
39
|
40
|
line = strings.TrimSpace(line)
|
40
|
41
|
|
41
|
42
|
arr := strings.Split(line, ";")
|
42
|
|
- if serverId == "0" || arr[1] == serverId {
|
43
|
|
- eventTime := utils.GetTime(arr[0])
|
|
43
|
+ if shareCode == "" || arr[3] == shareCode {
|
|
44
|
+ eventTime := utils.GetTime(arr[1])
|
44
|
45
|
|
45
|
46
|
sec := eventTime - startTime
|
46
|
|
- sec = int(math.Floor(float64(sec/300)))
|
47
|
|
- timeCount[sec] ++
|
48
|
|
- totalCount ++
|
|
47
|
+ sec = int(math.Floor(float64(sec / 300)))
|
|
48
|
+ timeCount[sec]++
|
|
49
|
+ totalCount++
|
|
50
|
+ }
|
|
51
|
+
|
|
52
|
+ if err != nil || io.EOF == err {
|
|
53
|
+ break
|
49
|
54
|
}
|
50
|
55
|
}
|
51
|
56
|
|
52
|
57
|
return timeCount, totalCount
|
53
|
58
|
}
|
54
|
59
|
|
55
|
|
-func Register_get_range_day_time_count(days int, serverId string) ([]*tgSeries, []string) {
|
|
60
|
+func Register_get_range_day_time_count(days int, shareCode string) ([]*tgSeries, []string) {
|
56
|
61
|
var series []*tgSeries
|
57
|
62
|
currTime := int(time.Now().Unix())
|
58
|
63
|
dayCount := 0
|
|
@@ -61,26 +66,26 @@ func Register_get_range_day_time_count(days int, serverId string) ([]*tgSeries,
|
61
|
66
|
date := time.Unix(int64(tiEvent), 0).Format("2006-01-02")
|
62
|
67
|
|
63
|
68
|
item := &tgSeries{}
|
64
|
|
- glCount, totalCount := Register_get_day_time_count(date, serverId)
|
|
69
|
+ glCount, totalCount := Register_get_day_time_count(date, shareCode)
|
65
|
70
|
item.Name = date + fmt.Sprintf(" 总人数:%d", totalCount)
|
66
|
|
- for i:=0; i < 289; i++ {
|
|
71
|
+ for i := 0; i < 289; i++ {
|
67
|
72
|
item.Data = append(item.Data, glCount[i])
|
68
|
73
|
}
|
69
|
74
|
item.MapCount = glCount
|
70
|
75
|
// log.Printf("item[%v]", item)
|
71
|
76
|
series = append(series, item)
|
72
|
77
|
|
73
|
|
- dayCount ++
|
|
78
|
+ dayCount++
|
74
|
79
|
if dayCount > days {
|
75
|
80
|
break
|
76
|
81
|
}
|
77
|
82
|
}
|
78
|
|
-
|
79
|
|
- var arrCate [] string
|
|
83
|
+
|
|
84
|
+ var arrCate []string
|
80
|
85
|
loc, _ := time.LoadLocation("Local")
|
81
|
|
- theTime, _ := time.ParseInLocation("2006-01-02 15:04:05", time.Now().Format("2006-01-02") + " 00:00:00", loc)
|
82
|
|
- for i:=0; i < 289; i++ {
|
83
|
|
- ti := theTime.Add(time.Minute*5*time.Duration(i))
|
|
86
|
+ theTime, _ := time.ParseInLocation("2006-01-02 15:04:05", time.Now().Format("2006-01-02")+" 00:00:00", loc)
|
|
87
|
+ for i := 0; i < 289; i++ {
|
|
88
|
+ ti := theTime.Add(time.Minute * 5 * time.Duration(i))
|
84
|
89
|
arrCate = append(arrCate, fmt.Sprintf("%02d:%02d:%02d", ti.Hour(), ti.Minute(), ti.Second()))
|
85
|
90
|
}
|
86
|
91
|
return series, arrCate
|
|
@@ -106,13 +111,13 @@ func Save_register_records(series []*tgSeries, user string) string {
|
106
|
111
|
row.AddCell().Value = "人数"
|
107
|
112
|
|
108
|
113
|
loc, _ := time.LoadLocation("Local")
|
109
|
|
- theTime, _ := time.ParseInLocation("2006-01-02 15:04:05", time.Now().Format("2006-01-02") + " 00:00:00", loc)
|
|
114
|
+ theTime, _ := time.ParseInLocation("2006-01-02 15:04:05", time.Now().Format("2006-01-02")+" 00:00:00", loc)
|
110
|
115
|
for i := 0; i < len(series); i++ {
|
111
|
116
|
item := series[i]
|
112
|
117
|
for k, v := range item.MapCount {
|
113
|
118
|
row = sheet.AddRow()
|
114
|
119
|
row.AddCell().SetString(item.Name)
|
115
|
|
- ti := theTime.Add(time.Minute*5*time.Duration(k))
|
|
120
|
+ ti := theTime.Add(time.Minute * 5 * time.Duration(k))
|
116
|
121
|
row.AddCell().SetString(fmt.Sprintf("%02d:%02d:%02d", ti.Hour(), ti.Minute(), ti.Second()))
|
117
|
122
|
row.AddCell().SetInt(v)
|
118
|
123
|
}
|
|
@@ -127,4 +132,4 @@ func Save_register_records(series []*tgSeries, user string) string {
|
127
|
132
|
}
|
128
|
133
|
|
129
|
134
|
return name
|
130
|
|
-}
|
|
135
|
+}
|