Skip to content

Response Model #94

Description

@solvicode

As we do with Window Metadata Fields, algorithms should be able to provide their response model.

When consuming results of this algorithm, that response model should be parseable in the language, so the dependant algorithm does not need to do any type checking. That elimininates this kind of code on teh client:

func parseResult(result orca.Result) (*ResultStruct, error) {
	switch result.Kind() {
	case orca.KindStruct:
		r, ok := result.(orca.StructResult)
		if !ok {
			return nil, errors.New("was told the result is a struct, but found otherwise")
		}
		s, ok := r.Value[COMBINED_VALUE_FIELD_NAME]
		if !ok {
			return nil, fmt.Errorf("could not find field %s in result struct", COMBINED_VALUE_FIELD_NAME)
		}
		sf, ok := s.(float32)
		if !ok {
			return nil, fmt.Errorf("could not parse field %s in into a float. recieved %v", COMBINED_VALUE_FIELD_NAME, s)
		}

		p, ok := r.Value[P_H_FIELD_NAME]
		if !ok {
			return nil, fmt.Errorf("could not find field %s in result struct", P_H_FIELD_NAME)
		}
		pf, ok := p.(float32)
		if !ok {
			return nil, fmt.Errorf("could not parse field %s in into a float. recieved %v", P_H_FIELD_NAME, p)
		}

		return &ResultStruct{
			combinedSignal: float64(sf),
			p_h:            float64(pf),
		}, nil

	default:
		return nil, fmt.Errorf("cannot parse result kind %v", result.Kind())
	}
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions