mirror of
https://github.com/arnaucube/cellMapVisualizer.git
synced 2026-02-07 11:16:40 +01:00
added log system, and added mongodb geolocation
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1,2 +1,3 @@
|
|||||||
*.csv
|
*.csv
|
||||||
*.csv.gz
|
*.csv.gz
|
||||||
|
*.log
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import "fmt"
|
import "log"
|
||||||
|
|
||||||
func check(err error) {
|
func check(err error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
log.Println(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
18
log.go
Normal file
18
log.go
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"io"
|
||||||
|
"log"
|
||||||
|
"os"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
func savelog() {
|
||||||
|
timeS := time.Now().String()
|
||||||
|
logFile, err := os.OpenFile("log-"+timeS+".log", os.O_CREATE|os.O_APPEND|os.O_RDWR, 0666)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
mw := io.MultiWriter(os.Stdout, logFile)
|
||||||
|
log.SetOutput(mw)
|
||||||
|
}
|
||||||
15
main.go
15
main.go
@@ -1,12 +1,10 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"github.com/fatih/color"
|
|
||||||
"github.com/gorilla/handlers"
|
"github.com/gorilla/handlers"
|
||||||
mgo "gopkg.in/mgo.v2"
|
mgo "gopkg.in/mgo.v2"
|
||||||
)
|
)
|
||||||
@@ -14,6 +12,8 @@ import (
|
|||||||
var cellCollection *mgo.Collection
|
var cellCollection *mgo.Collection
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
savelog()
|
||||||
|
|
||||||
//connect with mongodb
|
//connect with mongodb
|
||||||
readMongodbConfig("./mongodbConfig.json")
|
readMongodbConfig("./mongodbConfig.json")
|
||||||
session, err := getSession()
|
session, err := getSession()
|
||||||
@@ -22,17 +22,18 @@ func main() {
|
|||||||
|
|
||||||
if len(os.Args) > 1 {
|
if len(os.Args) > 1 {
|
||||||
if os.Args[1] == "-dataset" {
|
if os.Args[1] == "-dataset" {
|
||||||
color.Blue("starting to read dataset")
|
log.Println("starting to read dataset")
|
||||||
readDataset("cell_towers.csv")
|
readDataset("cell_towers.csv")
|
||||||
color.Blue("finished reading dataset")
|
//readDataset("dataModel_head.csv")
|
||||||
|
log.Println("finished reading dataset")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//http server start
|
//http server start
|
||||||
readServerConfig("./serverConfig.json")
|
readServerConfig("./serverConfig.json")
|
||||||
color.Green("server running")
|
log.Println("server running")
|
||||||
fmt.Print("port: ")
|
log.Print("port: ")
|
||||||
color.Green(serverConfig.ServerPort)
|
log.Println(serverConfig.ServerPort)
|
||||||
router := NewRouter()
|
router := NewRouter()
|
||||||
|
|
||||||
headersOk := handlers.AllowedHeaders([]string{"X-Requested-With", "Access-Control-Allow-Origin"})
|
headersOk := handlers.AllowedHeaders([]string{"X-Requested-With", "Access-Control-Allow-Origin"})
|
||||||
|
|||||||
@@ -1,18 +1,23 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
type CellModel struct {
|
type LocationModel struct {
|
||||||
Radio string `json:"radio"`
|
Type string `json:"type"`
|
||||||
MCC string `json:"mcc"`
|
Coordinates []float64 `json:"coordinates"`
|
||||||
Net int `json:"net"`
|
}
|
||||||
Area int `json:"area"`
|
type CellModel struct {
|
||||||
Cell int `json:"cell"`
|
Radio string `json:"radio"`
|
||||||
Unit int `json:"unit"`
|
MCC string `json:"mcc"`
|
||||||
Lat float64 `json:"lat"`
|
Net int `json:"net"`
|
||||||
Lon float64 `json:"lon"`
|
Area int `json:"area"`
|
||||||
Range float64 `json:"range"`
|
Cell int `json:"cell"`
|
||||||
Samples int `json:"samples"`
|
Unit int `json:"unit"`
|
||||||
Changeable string `json:"changeable"`
|
Lat float64 `json:"lat"`
|
||||||
Created int64 `json:"created"`
|
Lon float64 `json:"lon"`
|
||||||
Updated int64 `json:"updated"`
|
Location LocationModel `json:"location"`
|
||||||
AverageSignal float64 `json:"averagesignal"`
|
Range float64 `json:"range"`
|
||||||
|
Samples int `json:"samples"`
|
||||||
|
Changeable string `json:"changeable"`
|
||||||
|
Created int64 `json:"created"`
|
||||||
|
Updated int64 `json:"updated"`
|
||||||
|
AverageSignal float64 `json:"averagesignal"`
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
"fmt"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
@@ -29,6 +29,13 @@ func readDataset(path string) {
|
|||||||
cell.Unit, _ = strconv.Atoi(line[5])
|
cell.Unit, _ = strconv.Atoi(line[5])
|
||||||
cell.Lon, _ = strconv.ParseFloat(line[6], 64)
|
cell.Lon, _ = strconv.ParseFloat(line[6], 64)
|
||||||
cell.Lat, _ = strconv.ParseFloat(line[7], 64)
|
cell.Lat, _ = strconv.ParseFloat(line[7], 64)
|
||||||
|
var location LocationModel
|
||||||
|
location.Type = "Point"
|
||||||
|
lon, _ := strconv.ParseFloat(line[6], 64)
|
||||||
|
lat, _ := strconv.ParseFloat(line[7], 64)
|
||||||
|
location.Coordinates = append(location.Coordinates, lat)
|
||||||
|
location.Coordinates = append(location.Coordinates, lon)
|
||||||
|
cell.Location = location
|
||||||
cell.Range, _ = strconv.ParseFloat(line[8], 64)
|
cell.Range, _ = strconv.ParseFloat(line[8], 64)
|
||||||
cell.Samples, _ = strconv.Atoi(line[9])
|
cell.Samples, _ = strconv.Atoi(line[9])
|
||||||
cell.Changeable = line[10]
|
cell.Changeable = line[10]
|
||||||
@@ -42,8 +49,7 @@ func readDataset(path string) {
|
|||||||
}
|
}
|
||||||
lineNum++
|
lineNum++
|
||||||
}
|
}
|
||||||
fmt.Print("line num: ")
|
log.Println("line num: " + strconv.Itoa(lineNum))
|
||||||
fmt.Println(lineNum)
|
log.Print("time elapsed from start: ")
|
||||||
fmt.Print("time elapsed from start: ")
|
log.Println(time.Since(tStart))
|
||||||
fmt.Println(time.Since(tStart))
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user