Exemplo n.º 1
0
		private DataTable getMeasuredGraphDataTable(int runId, MeasureInfo measure) {

			//Get data in DataTable format
			DataTable tempTable = new DataTable();
			bool isColumnBuilt = false;
			List<String> attrValues = null;

			XPathNavigator firstDataSet = null;
			try {
				firstDataSet = this.measuresController.getMeasuredData(runId).CreateNavigator();

			}
			catch (NullReferenceException e) {
				String message = "Unable to find the raw data file for this Run ID " + runId;
				logger.Debug(e.Message + ": " + message);
				MessageBox.Show(message, "Graphing Error", MessageBoxButtons.OK, MessageBoxIcon.Error);

				return null;
			}

			XPathNavigator measureSet = firstDataSet.SelectSingleNode("/Measures/Measure[@name='" + measure.DisplayName +"']");
			if (measureSet == null)
				return null;
			XPathNodeIterator dataNodes = measureSet.Select("DataSet");
			foreach (XPathNavigator dataNav in dataNodes) {

				attrValues = new List<String>();
				XPathNodeIterator parameterNodes =
                    dataNav.SelectDescendants(XPathNodeType.Element, false);
				foreach (XPathNavigator parameter in parameterNodes) {

					if (parameter.Name.CompareTo("Data") != 0)
						continue;

					if (!isColumnBuilt) {
						String name = parameter.GetAttribute("name", parameter.NamespaceURI);

						if (!tempTable.Columns.Contains(name))
							tempTable.Columns.Add(name);
					}

					String value = parameter.GetAttribute("value", parameter.NamespaceURI);
					attrValues.Add(value);
				}
				isColumnBuilt = true;

				tempTable.Rows.Add(attrValues.ToArray());
			}

			return tempTable;
		}
Exemplo n.º 2
0
		public GraphSetupControl(int processId, int runId, MeasureInfo measure)
			: this() {

			this.simulationId = processId;

			DataTable dataTable = this.getMeasuredGraphDataTable(runId, measure);
			if (dataTable != null)
				this.tData.Add(runId, dataTable);

			if (this.tData.Count > 0) {
				this.tableColumn = this.getDataColumnNames();
				this.typeToGraphCombo.Items.AddRange(this.tableColumn);
			}
			else
				throw new Exception("Data for graphing is anavaliable");
		}
Exemplo n.º 3
0
		public GraphSetupForm(int simulationId, int simRunId, MeasureInfo measure)
			: base() {

			try {
				this.graphSetup = new GraphSetupControl(simulationId, simRunId, measure);
			}
			catch (Exception e) {
				throw e;
			}

			this.Text = "Graph Setup";
			//this.Icon = Form.

			this.graphSetup.Dock = DockStyle.Fill;
			this.graphSetup.AcceptButton.Click += new EventHandler(AcceptButton_Click);

			int width = graphSetup.Size.Width + 10;
			int height = graphSetup.Size.Height + 30;

			this.StartPosition = FormStartPosition.CenterScreen;
			this.Size = new Size(width, height);
			this.MaximumSize = new Size(width, height);
			this.MinimumSize = new Size(width, height);

			this.AcceptButton = graphSetup.AcceptButton;
			this.CancelButton = graphSetup.CancelButton;
			this.Controls.Add(graphSetup);
		}
Exemplo n.º 4
0
		private void okButton_Click(object sender, EventArgs e) {

			if (this.measureListBox.CheckedIndices.Count > 0) {
				int checkedItem = this.measureListBox.CheckedIndices[0];
				this.selectedMeasure = this.measures[checkedItem];

				if (("ChartType.MULTIBAR").Equals(this.selectedMeasure.GraphType)) {
					this.buildMultiBarChart(runId, this.selectedMeasure);
				}
				else if (("ChartType.BAR").Equals(this.selectedMeasure.GraphType)) {
					this.buildBarChart(runId, this.selectedMeasure);
				}

				this.DialogResult = DialogResult.OK;
			}
			else {
				this.DialogResult = DialogResult.Cancel;
			}
			this.Close();
		}
Exemplo n.º 5
0
		private void buildBarChart(int runId, MeasureInfo measure) {
			
			DataTable chartTable = this.getMeasuredGraphDataTable(runId, measure);
			if (chartTable == null) {
				String message = "There is no data for the measure: " + measure.DisplayName;
				logger.Debug(message + " for Run " + runId);
				MessageBox.Show(message, "Graphing Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
				return;
			}

			String[] labels = new String[chartTable.Rows.Count];
			double[] data = new double[labels.Length];

			DataRow row = null;
			for (int j = 0; j < chartTable.Columns.Count; j++) {

				for (int i = 0; i < chartTable.Rows.Count; i++) {

					row = chartTable.Rows[i];

					if (j == 0) {
						labels[i] = row[j].ToString();
					}
					else {
						data[i] = Double.Parse(row[j].ToString());
					}
				}
			}

			this.chartData = new BarChartData(measure.DisplayName, data, labels, null);
		}
Exemplo n.º 6
0
        }//GetEngineModelBaseType

        #endregion  //private methods

        #region Public Methods

        public void Run(int engineId, int runId)
        {
            try
            {
                string sEngineModelType = null;
                string sEngineModelBaseType = null;
                string sInputFileName = null;
                string sOutputFileName = null;
                string sGraphInputFileName = null;
                int iMeasureId = -1;
                string sRunCategory = null;
                Dictionary<string, IXPathNavigable> cMeasureOutputs = new Dictionary<string, IXPathNavigable>();

                //Getting Run type
                string sRunType = base._GetType(runId);

                //Getting Engine Model & Base type
                this.GetEngineModelTypes(engineId, out sEngineModelType, out sEngineModelBaseType);

                #region A. Reading measure's class names

                //[className, measureInfo]
                Dictionary<string, MeasureInfo> lMeasureInfo = new Dictionary<string, MeasureInfo>();
                IXPathNavigable componentRun = base.m_model.GetComponent(sRunType);
                if (componentRun == null)
                    return;

                XPathNavigator navComponentRun = componentRun.CreateNavigator();

                XPathNodeIterator measureClassIterator = navComponentRun.Select(String.Format("SubComponents/Component[@type='{0}']", "Measure"));
                foreach (XPathNavigator measureClass in measureClassIterator)
                {
                    String sMeasureClassName = measureClass.GetAttribute("name", navComponentRun.NamespaceURI);

                    MeasureInfo measureInfo = new MeasureInfo(sMeasureClassName);
                    measureInfo.DisplayName = measureClass.GetAttribute("displayName", navComponentRun.NamespaceURI);
                    measureInfo.GraphType = measureClass.GetAttribute("graphType", navComponentRun.NamespaceURI); ;

                    lMeasureInfo.Add(measureInfo.ClassName, measureInfo);
                }

                #endregion

                #region B. Instantiating all measure classes

                Dictionary<string, IMeasureModel> lMeasureModels = new Dictionary<string, IMeasureModel>();
                // Get the entry assembly which should always be the project name
                string projectAssemblyName = Assembly.GetEntryAssembly().GetName().Name;
                string typeString = ".";
                switch (sEngineModelBaseType)
                {
                    case ("Simulation"):
                        projectAssemblyName = sEngineModelType; // Need the namespace which happens to be the same as the ModelType...
                        typeString = string.Format(".Measures.");
                        Assembly.Load(projectAssemblyName);
                        break;

                    case ("Optimization"):
                        typeString = ".Optimizations.Measures.";
                        break;
                }
                foreach (KeyValuePair<string, MeasureInfo> pair in lMeasureInfo)
                {
                    MeasureInfo measureInfo = pair.Value;
                    string measureModelTypeName = projectAssemblyName + typeString + measureInfo.ClassName;

                    ObjectHandle objMeasureModel = Activator.CreateInstance(projectAssemblyName, measureModelTypeName);
                    IMeasureModel measureModel = (IMeasureModel)objMeasureModel.Unwrap();
                    measureModel.DisplayName = measureInfo.DisplayName;
                    measureModel.GraphType = measureInfo.GraphType;
                    lMeasureModels[measureInfo.ClassName] = measureModel;
                }

                #endregion

                #region C. Reading measure's input file name

                DataTable dtMeasures = base._GetChildComponents(runId, "Measure", true);

                if (dtMeasures.Rows.Count > 0)
                {
                    DataRow drMeasure = dtMeasures.Rows[0];
                    iMeasureId = base._GetID(drMeasure).Value;
                    sInputFileName = base._GetParameterValue(iMeasureId, "Measure Parameters.Input Filename");
                }

                if (iMeasureId == -1)
                {
                    return;
                }

                sOutputFileName = sInputFileName.Replace("Input", "Output");
                sGraphInputFileName = sInputFileName.Replace("Input", "GraphInput");
                string sFolderPath = this.OutputPath;
                string pInputFilePath = Path.Combine(sFolderPath, sInputFileName + ".xml");
                string pOutputFilePath = Path.Combine(sFolderPath, sOutputFileName + ".xml");
                string pGraphInputFilePath = Path.Combine(sFolderPath, sGraphInputFileName + ".xml");

                #endregion

                #region D. Reading measure's Input File

                FileInfo xmlInputFile = new FileInfo(pInputFilePath);
                XmlDocument xmlInputDoc = new XmlDocument();
                xmlInputDoc.Load(xmlInputFile.OpenText());

                //Reading Run Category
                XmlNode component = xmlInputDoc.SelectSingleNode("/Component");
                sRunCategory = component.Attributes["name"].Value;

                IXPathNavigable navComponent = component.CreateNavigator();

                #endregion

                #region E. Calling Measure Engines' run by passing parameters

                foreach (KeyValuePair<string, IMeasureModel> pair in lMeasureModels)
                {
                    IMeasureModel measureModel = pair.Value;
                    measureModel.MeasureInputXml = navComponent;
                    bool bSuccess = measureModel.Start();
                    IXPathNavigable outParameter = measureModel.MeasureOutputXml;
                    cMeasureOutputs.Add(pair.Key, outParameter);
                }

                #endregion

                #region F. Creating Measure Output File, Storing it & Updating Parameter

                XmlDocument measureOutputXmlFile = new XmlDocument();
                XmlDeclaration mDeclaration = measureOutputXmlFile.CreateXmlDeclaration("1.0", "UTF-8", String.Empty);
                measureOutputXmlFile.AppendChild(mDeclaration);

                XmlElement xeComponent = measureOutputXmlFile.CreateElement("Component");
                measureOutputXmlFile.AppendChild(xeComponent);

                // Added by CK for Report Card Threshhold Values
                IXPathNavigable iNavSimulationParameters = this.GetParametersForComponent(engineId);
                XPathNavigator navSimulationParameters = iNavSimulationParameters.CreateNavigator();
                XmlNode nodeSimulation = ((IHasXmlNode)navSimulationParameters).GetNode();
                nodeSimulation = measureOutputXmlFile.ImportNode(nodeSimulation, true);
                xeComponent.AppendChild(nodeSimulation);  
                /////////////////////////////////////////////////

                XmlAttribute xaComp_type = measureOutputXmlFile.CreateAttribute("type");
                xaComp_type.Value = "Measure";
                xeComponent.Attributes.Append(xaComp_type);

                XmlAttribute xaComp_name = measureOutputXmlFile.CreateAttribute("name");
                xaComp_name.Value = sRunCategory;
                xeComponent.Attributes.Append(xaComp_name);

                XmlElement xeMeasures = measureOutputXmlFile.CreateElement("Measures");
                xeComponent.AppendChild(xeMeasures);

                //Preparing XML file with all of the measure outputs.
                foreach (KeyValuePair<string, IXPathNavigable> pair in cMeasureOutputs)
                {
                    string measureName = pair.Key;
                    IXPathNavigable measureOut = pair.Value;
                    if (measureOut != null)
                    {
                        XPathNavigator navMeasureOut = measureOut.CreateNavigator();

                        XPathNodeIterator measureIterator = navMeasureOut.Select("/Measure");
                        measureIterator.MoveNext();
                        XmlNode origNode = ((IHasXmlNode)measureIterator.Current).GetNode();
                        xeMeasures.InnerXml += string.Copy(origNode.OuterXml);
                    }
                }//foreach measure output

                measureOutputXmlFile.Save(pOutputFilePath);
                //storing measure output file's name.
                this.UpdateParameters(iMeasureId, "Measure Parameters.Output Filename", sOutputFileName, eParamParentType.Component);

                #endregion

                #region G. Creating Measure Graph Input File, Storing it & Updating Parameter

                XPathNavigator navMeasureOutput = measureOutputXmlFile.CreateNavigator();
                this._measureGraphConverter = new MeasureGraphConverter(navMeasureOutput);

                IXPathNavigable navGraphInput = this._measureGraphConverter.Transform();

                if (navGraphInput != null)
                {
                    XmlDocument measureGraphInXmlFile = (XmlDocument)navGraphInput;
                    measureGraphInXmlFile.Save(pGraphInputFilePath);
                    //storing measure Graph Input file's name.
                    this.UpdateParameters(iMeasureId, "Measure Parameters.Graph Input Filename", sGraphInputFileName, eParamParentType.Component);
                }

                //setting it back to null, as we need a new instance of it for new input.
                this._measureGraphConverter = null;

                #endregion

            }//try
            catch 
            {
            }
        }//Run
Exemplo n.º 7
0
        }//Run

		public List<MeasureInfo> getAllGraphableMeasures(int runId) {

			List<MeasureInfo> measures = new List<MeasureInfo>();

				//string sEngineModelType = null;
				//string sEngineModelBaseType = null;

                //Getting Run type
                string runType = base._GetType(runId);

                //Getting Engine Model & Base type
                //this.GetEngineModelTypes(engineId, out sEngineModelType, out sEngineModelBaseType);

                IXPathNavigable componentRun = base.m_model.GetComponent(runType);
                if (componentRun == null)
                    return measures;

                XPathNavigator navComponentRun = componentRun.CreateNavigator();

                XPathNodeIterator measureClassIterator = navComponentRun.Select(String.Format("SubComponents/Component[@type='{0}' and @graphType!='']", "Measure"));
				foreach (XPathNavigator measureClass in measureClassIterator) {
					String measureClassName = measureClass.GetAttribute("name", navComponentRun.NamespaceURI);

					MeasureInfo measureInfo = new MeasureInfo(measureClassName);
					measureInfo.DisplayName = measureClass.GetAttribute("displayName", navComponentRun.NamespaceURI);
					measureInfo.GraphType = measureClass.GetAttribute("graphType", navComponentRun.NamespaceURI); ;

					measures.Add(measureInfo);
				}

				return measures;
		}