diff --git a/internal/ddosml/request.go b/internal/ddosml/request.go index 1834d47..7203f96 100644 --- a/internal/ddosml/request.go +++ b/internal/ddosml/request.go @@ -1,7 +1,25 @@ package ddosml +import "io" + +// Request struct represents http request +// in the more "readable" format in order +// to work with that with ML. type Request struct { - IsDDOS bool + IsDDOS bool + Method string + URL string + Protocol string + ProtocolMajor int + ProtocolMinor int + Headers map[string]any + Body io.ReadCloser + ContentLength int64 + TransferEncoding []string + Host string + Form map[string][]string + RemoteAddress string + RequestURI string } // data method returns slice of float64 representation of diff --git a/internal/ml/caterogical.go b/internal/ml/caterogical.go new file mode 100644 index 0000000..7ec2cce --- /dev/null +++ b/internal/ml/caterogical.go @@ -0,0 +1,43 @@ +package ml + +import ( + "runtime" + "sync" +) + +// CategoricalToNumericConverter converts passed struct +// to categorical []float64 format where +// each field is one element of the returned +// slice. +type CategoricalToNumericConverter[T any] struct { + // dataSlice is a slice of other entities of the same type + // used to convert categorical data to numeric one + dataSlice []T + + // convertRoutinesCount represents how many routines will be working + // in order to calculate given tree. + convertRoutinesCount int + + mu sync.Mutex +} + +// NewCategoricalConverter creates a new instance of the categorical converter +func NewCategoricalConverter[T any](dataSlice []T) *CategoricalToNumericConverter[T] { + return &CategoricalToNumericConverter[T]{ + dataSlice: dataSlice, + convertRoutinesCount: runtime.NumCPU(), // basically there is no need have more workers than cores. + } +} + +// Convert converts given struct fields into []float64 and returns it. +// It converts all the fields into numeric format. +func (c *CategoricalToNumericConverter[T]) Convert(obj T) []float64 { + c.mu.Lock() + defer c.mu.Unlock() + + var wg sync.WaitGroup + for i := range c.convertRoutinesCount { + + } + +}