forked from gsn/predictor
feat: predictor works
This commit is contained in:
parent
11be8f351f
commit
7a9f81e527
20 changed files with 1357 additions and 1794 deletions
|
|
@ -15,6 +15,7 @@ import (
|
|||
semconv "go.opentelemetry.io/otel/semconv/v1.26.0"
|
||||
"go.opentelemetry.io/otel/trace"
|
||||
|
||||
"github.com/ogen-go/ogen/conv"
|
||||
ht "github.com/ogen-go/ogen/http"
|
||||
"github.com/ogen-go/ogen/otelogen"
|
||||
"github.com/ogen-go/ogen/uri"
|
||||
|
|
@ -29,10 +30,10 @@ func trimTrailingSlashes(u *url.URL) {
|
|||
type Invoker interface {
|
||||
// PerformPrediction invokes performPrediction operation.
|
||||
//
|
||||
// Perform preidction.
|
||||
// Perform prediction.
|
||||
//
|
||||
// POST /api/v1/prediction
|
||||
PerformPrediction(ctx context.Context, request OptPredictionParameters, params PerformPredictionParams) (*PredictionResult, error)
|
||||
// GET /api/v1/prediction
|
||||
PerformPrediction(ctx context.Context, params PerformPredictionParams) (*PredictionResult, error)
|
||||
// ReadinessCheck invokes readinessCheck operation.
|
||||
//
|
||||
// Readiness check.
|
||||
|
|
@ -90,18 +91,18 @@ func (c *Client) requestURL(ctx context.Context) *url.URL {
|
|||
|
||||
// PerformPrediction invokes performPrediction operation.
|
||||
//
|
||||
// Perform preidction.
|
||||
// Perform prediction.
|
||||
//
|
||||
// POST /api/v1/prediction
|
||||
func (c *Client) PerformPrediction(ctx context.Context, request OptPredictionParameters, params PerformPredictionParams) (*PredictionResult, error) {
|
||||
res, err := c.sendPerformPrediction(ctx, request, params)
|
||||
// GET /api/v1/prediction
|
||||
func (c *Client) PerformPrediction(ctx context.Context, params PerformPredictionParams) (*PredictionResult, error) {
|
||||
res, err := c.sendPerformPrediction(ctx, params)
|
||||
return res, err
|
||||
}
|
||||
|
||||
func (c *Client) sendPerformPrediction(ctx context.Context, request OptPredictionParameters, params PerformPredictionParams) (res *PredictionResult, err error) {
|
||||
func (c *Client) sendPerformPrediction(ctx context.Context, params PerformPredictionParams) (res *PredictionResult, err error) {
|
||||
otelAttrs := []attribute.KeyValue{
|
||||
otelogen.OperationID("performPrediction"),
|
||||
semconv.HTTPRequestMethodKey.String("POST"),
|
||||
semconv.HTTPRequestMethodKey.String("GET"),
|
||||
semconv.HTTPRouteKey.String("/api/v1/prediction"),
|
||||
}
|
||||
|
||||
|
|
@ -141,16 +142,254 @@ func (c *Client) sendPerformPrediction(ctx context.Context, request OptPredictio
|
|||
stage = "EncodeQueryParams"
|
||||
q := uri.NewQueryEncoder()
|
||||
{
|
||||
// Encode "parameters" parameter.
|
||||
// Encode "launch_latitude" parameter.
|
||||
cfg := uri.QueryParameterEncodingConfig{
|
||||
Name: "parameters",
|
||||
Name: "launch_latitude",
|
||||
Style: uri.QueryStyleForm,
|
||||
Explode: true,
|
||||
}
|
||||
|
||||
if err := q.EncodeParam(cfg, func(e uri.Encoder) error {
|
||||
if val, ok := params.Parameters.Get(); ok {
|
||||
return val.EncodeURI(e)
|
||||
if val, ok := params.LaunchLatitude.Get(); ok {
|
||||
return e.EncodeValue(conv.Float64ToString(val))
|
||||
}
|
||||
return nil
|
||||
}); err != nil {
|
||||
return res, errors.Wrap(err, "encode query")
|
||||
}
|
||||
}
|
||||
{
|
||||
// Encode "launch_longitude" parameter.
|
||||
cfg := uri.QueryParameterEncodingConfig{
|
||||
Name: "launch_longitude",
|
||||
Style: uri.QueryStyleForm,
|
||||
Explode: true,
|
||||
}
|
||||
|
||||
if err := q.EncodeParam(cfg, func(e uri.Encoder) error {
|
||||
if val, ok := params.LaunchLongitude.Get(); ok {
|
||||
return e.EncodeValue(conv.Float64ToString(val))
|
||||
}
|
||||
return nil
|
||||
}); err != nil {
|
||||
return res, errors.Wrap(err, "encode query")
|
||||
}
|
||||
}
|
||||
{
|
||||
// Encode "launch_datetime" parameter.
|
||||
cfg := uri.QueryParameterEncodingConfig{
|
||||
Name: "launch_datetime",
|
||||
Style: uri.QueryStyleForm,
|
||||
Explode: true,
|
||||
}
|
||||
|
||||
if err := q.EncodeParam(cfg, func(e uri.Encoder) error {
|
||||
if val, ok := params.LaunchDatetime.Get(); ok {
|
||||
return e.EncodeValue(conv.DateTimeToString(val))
|
||||
}
|
||||
return nil
|
||||
}); err != nil {
|
||||
return res, errors.Wrap(err, "encode query")
|
||||
}
|
||||
}
|
||||
{
|
||||
// Encode "launch_altitude" parameter.
|
||||
cfg := uri.QueryParameterEncodingConfig{
|
||||
Name: "launch_altitude",
|
||||
Style: uri.QueryStyleForm,
|
||||
Explode: true,
|
||||
}
|
||||
|
||||
if err := q.EncodeParam(cfg, func(e uri.Encoder) error {
|
||||
if val, ok := params.LaunchAltitude.Get(); ok {
|
||||
return e.EncodeValue(conv.Float64ToString(val))
|
||||
}
|
||||
return nil
|
||||
}); err != nil {
|
||||
return res, errors.Wrap(err, "encode query")
|
||||
}
|
||||
}
|
||||
{
|
||||
// Encode "profile" parameter.
|
||||
cfg := uri.QueryParameterEncodingConfig{
|
||||
Name: "profile",
|
||||
Style: uri.QueryStyleForm,
|
||||
Explode: true,
|
||||
}
|
||||
|
||||
if err := q.EncodeParam(cfg, func(e uri.Encoder) error {
|
||||
if val, ok := params.Profile.Get(); ok {
|
||||
return e.EncodeValue(conv.StringToString(string(val)))
|
||||
}
|
||||
return nil
|
||||
}); err != nil {
|
||||
return res, errors.Wrap(err, "encode query")
|
||||
}
|
||||
}
|
||||
{
|
||||
// Encode "ascent_rate" parameter.
|
||||
cfg := uri.QueryParameterEncodingConfig{
|
||||
Name: "ascent_rate",
|
||||
Style: uri.QueryStyleForm,
|
||||
Explode: true,
|
||||
}
|
||||
|
||||
if err := q.EncodeParam(cfg, func(e uri.Encoder) error {
|
||||
if val, ok := params.AscentRate.Get(); ok {
|
||||
return e.EncodeValue(conv.Float64ToString(val))
|
||||
}
|
||||
return nil
|
||||
}); err != nil {
|
||||
return res, errors.Wrap(err, "encode query")
|
||||
}
|
||||
}
|
||||
{
|
||||
// Encode "burst_altitude" parameter.
|
||||
cfg := uri.QueryParameterEncodingConfig{
|
||||
Name: "burst_altitude",
|
||||
Style: uri.QueryStyleForm,
|
||||
Explode: true,
|
||||
}
|
||||
|
||||
if err := q.EncodeParam(cfg, func(e uri.Encoder) error {
|
||||
if val, ok := params.BurstAltitude.Get(); ok {
|
||||
return e.EncodeValue(conv.Float64ToString(val))
|
||||
}
|
||||
return nil
|
||||
}); err != nil {
|
||||
return res, errors.Wrap(err, "encode query")
|
||||
}
|
||||
}
|
||||
{
|
||||
// Encode "descent_rate" parameter.
|
||||
cfg := uri.QueryParameterEncodingConfig{
|
||||
Name: "descent_rate",
|
||||
Style: uri.QueryStyleForm,
|
||||
Explode: true,
|
||||
}
|
||||
|
||||
if err := q.EncodeParam(cfg, func(e uri.Encoder) error {
|
||||
if val, ok := params.DescentRate.Get(); ok {
|
||||
return e.EncodeValue(conv.Float64ToString(val))
|
||||
}
|
||||
return nil
|
||||
}); err != nil {
|
||||
return res, errors.Wrap(err, "encode query")
|
||||
}
|
||||
}
|
||||
{
|
||||
// Encode "float_altitude" parameter.
|
||||
cfg := uri.QueryParameterEncodingConfig{
|
||||
Name: "float_altitude",
|
||||
Style: uri.QueryStyleForm,
|
||||
Explode: true,
|
||||
}
|
||||
|
||||
if err := q.EncodeParam(cfg, func(e uri.Encoder) error {
|
||||
if val, ok := params.FloatAltitude.Get(); ok {
|
||||
return e.EncodeValue(conv.Float64ToString(val))
|
||||
}
|
||||
return nil
|
||||
}); err != nil {
|
||||
return res, errors.Wrap(err, "encode query")
|
||||
}
|
||||
}
|
||||
{
|
||||
// Encode "stop_datetime" parameter.
|
||||
cfg := uri.QueryParameterEncodingConfig{
|
||||
Name: "stop_datetime",
|
||||
Style: uri.QueryStyleForm,
|
||||
Explode: true,
|
||||
}
|
||||
|
||||
if err := q.EncodeParam(cfg, func(e uri.Encoder) error {
|
||||
if val, ok := params.StopDatetime.Get(); ok {
|
||||
return e.EncodeValue(conv.DateTimeToString(val))
|
||||
}
|
||||
return nil
|
||||
}); err != nil {
|
||||
return res, errors.Wrap(err, "encode query")
|
||||
}
|
||||
}
|
||||
{
|
||||
// Encode "ascent_curve" parameter.
|
||||
cfg := uri.QueryParameterEncodingConfig{
|
||||
Name: "ascent_curve",
|
||||
Style: uri.QueryStyleForm,
|
||||
Explode: true,
|
||||
}
|
||||
|
||||
if err := q.EncodeParam(cfg, func(e uri.Encoder) error {
|
||||
if val, ok := params.AscentCurve.Get(); ok {
|
||||
return e.EncodeValue(conv.StringToString(val))
|
||||
}
|
||||
return nil
|
||||
}); err != nil {
|
||||
return res, errors.Wrap(err, "encode query")
|
||||
}
|
||||
}
|
||||
{
|
||||
// Encode "descent_curve" parameter.
|
||||
cfg := uri.QueryParameterEncodingConfig{
|
||||
Name: "descent_curve",
|
||||
Style: uri.QueryStyleForm,
|
||||
Explode: true,
|
||||
}
|
||||
|
||||
if err := q.EncodeParam(cfg, func(e uri.Encoder) error {
|
||||
if val, ok := params.DescentCurve.Get(); ok {
|
||||
return e.EncodeValue(conv.StringToString(val))
|
||||
}
|
||||
return nil
|
||||
}); err != nil {
|
||||
return res, errors.Wrap(err, "encode query")
|
||||
}
|
||||
}
|
||||
{
|
||||
// Encode "interpolate" parameter.
|
||||
cfg := uri.QueryParameterEncodingConfig{
|
||||
Name: "interpolate",
|
||||
Style: uri.QueryStyleForm,
|
||||
Explode: true,
|
||||
}
|
||||
|
||||
if err := q.EncodeParam(cfg, func(e uri.Encoder) error {
|
||||
if val, ok := params.Interpolate.Get(); ok {
|
||||
return e.EncodeValue(conv.BoolToString(val))
|
||||
}
|
||||
return nil
|
||||
}); err != nil {
|
||||
return res, errors.Wrap(err, "encode query")
|
||||
}
|
||||
}
|
||||
{
|
||||
// Encode "format" parameter.
|
||||
cfg := uri.QueryParameterEncodingConfig{
|
||||
Name: "format",
|
||||
Style: uri.QueryStyleForm,
|
||||
Explode: true,
|
||||
}
|
||||
|
||||
if err := q.EncodeParam(cfg, func(e uri.Encoder) error {
|
||||
if val, ok := params.Format.Get(); ok {
|
||||
return e.EncodeValue(conv.StringToString(string(val)))
|
||||
}
|
||||
return nil
|
||||
}); err != nil {
|
||||
return res, errors.Wrap(err, "encode query")
|
||||
}
|
||||
}
|
||||
{
|
||||
// Encode "dataset" parameter.
|
||||
cfg := uri.QueryParameterEncodingConfig{
|
||||
Name: "dataset",
|
||||
Style: uri.QueryStyleForm,
|
||||
Explode: true,
|
||||
}
|
||||
|
||||
if err := q.EncodeParam(cfg, func(e uri.Encoder) error {
|
||||
if val, ok := params.Dataset.Get(); ok {
|
||||
return e.EncodeValue(conv.DateTimeToString(val))
|
||||
}
|
||||
return nil
|
||||
}); err != nil {
|
||||
|
|
@ -160,13 +399,10 @@ func (c *Client) sendPerformPrediction(ctx context.Context, request OptPredictio
|
|||
u.RawQuery = q.Values().Encode()
|
||||
|
||||
stage = "EncodeRequest"
|
||||
r, err := ht.NewRequest(ctx, "POST", u)
|
||||
r, err := ht.NewRequest(ctx, "GET", u)
|
||||
if err != nil {
|
||||
return res, errors.Wrap(err, "create request")
|
||||
}
|
||||
if err := encodePerformPredictionRequest(request, r); err != nil {
|
||||
return res, errors.Wrap(err, "encode request")
|
||||
}
|
||||
|
||||
stage = "SendRequest"
|
||||
resp, err := c.cfg.Client.Do(r)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue