cellMapVisualizer/readDataset.go
readDataset.goRaw
1package main
2
3import (
4 "bufio"
5 "log"
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 var location LocationModel
33 location.Type = "Point"
34 lon, _ := strconv.ParseFloat(line[6], 64)
35 lat, _ := strconv.ParseFloat(line[7], 64)
36 location.Coordinates = append(location.Coordinates, lat)
37 location.Coordinates = append(location.Coordinates, lon)
38 cell.Location = location
39 cell.Range, _ = strconv.ParseFloat(line[8], 64)
40 cell.Samples, _ = strconv.Atoi(line[9])
41 cell.Changeable = line[10]
42 cell.Created, _ = strconv.ParseInt(line[11], 10, 64)
43 cell.Updated, _ = strconv.ParseInt(line[12], 10, 64)
44 cell.AverageSignal, _ = strconv.ParseFloat(line[13], 64)
45
46 //save cell to mongodb
47 err := cellCollection.Insert(cell)
48 check(err)
49 }
50 lineNum++
51 }
52 log.Println("line num: " + strconv.Itoa(lineNum))
53 log.Print("time elapsed from start: ")
54 log.Println(time.Since(tStart))
55}