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.

49 lines
1.2 KiB

  1. package main
  2. import (
  3. "bufio"
  4. "fmt"
  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. cell.Range, _ = strconv.ParseFloat(line[8], 64)
  30. cell.Samples, _ = strconv.Atoi(line[9])
  31. cell.Changeable = line[10]
  32. cell.Created, _ = strconv.ParseInt(line[11], 10, 64)
  33. cell.Updated, _ = strconv.ParseInt(line[12], 10, 64)
  34. cell.AverageSignal, _ = strconv.ParseFloat(line[13], 64)
  35. //save cell to mongodb
  36. err := cellCollection.Insert(cell)
  37. check(err)
  38. }
  39. lineNum++
  40. }
  41. fmt.Print("line num: ")
  42. fmt.Println(lineNum)
  43. fmt.Print("time elapsed from start: ")
  44. fmt.Println(time.Since(tStart))
  45. }