Skip to content

Commit

Permalink
Fix properly calculated stats
Browse files Browse the repository at this point in the history
  • Loading branch information
Aliaksei Karneyeu committed Jun 26, 2020
1 parent 9fce401 commit a085f71
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
19 changes: 14 additions & 5 deletions cmd/send-report/report.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@ type Command struct {
EndDate string `short:"e" long:"end-date" required:"false"`
}

func printDiff(a, b int) string {
if a > b {
return "+" + strconv.Itoa(a-b)
} else {
return strconv.Itoa(a - b)
}
}

func (c *Command) Execute(_ []string) error {
var err error
var source io.Reader
Expand All @@ -55,6 +63,7 @@ func (c *Command) Execute(_ []string) error {
endTime = time.Now()
}
log.Println(endTime)
log.Println(logline.GetStartDate(c.Period, endTime))

collection := &collector.Collector{Domain: c.DomainName}
oldCollection := &collector.Collector{Domain: c.DomainName}
Expand All @@ -77,12 +86,12 @@ func (c *Command) Execute(_ []string) error {
// source.Close()
// }
messages := make([]string, 0)
msgLine := fmt.Sprintf("*%s*\n_Users: %d(%d) | Hits: %d(%d)_\n", collection.Domain, collection.Users, collection.Users-oldCollection.Users, collection.Hits, collection.Hits-oldCollection.Hits)
msgLine := fmt.Sprintf("*%s*\n_Users: %d(%s) | Hits: %d(%s)_\n", collection.Domain, collection.Users, printDiff(collection.Users, oldCollection.Users), collection.Hits, printDiff(collection.Hits, oldCollection.Hits))
msgLine += fmt.Sprintf("*Popular pages*:\n```\n%+v\n```\n", collection.GetViews(collection.PageViews))
msgLine += fmt.Sprintf("*Tags*:\n```\n%+v\n```\n", collection.GetViews(collection.TagViews))
msgLine += fmt.Sprintf("*Referers*:\n```\n%+v```\n", collection.GetViews(collection.Referers))
msgLine += fmt.Sprintf("*Browsers*:\n```\n%+v```\n", collection.GetViews(collection.ViewsByBrowser))
msgLine += fmt.Sprintf("*OS*:\n```\n%+v```\n", collection.GetViews(collection.ViewsByOS))
// msgLine += fmt.Sprintf("*Tags*:\n```\n%+v\n```\n", collection.GetViews(collection.TagViews))
// msgLine += fmt.Sprintf("*Referers*:\n```\n%+v```\n", collection.GetViews(collection.Referers))
// msgLine += fmt.Sprintf("*Browsers*:\n```\n%+v```\n", collection.GetViews(collection.ViewsByBrowser))
// msgLine += fmt.Sprintf("*OS*:\n```\n%+v```\n", collection.GetViews(collection.ViewsByOS))
curMsg := ""
properlyFinished := true
for _, msg := range strings.Split(msgLine, "\n") {
Expand Down
5 changes: 4 additions & 1 deletion pkg/logline/logline.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,5 +121,8 @@ func dateIsInInterval(line string, period string, endTime time.Time) bool {
return false
}
t, _ := time.Parse("02/Jan/2006:15:04:05 -0700", line)
return startDate.Before(t)
// if endTime.After(t) && startDate.Before(t) {
// log.Printf("| %v === %s === %v", endTime, line, startDate)
// }
return endTime.After(t) && startDate.Before(t)
}

0 comments on commit a085f71

Please sign in to comment.