//we can use directly the name of the plots as the name of the variables //it should be enough for now public void plotData(List<PlotViewModel> plots,string sourceOption) { int numLoggedSteps; int numEpisodes = 0, fileFormatVersion = 0; int episodeType = 0, episodeIndex = 0; int stepIndex = 0, numVariablesLogged = 0; bool bLastStep; double expRealTime = 0.0, episodeSimTime = 0.0, episodeRealTime = 0.0; List<VarPlotInfo> varInfoList = new List<VarPlotInfo>(); try { //init the series and get the index of each logged variable plots.ForEach((plot) => { VarPlotInfo varInfo = new VarPlotInfo(); varInfo.seriesId= plot.addLineSeries(m_name); varInfo.varIndexInLogFile= m_variablesInLog.FindIndex((name) => name == plot.name); varInfo.avg= 0.0; varInfoList.Add(varInfo); }); FileStream logFile = File.OpenRead(m_logFilePath); using (BinaryReader binaryReader = new BinaryReader(logFile)) { readExperimentLogHeader(binaryReader, ref numEpisodes, ref fileFormatVersion); for (int i = 0; i < numEpisodes; i++) { //reset the averaged data foreach (VarPlotInfo varInfo in varInfoList) varInfo.avg = 0.0; readEpisodeHeader(binaryReader, ref episodeType, ref episodeIndex , ref numVariablesLogged); numLoggedSteps = 0; bLastStep = readStepHeader(binaryReader, ref stepIndex , ref expRealTime, ref episodeSimTime, ref episodeRealTime); while (!bLastStep) { //do we have to draw data from this step? if (episodeType == m_episodeTypeEvaluation && (sourceOption == PlotEditorWindowViewModel.m_optionAllEvalEpisodes || (sourceOption == PlotEditorWindowViewModel.m_optionLastEvalEpisode && episodeIndex == numEpisodes))) { numLoggedSteps++; byte[] stepData = readStepData(binaryReader, m_variablesInLog.Count); double[] doubleData = new double[m_variablesInLog.Count]; Buffer.BlockCopy(stepData, 0, doubleData, 0, (int)m_variablesInLog.Count * sizeof(double)); for (int var = 0; var < varInfoList.Count; var++ ) { if (sourceOption == PlotEditorWindowViewModel.m_optionAllEvalEpisodes) varInfoList[var].addValue (doubleData[varInfoList[var].varIndexInLogFile]); else plots[var].addLineSeriesValue(varInfoList[var].seriesId, stepIndex , doubleData[varInfoList[var].varIndexInLogFile]); } } else readStepData(binaryReader, numVariablesLogged); bLastStep = readStepHeader(binaryReader, ref stepIndex , ref expRealTime, ref episodeSimTime, ref episodeRealTime); } //end of episode if (episodeType == m_episodeTypeEvaluation && sourceOption == PlotEditorWindowViewModel.m_optionAllEvalEpisodes) { for (int var = 0; var < varInfoList.Count; var++ ) { plots[var].addLineSeriesValue(varInfoList[var].seriesId, episodeIndex , varInfoList[var].avg / (double)numLoggedSteps); } } } } logFile.Close(); } catch(Exception ex) { Console.WriteLine(ex.ToString()); } }
//we can use directly the name of the plots as the name of the variables //it should be enough for now public void plotData(List <PlotViewModel> plots, string sourceOption) { List <VarPlotInfo> varInfoList = new List <VarPlotInfo>(); try { //init the series and get the index of each logged variable plots.ForEach((plot) => { VarPlotInfo varInfo = new VarPlotInfo(); varInfo.plot = plot; varInfo.seriesId = plot.addLineSeries(m_name); varInfo.varIndexInLogFile = m_variablesInLog.FindIndex((name) => name == plot.name); varInfo.avg = 0.0; varInfoList.Add(varInfo); }); ExperimentData experimentData = SimionLogFile.load(m_logFilePath); foreach (VarPlotInfo var in varInfoList) { int varIndex = var.varIndexInLogFile; if (sourceOption == ReportsWindowViewModel.m_optionAllEvalEpisodes) { experimentData.doForEachEvalEpisode(episode => { double avg = EpisodeData.calculateVarAvg(episode, varIndex); var.plot.addLineSeriesValue(var.seriesId, episode.index, avg); }); } else if (sourceOption == ReportsWindowViewModel.m_optionLastEvalEpisode) { experimentData.doForEpisodeSteps(experimentData.numEpisodes, step => { var.plot.addLineSeriesValue(var.seriesId, step.stepIndex , step.data[var.varIndexInLogFile]); }); } } // EpisodeData.calculateVarAvg // ,plots[var].addLineSeriesValue(varInfoList[var].seriesId,varIndex); // varInfoList[var].addValue(step.data[varInfoList[var].varIndexInLogFile]); // else plots[var].addLineSeriesValue(varInfoList[var].seriesId, step.stepIndex // , step.data[varInfoList[var].varIndexInLogFile]); // experimentData.doForEachEvalEpisode(EpisodeData.calculateVarAvg, varIndex); // } // } // foreach (EpisodeData episodeData in experimentData.episodes) // { // //do we have to draw data from this step? // if (episodeData.type == m_episodeTypeEvaluation && // (sourceOption == PlotEditorWindowViewModel.m_optionAllEvalEpisodes // || (sourceOption == PlotEditorWindowViewModel.m_optionLastEvalEpisode // && episodeData.index == experimentData.numEpisodes))) // { // foreach (StepData step in episodeData.steps) // { // for (int var = 0; var < varInfoList.Count; var++) // { // if (sourceOption == PlotEditorWindowViewModel.m_optionAllEvalEpisodes) // varInfoList[var].addValue(step.data[varInfoList[var].varIndexInLogFile]); // else plots[var].addLineSeriesValue(varInfoList[var].seriesId, step.stepIndex // , step.data[varInfoList[var].varIndexInLogFile]); // } // } // } // } // //end of episode // if (episodeType == m_episodeTypeEvaluation && sourceOption == PlotEditorWindowViewModel.m_optionAllEvalEpisodes) // { // for (int var = 0; var < varInfoList.Count; var++ ) // { // plots[var].addLineSeriesValue(varInfoList[var].seriesId, episodeIndex // , varInfoList[var].avg / (double)numLoggedSteps); // } // } // } // } // logFile.Close(); //} //catch(Exception ex) //{ // Console.WriteLine(ex.ToString()); //} } catch (Exception ex) { Console.WriteLine("Error generating plots"); Console.WriteLine(ex.ToString()); } }