예제 #1
0
        private ILayer[] getLayersData(int runId, bool isRunToRun, String xLabel, String yLabel, String layerName, String[] layerItem) {

            DataTable table = new DataTable();
            table.Columns.Add(layerName);
            table.Columns.Add(xLabel);
            table.Columns.Add(yLabel);

            XPathNavigator firstDataSet = this.assessmentController.GetSimRunData(runId).CreateNavigator();
            XPathNodeIterator dataNodes = firstDataSet.Select("//DataSet");
            
            String temp = null, name = null, xVal = null, yVal = null;
            //bool match = false;
            foreach (XPathNavigator dataNav in dataNodes) {

                XPathNodeIterator parameterNodes =
                    dataNav.SelectDescendants(XPathNodeType.Element, false);
                foreach (XPathNavigator parameter in parameterNodes) {

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

                    temp = parameter.GetAttribute("Name", parameter.NamespaceURI);
                    if (temp.CompareTo(layerName) == 0) {
                        name = parameter.GetAttribute("Value", parameter.NamespaceURI);
                    }
                    else if (temp.CompareTo(xLabel) == 0){
                        xVal = parameter.GetAttribute("Value", parameter.NamespaceURI);
                    }
                    else if (temp.CompareTo(yLabel) == 0) {
                        yVal = parameter.GetAttribute("Value", parameter.NamespaceURI);
                    }
                }

                //if (match)
                    table.Rows.Add(new String[] { name, xVal, yVal });

                temp = null;
                name = null;
                xVal = null;
                yVal = null;
            }

            ILayer[] finalLayer = new LinearLayer[layerItem.Length];
            int counter = 0;
            List<double> x = null;
            List<double> y = null;
            String legendName = null;
            foreach (String item in layerItem) {

                x = new List<double>();
                y = new List<double>();
                
                foreach (DataRow row in table.Rows) {
                    if (row[layerName].ToString().CompareTo(item) == 0) {

                        try {
                            x.Add(Double.Parse(row[xLabel].ToString()));
                            y.Add(Double.Parse(row[yLabel].ToString()));
                        }
                        catch (FormatException) {
                            String message = "Data you chose to graph is not numeric";
                            logger.Debug(message);
                            throw new FormatException(message);
                        }
                    }
                }

                if (isRunToRun) {
                    legendName = "SimRun " + runId + ": " + item;
                }
                else {
                    legendName = item;
                }
                finalLayer[counter++] = new LinearLayer(x.ToArray(), y.ToArray(), legendName);
            }

            return finalLayer;
        }
예제 #2
0
        private IChartData[] getGraphs(GraphDataType gdt) {

            List<IChartData> chartData = new List<IChartData>();

            String graphName = null;
            String chartType = null;
            String xLabel = null;
            String yLabel = null;
            String layerName = null;
            List<int> simRuns = null;
            List<String> layers = null;

			XPathNavigator firstDataSet = null;;
			switch (gdt) {
				case GraphDataType.CUSTOMGRAPHS:
					this.assessmentController.GetCustomGraphs(this.SimRunId).CreateNavigator();
					break;
				case GraphDataType.RUNTORUNGRAPHS:
					this.assessmentController.GetCustomGraphs(this.SimulationId).CreateNavigator();
					break;
				default:
					return null;

			}

            XPathNodeIterator graphNodes = firstDataSet.Select("//Graph");
            foreach (XPathNavigator graphNav in graphNodes) {

                if (gdt == GraphDataType.RUNTORUNGRAPHS && 
                    graphNav.SelectSingleNode(String.Format(@"SimRuns/SimRun[@id='{0}']", this.SimRunId)) == null) {

                    continue; //doesn't contain the current SimRun data
                }

                simRuns = new List<int>();
                int sRun;
                layers = new List<String>();
                graphName = graphNav.GetAttribute("name", graphNav.NamespaceURI);
                chartType = graphNav.GetAttribute("type", graphNav.NamespaceURI);
                XPathNodeIterator pathParameters = null;
                XPathNodeIterator graphParameters = graphNav.Select("*");
                foreach (XPathNavigator parameter in graphParameters) {
                    switch(parameter.Name) {
                        case("SimRuns"):
                            pathParameters = parameter.Select("SimRun");
                            foreach (XPathNavigator run in pathParameters) {
                                try {
                                    sRun = Int32.Parse(run.GetAttribute("id", run.NamespaceURI));
                                    if (!simRuns.Contains(sRun))
                                        simRuns.Add(sRun);
                                }
                                catch (FormatException) {
                                    logger.Warn("SimRun id is not an integer: " + 
                                        run.GetAttribute("id", run.NamespaceURI));
                                }
                            }
                            break;
                        case("XLabel"):
                            xLabel = parameter.GetAttribute("name", parameter.NamespaceURI);
                            break;
                        case("YLabel"):
                            yLabel = parameter.GetAttribute("name", parameter.NamespaceURI);
                            break;
                        case("Layers"):
                            layerName = parameter.GetAttribute("name", parameter.NamespaceURI);
                            pathParameters = parameter.Select("Layer");
                            foreach (XPathNavigator layerNode in pathParameters)
                                layers.Add(layerNode.GetAttribute("name", layerNode.NamespaceURI));
                            break;
                        default:
                            logger.Debug("Undefined parameter " + parameter.Name + " in graph " + graphName);
                            break;
                    }
                }

                List<ILayer> ll = new List<ILayer>();
                IChartData data = null;
                switch (chartType) {
                    case ("LINEAR"):

                        if (gdt == GraphDataType.RUNTORUNGRAPHS) {
                            foreach (int run in simRuns) {
                                ll.AddRange(getLayersData(run, true, xLabel, yLabel, layerName, layers.ToArray()));
                            }
                        }
                        else
                            ll.AddRange(getLayersData(this.SimRunId, false, xLabel, yLabel, layerName, layers.ToArray()));

                        LinearLayer[] lll = new LinearLayer[ll.Count];
                        int count = 0;
                        foreach (ILayer il in ll)
                            lll[count++] = (LinearLayer)il;

                        data = new LinearChartData(graphName, xLabel, yLabel, layerName, lll);
                        break;
                    default:
                        logger.Debug("Graph " + graphName + " is of undefined ChartType." + chartType);
                        break;
                }
                chartData.Add(data);
            }
            return chartData.ToArray();
        }
예제 #3
0
        private LinearChartData getChartDataSimRunAsX() {

            String title = "";
            String typeToGraph = "";
            String xLabel = "";
            String yLabel = "";
            try {
                title = this.graphNameTextBox.Text;
                typeToGraph = this.typeToGraphCombo.SelectedItem.ToString();
                xLabel = this.xAxisCombo.SelectedItem.ToString();
                yLabel = this.yAxisCombo.SelectedItem.ToString();
            }
            catch (NullReferenceException) {
                return null;
            }

            DataTable table = null;
            SortedDictionary<int, String[][]> allData = new SortedDictionary<int,String[][]>();
            List<String[]> dataPoints = null;
            String[] dataPoint = null;

            foreach (int key in this.tData.Keys) {

                table = this.tData[key];
                dataPoints = new List<String[]>();
                foreach (String checkedItemName in this.itemsToGraphListBox.CheckedItems) {

                    foreach (DataRow row in table.Rows) {

                        if (row[typeToGraph].ToString().CompareTo(checkedItemName) == 0) {

                            dataPoint = new String[3];
                            dataPoint[0] = checkedItemName + ": " + xLabel + " " + row[xLabel]; //CTL: Cycle 1 
                            dataPoint[1] = row[xLabel].ToString(); //1 - for now unused field
                            dataPoint[2] = row[yLabel].ToString(); //82
                            dataPoints.Add(dataPoint);
                        }
                    }
                }
                allData.Add(key, dataPoints.ToArray());
            }

            double[] xValues = new double[allData.Count];
            Dictionary<String, List<double>> yTemp = new Dictionary<string, List<double>>();
            int i = 0;
            foreach (int key in allData.Keys) {
                xValues[i++] = key;

                foreach (String[] array in allData[key]) {
                    if (!yTemp.ContainsKey(array[0]))
                        yTemp.Add(array[0], new List<double>());

                    try {
                        yTemp[array[0]].Add(Double.Parse(array[2]));
                    }
                    catch (FormatException) {    
                        throw new FormatException("Data you chose to graph is not numeric");
                    }
                }
            }

            LinearLayer[] layer = new LinearLayer[yTemp.Count];
            int j = 0;
            foreach (String key in yTemp.Keys) {
                layer[j++] = new LinearLayer(xValues, yTemp[key].ToArray(), key);
            }

            return new LinearChartData(title, "SimRun", yLabel, typeToGraph, layer);
        }
예제 #4
0
 public virtual bool removeLayer(LinearLayer layer) {
     return this.layers.Remove(layer);
 }
예제 #5
0
 public virtual void addLayer(LinearLayer layer) {
     this.layers.Add(layer);
 }
예제 #6
0
        public LinearChartData(String title, String xAxisLabel, String yAxisLabel, String layerName, LinearLayer[] layer)
            : this(title, xAxisLabel, yAxisLabel, layerName) {

            this.layers.AddRange(layer);
        }