Exemplo n.º 1
0
func main() {
	flag.Parse()

	sinceT, err := parseTime(*since)
	if err != nil {
		log.Fatalf("Invalid since param: %v", err)
	}
	untilT, err := parseTime(*until)
	if err != nil {
		log.Fatalf("Invalid unitl param: %v", err)
	}

	perfData, err := perflog.LoadPerf(*perflogFile, sinceT, untilT)
	if err != nil {
		log.Fatalf("Failed to load performance log: %v", err)
	}

	log.Printf("%v items loaded", len(perfData))

	runWebUI(*addr, perfData)
}
Exemplo n.º 2
0
func main() {
	cfg := gopnikprerenderlib.PrerenderGlobalConfig{
		Prerender: gopnikprerenderlib.PrerenderConfig{
			UIAddr:    ":8088",
			DebugAddr: ":8098",
		},
		CommonConfig: app.CommonConfig{
			MetaSize: 8,
			TileSize: 256,
		},
	}

	app.App.Configure("Prerender", &cfg)

	zooms, err := parseZoom(*zoom)
	if err != nil {
		log.Fatalf("Invalid zoom: %v", err)
	}

	var tags []string
	if *tagsF != "" {
		tags = strings.Split(*tagsF, ",")
	}

	var coords []gopnik.TileCoord

	if *doAppend {
		f, err := os.Open(*planFile)
		if err != nil {
			if !strings.Contains(err.Error(), "no such file or directory") {
				log.Fatalf("Failed to open plan file: %v", err)
			}
		} else {
			dec := json.NewDecoder(f)
			err = dec.Decode(&coords)
			if err != nil {
				log.Fatalf("Failed to parse plan file: %v", err)
			}
		}
	}

	if *allWorld {
		for _, zoom := range zooms {
			bbox := [4]float64{-85 /*latMin*/, 85 /*latMax*/, -180 /*lonMin*/, 180 /*lonMax*/}
			zoomCoords, err := genCoords(bbox, zoom)
			if err != nil {
				log.Fatal(err)
			}
			// append tags
			for i := 0; i < len(zoomCoords); i++ {
				zoomCoords[i].Tags = tags
			}
			coords = append(coords, zoomCoords...)
		}
	} else {
		if *csvFile != "" {
			csvCoords, err := readCSVFile(*csvFile, zooms)
			if err != nil {
				log.Fatal(err)
			}
			// append tags
			for i := 0; i < len(csvCoords); i++ {
				csvCoords[i].Tags = tags
			}
			coords = append(coords, csvCoords...)
		}

		for _, zoom := range zooms {
			flagCoords, err := latLon(zoom)
			if err != nil {
				log.Fatal(err)
			}
			// append tags
			for i := 0; i < len(flagCoords); i++ {
				flagCoords[i].Tags = tags
			}
			coords = append(coords, flagCoords...)
		}
	}

	if *subtractPerflog != "" {
		sinceT, err := parseTime(*subtractPerflogSince)
		if err != nil {
			log.Fatalf("Invalid since param: %v", err)
		}
		untilT, err := parseTime(*subtractPerflogUntil)
		if err != nil {
			log.Fatalf("Invalid unitl param: %v", err)
		}

		perfData, err := perflog.LoadPerf(*subtractPerflog, sinceT, untilT)
		if err != nil {
			log.Fatalf("Failed to load performance log: %v", err)
		}

		coords = subtractPerflogItems(coords, perfData)
	}

	if *shuffle {
		rand.Seed(time.Now().UnixNano())
		shuffleCoords(coords)
	}

	fout, err := os.OpenFile(*planFile, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0666)
	if err != nil {
		log.Fatalf("Failed to open plan file: %v", err)
	}
	enc := json.NewEncoder(fout)
	err = enc.Encode(coords)
	if err != nil {
		log.Fatalf("Failed to encode plan file: %v", err)
	}
}