_id stringlengths 2 7 | title stringlengths 1 118 | partition stringclasses 3 values | text stringlengths 52 85.5k | language stringclasses 1 value | meta_information dict |
|---|---|---|---|---|---|
q10300 | TLSTransport | train | func TLSTransport(opts TLSClientOptions) (http.RoundTripper, error) {
cfg, err := TLSClientAuth(opts)
if err != nil {
return nil, err
}
return &http.Transport{TLSClientConfig: cfg}, nil
} | go | {
"resource": ""
} |
q10301 | TLSClient | train | func TLSClient(opts TLSClientOptions) (*http.Client, error) {
transport, err := TLSTransport(opts)
if err != nil {
return nil, err
}
return &http.Client{Transport: transport}, nil
} | go | {
"resource": ""
} |
q10302 | New | train | func New(host, basePath string, schemes []string) *Runtime {
var rt Runtime
rt.DefaultMediaType = runtime.JSONMime
// TODO: actually infer this stuff from the spec
rt.Consumers = map[string]runtime.Consumer{
runtime.JSONMime: runtime.JSONConsumer(),
runtime.XMLMime: runtime.XMLConsumer(),
runtime.TextMime: runtime.TextConsumer(),
runtime.HTMLMime: runtime.TextConsumer(),
runtime.CSVMime: runtime.CSVConsumer(),
runtime.DefaultMime: runtime.ByteStreamConsumer(),
}
rt.Producers = map[string]runtime.Producer{
runtime.JSONMime: runtime.JSONProducer(),
runtime.XMLMime: runtime.XMLProducer(),
runtime.TextMime: runtime.TextProducer(),
runtime.HTMLMime: runtime.TextProducer(),
runtime.CSVMime: runtime.CSVProducer(),
runtime.DefaultMime: runtime.ByteStreamProducer(),
}
rt.Transport = http.DefaultTransport
rt.Jar = nil
rt.Host = host
rt.BasePath = basePath
rt.Context = context.Background()
rt.clientOnce = new(sync.Once)
if !strings.HasPrefix(rt.BasePath, "/") {
rt.BasePath = "/" + rt.BasePath
}
rt.Debug = logger.DebugEnabled()
rt.logger = logger.StandardLogger{}
if len(schemes) > 0 {
rt.schemes = schemes
}
return &rt
} | go | {
"resource": ""
} |
q10303 | NewWithClient | train | func NewWithClient(host, basePath string, schemes []string, client *http.Client) *Runtime {
rt := New(host, basePath, schemes)
if client != nil {
rt.clientOnce.Do(func() {
rt.client = client
})
}
return rt
} | go | {
"resource": ""
} |
q10304 | EnableConnectionReuse | train | func (r *Runtime) EnableConnectionReuse() {
if r.client == nil {
r.Transport = KeepAliveTransport(
transportOrDefault(r.Transport, http.DefaultTransport),
)
return
}
r.client.Transport = KeepAliveTransport(
transportOrDefault(r.client.Transport,
transportOrDefault(r.Transport, http.DefaultTransport),
),
)
} | go | {
"resource": ""
} |
q10305 | SetDebug | train | func (r *Runtime) SetDebug(debug bool) {
r.Debug = debug
middleware.Debug = debug
} | go | {
"resource": ""
} |
q10306 | SetLogger | train | func (r *Runtime) SetLogger(logger logger.Logger) {
r.logger = logger
middleware.Logger = logger
} | go | {
"resource": ""
} |
q10307 | XMLConsumer | train | func XMLConsumer() Consumer {
return ConsumerFunc(func(reader io.Reader, data interface{}) error {
dec := xml.NewDecoder(reader)
return dec.Decode(data)
})
} | go | {
"resource": ""
} |
q10308 | XMLProducer | train | func XMLProducer() Producer {
return ProducerFunc(func(writer io.Writer, data interface{}) error {
enc := xml.NewEncoder(writer)
return enc.Encode(data)
})
} | go | {
"resource": ""
} |
q10309 | Handler | train | func (m *Mux) Handler(method, path string, handler HandlerFunc) Handler {
return Handler{
Method: method,
Path: path,
Func: handler,
}
} | go | {
"resource": ""
} |
q10310 | Build | train | func (m *Mux) Build(handlers []Handler) (http.Handler, error) {
recordMap := make(map[string][]Record)
for _, h := range handlers {
recordMap[h.Method] = append(recordMap[h.Method], NewRecord(h.Path, h.Func))
}
mux := newServeMux()
for m, records := range recordMap {
router := New()
if err := router.Build(records); err != nil {
return nil, err
}
mux.routers[m] = router
}
return mux, nil
} | go | {
"resource": ""
} |
q10311 | NextSeparator | train | func NextSeparator(path string, start int) int {
for start < len(path) {
if c := path[start]; c == '/' || c == TerminationCharacter {
break
}
start++
}
return start
} | go | {
"resource": ""
} |
q10312 | newUntypedRequestBinder | train | func newUntypedRequestBinder(parameters map[string]spec.Parameter, spec *spec.Swagger, formats strfmt.Registry) *untypedRequestBinder {
binders := make(map[string]*untypedParamBinder)
for fieldName, param := range parameters {
binders[fieldName] = newUntypedParamBinder(param, spec, formats)
}
return &untypedRequestBinder{
Parameters: parameters,
paramBinders: binders,
Spec: spec,
Formats: formats,
}
} | go | {
"resource": ""
} |
q10313 | Bind | train | func (o *untypedRequestBinder) Bind(request *http.Request, routeParams RouteParams, consumer runtime.Consumer, data interface{}) error {
val := reflect.Indirect(reflect.ValueOf(data))
isMap := val.Kind() == reflect.Map
var result []error
debugLog("binding %d parameters for %s %s", len(o.Parameters), request.Method, request.URL.EscapedPath())
for fieldName, param := range o.Parameters {
binder := o.paramBinders[fieldName]
debugLog("binding parameter %s for %s %s", fieldName, request.Method, request.URL.EscapedPath())
var target reflect.Value
if !isMap {
binder.Name = fieldName
target = val.FieldByName(fieldName)
}
if isMap {
tpe := binder.Type()
if tpe == nil {
if param.Schema.Type.Contains("array") {
tpe = reflect.TypeOf([]interface{}{})
} else {
tpe = reflect.TypeOf(map[string]interface{}{})
}
}
target = reflect.Indirect(reflect.New(tpe))
}
if !target.IsValid() {
result = append(result, errors.New(500, "parameter name %q is an unknown field", binder.Name))
continue
}
if err := binder.Bind(request, routeParams, consumer, target); err != nil {
result = append(result, err)
continue
}
if binder.validator != nil {
rr := binder.validator.Validate(target.Interface())
if rr != nil && rr.HasErrors() {
result = append(result, rr.AsError())
}
}
if isMap {
val.SetMapIndex(reflect.ValueOf(param.Name), target)
}
}
if len(result) > 0 {
return errors.CompositeValidationError(result...)
}
return nil
} | go | {
"resource": ""
} |
q10314 | NotImplemented | train | func NotImplemented(message string) Responder {
return &errorResp{http.StatusNotImplemented, message, make(http.Header)}
} | go | {
"resource": ""
} |
q10315 | WriteToRequest | train | func (fn ClientRequestWriterFunc) WriteToRequest(req ClientRequest, reg strfmt.Registry) error {
return fn(req, reg)
} | go | {
"resource": ""
} |
q10316 | NamedReader | train | func NamedReader(name string, rdr io.Reader) NamedReadCloser {
rc, ok := rdr.(io.ReadCloser)
if !ok {
rc = ioutil.NopCloser(rdr)
}
return &namedReadCloser{
name: name,
cr: rc,
}
} | go | {
"resource": ""
} |
q10317 | WriteResponse | train | func (fn ResponderFunc) WriteResponse(rw http.ResponseWriter, pr runtime.Producer) {
fn(rw, pr)
} | go | {
"resource": ""
} |
q10318 | NewRoutableContext | train | func NewRoutableContext(spec *loads.Document, routableAPI RoutableAPI, routes Router) *Context {
var an *analysis.Spec
if spec != nil {
an = analysis.New(spec.Spec())
}
ctx := &Context{spec: spec, api: routableAPI, analyzer: an, router: routes}
return ctx
} | go | {
"resource": ""
} |
q10319 | NewContext | train | func NewContext(spec *loads.Document, api *untyped.API, routes Router) *Context {
var an *analysis.Spec
if spec != nil {
an = analysis.New(spec.Spec())
}
ctx := &Context{spec: spec, analyzer: an}
ctx.api = newRoutableUntypedAPI(spec, api, ctx)
ctx.router = routes
return ctx
} | go | {
"resource": ""
} |
q10320 | Serve | train | func Serve(spec *loads.Document, api *untyped.API) http.Handler {
return ServeWithBuilder(spec, api, PassthroughBuilder)
} | go | {
"resource": ""
} |
q10321 | ServeWithBuilder | train | func ServeWithBuilder(spec *loads.Document, api *untyped.API, builder Builder) http.Handler {
context := NewContext(spec, api, nil)
return context.APIHandler(builder)
} | go | {
"resource": ""
} |
q10322 | MatchedRouteFrom | train | func MatchedRouteFrom(req *http.Request) *MatchedRoute {
mr := req.Context().Value(ctxMatchedRoute)
if mr == nil {
return nil
}
if res, ok := mr.(*MatchedRoute); ok {
return res
}
return nil
} | go | {
"resource": ""
} |
q10323 | SecurityScopesFrom | train | func SecurityScopesFrom(req *http.Request) []string {
rs := req.Context().Value(ctxSecurityScopes)
if res, ok := rs.([]string); ok {
return res
}
return nil
} | go | {
"resource": ""
} |
q10324 | BindValidRequest | train | func (c *Context) BindValidRequest(request *http.Request, route *MatchedRoute, binder RequestBinder) error {
var res []error
requestContentType := "*/*"
// check and validate content type, select consumer
if runtime.HasBody(request) {
ct, _, err := runtime.ContentType(request.Header)
if err != nil {
res = append(res, err)
} else {
if err := validateContentType(route.Consumes, ct); err != nil {
res = append(res, err)
}
if len(res) == 0 {
cons, ok := route.Consumers[ct]
if !ok {
res = append(res, errors.New(500, "no consumer registered for %s", ct))
} else {
route.Consumer = cons
requestContentType = ct
}
}
}
}
// check and validate the response format
if len(res) == 0 && runtime.HasBody(request) {
if str := NegotiateContentType(request, route.Produces, requestContentType); str == "" {
res = append(res, errors.InvalidResponseFormat(request.Header.Get(runtime.HeaderAccept), route.Produces))
}
}
// now bind the request with the provided binder
// it's assumed the binder will also validate the request and return an error if the
// request is invalid
if binder != nil && len(res) == 0 {
if err := binder.BindRequest(request, route); err != nil {
return err
}
}
if len(res) > 0 {
return errors.CompositeValidationError(res...)
}
return nil
} | go | {
"resource": ""
} |
q10325 | ContentType | train | func (c *Context) ContentType(request *http.Request) (string, string, *http.Request, error) {
var rCtx = request.Context()
if v, ok := rCtx.Value(ctxContentType).(*contentTypeValue); ok {
return v.MediaType, v.Charset, request, nil
}
mt, cs, err := runtime.ContentType(request.Header)
if err != nil {
return "", "", nil, err
}
rCtx = stdContext.WithValue(rCtx, ctxContentType, &contentTypeValue{mt, cs})
return mt, cs, request.WithContext(rCtx), nil
} | go | {
"resource": ""
} |
q10326 | LookupRoute | train | func (c *Context) LookupRoute(request *http.Request) (*MatchedRoute, bool) {
if route, ok := c.router.Lookup(request.Method, request.URL.EscapedPath()); ok {
return route, ok
}
return nil, false
} | go | {
"resource": ""
} |
q10327 | RouteInfo | train | func (c *Context) RouteInfo(request *http.Request) (*MatchedRoute, *http.Request, bool) {
var rCtx = request.Context()
if v, ok := rCtx.Value(ctxMatchedRoute).(*MatchedRoute); ok {
return v, request, ok
}
if route, ok := c.LookupRoute(request); ok {
rCtx = stdContext.WithValue(rCtx, ctxMatchedRoute, route)
return route, request.WithContext(rCtx), ok
}
return nil, nil, false
} | go | {
"resource": ""
} |
q10328 | ResponseFormat | train | func (c *Context) ResponseFormat(r *http.Request, offers []string) (string, *http.Request) {
var rCtx = r.Context()
if v, ok := rCtx.Value(ctxResponseFormat).(string); ok {
debugLog("[%s %s] found response format %q in context", r.Method, r.URL.Path, v)
return v, r
}
format := NegotiateContentType(r, offers, "")
if format != "" {
debugLog("[%s %s] set response format %q in context", r.Method, r.URL.Path, format)
r = r.WithContext(stdContext.WithValue(rCtx, ctxResponseFormat, format))
}
debugLog("[%s %s] negotiated response format %q", r.Method, r.URL.Path, format)
return format, r
} | go | {
"resource": ""
} |
q10329 | AllowedMethods | train | func (c *Context) AllowedMethods(request *http.Request) []string {
return c.router.OtherMethods(request.Method, request.URL.EscapedPath())
} | go | {
"resource": ""
} |
q10330 | ResetAuth | train | func (c *Context) ResetAuth(request *http.Request) *http.Request {
rctx := request.Context()
rctx = stdContext.WithValue(rctx, ctxSecurityPrincipal, nil)
rctx = stdContext.WithValue(rctx, ctxSecurityScopes, nil)
return request.WithContext(rctx)
} | go | {
"resource": ""
} |
q10331 | BindAndValidate | train | func (c *Context) BindAndValidate(request *http.Request, matched *MatchedRoute) (interface{}, *http.Request, error) {
var rCtx = request.Context()
if v, ok := rCtx.Value(ctxBoundParams).(*validation); ok {
debugLog("got cached validation (valid: %t)", len(v.result) == 0)
if len(v.result) > 0 {
return v.bound, request, errors.CompositeValidationError(v.result...)
}
return v.bound, request, nil
}
result := validateRequest(c, request, matched)
rCtx = stdContext.WithValue(rCtx, ctxBoundParams, result)
request = request.WithContext(rCtx)
if len(result.result) > 0 {
return result.bound, request, errors.CompositeValidationError(result.result...)
}
debugLog("no validation errors found")
return result.bound, request, nil
} | go | {
"resource": ""
} |
q10332 | NotFound | train | func (c *Context) NotFound(rw http.ResponseWriter, r *http.Request) {
c.Respond(rw, r, []string{c.api.DefaultProduces()}, nil, errors.NotFound("not found"))
} | go | {
"resource": ""
} |
q10333 | APIHandler | train | func (c *Context) APIHandler(builder Builder) http.Handler {
b := builder
if b == nil {
b = PassthroughBuilder
}
var title string
sp := c.spec.Spec()
if sp != nil && sp.Info != nil && sp.Info.Title != "" {
title = sp.Info.Title
}
redocOpts := RedocOpts{
BasePath: c.BasePath(),
Title: title,
}
return Spec("", c.spec.Raw(), Redoc(redocOpts, c.RoutesHandler(b)))
} | go | {
"resource": ""
} |
q10334 | RoutesHandler | train | func (c *Context) RoutesHandler(builder Builder) http.Handler {
b := builder
if b == nil {
b = PassthroughBuilder
}
return NewRouter(c, b(NewOperationExecutor(c)))
} | go | {
"resource": ""
} |
q10335 | TextConsumer | train | func TextConsumer() Consumer {
return ConsumerFunc(func(reader io.Reader, data interface{}) error {
if reader == nil {
return errors.New("TextConsumer requires a reader") // early exit
}
buf := new(bytes.Buffer)
_, err := buf.ReadFrom(reader)
if err != nil {
return err
}
b := buf.Bytes()
// If the buffer is empty, no need to unmarshal it, which causes a panic.
if len(b) == 0 {
data = ""
return nil
}
if tu, ok := data.(encoding.TextUnmarshaler); ok {
err := tu.UnmarshalText(b)
if err != nil {
return fmt.Errorf("text consumer: %v", err)
}
return nil
}
t := reflect.TypeOf(data)
if data != nil && t.Kind() == reflect.Ptr {
v := reflect.Indirect(reflect.ValueOf(data))
if t.Elem().Kind() == reflect.String {
v.SetString(string(b))
return nil
}
}
return fmt.Errorf("%v (%T) is not supported by the TextConsumer, %s",
data, data, "can be resolved by supporting TextUnmarshaler interface")
})
} | go | {
"resource": ""
} |
q10336 | TextProducer | train | func TextProducer() Producer {
return ProducerFunc(func(writer io.Writer, data interface{}) error {
if writer == nil {
return errors.New("TextProducer requires a writer") // early exit
}
if data == nil {
return errors.New("no data given to produce text from")
}
if tm, ok := data.(encoding.TextMarshaler); ok {
txt, err := tm.MarshalText()
if err != nil {
return fmt.Errorf("text producer: %v", err)
}
_, err = writer.Write(txt)
return err
}
if str, ok := data.(error); ok {
_, err := writer.Write([]byte(str.Error()))
return err
}
if str, ok := data.(fmt.Stringer); ok {
_, err := writer.Write([]byte(str.String()))
return err
}
v := reflect.Indirect(reflect.ValueOf(data))
if t := v.Type(); t.Kind() == reflect.Struct || t.Kind() == reflect.Slice {
b, err := swag.WriteJSON(data)
if err != nil {
return err
}
_, err = writer.Write(b)
return err
}
if v.Kind() != reflect.String {
return fmt.Errorf("%T is not a supported type by the TextProducer", data)
}
_, err := writer.Write([]byte(v.String()))
return err
})
} | go | {
"resource": ""
} |
q10337 | CSVConsumer | train | func CSVConsumer() Consumer {
return ConsumerFunc(func(reader io.Reader, data interface{}) error {
if reader == nil {
return errors.New("CSVConsumer requires a reader")
}
csvReader := csv.NewReader(reader)
writer, ok := data.(io.Writer)
if !ok {
return errors.New("data type must be io.Writer")
}
csvWriter := csv.NewWriter(writer)
records, err := csvReader.ReadAll()
if err != nil {
return err
}
for _, r := range records {
if err := csvWriter.Write(r); err != nil {
return err
}
}
csvWriter.Flush()
return nil
})
} | go | {
"resource": ""
} |
q10338 | CSVProducer | train | func CSVProducer() Producer {
return ProducerFunc(func(writer io.Writer, data interface{}) error {
if writer == nil {
return errors.New("CSVProducer requires a writer")
}
dataBytes, ok := data.([]byte)
if !ok {
return errors.New("data type must be byte array")
}
csvReader := csv.NewReader(bytes.NewBuffer(dataBytes))
records, err := csvReader.ReadAll()
if err != nil {
return err
}
csvWriter := csv.NewWriter(writer)
for _, r := range records {
if err := csvWriter.Write(r); err != nil {
return err
}
}
csvWriter.Flush()
return nil
})
} | go | {
"resource": ""
} |
q10339 | JSON | train | func (m Map) JSON() (string, error) {
for k, v := range m {
m[k] = cleanUp(v)
}
result, err := json.Marshal(m)
if err != nil {
err = errors.New("objx: JSON encode failed with: " + err.Error())
}
return string(result), err
} | go | {
"resource": ""
} |
q10340 | MustJSON | train | func (m Map) MustJSON() string {
result, err := m.JSON()
if err != nil {
panic(err.Error())
}
return result
} | go | {
"resource": ""
} |
q10341 | Base64 | train | func (m Map) Base64() (string, error) {
var buf bytes.Buffer
jsonData, err := m.JSON()
if err != nil {
return "", err
}
encoder := base64.NewEncoder(base64.StdEncoding, &buf)
_, _ = encoder.Write([]byte(jsonData))
_ = encoder.Close()
return buf.String(), nil
} | go | {
"resource": ""
} |
q10342 | MustBase64 | train | func (m Map) MustBase64() string {
result, err := m.Base64()
if err != nil {
panic(err.Error())
}
return result
} | go | {
"resource": ""
} |
q10343 | SignedBase64 | train | func (m Map) SignedBase64(key string) (string, error) {
base64, err := m.Base64()
if err != nil {
return "", err
}
sig := HashWithKey(base64, key)
return base64 + SignatureSeparator + sig, nil
} | go | {
"resource": ""
} |
q10344 | MustSignedBase64 | train | func (m Map) MustSignedBase64(key string) string {
result, err := m.SignedBase64(key)
if err != nil {
panic(err.Error())
}
return result
} | go | {
"resource": ""
} |
q10345 | getKey | train | func getKey(s string) (string, string) {
selSegs := strings.SplitN(s, PathSeparator, 2)
thisSel := selSegs[0]
nextSel := ""
if len(selSegs) > 1 {
nextSel = selSegs[1]
}
mapMatches := mapAccessRegex.FindStringSubmatch(s)
if len(mapMatches) > 0 {
if _, err := strconv.Atoi(mapMatches[2]); err != nil {
thisSel = mapMatches[1]
nextSel = "[" + mapMatches[2] + "]" + mapMatches[3]
if thisSel == "" {
thisSel = mapMatches[2]
nextSel = mapMatches[3]
}
if nextSel == "" {
selSegs = []string{"", ""}
} else if nextSel[0] == '.' {
nextSel = nextSel[1:]
}
}
}
return thisSel, nextSel
} | go | {
"resource": ""
} |
q10346 | access | train | func access(current interface{}, selector string, value interface{}, isSet bool) interface{} {
thisSel, nextSel := getKey(selector)
index := -1
if strings.Contains(thisSel, "[") {
index, thisSel = getIndex(thisSel)
}
if curMap, ok := current.(Map); ok {
current = map[string]interface{}(curMap)
}
// get the object in question
switch current.(type) {
case map[string]interface{}:
curMSI := current.(map[string]interface{})
if nextSel == "" && isSet {
curMSI[thisSel] = value
return nil
}
_, ok := curMSI[thisSel].(map[string]interface{})
if (curMSI[thisSel] == nil || !ok) && index == -1 && isSet {
curMSI[thisSel] = map[string]interface{}{}
}
current = curMSI[thisSel]
default:
current = nil
}
// do we need to access the item of an array?
if index > -1 {
if array, ok := interSlice(current); ok {
if index < len(array) {
current = array[index]
} else {
current = nil
}
}
}
if nextSel != "" {
current = access(current, nextSel, value, isSet)
}
return current
} | go | {
"resource": ""
} |
q10347 | Dema | train | func Dema(inReal []float64, inTimePeriod int) []float64 {
outReal := make([]float64, len(inReal))
firstEMA := Ema(inReal, inTimePeriod)
secondEMA := Ema(firstEMA[inTimePeriod-1:], inTimePeriod)
for outIdx, secondEMAIdx := (inTimePeriod*2)-2, inTimePeriod-1; outIdx < len(inReal); outIdx, secondEMAIdx = outIdx+1, secondEMAIdx+1 {
outReal[outIdx] = (2.0 * firstEMA[outIdx]) - secondEMA[secondEMAIdx]
}
return outReal
} | go | {
"resource": ""
} |
q10348 | Ma | train | func Ma(inReal []float64, inTimePeriod int, inMAType MaType) []float64 {
outReal := make([]float64, len(inReal))
if inTimePeriod == 1 {
copy(outReal, inReal)
return outReal
}
switch inMAType {
case SMA:
outReal = Sma(inReal, inTimePeriod)
case EMA:
outReal = Ema(inReal, inTimePeriod)
case WMA:
outReal = Wma(inReal, inTimePeriod)
case DEMA:
outReal = Dema(inReal, inTimePeriod)
case TEMA:
outReal = Tema(inReal, inTimePeriod)
case TRIMA:
outReal = Trima(inReal, inTimePeriod)
case KAMA:
outReal = Kama(inReal, inTimePeriod)
case MAMA:
outReal, _ = Mama(inReal, 0.5, 0.05)
case T3MA:
outReal = T3(inReal, inTimePeriod, 0.7)
}
return outReal
} | go | {
"resource": ""
} |
q10349 | MaVp | train | func MaVp(inReal []float64, inPeriods []float64, inMinPeriod int, inMaxPeriod int, inMAType MaType) []float64 {
outReal := make([]float64, len(inReal))
startIdx := inMaxPeriod - 1
outputSize := len(inReal)
localPeriodArray := make([]float64, outputSize)
for i := startIdx; i < outputSize; i++ {
tempInt := int(inPeriods[i])
if tempInt < inMinPeriod {
tempInt = inMinPeriod
} else if tempInt > inMaxPeriod {
tempInt = inMaxPeriod
}
localPeriodArray[i] = float64(tempInt)
}
for i := startIdx; i < outputSize; i++ {
curPeriod := int(localPeriodArray[i])
if curPeriod != 0 {
localOutputArray := Ma(inReal, curPeriod, inMAType)
outReal[i] = localOutputArray[i]
for j := i + 1; j < outputSize; j++ {
if localPeriodArray[j] == float64(curPeriod) {
localPeriodArray[j] = 0
outReal[j] = localOutputArray[j]
}
}
}
}
return outReal
} | go | {
"resource": ""
} |
q10350 | MidPoint | train | func MidPoint(inReal []float64, inTimePeriod int) []float64 {
outReal := make([]float64, len(inReal))
nbInitialElementNeeded := inTimePeriod - 1
startIdx := nbInitialElementNeeded
outIdx := inTimePeriod - 1
today := startIdx
trailingIdx := startIdx - nbInitialElementNeeded
for today < len(inReal) {
lowest := inReal[trailingIdx]
trailingIdx++
highest := lowest
for i := trailingIdx; i <= today; i++ {
tmp := inReal[i]
if tmp < lowest {
lowest = tmp
} else if tmp > highest {
highest = tmp
}
}
outReal[outIdx] = (highest + lowest) / 2.0
outIdx++
today++
}
return outReal
} | go | {
"resource": ""
} |
q10351 | MidPrice | train | func MidPrice(inHigh []float64, inLow []float64, inTimePeriod int) []float64 {
outReal := make([]float64, len(inHigh))
nbInitialElementNeeded := inTimePeriod - 1
startIdx := nbInitialElementNeeded
outIdx := inTimePeriod - 1
today := startIdx
trailingIdx := startIdx - nbInitialElementNeeded
for today < len(inHigh) {
lowest := inLow[trailingIdx]
highest := inHigh[trailingIdx]
trailingIdx++
for i := trailingIdx; i <= today; i++ {
tmp := inLow[i]
if tmp < lowest {
lowest = tmp
}
tmp = inHigh[i]
if tmp > highest {
highest = tmp
}
}
outReal[outIdx] = (highest + lowest) / 2.0
outIdx++
today++
}
return outReal
} | go | {
"resource": ""
} |
q10352 | Sma | train | func Sma(inReal []float64, inTimePeriod int) []float64 {
outReal := make([]float64, len(inReal))
lookbackTotal := inTimePeriod - 1
startIdx := lookbackTotal
periodTotal := 0.0
trailingIdx := startIdx - lookbackTotal
i := trailingIdx
if inTimePeriod > 1 {
for i < startIdx {
periodTotal += inReal[i]
i++
}
}
outIdx := startIdx
for ok := true; ok; {
periodTotal += inReal[i]
tempReal := periodTotal
periodTotal -= inReal[trailingIdx]
outReal[outIdx] = tempReal / float64(inTimePeriod)
trailingIdx++
i++
outIdx++
ok = i < len(outReal)
}
return outReal
} | go | {
"resource": ""
} |
q10353 | Tema | train | func Tema(inReal []float64, inTimePeriod int) []float64 {
outReal := make([]float64, len(inReal))
firstEMA := Ema(inReal, inTimePeriod)
secondEMA := Ema(firstEMA[inTimePeriod-1:], inTimePeriod)
thirdEMA := Ema(secondEMA[inTimePeriod-1:], inTimePeriod)
outIdx := (inTimePeriod * 3) - 3
secondEMAIdx := (inTimePeriod * 2) - 2
thirdEMAIdx := inTimePeriod - 1
for outIdx < len(inReal) {
outReal[outIdx] = thirdEMA[thirdEMAIdx] + ((3.0 * firstEMA[outIdx]) - (3.0 * secondEMA[secondEMAIdx]))
outIdx++
secondEMAIdx++
thirdEMAIdx++
}
return outReal
} | go | {
"resource": ""
} |
q10354 | Wma | train | func Wma(inReal []float64, inTimePeriod int) []float64 {
outReal := make([]float64, len(inReal))
lookbackTotal := inTimePeriod - 1
startIdx := lookbackTotal
if inTimePeriod == 1 {
copy(outReal, inReal)
return outReal
}
divider := (inTimePeriod * (inTimePeriod + 1)) >> 1
outIdx := inTimePeriod - 1
trailingIdx := startIdx - lookbackTotal
periodSum, periodSub := 0.0, 0.0
inIdx := trailingIdx
i := 1
for inIdx < startIdx {
tempReal := inReal[inIdx]
periodSub += tempReal
periodSum += tempReal * float64(i)
inIdx++
i++
}
trailingValue := 0.0
for inIdx < len(inReal) {
tempReal := inReal[inIdx]
periodSub += tempReal
periodSub -= trailingValue
periodSum += tempReal * float64(inTimePeriod)
trailingValue = inReal[trailingIdx]
outReal[outIdx] = periodSum / float64(divider)
periodSum -= periodSub
inIdx++
trailingIdx++
outIdx++
}
return outReal
} | go | {
"resource": ""
} |
q10355 | AdxR | train | func AdxR(inHigh []float64, inLow []float64, inClose []float64, inTimePeriod int) []float64 {
outReal := make([]float64, len(inClose))
startIdx := (2 * inTimePeriod) - 1
tmpadx := Adx(inHigh, inLow, inClose, inTimePeriod)
i := startIdx
j := startIdx + inTimePeriod - 1
for outIdx := startIdx + inTimePeriod - 1; outIdx < len(inClose); outIdx, i, j = outIdx+1, i+1, j+1 {
outReal[outIdx] = ((tmpadx[i] + tmpadx[j]) / 2.0)
}
return outReal
} | go | {
"resource": ""
} |
q10356 | AroonOsc | train | func AroonOsc(inHigh []float64, inLow []float64, inTimePeriod int) []float64 {
outReal := make([]float64, len(inHigh))
startIdx := inTimePeriod
outIdx := startIdx
today := startIdx
trailingIdx := startIdx - inTimePeriod
lowestIdx := -1
highestIdx := -1
lowest := 0.0
highest := 0.0
factor := 100.0 / float64(inTimePeriod)
for today < len(inHigh) {
tmp := inLow[today]
if lowestIdx < trailingIdx {
lowestIdx = trailingIdx
lowest = inLow[lowestIdx]
i := lowestIdx
i++
for i <= today {
tmp = inLow[i]
if tmp <= lowest {
lowestIdx = i
lowest = tmp
}
i++
}
} else if tmp <= lowest {
lowestIdx = today
lowest = tmp
}
tmp = inHigh[today]
if highestIdx < trailingIdx {
highestIdx = trailingIdx
highest = inHigh[highestIdx]
i := highestIdx
i++
for i <= today {
tmp = inHigh[i]
if tmp >= highest {
highestIdx = i
highest = tmp
}
i++
}
} else if tmp >= highest {
highestIdx = today
highest = tmp
}
aroon := factor * float64(highestIdx-lowestIdx)
outReal[outIdx] = aroon
outIdx++
trailingIdx++
today++
}
return outReal
} | go | {
"resource": ""
} |
q10357 | Bop | train | func Bop(inOpen []float64, inHigh []float64, inLow []float64, inClose []float64) []float64 {
outReal := make([]float64, len(inClose))
for i := 0; i < len(inClose); i++ {
tempReal := inHigh[i] - inLow[i]
if tempReal < (0.00000000000001) {
outReal[i] = 0.0
} else {
outReal[i] = (inClose[i] - inOpen[i]) / tempReal
}
}
return outReal
} | go | {
"resource": ""
} |
q10358 | Cmo | train | func Cmo(inReal []float64, inTimePeriod int) []float64 {
outReal := make([]float64, len(inReal))
lookbackTotal := inTimePeriod
startIdx := lookbackTotal
outIdx := startIdx
if inTimePeriod == 1 {
copy(outReal, inReal)
return outReal
}
today := startIdx - lookbackTotal
prevValue := inReal[today]
prevGain := 0.0
prevLoss := 0.0
today++
for i := inTimePeriod; i > 0; i-- {
tempValue1 := inReal[today]
tempValue2 := tempValue1 - prevValue
prevValue = tempValue1
if tempValue2 < 0 {
prevLoss -= tempValue2
} else {
prevGain += tempValue2
}
today++
}
prevLoss /= float64(inTimePeriod)
prevGain /= float64(inTimePeriod)
if today > startIdx {
tempValue1 := prevGain + prevLoss
if !(((-(0.00000000000001)) < tempValue1) && (tempValue1 < (0.00000000000001))) {
outReal[outIdx] = 100.0 * ((prevGain - prevLoss) / tempValue1)
} else {
outReal[outIdx] = 0.0
}
outIdx++
} else {
for today < startIdx {
tempValue1 := inReal[today]
tempValue2 := tempValue1 - prevValue
prevValue = tempValue1
prevLoss *= float64(inTimePeriod - 1)
prevGain *= float64(inTimePeriod - 1)
if tempValue2 < 0 {
prevLoss -= tempValue2
} else {
prevGain += tempValue2
}
prevLoss /= float64(inTimePeriod)
prevGain /= float64(inTimePeriod)
today++
}
}
for today < len(inReal) {
tempValue1 := inReal[today]
today++
tempValue2 := tempValue1 - prevValue
prevValue = tempValue1
prevLoss *= float64(inTimePeriod - 1)
prevGain *= float64(inTimePeriod - 1)
if tempValue2 < 0 {
prevLoss -= tempValue2
} else {
prevGain += tempValue2
}
prevLoss /= float64(inTimePeriod)
prevGain /= float64(inTimePeriod)
tempValue1 = prevGain + prevLoss
if !(((-(0.00000000000001)) < tempValue1) && (tempValue1 < (0.00000000000001))) {
outReal[outIdx] = 100.0 * ((prevGain - prevLoss) / tempValue1)
} else {
outReal[outIdx] = 0.0
}
outIdx++
}
return outReal
} | go | {
"resource": ""
} |
q10359 | Cci | train | func Cci(inHigh []float64, inLow []float64, inClose []float64, inTimePeriod int) []float64 {
outReal := make([]float64, len(inClose))
circBufferIdx := 0
lookbackTotal := inTimePeriod - 1
startIdx := lookbackTotal
circBuffer := make([]float64, inTimePeriod)
maxIdxCircBuffer := (inTimePeriod - 1)
i := startIdx - lookbackTotal
if inTimePeriod > 1 {
for i < startIdx {
circBuffer[circBufferIdx] = (inHigh[i] + inLow[i] + inClose[i]) / 3
i++
circBufferIdx++
if circBufferIdx > maxIdxCircBuffer {
circBufferIdx = 0
}
}
}
outIdx := inTimePeriod - 1
for i < len(inClose) {
lastValue := (inHigh[i] + inLow[i] + inClose[i]) / 3
circBuffer[circBufferIdx] = lastValue
theAverage := 0.0
for j := 0; j < inTimePeriod; j++ {
theAverage += circBuffer[j]
}
theAverage /= float64(inTimePeriod)
tempReal2 := 0.0
for j := 0; j < inTimePeriod; j++ {
tempReal2 += math.Abs(circBuffer[j] - theAverage)
}
tempReal := lastValue - theAverage
if (tempReal != 0.0) && (tempReal2 != 0.0) {
outReal[outIdx] = tempReal / (0.015 * (tempReal2 / float64(inTimePeriod)))
} else {
outReal[outIdx] = 0.0
}
{
circBufferIdx++
if circBufferIdx > maxIdxCircBuffer {
circBufferIdx = 0
}
}
outIdx++
i++
}
return outReal
} | go | {
"resource": ""
} |
q10360 | MacdExt | train | func MacdExt(inReal []float64, inFastPeriod int, inFastMAType MaType, inSlowPeriod int, inSlowMAType MaType, inSignalPeriod int, inSignalMAType MaType) ([]float64, []float64, []float64) {
lookbackLargest := 0
if inFastPeriod < inSlowPeriod {
lookbackLargest = inSlowPeriod
} else {
lookbackLargest = inFastPeriod
}
lookbackTotal := (inSignalPeriod - 1) + (lookbackLargest - 1)
outMACD := make([]float64, len(inReal))
outMACDSignal := make([]float64, len(inReal))
outMACDHist := make([]float64, len(inReal))
slowMABuffer := Ma(inReal, inSlowPeriod, inSlowMAType)
fastMABuffer := Ma(inReal, inFastPeriod, inFastMAType)
tempBuffer1 := make([]float64, len(inReal))
for i := 0; i < len(slowMABuffer); i++ {
tempBuffer1[i] = fastMABuffer[i] - slowMABuffer[i]
}
tempBuffer2 := Ma(tempBuffer1, inSignalPeriod, inSignalMAType)
for i := lookbackTotal; i < len(outMACDHist); i++ {
outMACD[i] = tempBuffer1[i]
outMACDSignal[i] = tempBuffer2[i]
outMACDHist[i] = outMACD[i] - outMACDSignal[i]
}
return outMACD, outMACDSignal, outMACDHist
} | go | {
"resource": ""
} |
q10361 | MinusDM | train | func MinusDM(inHigh []float64, inLow []float64, inTimePeriod int) []float64 {
outReal := make([]float64, len(inHigh))
lookbackTotal := 1
if inTimePeriod > 1 {
lookbackTotal = inTimePeriod - 1
}
startIdx := lookbackTotal
outIdx := startIdx
today := startIdx
prevHigh := 0.0
prevLow := 0.0
if inTimePeriod <= 1 {
today = startIdx - 1
prevHigh = inHigh[today]
prevLow = inLow[today]
for today < len(inHigh)-1 {
today++
tempReal := inHigh[today]
diffP := tempReal - prevHigh
prevHigh = tempReal
tempReal = inLow[today]
diffM := prevLow - tempReal
prevLow = tempReal
if (diffM > 0) && (diffP < diffM) {
outReal[outIdx] = diffM
} else {
outReal[outIdx] = 0
}
outIdx++
}
return outReal
}
prevMinusDM := 0.0
today = startIdx - lookbackTotal
prevHigh = inHigh[today]
prevLow = inLow[today]
i := inTimePeriod - 1
for i > 0 {
i--
today++
tempReal := inHigh[today]
diffP := tempReal - prevHigh
prevHigh = tempReal
tempReal = inLow[today]
diffM := prevLow - tempReal
prevLow = tempReal
if (diffM > 0) && (diffP < diffM) {
prevMinusDM += diffM
}
}
i = 0
for i != 0 {
i--
today++
tempReal := inHigh[today]
diffP := tempReal - prevHigh
prevHigh = tempReal
tempReal = inLow[today]
diffM := prevLow - tempReal
prevLow = tempReal
if (diffM > 0) && (diffP < diffM) {
prevMinusDM = prevMinusDM - (prevMinusDM / float64(inTimePeriod)) + diffM
} else {
prevMinusDM = prevMinusDM - (prevMinusDM / float64(inTimePeriod))
}
}
outReal[startIdx] = prevMinusDM
outIdx = startIdx + 1
for today < len(inHigh)-1 {
today++
tempReal := inHigh[today]
diffP := tempReal - prevHigh
prevHigh = tempReal
tempReal = inLow[today]
diffM := prevLow - tempReal
prevLow = tempReal
if (diffM > 0) && (diffP < diffM) {
prevMinusDM = prevMinusDM - (prevMinusDM / float64(inTimePeriod)) + diffM
} else {
prevMinusDM = prevMinusDM - (prevMinusDM / float64(inTimePeriod))
}
outReal[outIdx] = prevMinusDM
outIdx++
}
return outReal
} | go | {
"resource": ""
} |
q10362 | Mom | train | func Mom(inReal []float64, inTimePeriod int) []float64 {
outReal := make([]float64, len(inReal))
inIdx, outIdx, trailingIdx := inTimePeriod, inTimePeriod, 0
for inIdx < len(inReal) {
outReal[outIdx] = inReal[inIdx] - inReal[trailingIdx]
inIdx, outIdx, trailingIdx = inIdx+1, outIdx+1, trailingIdx+1
}
return outReal
} | go | {
"resource": ""
} |
q10363 | Ppo | train | func Ppo(inReal []float64, inFastPeriod int, inSlowPeriod int, inMAType MaType) []float64 {
if inSlowPeriod < inFastPeriod {
inSlowPeriod, inFastPeriod = inFastPeriod, inSlowPeriod
}
tempBuffer := Ma(inReal, inFastPeriod, inMAType)
outReal := Ma(inReal, inSlowPeriod, inMAType)
for i := inSlowPeriod - 1; i < len(inReal); i++ {
tempReal := outReal[i]
if !(((-(0.00000000000001)) < tempReal) && (tempReal < (0.00000000000001))) {
outReal[i] = ((tempBuffer[i] - tempReal) / tempReal) * 100.0
} else {
outReal[i] = 0.0
}
}
return outReal
} | go | {
"resource": ""
} |
q10364 | Rsi | train | func Rsi(inReal []float64, inTimePeriod int) []float64 {
outReal := make([]float64, len(inReal))
if inTimePeriod < 2 {
return outReal
}
// variable declarations
tempValue1 := 0.0
tempValue2 := 0.0
outIdx := inTimePeriod
today := 0
prevValue := inReal[today]
prevGain := 0.0
prevLoss := 0.0
today++
for i := inTimePeriod; i > 0; i-- {
tempValue1 = inReal[today]
today++
tempValue2 = tempValue1 - prevValue
prevValue = tempValue1
if tempValue2 < 0 {
prevLoss -= tempValue2
} else {
prevGain += tempValue2
}
}
prevLoss /= float64(inTimePeriod)
prevGain /= float64(inTimePeriod)
if today > 0 {
tempValue1 = prevGain + prevLoss
if !((-0.00000000000001 < tempValue1) && (tempValue1 < 0.00000000000001)) {
outReal[outIdx] = 100.0 * (prevGain / tempValue1)
} else {
outReal[outIdx] = 0.0
}
outIdx++
} else {
for today < 0 {
tempValue1 = inReal[today]
tempValue2 = tempValue1 - prevValue
prevValue = tempValue1
prevLoss *= float64(inTimePeriod - 1)
prevGain *= float64(inTimePeriod - 1)
if tempValue2 < 0 {
prevLoss -= tempValue2
} else {
prevGain += tempValue2
}
prevLoss /= float64(inTimePeriod)
prevGain /= float64(inTimePeriod)
today++
}
}
for today < len(inReal) {
tempValue1 = inReal[today]
today++
tempValue2 = tempValue1 - prevValue
prevValue = tempValue1
prevLoss *= float64(inTimePeriod - 1)
prevGain *= float64(inTimePeriod - 1)
if tempValue2 < 0 {
prevLoss -= tempValue2
} else {
prevGain += tempValue2
}
prevLoss /= float64(inTimePeriod)
prevGain /= float64(inTimePeriod)
tempValue1 = prevGain + prevLoss
if !((-0.00000000000001 < tempValue1) && (tempValue1 < 0.00000000000001)) {
outReal[outIdx] = 100.0 * (prevGain / tempValue1)
} else {
outReal[outIdx] = 0.0
}
outIdx++
}
return outReal
} | go | {
"resource": ""
} |
q10365 | Stoch | train | func Stoch(inHigh []float64, inLow []float64, inClose []float64, inFastKPeriod int, inSlowKPeriod int, inSlowKMAType MaType, inSlowDPeriod int, inSlowDMAType MaType) ([]float64, []float64) {
outSlowK := make([]float64, len(inClose))
outSlowD := make([]float64, len(inClose))
lookbackK := inFastKPeriod - 1
lookbackKSlow := inSlowKPeriod - 1
lookbackDSlow := inSlowDPeriod - 1
lookbackTotal := lookbackK + lookbackDSlow + lookbackKSlow
startIdx := lookbackTotal
outIdx := 0
trailingIdx := startIdx - lookbackTotal
today := trailingIdx + lookbackK
lowestIdx, highestIdx := -1, -1
diff, highest, lowest := 0.0, 0.0, 0.0
tempBuffer := make([]float64, len(inClose)-today+1)
for today < len(inClose) {
tmp := inLow[today]
if lowestIdx < trailingIdx {
lowestIdx = trailingIdx
lowest = inLow[lowestIdx]
i := lowestIdx + 1
for i <= today {
tmp := inLow[i]
if tmp < lowest {
lowestIdx = i
lowest = tmp
}
i++
}
diff = (highest - lowest) / 100.0
} else if tmp <= lowest {
lowestIdx = today
lowest = tmp
diff = (highest - lowest) / 100.0
}
tmp = inHigh[today]
if highestIdx < trailingIdx {
highestIdx = trailingIdx
highest = inHigh[highestIdx]
i := highestIdx + 1
for i <= today {
tmp := inHigh[i]
if tmp > highest {
highestIdx = i
highest = tmp
}
i++
}
diff = (highest - lowest) / 100.0
} else if tmp >= highest {
highestIdx = today
highest = tmp
diff = (highest - lowest) / 100.0
}
if diff != 0.0 {
tempBuffer[outIdx] = (inClose[today] - lowest) / diff
} else {
tempBuffer[outIdx] = 0.0
}
outIdx++
trailingIdx++
today++
}
tempBuffer1 := Ma(tempBuffer, inSlowKPeriod, inSlowKMAType)
tempBuffer2 := Ma(tempBuffer1, inSlowDPeriod, inSlowDMAType)
//for i, j := lookbackK, lookbackTotal; j < len(inClose); i, j = i+1, j+1 {
for i, j := lookbackDSlow+lookbackKSlow, lookbackTotal; j < len(inClose); i, j = i+1, j+1 {
outSlowK[j] = tempBuffer1[i]
outSlowD[j] = tempBuffer2[i]
}
return outSlowK, outSlowD
} | go | {
"resource": ""
} |
q10366 | StochF | train | func StochF(inHigh []float64, inLow []float64, inClose []float64, inFastKPeriod int, inFastDPeriod int, inFastDMAType MaType) ([]float64, []float64) {
outFastK := make([]float64, len(inClose))
outFastD := make([]float64, len(inClose))
lookbackK := inFastKPeriod - 1
lookbackFastD := inFastDPeriod - 1
lookbackTotal := lookbackK + lookbackFastD
startIdx := lookbackTotal
outIdx := 0
trailingIdx := startIdx - lookbackTotal
today := trailingIdx + lookbackK
lowestIdx, highestIdx := -1, -1
diff, highest, lowest := 0.0, 0.0, 0.0
tempBuffer := make([]float64, (len(inClose) - today + 1))
for today < len(inClose) {
tmp := inLow[today]
if lowestIdx < trailingIdx {
lowestIdx = trailingIdx
lowest = inLow[lowestIdx]
i := lowestIdx
i++
for i <= today {
tmp = inLow[i]
if tmp < lowest {
lowestIdx = i
lowest = tmp
}
i++
}
diff = (highest - lowest) / 100.0
} else if tmp <= lowest {
lowestIdx = today
lowest = tmp
diff = (highest - lowest) / 100.0
}
tmp = inHigh[today]
if highestIdx < trailingIdx {
highestIdx = trailingIdx
highest = inHigh[highestIdx]
i := highestIdx
i++
for i <= today {
tmp = inHigh[i]
if tmp > highest {
highestIdx = i
highest = tmp
}
i++
}
diff = (highest - lowest) / 100.0
} else if tmp >= highest {
highestIdx = today
highest = tmp
diff = (highest - lowest) / 100.0
}
if diff != 0.0 {
tempBuffer[outIdx] = (inClose[today] - lowest) / diff
} else {
tempBuffer[outIdx] = 0.0
}
outIdx++
trailingIdx++
today++
}
tempBuffer1 := Ma(tempBuffer, inFastDPeriod, inFastDMAType)
for i, j := lookbackFastD, lookbackTotal; j < len(inClose); i, j = i+1, j+1 {
outFastK[j] = tempBuffer[i]
outFastD[j] = tempBuffer1[i]
}
return outFastK, outFastD
} | go | {
"resource": ""
} |
q10367 | StochRsi | train | func StochRsi(inReal []float64, inTimePeriod int, inFastKPeriod int, inFastDPeriod int, inFastDMAType MaType) ([]float64, []float64) {
outFastK := make([]float64, len(inReal))
outFastD := make([]float64, len(inReal))
lookbackSTOCHF := (inFastKPeriod - 1) + (inFastDPeriod - 1)
lookbackTotal := inTimePeriod + lookbackSTOCHF
startIdx := lookbackTotal
tempRSIBuffer := Rsi(inReal, inTimePeriod)
tempk, tempd := StochF(tempRSIBuffer, tempRSIBuffer, tempRSIBuffer, inFastKPeriod, inFastDPeriod, inFastDMAType)
for i := startIdx; i < len(inReal); i++ {
outFastK[i] = tempk[i]
outFastD[i] = tempd[i]
}
return outFastK, outFastD
} | go | {
"resource": ""
} |
q10368 | WillR | train | func WillR(inHigh []float64, inLow []float64, inClose []float64, inTimePeriod int) []float64 {
outReal := make([]float64, len(inClose))
nbInitialElementNeeded := (inTimePeriod - 1)
diff := 0.0
outIdx := inTimePeriod - 1
startIdx := inTimePeriod - 1
today := startIdx
trailingIdx := startIdx - nbInitialElementNeeded
highestIdx := -1
lowestIdx := -1
highest := 0.0
lowest := 0.0
i := 0
for today < len(inClose) {
tmp := inLow[today]
if lowestIdx < trailingIdx {
lowestIdx = trailingIdx
lowest = inLow[lowestIdx]
i = lowestIdx
i++
for i <= today {
tmp = inLow[i]
if tmp < lowest {
lowestIdx = i
lowest = tmp
}
i++
}
diff = (highest - lowest) / (-100.0)
} else if tmp <= lowest {
lowestIdx = today
lowest = tmp
diff = (highest - lowest) / (-100.0)
}
tmp = inHigh[today]
if highestIdx < trailingIdx {
highestIdx = trailingIdx
highest = inHigh[highestIdx]
i = highestIdx
i++
for i <= today {
tmp = inHigh[i]
if tmp > highest {
highestIdx = i
highest = tmp
}
i++
}
diff = (highest - lowest) / (-100.0)
} else if tmp >= highest {
highestIdx = today
highest = tmp
diff = (highest - lowest) / (-100.0)
}
if diff != 0.0 {
outReal[outIdx] = (highest - inClose[today]) / diff
} else {
outReal[outIdx] = 0.0
}
outIdx++
trailingIdx++
today++
}
return outReal
} | go | {
"resource": ""
} |
q10369 | Obv | train | func Obv(inReal []float64, inVolume []float64) []float64 {
outReal := make([]float64, len(inReal))
startIdx := 0
prevOBV := inVolume[startIdx]
prevReal := inReal[startIdx]
outIdx := 0
for i := startIdx; i < len(inReal); i++ {
tempReal := inReal[i]
if tempReal > prevReal {
prevOBV += inVolume[i]
} else if tempReal < prevReal {
prevOBV -= inVolume[i]
}
outReal[outIdx] = prevOBV
prevReal = tempReal
outIdx++
}
return outReal
} | go | {
"resource": ""
} |
q10370 | TRange | train | func TRange(inHigh []float64, inLow []float64, inClose []float64) []float64 {
outReal := make([]float64, len(inClose))
startIdx := 1
outIdx := startIdx
today := startIdx
for today < len(inClose) {
tempLT := inLow[today]
tempHT := inHigh[today]
tempCY := inClose[today-1]
greatest := tempHT - tempLT
val2 := math.Abs(tempCY - tempHT)
if val2 > greatest {
greatest = val2
}
val3 := math.Abs(tempCY - tempLT)
if val3 > greatest {
greatest = val3
}
outReal[outIdx] = greatest
outIdx++
today++
}
return outReal
} | go | {
"resource": ""
} |
q10371 | LinearReg | train | func LinearReg(inReal []float64, inTimePeriod int) []float64 {
outReal := make([]float64, len(inReal))
inTimePeriodF := float64(inTimePeriod)
lookbackTotal := inTimePeriod
startIdx := lookbackTotal
outIdx := startIdx - 1
today := startIdx - 1
sumX := inTimePeriodF * (inTimePeriodF - 1) * 0.5
sumXSqr := inTimePeriodF * (inTimePeriodF - 1) * (2*inTimePeriodF - 1) / 6
divisor := sumX*sumX - inTimePeriodF*sumXSqr
//initialize values of sumY and sumXY over first (inTimePeriod) input values
sumXY := 0.0
sumY := 0.0
i := inTimePeriod
for i != 0 {
i--
tempValue1 := inReal[today-i]
sumY += tempValue1
sumXY += float64(i) * tempValue1
}
for today < len(inReal) {
//sumX and sumXY are already available for first output value
if today > startIdx-1 {
tempValue2 := inReal[today-inTimePeriod]
sumXY += sumY - inTimePeriodF*tempValue2
sumY += inReal[today] - tempValue2
}
m := (inTimePeriodF*sumXY - sumX*sumY) / divisor
b := (sumY - m*sumX) / inTimePeriodF
outReal[outIdx] = b + m*(inTimePeriodF-1)
outIdx++
today++
}
return outReal
} | go | {
"resource": ""
} |
q10372 | StdDev | train | func StdDev(inReal []float64, inTimePeriod int, inNbDev float64) []float64 {
outReal := Var(inReal, inTimePeriod)
if inNbDev != 1.0 {
for i := 0; i < len(inReal); i++ {
tempReal := outReal[i]
if !(tempReal < 0.00000000000001) {
outReal[i] = math.Sqrt(tempReal) * inNbDev
} else {
outReal[i] = 0.0
}
}
} else {
for i := 0; i < len(inReal); i++ {
tempReal := outReal[i]
if !(tempReal < 0.00000000000001) {
outReal[i] = math.Sqrt(tempReal)
} else {
outReal[i] = 0.0
}
}
}
return outReal
} | go | {
"resource": ""
} |
q10373 | Var | train | func Var(inReal []float64, inTimePeriod int) []float64 {
outReal := make([]float64, len(inReal))
nbInitialElementNeeded := inTimePeriod - 1
startIdx := nbInitialElementNeeded
periodTotal1 := 0.0
periodTotal2 := 0.0
trailingIdx := startIdx - nbInitialElementNeeded
i := trailingIdx
if inTimePeriod > 1 {
for i < startIdx {
tempReal := inReal[i]
periodTotal1 += tempReal
tempReal *= tempReal
periodTotal2 += tempReal
i++
}
}
outIdx := startIdx
for ok := true; ok; {
tempReal := inReal[i]
periodTotal1 += tempReal
tempReal *= tempReal
periodTotal2 += tempReal
meanValue1 := periodTotal1 / float64(inTimePeriod)
meanValue2 := periodTotal2 / float64(inTimePeriod)
tempReal = inReal[trailingIdx]
periodTotal1 -= tempReal
tempReal *= tempReal
periodTotal2 -= tempReal
outReal[outIdx] = meanValue2 - meanValue1*meanValue1
i++
trailingIdx++
outIdx++
ok = i < len(inReal)
}
return outReal
} | go | {
"resource": ""
} |
q10374 | Asin | train | func Asin(inReal []float64) []float64 {
outReal := make([]float64, len(inReal))
for i := 0; i < len(inReal); i++ {
outReal[i] = math.Asin(inReal[i])
}
return outReal
} | go | {
"resource": ""
} |
q10375 | Atan | train | func Atan(inReal []float64) []float64 {
outReal := make([]float64, len(inReal))
for i := 0; i < len(inReal); i++ {
outReal[i] = math.Atan(inReal[i])
}
return outReal
} | go | {
"resource": ""
} |
q10376 | Ceil | train | func Ceil(inReal []float64) []float64 {
outReal := make([]float64, len(inReal))
for i := 0; i < len(inReal); i++ {
outReal[i] = math.Ceil(inReal[i])
}
return outReal
} | go | {
"resource": ""
} |
q10377 | Cos | train | func Cos(inReal []float64) []float64 {
outReal := make([]float64, len(inReal))
for i := 0; i < len(inReal); i++ {
outReal[i] = math.Cos(inReal[i])
}
return outReal
} | go | {
"resource": ""
} |
q10378 | Cosh | train | func Cosh(inReal []float64) []float64 {
outReal := make([]float64, len(inReal))
for i := 0; i < len(inReal); i++ {
outReal[i] = math.Cosh(inReal[i])
}
return outReal
} | go | {
"resource": ""
} |
q10379 | Exp | train | func Exp(inReal []float64) []float64 {
outReal := make([]float64, len(inReal))
for i := 0; i < len(inReal); i++ {
outReal[i] = math.Exp(inReal[i])
}
return outReal
} | go | {
"resource": ""
} |
q10380 | Floor | train | func Floor(inReal []float64) []float64 {
outReal := make([]float64, len(inReal))
for i := 0; i < len(inReal); i++ {
outReal[i] = math.Floor(inReal[i])
}
return outReal
} | go | {
"resource": ""
} |
q10381 | Ln | train | func Ln(inReal []float64) []float64 {
outReal := make([]float64, len(inReal))
for i := 0; i < len(inReal); i++ {
outReal[i] = math.Log(inReal[i])
}
return outReal
} | go | {
"resource": ""
} |
q10382 | Log10 | train | func Log10(inReal []float64) []float64 {
outReal := make([]float64, len(inReal))
for i := 0; i < len(inReal); i++ {
outReal[i] = math.Log10(inReal[i])
}
return outReal
} | go | {
"resource": ""
} |
q10383 | Sin | train | func Sin(inReal []float64) []float64 {
outReal := make([]float64, len(inReal))
for i := 0; i < len(inReal); i++ {
outReal[i] = math.Sin(inReal[i])
}
return outReal
} | go | {
"resource": ""
} |
q10384 | Sinh | train | func Sinh(inReal []float64) []float64 {
outReal := make([]float64, len(inReal))
for i := 0; i < len(inReal); i++ {
outReal[i] = math.Sinh(inReal[i])
}
return outReal
} | go | {
"resource": ""
} |
q10385 | Sqrt | train | func Sqrt(inReal []float64) []float64 {
outReal := make([]float64, len(inReal))
for i := 0; i < len(inReal); i++ {
outReal[i] = math.Sqrt(inReal[i])
}
return outReal
} | go | {
"resource": ""
} |
q10386 | Tan | train | func Tan(inReal []float64) []float64 {
outReal := make([]float64, len(inReal))
for i := 0; i < len(inReal); i++ {
outReal[i] = math.Tan(inReal[i])
}
return outReal
} | go | {
"resource": ""
} |
q10387 | Tanh | train | func Tanh(inReal []float64) []float64 {
outReal := make([]float64, len(inReal))
for i := 0; i < len(inReal); i++ {
outReal[i] = math.Tanh(inReal[i])
}
return outReal
} | go | {
"resource": ""
} |
q10388 | Div | train | func Div(inReal0 []float64, inReal1 []float64) []float64 {
outReal := make([]float64, len(inReal0))
for i := 0; i < len(inReal0); i++ {
outReal[i] = inReal0[i] / inReal1[i]
}
return outReal
} | go | {
"resource": ""
} |
q10389 | Max | train | func Max(inReal []float64, inTimePeriod int) []float64 {
outReal := make([]float64, len(inReal))
if inTimePeriod < 2 {
return outReal
}
nbInitialElementNeeded := inTimePeriod - 1
startIdx := nbInitialElementNeeded
outIdx := startIdx
today := startIdx
trailingIdx := startIdx - nbInitialElementNeeded
highestIdx := -1
highest := 0.0
for today < len(outReal) {
tmp := inReal[today]
if highestIdx < trailingIdx {
highestIdx = trailingIdx
highest = inReal[highestIdx]
i := highestIdx + 1
for i <= today {
tmp = inReal[i]
if tmp > highest {
highestIdx = i
highest = tmp
}
i++
}
} else if tmp >= highest {
highestIdx = today
highest = tmp
}
outReal[outIdx] = highest
outIdx++
trailingIdx++
today++
}
return outReal
} | go | {
"resource": ""
} |
q10390 | Min | train | func Min(inReal []float64, inTimePeriod int) []float64 {
outReal := make([]float64, len(inReal))
if inTimePeriod < 2 {
return outReal
}
nbInitialElementNeeded := inTimePeriod - 1
startIdx := nbInitialElementNeeded
outIdx := startIdx
today := startIdx
trailingIdx := startIdx - nbInitialElementNeeded
lowestIdx := -1
lowest := 0.0
for today < len(outReal) {
tmp := inReal[today]
if lowestIdx < trailingIdx {
lowestIdx = trailingIdx
lowest = inReal[lowestIdx]
i := lowestIdx + 1
for i <= today {
tmp = inReal[i]
if tmp < lowest {
lowestIdx = i
lowest = tmp
}
i++
}
} else if tmp <= lowest {
lowestIdx = today
lowest = tmp
}
outReal[outIdx] = lowest
outIdx++
trailingIdx++
today++
}
return outReal
} | go | {
"resource": ""
} |
q10391 | MinMax | train | func MinMax(inReal []float64, inTimePeriod int) ([]float64, []float64) {
outMin := make([]float64, len(inReal))
outMax := make([]float64, len(inReal))
nbInitialElementNeeded := (inTimePeriod - 1)
startIdx := nbInitialElementNeeded
outIdx := startIdx
today := startIdx
trailingIdx := startIdx - nbInitialElementNeeded
highestIdx := -1
highest := 0.0
lowestIdx := -1
lowest := 0.0
for today < len(inReal) {
tmpLow, tmpHigh := inReal[today], inReal[today]
if highestIdx < trailingIdx {
highestIdx = trailingIdx
highest = inReal[highestIdx]
i := highestIdx
i++
for i <= today {
tmpHigh = inReal[i]
if tmpHigh > highest {
highestIdx = i
highest = tmpHigh
}
i++
}
} else if tmpHigh >= highest {
highestIdx = today
highest = tmpHigh
}
if lowestIdx < trailingIdx {
lowestIdx = trailingIdx
lowest = inReal[lowestIdx]
i := lowestIdx
i++
for i <= today {
tmpLow = inReal[i]
if tmpLow < lowest {
lowestIdx = i
lowest = tmpLow
}
i++
}
} else if tmpLow <= lowest {
lowestIdx = today
lowest = tmpLow
}
outMax[outIdx] = highest
outMin[outIdx] = lowest
outIdx++
trailingIdx++
today++
}
return outMin, outMax
} | go | {
"resource": ""
} |
q10392 | MinMaxIndex | train | func MinMaxIndex(inReal []float64, inTimePeriod int) ([]float64, []float64) {
outMinIdx := make([]float64, len(inReal))
outMaxIdx := make([]float64, len(inReal))
nbInitialElementNeeded := (inTimePeriod - 1)
startIdx := nbInitialElementNeeded
outIdx := startIdx
today := startIdx
trailingIdx := startIdx - nbInitialElementNeeded
highestIdx := -1
highest := 0.0
lowestIdx := -1
lowest := 0.0
for today < len(inReal) {
tmpLow, tmpHigh := inReal[today], inReal[today]
if highestIdx < trailingIdx {
highestIdx = trailingIdx
highest = inReal[highestIdx]
i := highestIdx
i++
for i <= today {
tmpHigh = inReal[i]
if tmpHigh > highest {
highestIdx = i
highest = tmpHigh
}
i++
}
} else if tmpHigh >= highest {
highestIdx = today
highest = tmpHigh
}
if lowestIdx < trailingIdx {
lowestIdx = trailingIdx
lowest = inReal[lowestIdx]
i := lowestIdx
i++
for i <= today {
tmpLow = inReal[i]
if tmpLow < lowest {
lowestIdx = i
lowest = tmpLow
}
i++
}
} else if tmpLow <= lowest {
lowestIdx = today
lowest = tmpLow
}
outMaxIdx[outIdx] = float64(highestIdx)
outMinIdx[outIdx] = float64(lowestIdx)
outIdx++
trailingIdx++
today++
}
return outMinIdx, outMaxIdx
} | go | {
"resource": ""
} |
q10393 | Mult | train | func Mult(inReal0 []float64, inReal1 []float64) []float64 {
outReal := make([]float64, len(inReal0))
for i := 0; i < len(inReal0); i++ {
outReal[i] = inReal0[i] * inReal1[i]
}
return outReal
} | go | {
"resource": ""
} |
q10394 | Sub | train | func Sub(inReal0 []float64, inReal1 []float64) []float64 {
outReal := make([]float64, len(inReal0))
for i := 0; i < len(inReal0); i++ {
outReal[i] = inReal0[i] - inReal1[i]
}
return outReal
} | go | {
"resource": ""
} |
q10395 | Sum | train | func Sum(inReal []float64, inTimePeriod int) []float64 {
outReal := make([]float64, len(inReal))
lookbackTotal := inTimePeriod - 1
startIdx := lookbackTotal
periodTotal := 0.0
trailingIdx := startIdx - lookbackTotal
i := trailingIdx
if inTimePeriod > 1 {
for i < startIdx {
periodTotal += inReal[i]
i++
}
}
outIdx := startIdx
for i < len(inReal) {
periodTotal += inReal[i]
tempReal := periodTotal
periodTotal -= inReal[trailingIdx]
outReal[outIdx] = tempReal
i++
trailingIdx++
outIdx++
}
return outReal
} | go | {
"resource": ""
} |
q10396 | contextID | train | func contextID() (uint32, error) {
// Fetch the context ID using a real filesystem.
var cid uint32
if err := sysContextID(sysFS{}, &cid); err != nil {
return 0, err
}
return cid, nil
} | go | {
"resource": ""
} |
q10397 | sysContextID | train | func sysContextID(fs fs, cid *uint32) error {
f, err := fs.Open(devVsock)
if err != nil {
return err
}
defer f.Close()
// Retrieve the context ID of this machine from /dev/vsock.
return fs.Ioctl(f.Fd(), unix.IOCTL_VM_SOCKETS_GET_LOCAL_CID, unsafe.Pointer(cid))
} | go | {
"resource": ""
} |
q10398 | Accept | train | func Accept(l net.Listener, timeout time.Duration) (net.Conn, error) {
// This function accommodates both Go1.12+ and Go1.11 functionality to allow
// net.Listener.Accept to be canceled by net.Listener.Close.
//
// If a timeout is set, set up a timer to close the listener and either:
// - Go 1.12+: unblock the call to Accept
// - Go 1.11 : eventually halt the loop due to closed file descriptor
//
// For Go 1.12+, we could use vsock.Listener.SetDeadline, but this approach
// using a timer works for Go 1.11 as well.
cancel := func() {}
if timeout != 0 {
timer := time.AfterFunc(timeout, func() { _ = l.Close() })
cancel = func() { timer.Stop() }
}
for {
c, err := l.Accept()
if err != nil {
if nerr, ok := err.(net.Error); ok && nerr.Temporary() {
time.Sleep(250 * time.Millisecond)
continue
}
return nil, err
}
// Got a connection, stop the timer.
cancel()
return c, nil
}
} | go | {
"resource": ""
} |
q10399 | SkipHostIntegration | train | func SkipHostIntegration(t *testing.T) {
t.Helper()
if IsHypervisor(t) {
t.Skip("skipping, this integration test must be run in a guest")
}
} | go | {
"resource": ""
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.