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