func populateSet(resultRepo repository.ResultDataRepo, effRepo repository.EfficiencyRepo) (*entities.ResultDataListResponse, *entities.ResultDataResponse, *entities.Signal, error) { eff, found := effRepo.GetLast() if !found { return nil, nil, nil, errors.New("populateSet error, in get last EFF not found") } score10, score100 := get10_100Score(eff) results := resultRepo.GetAll() l := len(results) var resultSet []entities.ResultResponse limit := historyLimit if l < historyLimit { limit = l } resultSet = make([]entities.ResultResponse, limit) counter := 1 for i := l - 1; i >= l-limit && i >= 0; i-- { result := new(entities.ResultResponse) result.Prediction = results[i].Prediction result.Result = results[i].Result result.Source = make([]int32, len(results[i].Source)) copy(result.Source, results[i].Source) result.Timestamp = results[i].Timestamp result.Levels = results[i].RangesCount if err := populateDataFor(result.Timestamp, results[i].Step, results[i].Symbol, results, result); err != nil { return nil, nil, nil, fmt.Errorf("PopulateSet error, in populate data: %v.", err) } result.Symbol = results[i].Symbol resultSet[limit-counter] = *result counter++ } var signal *entities.Signal if last, found := resultRepo.GetLast(); found { signal = new(entities.Signal) signal.RangesCount = last.RangesCount signal.Symbol = last.Symbol signal.Timestamp = last.Timestamp signal.Prediction = last.Prediction signal.Score10 = score10 signal.Score100 = score100 } retList := new(entities.ResultDataListResponse) retList.Data = resultSet retList.Score10 = score10 retList.Score100 = score100 retCurrent := new(entities.ResultDataResponse) retCurrent.Data = *(resultSet[len(resultSet)-1].Clone()) retCurrent.Score10 = score10 retCurrent.Score100 = score100 return retList, retCurrent, signal, nil }
func populateDataFor(timestamp int64, frame int32, symbol string, results []entities.ResultData, result *entities.ResultResponse) error { l := len(_rates) addExtendedData := false if _rates[l-1].ID > timestamp { addExtendedData = true frame++ } result.Data = make([]float32, frame) result.Time = make([]int64, frame) var counter int32 = 1 var prevRate entities.Rate for i := l - 1; i > 0 && counter <= frame; i-- { if _rates[i].ID <= timestamp { if addExtendedData { value, err := prevRate.GetForSymbol(symbol) if err != nil { return fmt.Errorf("ExtrudeDataFor error: %v", err) } result.Data[frame-counter] = value result.Time[frame-counter] = prevRate.ID counter++ addExtendedData = false } value, err := _rates[i].GetForSymbol(symbol) if err != nil { return fmt.Errorf("ExtrudeDataFor error: %v", err) } result.Data[frame-counter] = value result.Time[frame-counter] = _rates[i].ID counter++ } prevRate = _rates[i] } return nil }