Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 17834 was 17834, checked in by dpiringe, 3 years 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: 1.0 KB
RevLine 
[17446]1using System;
2using System.Linq;
3using HeuristicLab.Core;
4using HeuristicLab.Optimization;
5
6namespace HeuristicLab.JsonInterface {
7  public class ResultParameterConverter : BaseConverter {
8    public override int Priority => 5;
9
10    public override Type ConvertableType => typeof(IResultParameter);
11
[17828]12    public override bool CanConvertType(Type t) =>
[17834]13      t.GetInterfaces().Any(x => x == ConvertableType);
[17828]14
[17446]15    public override IJsonItem Extract(IItem value, IJsonItemConverter root) {
16      IResultParameter res = value as IResultParameter;
[17834]17      var formatter = ResultFormatter.ForType(res.DataType).Last();
[17451]18      return new ResultJsonItem() {
[17446]19        Name = res.ActualName,
[17834]20        Description = res.Description,
21        ResultFormatterType = formatter.GetType().FullName,
22        ValueType = res.DataType
[17446]23      };
24    }
25
26    public override void Inject(IItem item, IJsonItem data, IJsonItemConverter root) {
27      IResultParameter res = item as IResultParameter;
[17473]28      res.ActualName = data.Name;
[17446]29    }
30  }
31}
Note: See TracBrowser for help on using the repository browser.