public void Define(string dest, string calcStr) { // pull out into command pattern var re = new Regex(@"(SUM|AVERAGE)\(([a-z]+\d+):([a-z]+\d+)\)", RegexOptions.IgnoreCase); var m = re.Match(calcStr); string command = m.Groups[1].Value; string start = m.Groups[2].Value; string end = m.Groups[3].Value; Tuple <int, int> indexStart = IndexParser.Parse(start); Tuple <int, int> indexEnd = IndexParser.Parse(end); ICalculation calc = AtlasGridCalculation.Value(start); // + 1 because we have added the first value already above.. for (var i = indexStart.Item2 + 1; i <= indexEnd.Item2; i++) { string grid = IndexParser.Generate(indexStart.Item1, i); // blah calc = ((AtlasGridCalculation)calc).Sum(grid); } if (command == "AVERAGE") { calc = new Average(calc, indexEnd.Item2 - indexStart.Item2); } _calcs.Add(dest, calc); }
public LoadedCalculation Take(string indexStr) { var data = new Dictionary <string, int>(); for (int i = 0; i < _table.GetLength(0); i++) { for (int j = 0; j < _table.GetLength(1); j++) { int x = i + 1; int y = j + 1; string indexer = IndexParser.Generate(x, y); // unsafe int val = Int32.Parse(_table[i, j]); data.Add(indexer, val); } } return(new LoadedCalculation(data).Value(indexStr)); }