import { NMNPrediction } from '../types' ; interface Output { inputName : string ; values : number [ ] ; label ? : string ; } export class Step { constructor ( public moduleName , public outputs ) { } getOutputsForInput ( inputName ) { return this . outputs . filter ( ( o ) => o . inputName === inputName ) ; } } export interface Input { name : string ; tokens : string [ ] ; } export class Explanation { constructor ( public answer , public inputs , public steps ) { } static fromResponse ( response ) { const inputs = response . inputs . map ( ( i ) => { return { name : i . name , tokens : i . tokens } ; } ) ; const steps = [ ] ; for ( const step of response . program_execution ) { for ( const [ key , value ] of Object . entries ( step ) ) { const outputs = value . map ( ( o ) => { return { inputName : o . input_name , values : o . values , label : o . label , } ; } ) ; steps . push ( new Step ( key , outputs ) ) ; } } return new Explanation ( response . answer , inputs , steps ) ; } }