コード例 #1
0
ファイル: t005.go プロジェクト: ruphin/go-gnuplot
func main() {
	fname := ""
	persist := false
	debug := true

	p, err := gnuplot.NewPlotter(fname, persist, debug)
	if err != nil {
		err_string := fmt.Sprintf("** err: %v\n", err)
		panic(err_string)
	}
	defer p.Close()

	p.CheckedCmd("set grid x")
	p.CheckedCmd("set grid y")
	p.CheckedCmd("set grid z")
	p.PlotXYZ(
		[]float64{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10},
		[]float64{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10},
		[]float64{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10},
		"test 3d plot")
	p.SetLabels("x", "y", "z")
	p.CheckedCmd("set terminal pdf")
	p.CheckedCmd("set output 'plot005.pdf'")
	p.CheckedCmd("replot")

	p.CheckedCmd("q")
	return
}
コード例 #2
0
ファイル: map.go プロジェクト: WoLfh0UnD/wifi
func graphReponseRate(distances []float64, responseRates []float64) {
	// Initialize the plotters
	fname := ""
	persist := false
	debug := false

	p, err := gnuplot.NewPlotter(fname, persist, debug)
	if err != nil {
		err_string := fmt.Sprintf("** err: %v\n", err)
		panic(err_string)
	}
	defer p.Close()

	p.CheckedCmd("set xrange [0:100]")
	p.CheckedCmd("set key right top")
	p.CheckedCmd("set yrange [0:100]")

	p.SetStyle("linespoints lt 1 lw 1 ps 0.6 pt 5")
	p.PlotXY(distances, responseRates, "Response Rate")

	p.SetXLabel("Distance from AP (meters)")
	p.SetYLabel("Response Rate (%%)")
	p.CheckedCmd("set terminal pdf monochrome lw 2")
	p.CheckedCmd("set output 'graphs/responseRates.pdf'")
	p.CheckedCmd("replot")
}
コード例 #3
0
ファイル: t004.go プロジェクト: ruphin/go-gnuplot
func main() {
	fname := ""
	persist := false
	debug := true

	p, err := gnuplot.NewPlotter(fname, persist, debug)
	if err != nil {
		err_string := fmt.Sprintf("** err: %v\n", err)
		panic(err_string)
	}
	defer p.Close()

	p.SetStyle("steps")
	p.PlotFunc([]float64{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10},
		func(x float64) float64 { return math.Exp(float64(x) + 2.) },
		"test plot-func")
	p.SetXLabel("my x data")
	p.SetYLabel("my y data")
	p.CheckedCmd("set terminal pdf")
	p.CheckedCmd("set output 'plot004.pdf'")
	p.CheckedCmd("replot")

	p.CheckedCmd("q")
	return
}
コード例 #4
0
ファイル: engine.go プロジェクト: WoLfh0UnD/wifi
func (e *engine) drawLastFrame() {
	mapWidth := e.config.MapWidth
	mapHeight := e.config.MapHeight
	directory := e.config.OutputDir
	distance := (mapWidth - 170) / 6

	sources := make(map[string][]*Location)
	results := make(map[string][]*Location)

	var location *Location
	var result *Location
	var signals Signals
	var success bool
	for x := 85.0; x <= mapWidth-84.0; x += distance {
		for y := 85.0; y <= mapHeight-84.0; y += distance {
			location = NewLocation(x, y)
			signals = e.m.Read(location)
			for name, algorithm := range e.algorithms {
				result, success = algorithm.read(signals, location)
				if success {
					sources[name] = append(sources[name], location)
					results[name] = append(results[name], result)
				}
			}
		}
	}

	for name, _ := range e.algorithms {
		// Initialize the plotters
		fname := ""
		persist := false
		debug := false

		p, err := gnuplot.NewPlotter(fname, persist, debug)
		if err != nil {
			err_string := fmt.Sprintf("** err: %v\n", err)
			panic(err_string)
		}
		defer p.Close()

		p.CheckedCmd("unset key")
		p.CheckedCmd(fmt.Sprintf("set xrange [0:%.0f]", mapWidth))
		p.CheckedCmd(fmt.Sprintf("set yrange [0:%.0f]", mapHeight))

		p.SetStyle("linespoints lt 1 lw 1 ps 0.6 pt 1 rgb 'black'")
		for i, _ := range sources[name] {
			p.CheckedCmd(fmt.Sprintf("set arrow from %.0f,%.0f to %.0f,%.0f", sources[name][i].X, sources[name][i].Y, results[name][i].X, results[name][i].Y))
		}
		p.PlotXY([]float64{0, 0}, []float64{0, 0}, "")

		p.SetXLabel("X-coordinate")
		p.SetYLabel("Y-coordinate")
		p.CheckedCmd("set terminal pdf")
		p.CheckedCmd(fmt.Sprintf("set output '%v/%v-full.pdf'", directory, name))
		p.CheckedCmd("replot")
	}
}
コード例 #5
0
ファイル: t002.go プロジェクト: ruphin/go-gnuplot
func main() {
	fname := ""
	persist := false
	debug := true

	p, err := gnuplot.NewPlotter(fname, persist, debug)
	if err != nil {
		err_string := fmt.Sprintf("** err: %v\n", err)
		panic(err_string)
	}
	defer p.Close()

	p.PlotX([]float64{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, "some data")
	p.CheckedCmd("set terminal pdf")
	p.CheckedCmd("set output 'plot002.pdf'")
	p.CheckedCmd("replot")

	p.CheckedCmd("q")
	return
}
コード例 #6
0
ファイル: map.go プロジェクト: WoLfh0UnD/wifi
func graphSignalStrength() {
	// Initialize the plotters
	fname := ""
	persist := false
	debug := false

	p, err := gnuplot.NewPlotter(fname, persist, debug)
	if err != nil {
		err_string := fmt.Sprintf("** err: %v\n", err)
		panic(err_string)
	}
	defer p.Close()

	p.CheckedCmd("set xrange [0:140]")
	p.CheckedCmd("set datafile missing '0'")
	p.CheckedCmd("set key right top")
	p.CheckedCmd("set yrange [-100:-50]")

	signalStrengths := make([]float64, 125)
	byDistance := make([]float64, 125)
	for i := 5; i < 125; i++ {
		signalStrengths[i] = -58 - (14 * math.Log(float64(i)+5) / log10)
		byDistance[i] = float64(i)
	}
	fmt.Println(byDistance)
	fmt.Println(signalStrengths)
	p.SetStyle("lines lt 1 lw 2 ps 0.6 pt 5")
	p.PlotXY(byDistance, signalStrengths, "Median signal strength")

	p.SetXLabel("Distance (meters)")
	p.SetYLabel("Signal Strength (dBm)")
	p.CheckedCmd("set terminal pdf monochrome lw 2")
	p.CheckedCmd("set output 'graphs/signalStrengths.pdf'")
	p.CheckedCmd("replot")

}
コード例 #7
0
ファイル: t001.go プロジェクト: ruphin/go-gnuplot
func main() {
	fname := ""
	persist := false
	debug := true

	p, err := gnuplot.NewPlotter(fname, persist, debug)
	if err != nil {
		err_string := fmt.Sprintf("** err: %v\n", err)
		panic(err_string)
	}
	defer p.Close()

	p.CheckedCmd("plot %f*x", 23.0)
	p.CheckedCmd("plot %f * cos(%f * x)", 32.0, -3.0)
	//p.CheckedCmd("save foo.ps")
	p.CheckedCmd("set terminal pdf")
	p.CheckedCmd("set output 'plot001.pdf'")
	p.CheckedCmd("replot")

	p.CheckedCmd("q")
	//p.proc.Wait(0)

	return
}
コード例 #8
0
ファイル: map.go プロジェクト: WoLfh0UnD/wifi
func Test() {
	distances := []float64{5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95, 100}
	results := make([]map[int]float64, len(distances))
	for i, _ := range results {
		results[i] = make(map[int]float64)
	}
	testSize := 1000000
	for i := 0; i < testSize; i++ {
		for i, distance := range distances {
			if signalReceived(distance) {
				results[i][int(signalStrength(distance))]++
			}
		}
	}

	resultLists := make([][]float64, len(distances))
	for i, _ := range resultLists {
		resultLists[i] = make([]float64, 50)
	}

	var resultList []float64
	var totalHits float64
	responseRates := make([]float64, len(distances))
	for i, _ := range distances {
		resultList = resultLists[i]
		totalHits = 0
		for j := -100; j < -50; j++ {
			resultList[j+100] = results[i][j]
			totalHits += results[i][j]
		}
		for j, result := range resultList {
			resultList[j] = result / totalHits * 100
		}
		responseRates[i] = totalHits / float64(testSize) * 100
	}

	graphReponseRate(distances, responseRates)
	graphSignalStrength()

	// Initialize the plotters
	fname := ""
	persist := false
	debug := false

	p, err := gnuplot.NewPlotter(fname, persist, debug)
	if err != nil {
		err_string := fmt.Sprintf("** err: %v\n", err)
		panic(err_string)
	}
	defer p.Close()

	p.CheckedCmd("set xrange [-100:-50]")
	p.CheckedCmd("set datafile missing '0'")
	p.CheckedCmd("set key right top")
	p.CheckedCmd("set yrange [0:30]")

	bySignalStrength := make([]float64, 50)
	for i := 0; i < 50; i++ {
		bySignalStrength[i] = float64(i - 100)
	}

	p.SetStyle("linespoints lt 1 lw 1 ps 0.6 pt 5")
	p.PlotXY(bySignalStrength, resultLists[14], fmt.Sprintf("Response Rate=%.0f%v", responseRates[14], "%%"))

	p.SetStyle("linespoints lt 1 lw 1 ps 0.6 pt 9")
	p.PlotXY(bySignalStrength, resultLists[8], fmt.Sprintf("Response Rate=%.0f%v", responseRates[8], "%%"))

	p.SetStyle("linespoints lt 1 lw 1 ps 0.6 pt 13")
	p.PlotXY(bySignalStrength, resultLists[0], fmt.Sprintf("Response Rate=%.0f%v", responseRates[0], "%%"))

	p.SetXLabel("Signal Strength (dBm)")
	p.SetYLabel("Percentage of readings")
	p.CheckedCmd("set terminal pdf monochrome lw 2")
	p.CheckedCmd("set output 'graphs/readings.pdf'")
	p.CheckedCmd("replot")
}
コード例 #9
0
ファイル: engine.go プロジェクト: WoLfh0UnD/wifi
func (e *engine) plot(algorithmErrors map[string][][]float64, algorithmMisses map[string][]float64, plottype string) {
	testCycles := e.config.TestCycles
	directory := e.config.OutputDir
	perCycle := make([]float64, testCycles+1)
	for i := 0; i <= testCycles; i++ {
		perCycle[i] = float64(i)
	}

	// Initialize the plotters
	fname := ""
	persist := false
	debug := false

	errorPlot, err := gnuplot.NewPlotter(fname, persist, debug)
	if err != nil {
		err_string := fmt.Sprintf("** err: %v\n", err)
		panic(err_string)
	}
	defer errorPlot.Close()

	missPlot, err := gnuplot.NewPlotter(fname, persist, debug)
	if err != nil {
		err_string := fmt.Sprintf("** err: %v\n", err)
		panic(err_string)
	}
	defer missPlot.Close()

	errorPlot.CheckedCmd(fmt.Sprintf("set xrange [0:%d]", testCycles))
	errorPlot.CheckedCmd("set datafile missing 'NaN'")
	errorPlot.CheckedCmd("set key left top")
	errorPlot.CheckedCmd("set yrange [0:60]")
	missPlot.CheckedCmd(fmt.Sprintf("set xrange [0:%d]", testCycles))
	missPlot.CheckedCmd("set key left top")
	missPlot.CheckedCmd("set yrange [0:100]")

	graphStyle := []int{4, 6, 8, 12, 5, 7, 9, 13}
	graph := 0

	var errors []float64
	var misses []float64
	var sum float64
	var hits float64
	for name, _ := range e.algorithms {
		misses = algorithmMisses[name]
		errors = make([]float64, 0)
		for i, _ := range algorithmMisses[name] {
			sum = 0
			hits = float64(len(algorithmErrors[name][i]))
			for j := 0; j < int(hits); j++ {
				sum += algorithmErrors[name][i][j]
			}
			errors = append(errors, sum/hits)
			misses[i] = misses[i] / (misses[i] + hits) * 100
		}

		errorPlot.SetStyle(fmt.Sprintf("linespoints lt 1 lw 2 pi 2 pt %d linecolor rgb 'black'", graphStyle[graph]))
		errorPlot.PlotXY(perCycle, errors, name)

		missPlot.SetStyle(fmt.Sprintf("linespoints lt 1 lw 2 pi 2 pt %d linecolor rgb 'black'", graphStyle[graph]))
		missPlot.PlotXY(perCycle, misses, name)
		graph += 1
		fmt.Println(fmt.Sprintf("%v Errors: %v", name, errors))
	}

	if os.MkdirAll(directory, 0777) != nil {
		panic("Unable to create directory for graphs")
	}
	algorithms := ""
	for name, _ := range e.algorithms {
		if strings.Contains(name, "Enhanced") {
			algorithms = strings.Join([]string{algorithms, "E"}, "")
		}
		if strings.Contains(name, "Learning") {
			algorithms = strings.Join([]string{algorithms, "L"}, "")
		}
		if strings.Contains(name, "Centroid") {
			algorithms = strings.Join([]string{algorithms, "C"}, "")
		}
		if strings.Contains(name, "Fingerprinting") {
			algorithms = strings.Join([]string{algorithms, "F"}, "")
		}
	}

	filename := fmt.Sprintf("dens%d-dist%.0f-Cyc%d-%d-%d-%v", e.config.AccessPointDensity/100, e.config.SeedDistance, e.config.TestCycles, int(e.config.ReplacementRate*100), e.config.ReplacementStrategy, algorithms)

	errorPlot.SetXLabel("Cycles")
	errorPlot.SetYLabel("Average Error")
	errorPlot.CheckedCmd("set terminal pdf")
	errorPlot.CheckedCmd(fmt.Sprintf("set output '%v/%v-errors-%v.pdf'", directory, filename, plottype))
	errorPlot.CheckedCmd("replot")

	missPlot.SetXLabel("Cycles")
	missPlot.SetYLabel("Miss Percentage")
	missPlot.CheckedCmd("set terminal pdf")
	missPlot.CheckedCmd(fmt.Sprintf("set output '%v/%v-misses-%v.pdf'", directory, filename, plottype))
	missPlot.CheckedCmd("replot")
}