//get average difference between current CSV object values and object a //(using root mean square distrib) public Dictionary<string, int> AverageDifferenceCSVs(CSVObject a) { Dictionary<string, int> diffList = new Dictionary<string, int> (); foreach (string name in a.csvList.Keys) { float sum = 0.0f; for (int i = 0; i < a.csvList[name].Count; i++) { if (!this.csvList.ContainsKey(name)) { Debug.LogError ("In AverageDifferenceCSVs, name not found: " + name); continue; } string aVal = a.csvList [name] [i], thisVal = this.csvList [name] [i]; if (aVal == "" || thisVal == "") { continue; } float diff = (float.Parse (aVal) - float.Parse (thisVal)); sum += diff * diff; } diffList.Add (name, (int) Mathf.Sqrt (sum / (float) a.csvList[name].Count)); } return diffList; }
public void UpdateGraph1Data(CSVObject graph1CSV, string graph1Title) { graph1.csv = graph1CSV; graph1.UpdateData(); graph1.title = graph1Title; NormalizeYScale(); }
public int CalculateScore(CSVObject a) { int score = 0; Dictionary<string, int> diffList = AverageDifferenceCSVs (a); foreach (KeyValuePair<string, int> entry in diffList) { score += entry.Value; } return score; }
private bool isActiveLegend = false; //disabled permanently public GraphsCompare( CSVObject csv1, CSVObject csv2, float left, float top, float pageWidth, float height, string title1, string title2, int xNumMarkers, Database foodWeb, ConvergeManager manager ) { this.left = left; this.top = top; this.height = height; if (isActiveLegend) { widthGraph = (pageWidth - widthLegend - (bufferGraph * 2)) / 2; } else { widthGraph = (pageWidth - (bufferGraph * 2)) / 2;; } this.foodWeb = foodWeb; //object for handling common graph control info this.manager = manager; graph1 = new GraphUnit( csv1, left, top, widthGraph, height, title1, xNumMarkers, manager, true ); graph2 = new GraphUnit( csv2, left + widthGraph + bufferGraph, top, widthGraph, height, title2, xNumMarkers, manager, false ); NormalizeYScale(); }
public int CalculateScore(CSVObject a) { int score = 0; Dictionary <string, int> diffList = AverageDifferenceCSVs(a); foreach (KeyValuePair <string, int> entry in diffList) { score += entry.Value; } return(score); }
public static CSVObject ParseCSV(string csv) { if (csv == null) { return(null); } CSVObject csvObject = new CSVObject(); List <string> xAxisLabels = new List <string> (); // i.e. Months string[] rowList = csv.Split('\n'); for (int i = 0; i < rowList.Length; i++) { if (rowList [i].Length <= 1) { continue; } string[] elements = rowList [i].Split(','); if (i == 0) // Labels { for (int j = 1; j < elements.Length; j++) { xAxisLabels.Add(elements [j]); } csvObject.xLabels = xAxisLabels; } else { string seriesLabel = "Untitled"; // i.e. Species List <string> values = new List <string> (); for (int j = 0; j < elements.Length; j++) { if (j == 0) { //seriesLabel = elements[0].Trim(); seriesLabel = NormalizeSpeciesName(elements[0]); } else { values.Add(elements [j].Trim()); } } csvObject.csvList [seriesLabel] = values; } } return(csvObject); }
public GraphsCompare( CSVObject csv1, CSVObject csv2, float left, float top, float pageWidth, float height, string title1, string title2, int xNumMarkers, Database foodWeb, ConvergeManager manager ) { this.left = left; this.top = top; this.height = height; if (isActiveLegend) { widthGraph = (pageWidth - widthLegend - (bufferGraph * 2)) / 2; } else { widthGraph = (pageWidth - (bufferGraph * 2)) / 2;; } this.foodWeb = foodWeb; //object for handling common graph control info this.manager = manager; graph1 = new GraphUnit ( csv1, left, top, widthGraph, height, title1, xNumMarkers, manager, true ); graph2 = new GraphUnit ( csv2, left + widthGraph + bufferGraph, top, widthGraph, height, title2, xNumMarkers, manager, false ); NormalizeYScale (); }
public GraphUnit( CSVObject csv, float left, float top, float width, float height, string title, int xNumMarkers, ConvergeManager convergeManager, bool isFirstGraph ) { this.csv = csv; this.labels = this.csv.xLabels; this.left = left + (isFirstGraph ? 0 : yLabelingWidth / 2); this.top = top; this.width = width + (isFirstGraph ? yLabelingWidth / 2 : - yLabelingWidth / 2); this.height = height; this.title = title; this.xNumMarkers = xNumMarkers; this.convergeManager = convergeManager; this.isFirstGraph = isFirstGraph; xTitle = "Month"; yTitle = "Score"; yTitle = "Biomass"; seriesList = new Dictionary<string, Series> (); graphRect = new Rect (this.left, this.top, this.width, this.height); hStart = new Vector2 ((isFirstGraph ? yLabelingWidth : 0) + bufferBorder, graphRect.height - 35); hEnd = new Vector2 (graphRect.width - bufferBorder, hStart.y); xAxisLength = Vector2.Distance (hStart, hEnd); // * 0.95f; xUnitLength = xAxisLength / xNumMarkers; vStart = new Vector2 (hStart.x, hStart.y); vEnd = new Vector2 (vStart.x, bufferBorder); yAxisLength = Vector2.Distance (vStart, vEnd); // * 0.95f; yUnitLength = yAxisLength / yNumMarkers; lineMarkerTex = Resources.Load<Texture2D> ("chart_dot"); font = Resources.Load<Font> ("Fonts/" + "Chalkboard"); UpdateData (); }
public GraphUnit( CSVObject csv, float left, float top, float width, float height, string title, int xNumMarkers, ConvergeManager convergeManager, bool isFirstGraph ) { this.csv = csv; this.labels = this.csv.xLabels; this.left = left + (isFirstGraph ? 0 : yLabelingWidth / 2); this.top = top; this.width = width + (isFirstGraph ? yLabelingWidth / 2 : -yLabelingWidth / 2); this.height = height; this.title = title; this.xNumMarkers = xNumMarkers; this.convergeManager = convergeManager; this.isFirstGraph = isFirstGraph; xTitle = "Month"; yTitle = "Score"; yTitle = "Biomass"; seriesList = new Dictionary <string, Series> (); graphRect = new Rect(this.left, this.top, this.width, this.height); hStart = new Vector2((isFirstGraph ? yLabelingWidth : 0) + bufferBorder, graphRect.height - 35); hEnd = new Vector2(graphRect.width - bufferBorder, hStart.y); xAxisLength = Vector2.Distance(hStart, hEnd); // * 0.95f; xUnitLength = xAxisLength / xNumMarkers; vStart = new Vector2(hStart.x, hStart.y); vEnd = new Vector2(vStart.x, bufferBorder); yAxisLength = Vector2.Distance(vStart, vEnd); // * 0.95f; yUnitLength = yAxisLength / yNumMarkers; lineMarkerTex = Resources.Load <Texture2D> ("chart_dot"); font = Resources.Load <Font> ("Fonts/" + "Chalkboard"); UpdateData(); }
public void UpdateData() { CSVObject csvObject = SubtractCSVs(csvList [0], csvList [1]); CreateSeriesSet(csvObject); // Update X-Axis Labels // List<string> labels = csvObject.xLabels; // for (int i = 0; i < labels.Count; i++) { // int month = int.Parse(labels[i]); // string name = DateTimeFormatInfo.CurrentInfo.GetMonthName((month - 1) % 12 + 1).Substring(0, 3); // // if (xAxisLabels.Count != labels.Count) { // xAxisLabels.Add(name + ((month - 1) % 12 == 0 ? "\n'0" + (month / 12 + 1) : "")); // } else if (xAxisLabels[i] != name) { // xAxisLabels[i] = name; // } // } }
public void CreateSeriesSet(CSVObject csvObject) { csvList.Add (csvObject); if (csvList.Count == 1) { return; } //csvObject = SubtractCSVs (csvList [0], csvObject); Dictionary<string, int> diffList = csvObject.AverageDifferenceCSVs (csvList [0]); string label = seriesSets.Count == 0 ? "Initial" : seriesSets.Count.ToString (); SeriesSet seriesSet = new SeriesSet (label, new DynamicRect (0, 0, 0, barWidth)); int seriesScore = 1; foreach (KeyValuePair<string, List<string>> entry in csvObject.csvList) { string name = entry.Key; // Designate color for Series (only used if no convergeManager) if (!colorList.ContainsKey (name)) { if (convergeManager == null) { colorList [name] = new Color ( Random.Range (0.4f, 0.7f), Random.Range (0.4f, 0.7f), Random.Range (0.4f, 0.7f)); } else { colorList [name] = convergeManager.seriesColors [name]; } } // Convert values from String to Float. -1 to represent empty. //List<string> strValues = entry.Value; //List<float> values = new List<float> (); //for (int i = 0; i < strValues.Count; i++) { // float value = (strValues [i] == "" ? -1f : float.Parse (strValues [i])); // values.Add (value); //} int score = diffList [name]; seriesScore += score; // Create a Series to store series BarSeries series = new BarSeries ( name, score, //values, new DynamicRect (0, 0, 0, seriesSet.rect.height), colorList [name]); seriesSet.Add (series); } //sort seriesList in seriesSet seriesSet.Sort (convergeManager.seriesLabels); seriesSets.Add (seriesSet); // Adjust Max Y-Range //UpdateRange (); yRange = Mathf.Max (yRange, seriesScore); // Adjust init slider val; exclude initial (default) bar maxSliderValue = Mathf.Max (0, seriesSets.Count - perPage); sliderValue = maxSliderValue; }
//depricated, using CSVObject::AverageDifferenceCSVs public CSVObject SubtractCSVs(CSVObject a, CSVObject b) { CSVObject csvObject = new CSVObject (); csvObject.xLabels = a.xLabels; foreach (string name in a.csvList.Keys) { List<string> csvList = new List<string> (); for (int i = 0; i < a.csvList[name].Count; i++) { string aVal = a.csvList [name] [i], bVal = b.csvList [name] [i]; if (aVal == "" || bVal == "") { csvList.Add (aVal.Length > bVal.Length ? aVal : bVal); } else { float target = float.Parse (aVal), current = float.Parse (bVal); csvList.Add (Mathf.Abs (current - target).ToString ()); } } csvObject.csvList [name] = csvList; } return csvObject; }
public void InputToCSVObject(string text) { CSVObject csvObject = Functions.ParseCSV(text); graph.CreateSeriesSet(csvObject); }
public void CreateSeriesSet(CSVObject csvObject) { csvList.Add(csvObject); if (csvList.Count == 1) { return; } //csvObject = SubtractCSVs (csvList [0], csvObject); Dictionary <string, int> diffList = csvObject.AverageDifferenceCSVs(csvList [0]); string label = seriesSets.Count == 0 ? "Initial" : seriesSets.Count.ToString(); SeriesSet seriesSet = new SeriesSet(label, new DynamicRect(0, 0, 0, barWidth)); int seriesScore = 1; foreach (KeyValuePair <string, List <string> > entry in csvObject.csvList) { string name = entry.Key; // Designate color for Series (only used if no convergeManager) if (!colorList.ContainsKey(name)) { if (convergeManager == null) { colorList [name] = new Color( Random.Range(0.4f, 0.7f), Random.Range(0.4f, 0.7f), Random.Range(0.4f, 0.7f)); } else { colorList [name] = convergeManager.seriesColors [name]; } } // Convert values from String to Float. -1 to represent empty. //List<string> strValues = entry.Value; //List<float> values = new List<float> (); //for (int i = 0; i < strValues.Count; i++) { // float value = (strValues [i] == "" ? -1f : float.Parse (strValues [i])); // values.Add (value); //} int score = diffList [name]; seriesScore += score; // Create a Series to store series BarSeries series = new BarSeries( name, score, //values, new DynamicRect(0, 0, 0, seriesSet.rect.height), colorList [name]); seriesSet.Add(series); } //sort seriesList in seriesSet seriesSet.Sort(convergeManager.seriesLabels); seriesSets.Add(seriesSet); // Adjust Max Y-Range //UpdateRange (); yRange = Mathf.Max(yRange, seriesScore); // Adjust init slider val; exclude initial (default) bar maxSliderValue = Mathf.Max(0, seriesSets.Count - perPage); sliderValue = maxSliderValue; }
public static CSVObject ParseCSV(string csv) { if (csv == null) { return null; } CSVObject csvObject = new CSVObject (); List<string> xAxisLabels = new List<string> (); // i.e. Months string[] rowList = csv.Split ('\n'); for (int i = 0; i < rowList.Length; i++) { if (rowList [i].Length <= 1) { continue; } string[] elements = rowList [i].Split (','); if (i == 0) { // Labels for (int j = 1; j < elements.Length; j++) { xAxisLabels.Add (elements [j]); } csvObject.xLabels = xAxisLabels; } else { string seriesLabel = "Untitled"; // i.e. Species List<string> values = new List<string> (); for (int j = 0; j < elements.Length; j++) { if (j == 0) { //seriesLabel = elements[0].Trim(); seriesLabel = NormalizeSpeciesName (elements[0]); } else { values.Add (elements [j].Trim ()); } } csvObject.csvList [seriesLabel] = values; } } return csvObject; }
public void UpdateGraph1Data(CSVObject graph1CSV, string graph1Title) { graph1.csv = graph1CSV; graph1.UpdateData (); graph1.title = graph1Title; NormalizeYScale (); }