public static void SafeSetValue(string val, CSVObject obj, string key2) { if (obj != null) { if (obj.HadKey(key2)) { obj[key2] = val; } } }
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 static void ForceSetValue(string val, CSVTable table, string key1, string key2) { if (table != null) { var obj = table[key1]; if (obj != null) { table[key1] = new CSVObject(key1, null, null); } table[key1][key2] = val; } }
public DataParser(String PIn) { PathIn = PIn; if (PathIn != null && File.Exists(PathIn)) { fName = Path.GetFileName(PathIn).Split(new char[] { '.' })[0]; isLi = fName.Contains("li"); PathOut = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location) + @"\" + ((isLi) ? fName.Split(new[] { "li" }, StringSplitOptions.None)[0] : fName.Split(new[] { "mZ" }, StringSplitOptions.None)[0]) + @"\" + fName + @"\"; Options = new CSVObject(fName, PIn); ReadData(); } }
//安全取得值 public static CSVValue SafeGetValue(CSVValue val, CSVObject obj, string key2) { if (obj != null) { if (obj.HadKey(key2)) { return(obj[key2]); } } return(val); }
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 DataParser(String PIn, String POut, CSVObject Opts) { PathIn = PIn; if (PathIn != null && POut != null && File.Exists(PathIn)) { fName = Path.GetFileName(PathIn).Split('.')[0]; isLi = fName.Contains("li"); PathOut = POut + (isLi ? fName.Split(new[] { "li" }, StringSplitOptions.None)[0] : fName.Split(new[] { "mZ" }, StringSplitOptions.None)[0]) + @"\" + fName + @"\"; Options = Opts; ReadData(); } }
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(); }
private void imp_wiz_files_SelectedIndexChanged(object sender, EventArgs e) { ComboBox DropDown = (ComboBox)sender; if (DropDown.SelectedItem != null) { CurrObj = CSVOptions[DropDown.SelectedItem.ToString()]; foreach (string str in Opts) { ((TextBox)Controls.Find(str + "_input", true)[0]).Text = CurrObj.GetOption(str).ToString(); } options_group.Enabled = true; save_imp_btn.Enabled = true; } }
public static CSVObject GetEntityInfo(string code) { //按类型区分 EEntityType entityType = EntityUtil.GetEntityTypeByCode(code); CSVObject obj = null; switch (entityType) { case EEntityType.Hero: obj = GetRoleInfo(code); break; case EEntityType.Wingman: obj = GetWingmanInfo(code); break; case EEntityType.Mob: for (int i = 0; i < 2; i++) { code = ReplaceChar(code, code.Length - i, '0'); obj = GetMobInfo(code); if (obj != null) { break; } } break; case EEntityType.Boss: obj = GetBossInfo(code); break; case EEntityType.Bullet: { for (int i = 0; i < 2; i++) { code = ReplaceChar(code, code.Length - i, '0'); obj = GetBulletInfo(code); if (obj != null) { break; } } } break; } return(obj); }
public WorkbookReader(String @path, String name, CSVObject Opts) { try { if (App == null) { App = new Origin.Application(); } } catch (Exception e) { Console.WriteLine(e.Message); return; } InitWorkBook(path, name, Opts); }
private void AddMissingKeys(CSVObject csv) { string[] keys = Enum.GetNames(typeof(ELocKey)); for (int x = 0; x < keys.Length; x++) { if (csv.Find(0, keys[x]) == null) { CSVEntry entry = new CSVEntry(csv.Width); for (int entryColumn = 0; entryColumn < entry.Size; entryColumn++) { entry[entryColumn] = keys[entryColumn]; } csv.Add(entry); } } }
private void GenerateGraphs(bool newEcosystem) { string title = ( referenceAttemptIdx == Constants.ID_NOT_SET ? "Initial config" : String.Format("Attempt #{0}", referenceAttemptIdx + 1) ); //hide 0 start from user CSVObject graph1CSV = (referenceAttemptIdx == Constants.ID_NOT_SET) ? ecosystemList [ecosystem_idx].csv_default_object : attemptList [referenceAttemptIdx].csv_object; if (newEcosystem) { //destroy prior bargraph if it exists //Note: barGraph is regenerated when requested if (barGraph != null) { Destroy(barGraph); barGraph = null; } GenerateFoodWeb(); graphs = new GraphsCompare( graph1CSV, ecosystemList [ecosystem_idx].csv_target_object, leftGraph, topGraph, widthGraph, heightGraph, title, "Target Graph", ecosystemList [ecosystem_idx].timesteps, foodWeb, manager ); } else { graphs.UpdateGraph1Data(graph1CSV, title); } }
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; // } // } }
private CSVObject LoadCSV(string path) { string[] lines = File.ReadAllLines(path); CSVParser parser = new CSVParser(); for (int x = 0; x < lines.Length; x++) { parser.ParseLine(lines[x]); } CSVObject csv = parser.Flush(); if (csv == null) { csv = new CSVObject(); } csv.AddHeaders("key", "en-us"); string[] keyNames = Enum.GetNames(typeof(ELocKey)); HashSet <string> knownNames = new HashSet <string>(); for (int x = 0; x < csv.Count; x++) { knownNames.Add(csv[x][0]); } for (int x = 0; x < keyNames.Length; x++) { string key = keyNames[x]; if (!knownNames.Contains(key)) { CSVEntry row = new CSVEntry(csv.Width); for (int iRow = 0; iRow < row.Size; iRow++) { row[iRow] = key; } csv.Add(row); } } return(csv); }
protected override void Draw() { EditorGUILayout.BeginHorizontal(); if (GUILayout.Button("Reload")) { m_CSV = LoadCSV(); AddMissingKeys(m_CSV); SaveCSV(); } if (GUILayout.Button("Save")) { SaveCSV(); } EditorGUILayout.EndHorizontal(); if (m_CSV != null) { DrawLocalizationEntries(); } }
private CSVObject LoadCSV() { m_Headers = null; TextAsset asset = Target.LocalizationCSV; if (asset != null) { string path = AssetDatabase.GetAssetPath(asset); CSVObject csv = LoadCSV(path); if (csv != null) { m_Headers = new string[csv.Header.Size - 1]; for (int x = 1; x < csv.Header.Size; x++) { m_Headers[x - 1] = csv.Header[x]; } } return(csv); } return(null); }
private static CSVObject ConvertStringsToObject(string[][] strings) { var headers = strings[0]; var obj = new CSVObject(); obj.Rows = new Dictionary <string, string> [strings.Length - 1]; for (int i = 1; i < strings.Length; i++) { obj.Rows[i - 1] = new Dictionary <string, string>(); for (int j = 0; j < headers.Length; j++) { var header = headers[j]; if (string.IsNullOrEmpty(header)) { continue; } obj.Rows[i - 1].Add(header, strings[i][j]); } } return(obj); }
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; }
protected override void Initialize() { DrawDefault = true; m_CSV = LoadCSV(); }
public static CSVObject ParseCSV(string csv) { if (csv == null) { return null; } CSVObject csvObject = new CSVObject (); int cnt = 0; 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 cnt = elements.Length; //set definite count of elements 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 ()); } } //add zeros if any elements are missing (i.e. species extinct) for (int j = elements.Length; j < cnt; j++) { values.Add ("0"); } csvObject.csvList [seriesLabel] = values; } } 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; }
//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 UpdateData() { // Update X-Axis Labels List <string> labels = GameState.csvList.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; } } // Update Values float yMaxValue = 1; CSVObject csv = GameState.csvList; foreach (KeyValuePair <string, List <string> > entry in csv.csvList) { string name = entry.Key; List <string> values = entry.Value; if (name == ".xLabels") { continue; } if (!seriesList.ContainsKey(name)) { Rect seriesRect = new Rect(0, 0, 0, graphRect.height); Color color = new Color(Random.Range(0.5f, 0.9f), Random.Range(0.5f, 0.9f), Random.Range(0.5f, 0.9f)); seriesList[name] = new Series(name, seriesRect, color); seriesLabels.Add(name); if (lastSeriesToDraw == null) { lastSeriesToDraw = name; } } List <float> temp = seriesList[name].values; for (int i = 0; i < values.Count - 1; i++) // Exclude Last Point { float value = (values[i] == "" ? -1f : float.Parse(values[i])); if (temp.Count != values.Count) { temp.Add(value); } else if (!Mathf.Approximately(temp[i], value)) { temp[i] = value; } yMaxValue = Mathf.Max(value, yMaxValue); } } seriesLabels.Sort(); int roundTo = int.Parse("5".PadRight(((int)yMaxValue).ToString().Length - 1, '0')); yRange = Mathf.CeilToInt(yMaxValue / roundTo) * roundTo; }
public void UpdateGraph1Data(CSVObject graph1CSV, string graph1Title) { graph1.csv = graph1CSV; graph1.UpdateData (); graph1.title = graph1Title; NormalizeYScale (); }
public void ProcessConvergeNewAttempt(NetworkResponse response) { ConvergeAttempt attempt; ResponseConvergeNewAttempt args = response as ResponseConvergeNewAttempt; attempt = args.attempt; //if the submission resulted in a valid attempt, add to attempt list and reinitialize //currAttempt for next attempt. Otherwise, keep current attempt if (attempt != null && attempt.attempt_id != Constants.ID_NOT_SET) { currAttempt.attempt_id = attempt.attempt_id; currAttempt.SetCSV(attempt.csv_string); attemptList.Add(currAttempt); attemptCount = attemptList.Count; //calculate score and send back to server. CSVObject target = ecosystemList[ecosystem_idx].csv_target_object; int score = currAttempt.csv_object.CalculateScore(target); NetworkManager.Send( ConvergeNewAttemptScoreProtocol.Prepare( player_id, ecosystem_id, attempt.attempt_id, score ), ProcessConvergeNewAttemptScore ); //update pertinent variables with new data if (currAttempt.hint_id != Constants.ID_NOT_SET) { priorHintIdList.Add(currAttempt.hint_id); } //need to recalc reset slider config due to additional attempt isResetSliderInitialized = false; if (barGraph != null) { barGraph.InputToCSVObject(currAttempt.csv_string, manager); } currAttempt = new ConvergeAttempt( player_id, ecosystem_id, attempt.attempt_id + 1, allowHintsMaster, Constants.ID_NOT_SET, attempt.config, null, manager ); FinalizeAttemptUpdate(attemptCount - 1, false); } else { Debug.LogError("Submission of new attempt failed to produce results."); SetIsProcessing(false); } }