Lines Matching +full:beer +full:- +full:ware

1 /*-
2 * SPDX-License-Identifier: Beerware
4 * ----------------------------------------------------------------------------
5 * "THE BEER-WARE LICENSE" (Revision 42):
8 * this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp
9 * ----------------------------------------------------------------------------
158 ds->lpoints = 100000; in NewSet()
159 ds->points = calloc(sizeof *ds->points, ds->lpoints); in NewSet()
160 assert(ds->points != NULL); in NewSet()
161 ds->syy = NAN; in NewSet()
170 if (ds->n >= ds->lpoints) { in AddPoint()
171 dp = ds->points; in AddPoint()
172 ds->lpoints *= 4; in AddPoint()
173 ds->points = calloc(sizeof *ds->points, ds->lpoints); in AddPoint()
174 assert(ds->points != NULL); in AddPoint()
175 memcpy(ds->points, dp, sizeof *dp * ds->n); in AddPoint()
178 ds->points[ds->n++] = a; in AddPoint()
179 ds->sy += a; in AddPoint()
186 return (ds->points[0]); in Min()
193 return (ds->points[ds->n -1]); in Max()
200 return(ds->sy / ds->n); in Avg()
206 const size_t m = ds->n / 2; in Median()
208 if ((ds->n % 2) == 0) in Median()
209 return ((ds->points[m] + (ds->points[m - 1])) / 2); in Median()
210 return (ds->points[m]); in Median()
219 if (isnan(ds->syy)) { in Var()
220 ds->syy = 0.0; in Var()
221 for (z = 0; z < ds->n; z++) in Var()
222 ds->syy += (ds->points[z] - a) * (ds->points[z] - a); in Var()
225 return (ds->syy / (ds->n - 1.0)); in Var()
247 ds->n, Min(ds), Max(ds), Median(ds), Avg(ds), Stddev(ds)); in Vitals()
258 z = ds->n + rs->n - 2; in Relative()
263 spool = (ds->n - 1) * Var(ds) + (rs->n - 1) * Var(rs); in Relative()
264 spool /= ds->n + rs->n - 2; in Relative()
266 s = spool * sqrt(1.0 / ds->n + 1.0 / rs->n); in Relative()
267 d = Avg(ds) - Avg(rs); in Relative()
270 re = (ds->n - 1) * Var(ds) + (rs->n - 1) * Var(rs) * in Relative()
272 re *= (ds->n + rs->n) / (ds->n * rs->n * (ds->n + rs->n - 2.0)); in Relative()
277 printf(" %g +/- %g\n", d, e); in Relative()
278 printf(" %g%% +/- %g%%\n", d * 100 / Avg(rs), re * 100 / Avg(rs)); in Relative()
308 pl->width = width; in SetupPlot()
309 pl->height = 0; in SetupPlot()
310 pl->data = NULL; in SetupPlot()
311 pl->bar = NULL; in SetupPlot()
312 pl->separate_bars = separate; in SetupPlot()
313 pl->num_datasets = num_datasets; in SetupPlot()
314 pl->min = 999e99; in SetupPlot()
315 pl->max = -999e99; in SetupPlot()
324 if (a < pl->min) in AdjPlot()
325 pl->min = a; in AdjPlot()
326 if (a > pl->max) in AdjPlot()
327 pl->max = a; in AdjPlot()
328 pl->span = pl->max - pl->min; in AdjPlot()
329 pl->dx = pl->span / (pl->width - 1.0); in AdjPlot()
330 pl->x0 = pl->min - .5 * pl->dx; in AdjPlot()
338 AdjPlot(Avg(ds) - Stddev(ds)); in DimPlot()
353 if (pl->span == 0) in PlotSet()
356 if (pl->separate_bars) in PlotSet()
357 bar = val-1; in PlotSet()
361 if (pl->bar == NULL) { in PlotSet()
362 pl->bar = calloc(sizeof(char *), pl->num_datasets); in PlotSet()
363 assert(pl->bar != NULL); in PlotSet()
366 if (pl->bar[bar] == NULL) { in PlotSet()
367 pl->bar[bar] = malloc(pl->width); in PlotSet()
368 assert(pl->bar[bar] != NULL); in PlotSet()
369 memset(pl->bar[bar], 0, pl->width); in PlotSet()
373 i = -1; in PlotSet()
376 for (n = 0; n < ds->n; n++) { in PlotSet()
377 x = (ds->points[n] - pl->x0) / pl->dx; in PlotSet()
388 if (m > pl->height) { in PlotSet()
389 pl->data = realloc(pl->data, pl->width * m); in PlotSet()
390 assert(pl->data != NULL); in PlotSet()
391 memset(pl->data + pl->height * pl->width, 0, in PlotSet()
392 (m - pl->height) * pl->width); in PlotSet()
394 pl->height = m; in PlotSet()
395 i = -1; in PlotSet()
396 for (n = 0; n < ds->n; n++) { in PlotSet()
397 x = (ds->points[n] - pl->x0) / pl->dx; in PlotSet()
404 pl->data[j * pl->width + x] |= val; in PlotSet()
409 x = ((av - sd) - pl->x0) / pl->dx; in PlotSet()
410 m = ((av + sd) - pl->x0) / pl->dx; in PlotSet()
411 pl->bar[bar][m] = '|'; in PlotSet()
412 pl->bar[bar][x] = '|'; in PlotSet()
414 if (pl->bar[bar][z] == 0) in PlotSet()
415 pl->bar[bar][z] = '_'; in PlotSet()
417 x = (Median(ds) - pl->x0) / pl->dx; in PlotSet()
418 pl->bar[bar][x] = 'M'; in PlotSet()
419 x = (av - pl->x0) / pl->dx; in PlotSet()
420 pl->bar[bar][x] = 'A'; in PlotSet()
431 if (pl->span == 0) { in DumpPlot()
437 for (i = 0; i < pl->width; i++) in DumpPlot()
438 putchar('-'); in DumpPlot()
441 for (z = 1; z < pl->height; z++) { in DumpPlot()
443 for (j = 0; j < pl->width; j++) { in DumpPlot()
444 k = pl->data[(pl->height - z) * pl->width + j]; in DumpPlot()
453 for (i = 0; i < pl->num_datasets; i++) { in DumpPlot()
454 if (pl->bar[i] == NULL) in DumpPlot()
457 for (j = 0; j < pl->width; j++) { in DumpPlot()
458 k = pl->bar[i][j]; in DumpPlot()
467 for (i = 0; i < pl->width; i++) in DumpPlot()
468 putchar('-'); in DumpPlot()
480 return (-1); in dbl_cmp()
497 s->name = strdup(n); in ReadSet()
498 assert(s->name != NULL); in ReadSet()
504 while (i > 0 && isspace(buf[i - 1])) in ReadSet()
505 buf[--i] = '\0'; in ReadSet()
521 if (s->n < 3) { in ReadSet()
526 qsort(s->points, s->n, sizeof *s->points, dbl_cmp); in ReadSet()
537 …"Usage: ministat [-C column] [-c confidence] [-d delimiter(s)] [-Ans] [-w width] [file [file ...]]… in usage()
545 fprintf(stderr, "\t-A : print statistics only. suppress the graph.\n"); in usage()
546 fprintf(stderr, "\t-C : column number to extract (starts and defaults to 1)\n"); in usage()
547 fprintf(stderr, "\t-d : delimiter(s) string, default to \" \\t\"\n"); in usage()
548 fprintf(stderr, "\t-n : print summary statistics only, no graph/test\n"); in usage()
549 fprintf(stderr, "\t-s : print avg/median/stddev bars on separate lines\n"); in usage()
550 fprintf(stderr, "\t-w : width of graph/test output (default 74 or terminal width)\n"); in usage()
557 const char *setfilenames[MAX_DS - 1]; in main()
558 struct dataset *ds[MAX_DS - 1]; in main()
559 FILE *setfiles[MAX_DS - 1]; in main()
576 else if (ioctl(STDOUT_FILENO, TIOCGWINSZ, &wsz) != -1 && in main()
578 termwidth = wsz.ws_col - 2; in main()
581 ci = -1; in main()
582 while ((c = getopt(argc, argv, "AC:c:d:snw:")) != -1) in main()
601 if (ci == -1) in main()
626 if (ci == -1) in main()
628 argc -= optind; in main()
636 if (argc > (MAX_DS - 1)) in main()
641 if (!strcmp(argv[i], "-")) in main()
657 printf("%c %s\n", symbol[i+1], ds[i]->name); in main()