Skip to content

Commit

Permalink
#9 Add part of categorical converter
Browse files Browse the repository at this point in the history
  • Loading branch information
thegodenage committed May 11, 2024
1 parent a80eb99 commit abe5686
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 1 deletion.
20 changes: 19 additions & 1 deletion internal/ddosml/request.go
Original file line number Diff line number Diff line change
@@ -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
Expand Down
43 changes: 43 additions & 0 deletions internal/ml/caterogical.go
Original file line number Diff line number Diff line change
@@ -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 {

}

}

0 comments on commit abe5686

Please sign in to comment.