public CreateGraphR ( string fileName, bool show, int graphNum ) : bool | ||
fileName | string | |
show | bool | |
graphNum | int | |
return | bool |
public bool CreateGraphR(string fileName, bool show, int graphNum)
{
//only graph if there's data
//TODO: check also later if none row is selected
if(CurrentGraphData.XAxisNames.Count == 0) {
return false;
}
if (!show) { //report
string directoryName = Util.GetReportDirectoryName(fileName);
/*
string [] pngs = Directory.GetFiles(directoryName, "*.png");
//if found 3 images, sure will be 1.png, 2.png and 3.png, next will be 4.png
//there will be always a png with chronojump_logo
fileName = directoryName+"/"+pngs.Length.ToString() + ".png";
*/
fileName = directoryName+"/"+(graphNum+1).ToString() + ".png";
} else
fileName = Path.GetTempPath()+"/"+fileName;
//On win32 R understands backlash as an escape character and
//a file path uses Unix-like path separator '/'
fileName = fileName.Replace("\\","/");
string cexAxisString = "";
if(gRO.Type == Constants.GraphTypeBarplot || gRO.Type == Constants.GraphTypeLines)
cexAxisString = ", cex.axis=" + Util.ConvertToPoint(gRO.XAxisFontSize);
string rString = "";
if(UtilAll.IsWindows())
rString = "library(\"Cairo\")\n" +
"Cairo(" + gRO.Width + ", " + gRO.Height +
", file = '" + fileName + "', type=\"png\", bg=\"white\")\n";
else
rString = "png(filename = '" + fileName + "'\n" +
" , width = " + gRO.Width + ", height = " + gRO.Height + ", units = 'px'\n" +
" , pointsize = 12, bg = 'white', res = NA)\n";
rString += "par(mar=c(" + gRO.MarginBottom + "," + gRO.MarginLeft + "," +
gRO.MarginTop + "," + gRO.MarginRight + ")" + cexAxisString + ")\n";
if(gRO.Type == Constants.GraphTypeBoxplot) {
if(hasTwoAxis()) {
rString += "par(mfrow=c(1,2))\n";
rString += getRBoxplotString(
gRO, fileName, Sides.LEFT);
rString += getRBoxplotString(
gRO, fileName, Sides.RIGHT);
}
else
rString += getRBoxplotString(
gRO, fileName, Sides.ALL);
}
else if(gRO.Type == Constants.GraphTypeBarplot) {
if(hasTwoAxis()) {
rString += "par(mfrow=c(1,2))\n";
rString += getRBarplotString(
gRO, fileName, Sides.LEFT);
rString += getRBarplotString(
gRO, fileName, Sides.RIGHT);
}
else
rString += getRBarplotString(
gRO, fileName, Sides.ALL);
}
else if(gRO.Type == Constants.GraphTypeLines) {
if(hasTwoAxis()) {
rString += "par(mfrow=c(1,2))\n";
rString += getRLinesString(
gRO, fileName, Sides.LEFT);
rString += getRLinesString(
gRO, fileName, Sides.RIGHT);
}
else
rString += getRLinesString(
gRO, fileName, Sides.ALL);
}
else if(gRO.Type == Constants.GraphTypeStripchart) {
if(hasTwoAxis()) {
rString += "par(mfrow=c(2,1))\n";
rString += getRStripchartString(
gRO, fileName, Sides.LEFT);
rString += getRStripchartString(
gRO, fileName, Sides.RIGHT);
}
else
rString += getRStripchartString(
gRO, fileName, Sides.ALL);
}
else if(gRO.Type == Constants.GraphTypeXY)
rString += getRXYString(gRO, fileName);
else if(gRO.Type == Constants.GraphTypeHistogram)
rString += getRHistogramString(gRO, fileName);
else //if(CurrentGraphData.GraphType == Constants.GraphTypeDotchart))
rString += getRDotchartString(gRO, fileName);
rString += " dev.off()\n";
//fileName = System.IO.Path.Combine(Path.GetTempPath(), fileName);
string rScript = System.IO.Path.Combine(Path.GetTempPath(), graphNum+Constants.FileNameRScript);
TextWriter writer = File.CreateText(rScript);
writer.Write(rString);
writer.Flush();
writer.Close();
((IDisposable)writer).Dispose();
Util.RunRScript(rScript);
if(show) {
if(! File.Exists(fileName) || File.GetLastWriteTime(fileName) < File.GetLastWriteTime(rScript))
new DialogMessage(Constants.MessageTypes.WARNING,
Catalog.GetString("Sorry. Error doing graph.") +
"\n" + Catalog.GetString("Maybe R is not installed.") +
"\n" + Catalog.GetString("Please, install it from here:") +
"\n\nhttp://cran.cnr.berkeley.edu/bin/macosx/R-latest.pkg");
else
new DialogImageTest(Catalog.GetString("Chronojump Graph"), fileName, DialogImageTest.ArchiveType.FILE);
}
return true;
}
public bool ChooseStat() { if (statisticType == Constants.TypeSessionSummary) { int jumperID = -1; //all jumpers string jumperName = ""; //all jumpers if (graph) { myStat = new GraphGlobal(myStatTypeStruct, jumperID, jumperName); } else { myStat = new StatGlobal(myStatTypeStruct, treeview_stats, jumperID, jumperName); } } else if (statisticType == Constants.TypeJumperSummary) { if (statisticApplyTo.Length == 0) { LogB.Information("Jumper-ret"); return(false); } int jumperID = Util.FetchID(statisticApplyTo); if (jumperID == -1) { return(false); } string jumperName = Util.FetchName(statisticApplyTo); if (graph) { myStat = new GraphGlobal(myStatTypeStruct, jumperID, jumperName); } else { myStat = new StatGlobal(myStatTypeStruct, treeview_stats, jumperID, jumperName); } } else if (statisticType == Constants.TypeJumpsSimple) { if (statisticApplyTo.Length == 0) { LogB.Information("Simple-ret"); return(false); } if (statisticSubType != Catalog.GetString("No indexes")) { string indexType = ""; if (statisticSubType == Catalog.GetString(Constants.SubtractionBetweenTests)) { indexType = "subtraction"; } else if (statisticSubType == Constants.ChronojumpProfile) { indexType = "ChronojumpProfile"; } else if (statisticSubType == Constants.IeIndexFormula) { indexType = "IE"; } else if (statisticSubType == Constants.ArmsUseIndexFormula) { indexType = "Arms Use Index"; } else if (statisticSubType == Constants.IRnaIndexFormula) { indexType = "IRna"; } else if (statisticSubType == Constants.IRaIndexFormula) { indexType = "IRa"; } else if (statisticSubType == Constants.FvIndexFormula) { indexType = "F/V"; } else if ( statisticSubType == Constants.PotencyLewisFormulaShort || statisticSubType == Constants.PotencyHarmanFormulaShort || statisticSubType == Constants.PotencySayersSJFormulaShort || statisticSubType == Constants.PotencySayersCMJFormulaShort || statisticSubType == Constants.PotencyShettyFormulaShort || statisticSubType == Constants.PotencyCanavanFormulaShort || //statisticSubType == Constants.PotencyBahamondeFormula || statisticSubType == Constants.PotencyLaraMaleApplicantsSCFormulaShort || statisticSubType == Constants.PotencyLaraFemaleEliteVoleiFormulaShort || statisticSubType == Constants.PotencyLaraFemaleMediumVoleiFormulaShort || statisticSubType == Constants.PotencyLaraFemaleSCStudentsFormulaShort || statisticSubType == Constants.PotencyLaraFemaleSedentaryFormulaShort ) { indexType = statisticSubType; } if (indexType == "subtraction") { if (graph) { myStat = new GraphJumpSimpleSubtraction(myStatTypeStruct); } else { myStat = new StatJumpSimpleSubtraction(myStatTypeStruct, treeview_stats); } } else if (indexType == "ChronojumpProfile") { if (graph) { //myStat = new GraphChronojumpProfile(myStatTypeStruct); LogB.Warning("TODO"); } else { myStat = new StatChronojumpProfile(myStatTypeStruct, treeview_stats); } } else if (indexType == "IE" || indexType == Constants.ArmsUseIndexName || indexType == "IRna" || indexType == "IRa") { if (graph) { myStat = new GraphJumpIndexes(myStatTypeStruct, indexType); } else { myStat = new StatJumpIndexes(myStatTypeStruct, treeview_stats, indexType); } } else if (indexType == "F/V") { if (graph) { myStat = new GraphFv(myStatTypeStruct, indexType); } else { myStat = new StatFv(myStatTypeStruct, treeview_stats, indexType); } } else { //indexType = (Potency sayers or lewis); if (graph) { myStat = new GraphPotency(myStatTypeStruct, indexType); } else { myStat = new StatPotency(myStatTypeStruct, treeview_stats, indexType); } } } else { JumpType myType = new JumpType(statisticApplyTo); //manage all weight jumps and the AllJumpsName (simple) if (myType.HasWeight || statisticApplyTo == Constants.AllJumpsName) { if (graph) { myStat = new GraphSjCmjAbkPlus(myStatTypeStruct); } else { myStat = new StatSjCmjAbkPlus(myStatTypeStruct, treeview_stats); } } else { if (graph) { myStat = new GraphSjCmjAbk(myStatTypeStruct); } else { myStat = new StatSjCmjAbk(myStatTypeStruct, treeview_stats); } } } } else if (statisticType == Constants.TypeJumpsSimpleWithTC) { if (statisticApplyTo.Length == 0) { LogB.Information("WithTC-ret"); return(false); } if (statisticSubType == Constants.DjIndexFormula) { if (graph) { myStat = new GraphDjIndex(myStatTypeStruct); } //heightPreferred is not used, check this else { myStat = new StatDjIndex(myStatTypeStruct, treeview_stats); } //heightPreferred is not used, check this } else if (statisticSubType == Constants.QIndexFormula) { if (graph) { myStat = new GraphDjQ(myStatTypeStruct); } //heightPreferred is not used, check this else { myStat = new StatDjQ(myStatTypeStruct, treeview_stats); } //heightPreferred is not used, check this } else if (statisticSubType == Constants.DjPowerFormula) { if (graph) { myStat = new GraphDjPower(myStatTypeStruct); } //heightPreferred is not used, check this else { myStat = new StatDjPower(myStatTypeStruct, treeview_stats); } //heightPreferred is not used, check this } } else if (statisticType == Constants.TypeJumpsReactive) { if (statisticSubType == Catalog.GetString("Average Index")) { if (graph) { myStat = new GraphRjIndex(myStatTypeStruct); } else { myStat = new StatRjIndex(myStatTypeStruct, treeview_stats); } } else if (statisticSubType == Constants.RJPotencyBoscoFormula) { if (graph) { myStat = new GraphRjPotencyBosco(myStatTypeStruct); } else { myStat = new StatRjPotencyBosco(myStatTypeStruct, treeview_stats); } } else if (statisticSubType == Catalog.GetString("Evolution")) { if (graph) { myStat = new GraphRjEvolution(myStatTypeStruct, evolution_mark_consecutives); } else { myStat = new StatRjEvolution(myStatTypeStruct, evolution_mark_consecutives, treeview_stats); } } else if (statisticSubType == Constants.RJAVGSDRjIndexName) { if (graph) { myStat = new GraphRjAVGSD(myStatTypeStruct, Constants.RjIndexName); } else { myStat = new StatRjAVGSD(myStatTypeStruct, treeview_stats, Constants.RjIndexName); } } else if (statisticSubType == Constants.RJAVGSDQIndexName) { if (graph) { myStat = new GraphRjAVGSD(myStatTypeStruct, Constants.QIndexName); } else { myStat = new StatRjAVGSD(myStatTypeStruct, treeview_stats, Constants.QIndexName); } } } else if (statisticType == Constants.TypeRunsSimple) { if (statisticApplyTo.Length == 0) { LogB.Information("Simple-ret"); return(false); } if (graph) { myStat = new GraphRunSimple(myStatTypeStruct); } else { myStat = new StatRunSimple(myStatTypeStruct, treeview_stats); } } else if (statisticType == Constants.TypeRunsIntervallic) { if (statisticApplyTo.Length == 0) { LogB.Information("Simple-ret"); return(false); } if (graph) { myStat = new GraphRunIntervallic(myStatTypeStruct, evolution_mark_consecutives); } else { myStat = new StatRunIntervallic(myStatTypeStruct, evolution_mark_consecutives, treeview_stats); } } myStat.FakeButtonRowCheckedUnchecked.Clicked += new EventHandler(on_fake_button_row_checked_clicked); myStat.FakeButtonRowsSelected.Clicked += new EventHandler(on_fake_button_rows_selected_clicked); myStat.FakeButtonNoRowsSelected.Clicked += new EventHandler(on_fake_button_no_rows_selected_clicked); myStat.PrepareData(); if (toReport) { if (graph) { bool notEmpty = myStat.CreateGraphR(fileName, false, statCount); //dont' show if (notEmpty) { linkImage(fileName); } } else { writer.WriteLine(myStat.ReportString()); } } else { if (graph) { //myStat.CreateGraph(); myStat.CreateGraphR(Constants.FileNameRGraph, true, -1); //show } } //if we just made a graph, store is not made, //and we cannot change the Male/female visualizations in the combo //with this we can assign a store to the graph (we assign the store of the last stat (not graph) if (!toReport) { if (!graph) { lastStore = myStat.Store; } else { myStat.Store = lastStore; myStat.MarkedRows = markedRows; } } return(true); }