Beispiel #1
0
func GeneratePlot(x, y []float64, title, xLabel, yLabel, legendLabel, fileName string) {
	outPlotPoints := make(plotter.XYs, len(x))

	for i, _ := range x {
		outPlotPoints[i].X = x[i]
		outPlotPoints[i].Y = y[i]
	}

	outPlot, err := plot.New()
	if err != nil {
		panic(err)
	}

	outPlot.Title.Text = title
	outPlot.X.Label.Text = xLabel
	outPlot.Y.Label.Text = yLabel

	err = plotutil.AddLines(outPlot,
		legendLabel, outPlotPoints)
	if err != nil {
		panic(err)
	}

	if err := outPlot.Save(6*vg.Inch, 6*vg.Inch, fileName); err != nil {
		panic(err)
	}
}
Beispiel #2
0
func PlotLine(pts, pts2 plotter.XYs, w []float64, b float64, path string) {
	p, err := plot.New()
	if err != nil {
		panic(err)
	}
	p.X.Label.Text = "x"
	p.Y.Label.Text = "y"

	x := []float64{}
	y := []float64{}
	for i := range make([]float64, 150) {
		bx := float64(i)*0.1 - 6.0
		x = append(x, bx)
		y = append(y, -b/w[1]-w[0]/w[1]*bx)
	}
	pts_res := makeLine(x, y)
	err = plotutil.AddScatters(p,
		"Class 0", pts,
		"Class 1", pts2,
	)
	if err != nil {
		panic(err)
	}
	err = plotutil.AddLines(p,
		"Line", pts_res,
	)
	if err != nil {
		panic(err)
	}
	if err := p.Save(10*vg.Inch, 10*vg.Inch, path); err != nil {
		panic(err)
	}
}
Beispiel #3
0
func GeneratePlots(x, y [][]float64, title, xLabel, yLabel, fileName string, legendLabel []string) {
	outPlotPoints := make([]plotter.XYs, len(x))
	outPlots := make([]*plot.Plot, len(x))

	for i, _ := range outPlotPoints {
		outPlot, err := plot.New()
		outPlots[i] = outPlot
		outPlots[i].Title.Text = title
		outPlots[i].X.Label.Text = xLabel
		outPlots[i].Y.Label.Text = yLabel
		outPlotPoints[i] = make(plotter.XYs, len(x[0]))
		for j, _ := range x[0] {
			outPlotPoints[i][j].X = x[i][j]
			outPlotPoints[i][j].Y = y[i][j]
		}
		err = plotutil.AddLines(outPlots[i],
			legendLabel[i], outPlotPoints[i])
		if err != nil {
			panic(err)
		}

		if err = outPlot.Save(6*vg.Inch, 6*vg.Inch, (fileName+strconv.FormatInt(int64(i), 16))+".png"); err != nil {
			panic(err)
		}
	}
}
Beispiel #4
0
func drawOpenIssueFraction(ctx *context, per *period, filename string) {
	start, end := ctx.StartTime(), ctx.EndTime()

	l := end.Sub(start)/DayDuration + 1
	totals := make([]int, l)
	opens := make([]int, l)
	ctx.WalkIssues(func(i github.Issue, isPullRequest bool) {
		if isPullRequest {
			return
		}
		created := i.CreatedAt
		closed := end
		if i.ClosedAt != nil {
			closed = *i.ClosedAt
		}
		for k := created.Sub(start) / DayDuration; k <= end.Sub(start)/DayDuration; k++ {
			totals[k]++
		}
		for k := created.Sub(start) / DayDuration; k <= closed.Sub(start)/DayDuration; k++ {
			opens[k]++
		}
	})

	fractions := make([]float64, len(totals))
	for i := range totals {
		if totals[i] != 0 {
			fractions[i] = float64(opens[i]) / float64(totals[i])
		}
	}

	p, err := plot.New()
	if err != nil {
		panic(err)
	}

	p.Title.Text = "Open:Total Issues"
	p.X.Label.Text = fmt.Sprintf("Date from %s to %s", per.start.Format(DateFormat), per.end.Format(DateFormat))
	p.Y.Label.Text = "Fraction"
	err = plotutil.AddLines(p, per.seqFloats(fractions, DayDuration))
	if err != nil {
		panic(err)
	}
	p.X.Tick.Marker = newDayTicker(p.X.Tick.Marker, per.start)

	// Save the plot to a PNG file.
	if err := p.Save(defaultWidth, defaultHeight, filename); err != nil {
		panic(err)
	}
}
Beispiel #5
0
func drawOpenIssueAge(ctx *context, per *period, filename string) {
	start, end := ctx.StartTime(), ctx.EndTime()

	l := end.Sub(start)/DayDuration + 1
	qs := make([]*quantile.Stream, l)
	for i := range qs {
		qs[i] = quantile.NewTargeted(0.25, 0.50, 0.75)
	}
	ctx.WalkIssues(func(i github.Issue, isPullRequest bool) {
		if isPullRequest {
			return
		}
		created := i.CreatedAt
		closed := end
		if i.ClosedAt != nil {
			closed = *i.ClosedAt
		}
		firsti := created.Sub(start) / DayDuration
		for k := firsti; k <= closed.Sub(start)/DayDuration; k++ {
			qs[k].Insert(float64(k - firsti))
		}
	})

	p, err := plot.New()
	if err != nil {
		panic(err)
	}

	p.Title.Text = "Age of Open Issues"
	p.X.Label.Text = fmt.Sprintf("Date from %s to %s", per.start.Format(DateFormat), per.end.Format(DateFormat))
	p.Y.Label.Text = "Age (days)"
	err = plotutil.AddLines(p, "25th percentile", per.seqFloats(quantileAt(qs, 0.25), DayDuration),
		"Median", per.seqFloats(quantileAt(qs, 0.50), DayDuration),
		"75th percentile", per.seqFloats(quantileAt(qs, 0.75), DayDuration))
	if err != nil {
		panic(err)
	}
	p.X.Tick.Marker = newDayTicker(p.X.Tick.Marker, per.start)

	// Save the plot to a PNG file.
	if err := p.Save(defaultWidth, defaultHeight, filename); err != nil {
		panic(err)
	}
}
Beispiel #6
0
func TestBenchmark(t *testing.T) {
	points := make(plotter.XYs, 9)

	points[0].X = 10
	points[1].X = 100
	points[2].X = 1000
	points[3].X = 10000
	points[4].X = 100000
	points[5].X = 1000000
	points[6].X = 10000000
	points[7].X = 100000000
	points[8].X = 1000000000
	points[0].Y = 496.0
	points[1].Y = 1196
	points[2].Y = 7724
	points[3].Y = 58489
	points[4].Y = 414589
	points[5].Y = 5590372
	points[6].Y = 96922714
	points[7].Y = 1431869649
	points[8].Y = 24368113980

	p, err := plot.New()
	if err != nil {
		panic(err)
	}

	p.Title.Text = "Calculation of the primes between 0 and n"
	p.X.Label.Text = "Primes Range"
	p.Y.Label.Text = "Running Time (ns/op)"

	err = plotutil.AddLines(p,
		"Sieve", points)
	if err != nil {
		panic(err)
	}

	// Save the plot to a PNG file.
	if err := p.Save(14, 10, "benchmark.png"); err != nil {
		panic(err)
	}
}
Beispiel #7
0
func drawIssueSolvedDuration(ctx *context, per *period, filename string) {
	start, end := ctx.StartTime(), ctx.EndTime()

	l := end.Sub(start)/MonthDuration + 1
	qs := make([]*quantile.Stream, l)
	for i := range qs {
		qs[i] = quantile.NewTargeted(0.50)
	}
	ctx.WalkIssues(func(i github.Issue, isPullRequest bool) {
		if isPullRequest {
			return
		}
		// count unresolved as the longest period
		d := end.Sub(start)
		if i.ClosedAt != nil {
			d = i.ClosedAt.Sub(*i.CreatedAt)
		}
		for k := i.CreatedAt.Sub(start) / MonthDuration; k <= end.Sub(start)/MonthDuration; k++ {
			qs[k].Insert(float64(d) / float64(DayDuration))
		}
	})

	p, err := plot.New()
	if err != nil {
		panic(err)
	}

	p.Title.Text = "Solved Duration of Issues"
	p.X.Label.Text = fmt.Sprintf("Month from %s to %s", per.start.Format(DateFormat), per.end.Format(DateFormat))
	p.Y.Label.Text = "Duration (days)"
	err = plotutil.AddLines(p, "Median", per.seqFloats(quantileAt(qs, 0.50), MonthDuration))
	if err != nil {
		panic(err)
	}
	p.X.Tick.Marker = newMonthTicker(p.X.Tick.Marker, per.start)

	// Save the plot to a PNG file.
	if err := p.Save(defaultWidth, defaultHeight, filename); err != nil {
		panic(err)
	}
}
Beispiel #8
0
func drawOpenIssues(ctx *context, per *period, filename string) {
	start, end := ctx.StartTime(), ctx.EndTime()

	l := end.Sub(start)/DayDuration + 1
	issues := make([]int, l)
	prs := make([]int, l)
	ctx.WalkIssues(func(i github.Issue, isPullRequest bool) {
		created := i.CreatedAt
		closed := end
		if i.ClosedAt != nil {
			closed = *i.ClosedAt
		}
		for k := created.Sub(start) / DayDuration; k <= closed.Sub(start)/DayDuration; k++ {
			if isPullRequest {
				prs[k]++
			} else {
				issues[k]++
			}
		}
	})

	p, err := plot.New()
	if err != nil {
		panic(err)
	}

	p.Title.Text = "Open Issues/PR"
	p.X.Label.Text = fmt.Sprintf("Date from %s to %s", per.start.Format(DateFormat), per.end.Format(DateFormat))
	p.Y.Label.Text = "Count"
	err = plotutil.AddLines(p, "issues", per.seqInts(issues, DayDuration), "PRs", per.seqInts(prs, DayDuration))
	if err != nil {
		panic(err)
	}
	p.X.Tick.Marker = newDayTicker(p.X.Tick.Marker, per.start)

	// Save the plot to a PNG file.
	if err := p.Save(defaultWidth, defaultHeight, filename); err != nil {
		panic(err)
	}
}