You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

64 lines
1.5 KiB

  1. package main
  2. import (
  3. "fmt"
  4. "strconv"
  5. "strings"
  6. "time"
  7. "gopkg.in/mgo.v2/bson"
  8. )
  9. func timeToDate(blockTime int64) string {
  10. stringTime := strconv.FormatInt(blockTime, 10)
  11. i, err := strconv.ParseInt(stringTime, 10, 64)
  12. if err != nil {
  13. panic(err)
  14. }
  15. tm := time.Unix(i, 0)
  16. //fmt.Println(tm)
  17. stringDate := tm.String()
  18. //fmt.Println(stringDate)
  19. return stringDate
  20. }
  21. func hourAnalysis(e EdgeModel, blockTime int64) {
  22. //fmt.Println(blockTime)
  23. date := timeToDate(blockTime)
  24. date_hour := strings.Split(date, " ")[1]
  25. hour := strings.Split(date_hour, ":")[0]
  26. hourCount := HourCountModel{}
  27. err := hourCountCollection.Find(bson.M{"hour": hour}).One(&hourCount)
  28. if err != nil {
  29. //date not yet in DB
  30. var hourCount HourCountModel
  31. hourCount.Hour = hour
  32. hourCount.Count = 1
  33. err = hourCountCollection.Insert(hourCount)
  34. check(err)
  35. } else {
  36. hourCount.Count++
  37. err = hourCountCollection.Update(bson.M{"hour": hour}, &hourCount)
  38. check(err)
  39. }
  40. }
  41. func dateAnalysis(e EdgeModel, blockTime int64) {
  42. fmt.Println(blockTime)
  43. date := timeToDate(blockTime)
  44. dateCount := DateCountModel{}
  45. err := dateCountCollection.Find(bson.M{"date": date}).One(&dateCount)
  46. if err != nil {
  47. //date not yet in DB
  48. var dateCount DateCountModel
  49. dateCount.Date = date
  50. dateCount.Time = blockTime
  51. dateCount.Count = 1
  52. err = dateCountCollection.Insert(dateCount)
  53. check(err)
  54. } else {
  55. dateCount.Count++
  56. err = dateCountCollection.Update(bson.M{"date": date}, &dateCount)
  57. check(err)
  58. }
  59. }