source: branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/Converters/ResultConverter.cs @ 17834

Last change on this file since 17834 was 17834, checked in by dpiringe, 2 months ago

#3026

  • added ResultFormatter to add an extra layer of result transformation logic (converting a result value to a string with a defined logic, e.g. MatlabResultFormatter for ISymbolicRegressionSolution)
  • extended the IResultJsonItem with two properties for result formatting
  • added a new control to selected a result formatter for a result value
  • refactored the Runner for the new result formatting process
File size: 988 bytes
Line 
1using System;
2using System.Linq;
3using HeuristicLab.Core;
4using HeuristicLab.Optimization;
5
6namespace HeuristicLab.JsonInterface {
7  public class ResultConverter : BaseConverter {
8    public override int Priority => 1;
9
10    public override Type ConvertableType => typeof(IResult);
11
12    public override bool CanConvertType(Type t) =>
13      t.GetInterfaces().Any(x => x == ConvertableType);
14
15    public override IJsonItem Extract(IItem value, IJsonItemConverter root) {
16      IResult res = value as IResult;
17      var formatter = ResultFormatter.ForType(res.Value.GetType()).Last();
18      return new ResultJsonItem() {
19        Name = res.Name,
20        Description = res.Description,
21        ResultFormatterType = formatter.GetType().FullName,
22        ValueType = res.DataType
23      };
24    }
25
26    public override void Inject(IItem item, IJsonItem data, IJsonItemConverter root) {
27      IResult res = item as IResult;
28      res.Name = data.Name;
29    }
30  }
31}
Note: See TracBrowser for help on using the repository browser.