void plotMAEGraph(int bars) { if(!is(TESTMODE) || !is(EXITRUN)) return; if(!bars) bars = 50; var vMaxMAE = 0; for(all_trades) // calculate maximum MAE in pips vMaxMAE = max(vMaxMAE,TradeMAE/TradePIP); //printf("\nMaxMAE: %.0f",vMaxMAE); var vStep; if(bars < 0) // bucket size in pips vStep = -bars; else vStep = 10*(int)(vMaxMAE/bars/10); for(all_trades) { var vResult = toPIP(TradeResult); var vMAE = TradeMAE/TradePIP/vStep; int n = floor(vMAE); plotBar("Profit",n,n*vStep,0,AVG|BARS|LBL2,COLOR_DEV); if(vResult > 0) plotGraph("Win",vMAE,vResult,DOT,GREEN); else plotGraph("Loss",vMAE,vResult,DOT,RED); } }
// returns false if blocked, true otherwise bool Statsdb::gifLoop ( ) { // shortcut Msg5 *m = &m_msg5; //#ifndef _USEPLOTTER_ //return true; //#endif // loop over all the lists in the time range, [m_t1,m_t2] for ( ; ! m_done ; ) { if ( ! m->getList ( (char)RDB_STATSDB , "statsdb" , // coll &m_list , (char *)&m_startKey , (char *)&m_endKey , 32000 , // requested scan size true , // include tree? false , // add to cache? 0 , // max cache age 0 , // start file number -1 , // number of files NULL , // state gotListWrapper, // callback m_niceness , // niceness false , // do error correction? NULL , // cache key pointer 0 , // # retries -1 , // max # retries true , // compensate for merge? -1 , // sync point NULL ) ) // msg5b return false; // . process list // . returns false with g_errno set on error if ( ! processList() ) return true; } // define time delta - commented out because it's currently not used. long dt = m_t2 - m_t1; //#ifdef _USEPLOTTER_ // gif size //char tmp[64]; // dimensions of the gif //sprintf ( tmp , "%lix%li", (long)DX+m_bx*2 , (long)DY+m_by*2 ); //GIFPlotter::parampl ( "BITMAPSIZE" , (void *)tmp ); // create one //GIFPlotter plotter ( NULL , m_fd , NULL ); // open it //plotter.openpl ( ); // define the space with boundaries 100 unit wide boundaries //plotter.space ( 0 , 0 , DX + m_bx * 2 , DY + m_by * 2 ); // line thickness in user coordinates (pixels for us) //plotter.linewidth ( 1 ); // set bg color to gray (r/g/b) //plotter.bgcolor ( 0xd600 , 0xce00 , 0xd600 ); // erase Plotter's graphics display //plotter.erase (); // draw axises in black //plotter.pencolorname ("black"); // // main graphing window // m_gw.safePrintf("<div style=\"position:relative;" "background-color:#c0c0c0;" //"overflow-y:hidden;" "overflow-x:hidden;" "z-index:-10;" // the tick marks we print below are based on it // being a window of the last 20 seconds... and using // DX pixels "min-width:%lipx;" "min-height:%lipx;" //"width:100%%;" //"min-height:600px;" "margin-top:10px;" "margin-bottom:10px;" "margin-right:10px;" "margin-left:10px;\">" ,(long)DX + 2 *m_bx ,(long)DY + 2*m_by); // draw the x-axis //plotter.line ( m_bx , m_by , DX + m_bx , m_by ); // 10 x-axis tick marks for ( int x = DX/20 ; x <= DX ; x += DX/20 ) { // tick mark //plotter.line ( x , -20 , x , 20 ); m_gw.safePrintf("<div style=\"position:absolute;" "left:%li;" "bottom:0;" "background-color:#000000;" "z-index:110;" "min-height:20px;" "min-width:3px;\"></div>\n" , m_bx + (long)x-1 ); long xv = (long)(dt * (long long)x/(long long)DX)-(long)dt; // LABEL m_gw.safePrintf("<div style=\"position:absolute;" "left:%li;" "bottom:20;" //"background-color:#000000;" "z-index:110;" "min-height:20px;" "min-width:3px;\">%lis</div>\n" , (long)x-10 + m_bx // the label: , xv ); } HashTableX tmpht; tmpht.set(4,0,0,NULL,0,false,m_niceness,"statsparms"); long col = 0; m_sb2->safePrintf("<table border=1 width=100%%>\n"); // label offset to prevent collisions of superimposing multiple // graph calbrations long zoff = 0; // // point to the triplets in m_sb1's buffer (x,y,c) // char *p = m_sb1.getBufStart(); char *pend = p + m_sb1.length(); for ( ; p < pend ; p += 12 ) { // breathe QUICKPOLL ( m_niceness ); // get graph hash of this point long gh = *(long *)(p +8); // if we already did this graph, skip it if ( tmpht.isInTable ( &gh ) ) continue; // . graph this single graph of this color // . returns ptr to first point of different color! plotGraph ( p , pend , gh , m_gw , zoff ); // prevent collisions zoff += 20; // get the label based on graphHash Label *bb = getLabel ( gh ); // add to key if ( col == 0 ) m_sb2->safePrintf("<tr>"); m_sb2->safePrintf("<td bgcolor=#%06lx> </td>" "<td>%s</td>\n", bb->m_color , bb->m_keyDesc ); if ( col == 1 ) m_sb2->safePrintf("</tr>\n"); // inc column and wrap if ( ++col >= 2 ) col = 0; // . do not re-display // . TODO: deal with error tmpht.addKey ( &gh ); } // clear that up m_sb1.reset(); // now plot the events, horizontal line segments like the performance // graph uses for ( long i = 0 ; i < m_ht3.m_numSlots ; i++ ) { // breathe QUICKPOLL ( m_niceness ); // skip if slot empty if ( ! m_ht3.m_flags[i] ) continue; // get the offset into m_sb3 long offset = *(long *)m_ht3.getValueFromSlot(i); // get buf start char *bufStart = m_sb3.getBufStart(); // get the ptr EventPoint *pp = (EventPoint *)(bufStart + offset); // get name of parm Parm *m = g_parms.getParmFromParmHash ( pp->m_parmHash ); // make sure we got it if ( ! m ) { log("statsdb: unrecognized parm hash = %li", pp->m_parmHash); continue; //char *xx=NULL;*xx=0; } } // set the line width //plotter.linewidth ( pp->m_thickness ); // get parm hash long colorHash = pp->m_parmHash; // add in old/new values to make it different colorHash = hash32h ( (long)pp->m_oldVal , colorHash ); colorHash = hash32h ( (long)pp->m_newVal , colorHash ); // . get color // . is really the parm hash in disguise long c1 = colorHash & 0x00ffffff; // use the color specified from addStat_r() for this line/pt //plotter.pencolor ( ((c1 >> 16) & 0xff) << 8 , // ((c1 >> 8) & 0xff) << 8 , // ((c1 >> 0) & 0xff) << 8 ); long x1 = pp->m_a; long x2 = pp->m_b; long y1 = *(long *)m_ht3.getKey(i); // i value // ensure at least 3 units wide for visibility if ( x2 < x1 + 10 ) x2 = x1 + 10; // . flip the y so we don't have to scroll the browser down // . DY does not include the axis and tick marks //long fy1 = DY - y1 + m_by ; // plot it //plotter.line ( x1 , fy1 , x2 , fy1 ); drawLine3 ( m_gw , x1 , x2 , y1 , c1 , pp->m_thickness ); // add to map key? only if we haven't already if ( tmpht.isInTable ( &colorHash ) ) continue; // add it if ( col == 0 ) m_sb2->safePrintf("<tr>"); char *title = "unknown parm"; if ( m ) title = m->m_title; m_sb2->safePrintf("<td bgcolor=#%06lx> </td>",c1); // print the parm name and old/new values m_sb2->safePrintf("<td><b>%s</b>",title); if ( pp->m_oldVal != pp->m_newVal ) m_sb2->safePrintf(" (%.02f -> %.02f)", pp->m_oldVal,pp->m_newVal); m_sb2->safePrintf("</td>"); if ( col == 1 ) m_sb2->safePrintf("</tr>\n"); // inc column and wrap if ( ++col >= 2 ) col = 0; // . do not re-display // . TODO: deal with error tmpht.addKey ( &colorHash ) ; } m_sb2->safePrintf("</table>\n"); // clear that up m_ht3.reset(); m_sb3.reset(); // and stat states m_ht0.reset(); m_sb0.reset(); // all done free some mem m_sb1.reset(); //m_sb2.reset(); // // but not m_sb2 cuz that has the html in it!! // // all done //if ( plotter.closepl () < 0 ) // log("admin: Could not close performance graph object."); // close the file //fclose ( m_fd ); //#endif // close main graphing window m_gw.safePrintf("</div>\n"); return true; }
int main(int argc, char *argv[]) { char *me, *err, *outS; hestOpt *hopt=NULL; airArray *mop; int numGrth, numDtdi, numGrgr, numDtgr, numNrrd, ni; plotPS pps; plotParm pparm; Nrrd **_ndata, **ndata; mop = airMopNew(); me = argv[0]; hestOptAdd(&hopt, "i", "data", airTypeOther, 1, -1, &_ndata, NULL, "input nrrd containing data to plot", &numNrrd, NULL, nrrdHestNrrd); hestOptAdd(&hopt, "dbox", "minX minY maxX maxY", airTypeDouble, 4, 4, pparm.dbox, NULL, "bounding box, in data space"); hestOptAdd(&hopt, "bbox", "minX minY maxX maxY", airTypeDouble, 4, 4, pps.bbox, NULL, "bounding box, in graph space"); hestOptAdd(&hopt, "psc", "PS scale", airTypeDouble, 1, 1, &(pps.psc), "300", "scaling from graph space to PostScript points"); hestOptAdd(&hopt, "nobg", NULL, airTypeInt, 0, 0, &(pps.nobg), NULL, "don't fill with background color"); hestOptAdd(&hopt, "bg", "background", airTypeDouble, 3, 3, &(pps.bgColor), "1 1 1", "background RGB color; each component in range [0.0,1.0]"); hestOptAdd(&hopt, "grth", "graph thickness", airTypeDouble, 1, -1, &(pparm.graphThick), "0.01", "thickness of line for graph, or \"0\" for no graph line", &numGrth); hestOptAdd(&hopt, "grgr", "graph gray", airTypeDouble, 1, -1, &(pparm.graphGray), "0", "grayscale to use for graph", &numGrgr); hestOptAdd(&hopt, "dtdi", "dot diameter", airTypeDouble, 1, -1, &(pparm.dotDiameter), "0.1", "radius of dot drawn at data points, or \"0\" for no dots", &numDtdi); hestOptAdd(&hopt, "dtgr", "dot gray", airTypeDouble, 1, -1, &(pparm.dotGray), "0", "grayscale to use for dots", &numDtgr); hestOptAdd(&hopt, "dtid", "dot inner diam frac", airTypeDouble, 1, 1, &(pparm.dotInnerDiameterFraction), "0.0", "fractional radius of white dot drawn within dot"); hestOptAdd(&hopt, "tihz", "pos", airTypeDouble, 0, -1, &(pparm.horzTick), "", "locations for tickmarks on horizontal axis", &(pparm.numHorzTick)); hestOptAdd(&hopt, "tivt", "pos", airTypeDouble, 0, -1, &(pparm.vertTick), "", "locations for tickmarks on vertical axis", &(pparm.numVertTick)); hestOptAdd(&hopt, "tiho", "offset", airTypeDouble, 1, 1, &(pparm.horzTickLabelOffset), "0", "horizontal tick label offset"); hestOptAdd(&hopt, "tivo", "offset", airTypeDouble, 1, 1, &(pparm.vertTickLabelOffset), "0", "vertical tick label offset"); hestOptAdd(&hopt, "tils", "size", airTypeDouble, 1, 1, &(pparm.tickLabelSize), "0", "font size for labels on tick marks, or \"0\" for no labels"); hestOptAdd(&hopt, "tith", "tick thickness", airTypeDouble, 1, 1, &(pparm.tickThick), "0.01", "thickness of lines for tick marks"); hestOptAdd(&hopt, "tiln", "tick length", airTypeDouble, 1, 1, &(pparm.tickLength), "0.08", "length of lines for tick marks"); hestOptAdd(&hopt, "axth", "axis thickness", airTypeDouble, 1, 1, &(pparm.axisThick), "0.01", "thickness of lines for axes"); hestOptAdd(&hopt, "axor", "axis origin", airTypeDouble, 2, 2, &(pparm.axisOrig), "0 0", "origin of lines for axes, in data space"); hestOptAdd(&hopt, "axhl", "horiz axis label", airTypeString, 1, 1, &(pparm.axisHorzLabel), "", "label on horizontal axis"); hestOptAdd(&hopt, "axvl", "vert axis label", airTypeString, 1, 1, &(pparm.axisVertLabel), "", "label on vertical axis"); hestOptAdd(&hopt, "o", "output PS", airTypeString, 1, 1, &outS, "out.ps", "output file to render postscript into"); hestParseOrDie(hopt, argc-1, argv+1, NULL, me, info, AIR_TRUE, AIR_TRUE, AIR_TRUE); airMopAdd(mop, hopt, (airMopper)hestOptFree, airMopAlways); airMopAdd(mop, hopt, (airMopper)hestParseFree, airMopAlways); if (!( numGrth == numDtdi && numDtdi == numGrgr && numGrgr == numDtgr )) { fprintf(stderr, "%s: number of arguments given to grth (%d), dtdi (%d), " "grgr (%d), dtgr (%d) not all equal\n", me, numGrth, numDtdi, numGrgr, numDtgr); airMopError(mop); return 1; } if (!( numNrrd == numGrth )) { fprintf(stderr, "%s: number of nrrds (%d) != number graph options (%d)\n", me, numNrrd, numGrth); airMopError(mop); return 1; } /* check nrrds */ for (ni=0; ni<numNrrd; ni++) { if (!( (1 == _ndata[ni]->dim || 2 == _ndata[ni]->dim) && nrrdTypeBlock != _ndata[ni]->type )) { fprintf(stderr, "%s: input nrrd must be 1-D or 2-D array of scalars", me); airMopError(mop); return 1; } } ndata = (Nrrd**)calloc(numNrrd, sizeof(Nrrd *)); airMopAdd(mop, ndata, airFree, airMopAlways); for (ni=0; ni<numNrrd; ni++) { ndata[ni] = nrrdNew(); airMopAdd(mop, ndata[ni], (airMopper)nrrdNuke, airMopAlways); if (nrrdConvert(ndata[ni], _ndata[ni], nrrdTypeDouble)) { airMopAdd(mop, err = biffGetDone(NRRD), airFree, airMopAlways); fprintf(stderr, "%s: couldn't convert input %d to %s:\n%s\n", me, ni, airEnumStr(nrrdType, nrrdTypeDouble), err); airMopError(mop); return 1; } if (1 == ndata[ni]->dim) { if (nrrdAxesInsert(ndata[ni], ndata[ni], 0)) { airMopAdd(mop, err = biffGetDone(NRRD), airFree, airMopAlways); fprintf(stderr, "%s: couldn't insert axis 0 on nrrd %d:\n%s\n", me, ni, err); airMopError(mop); return 1; } } /* currently assuming node centering */ if (!AIR_EXISTS(ndata[ni]->axis[1].min)) { ndata[ni]->axis[1].min = 0; } if (!AIR_EXISTS(ndata[ni]->axis[1].max)) { ndata[ni]->axis[1].max = ndata[ni]->axis[1].size-1; } } if (!(pps.file = airFopen(outS, stdout, "wb"))) { fprintf(stderr, "%s: couldn't open output file\n", me); airMopError(mop); return 1; } airMopAdd(mop, pps.file, (airMopper)airFclose, airMopAlways); plotPreamble(&pps, &pparm); plotAxes(&pps, &pparm, ndata[0]); for (ni=0; ni<numNrrd; ni++) { plotGraph(&pps, &pparm, ndata, ni); plotDots(&pps, &pparm, ndata, ni); } plotEpilog(&pps, &pparm); airMopOkay(mop); return 0; }