Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
06/13/13 19:45:37 (11 years ago)
Author:
mkommend
Message:

#1730: Implemented new features for the excel export:

  • The menu item is enabled if any view containing a symreg solution is displayed.
  • Classifications are not longer supported.
  • Export is performed asynchronously.
  • Inputs are sorted in the same order if a dataset is passed.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Formatters/SymbolicDataAnalysisExpressionExcelFormatter.cs

    r9587 r9626  
    2323using System.Collections.Generic;
    2424using System.Globalization;
     25using System.Linq;
    2526using System.Text;
    2627using HeuristicLab.Common;
     
    6667      return string.Format("${0}1", variableNameMapping[variabelName]);
    6768    }
    68 
    6969    public string Format(ISymbolicExpressionTree symbolicExpressionTree) {
     70      return Format(symbolicExpressionTree, null);
     71    }
     72
     73    public string Format(ISymbolicExpressionTree symbolicExpressionTree, Dataset dataset) {
    7074      var stringBuilder = new StringBuilder();
     75      if (dataset != null) CalculateVariableMapping(symbolicExpressionTree, dataset);
     76
    7177      stringBuilder.Append("=");
    7278      stringBuilder.Append(FormatRecursively(symbolicExpressionTree.Root));
     79
    7380      foreach (var variable in variableNameMapping) {
    7481        stringBuilder.AppendLine();
     
    7683      }
    7784      return stringBuilder.ToString();
     85    }
     86
     87    private void CalculateVariableMapping(ISymbolicExpressionTree tree, Dataset dataset) {
     88      int columnIndex = 0;
     89      int inputIndex = 0;
     90      var usedVariables = tree.IterateNodesPrefix().OfType<VariableTreeNode>().Select(v => v.VariableName).Distinct();
     91      foreach (var variable in dataset.VariableNames) {
     92        columnIndex++;
     93        if (!usedVariables.Contains(variable)) continue;
     94        inputIndex++;
     95        variableNameMapping[variable] = GetExcelColumnName(inputIndex);
     96      }
    7897    }
    7998
     
    137156        stringBuilder.Append(")");
    138157      } else if (symbol is Logarithm) {
    139         stringBuilder.Append("LOG(");
    140         stringBuilder.Append(FormatRecursively(node.GetSubtree(0)));
    141         stringBuilder.Append(", EXP(1))"); // Excel does not use the natural logarithm, therefor the base has to be set
     158        stringBuilder.Append("LN(");
     159        stringBuilder.Append(FormatRecursively(node.GetSubtree(0)));
     160        stringBuilder.Append(")");
    142161      } else if (symbol is Multiplication) {
    143162        for (int i = 0; i < node.SubtreeCount; i++) {
Note: See TracChangeset for help on using the changeset viewer.