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.

55 lines
1.5 KiB

  1. package main
  2. import (
  3. "bufio"
  4. "log"
  5. "os"
  6. "strconv"
  7. "strings"
  8. "time"
  9. )
  10. func readDataset(path string) {
  11. tStart := time.Now()
  12. inFile, _ := os.Open(path)
  13. defer inFile.Close()
  14. scanner := bufio.NewScanner(inFile)
  15. scanner.Split(bufio.ScanLines)
  16. var lineNum int
  17. for scanner.Scan() {
  18. if lineNum > 0 {
  19. line := strings.Split(scanner.Text(), ",")
  20. var cell CellModel
  21. cell.Radio = line[0]
  22. cell.MCC = line[1]
  23. cell.Net, _ = strconv.Atoi(line[2])
  24. cell.Area, _ = strconv.Atoi(line[3])
  25. cell.Cell, _ = strconv.Atoi(line[4])
  26. cell.Unit, _ = strconv.Atoi(line[5])
  27. cell.Lon, _ = strconv.ParseFloat(line[6], 64)
  28. cell.Lat, _ = strconv.ParseFloat(line[7], 64)
  29. var location LocationModel
  30. location.Type = "Point"
  31. lon, _ := strconv.ParseFloat(line[6], 64)
  32. lat, _ := strconv.ParseFloat(line[7], 64)
  33. location.Coordinates = append(location.Coordinates, lat)
  34. location.Coordinates = append(location.Coordinates, lon)
  35. cell.Location = location
  36. cell.Range, _ = strconv.ParseFloat(line[8], 64)
  37. cell.Samples, _ = strconv.Atoi(line[9])
  38. cell.Changeable = line[10]
  39. cell.Created, _ = strconv.ParseInt(line[11], 10, 64)
  40. cell.Updated, _ = strconv.ParseInt(line[12], 10, 64)
  41. cell.AverageSignal, _ = strconv.ParseFloat(line[13], 64)
  42. //save cell to mongodb
  43. err := cellCollection.Insert(cell)
  44. check(err)
  45. }
  46. lineNum++
  47. }
  48. log.Println("line num: " + strconv.Itoa(lineNum))
  49. log.Print("time elapsed from start: ")
  50. log.Println(time.Since(tStart))
  51. }