diff --git a/.bazelrc b/.bazelrc index be5857ff..33726f6c 100644 --- a/.bazelrc +++ b/.bazelrc @@ -48,3 +48,31 @@ build --sandbox_default_allow_network # Custom flags build --define enable_telemetry=false + +# Force use of standard C++ toolchain, ignore Apple toolchain +build --crosstool_top=@bazel_tools//tools/cpp:toolchain +build --host_crosstool_top=@bazel_tools//tools/cpp:toolchain + +# Critical flags that made it work +build --incompatible_enable_apple_toolchain_resolution=false +build --incompatible_require_ctx_in_configure_features=false +build --action_env=BAZEL_USE_CPP_ONLY_TOOLCHAIN=1 + +# C++ standard +build --cxxopt=-std=c++17 +build --host_cxxopt=-std=c++17 + +# Use standalone strategies +build --spawn_strategy=standalone +build --strategy=CppCompile=standalone +build --strategy=CppLink=standalone +build --genrule_strategy=standalone + +# Disable Apple features +build --features=-apple +build --features=-supports_dynamic_linker +build --features=-supports_interface_shared_libraries + +# Environment overrides +build --action_env=PATH +build --host_action_env=PATH diff --git a/WORKSPACE b/WORKSPACE index 45b7bd93..c9038276 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -4,13 +4,6 @@ load("//:deps.bzl", "deps") deps() -load( - "@build_bazel_apple_support//lib:repositories.bzl", - "apple_support_dependencies", -) - -apple_support_dependencies() - load("@bazel_features//:deps.bzl", "bazel_features_deps") bazel_features_deps() diff --git a/deps.bzl b/deps.bzl index 8f0eae64..b6bdf738 100644 --- a/deps.bzl +++ b/deps.bzl @@ -1,6 +1,14 @@ load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") def deps(): + + http_archive( + name = "bazel_features", + sha256 = "d7787da289a7fb497352211ad200ec9f698822a9e0757a4976fd9f713ff372b3", + strip_prefix = "bazel_features-1.9.1", + url = "https://github.com/bazel-contrib/bazel_features/releases/download/v1.9.1/bazel_features-v1.9.1.tar.gz", + ) + http_archive( name = "bazel_skylib", sha256 = "74d544d96f4a5bb630d465ca8bbcfe231e3594e5aae57e1edbf17a6eb3ca2506", diff --git a/libs/finance/include/rtbot/finance/RelativeStrengthIndex.h b/libs/finance/include/rtbot/finance/RelativeStrengthIndex.h deleted file mode 100644 index 8f2b8575..00000000 --- a/libs/finance/include/rtbot/finance/RelativeStrengthIndex.h +++ /dev/null @@ -1,94 +0,0 @@ -#ifndef RELATIVESTRENGTHINDEX_H -#define RELATIVESTRENGTHINDEX_H - -#include -#include -#include - -#include "rtbot/Operator.h" - -namespace rtbot { - -template -struct RelativeStrengthIndex : public Operator { - RelativeStrengthIndex() = default; - - RelativeStrengthIndex(string const& id, size_t n) : Operator(id), initialized(false) { - this->addDataInput("i1", n + 1); - this->addOutput("o1"); - } - - string typeName() const override { return "RelativeStrengthIndex"; } - - OperatorMessage processData() override { - string inputPort; - auto in = this->getDataInputs(); - if (in.size() == 1) - inputPort = in.at(0); - else - throw runtime_error(typeName() + " : more than 1 input port found"); - Message out; - size_t n = this->getDataInputSize(inputPort); - V diff, rs, rsi, gain, loss; - - if (!initialized) { - averageGain = 0; - averageLoss = 0; - for (size_t i = 1; i < n; i++) { - diff = this->getDataInputMessage(inputPort, i).value - this->getDataInputMessage(inputPort, i - 1).value; - if (diff > 0) - averageGain = averageGain + diff; - else if (diff < 0) - averageLoss = averageLoss - diff; - } - averageGain = averageGain / (n - 1); - averageLoss = averageLoss / (n - 1); - - initialized = true; - } else { - diff = this->getDataInputMessage(inputPort, n - 1).value - this->getDataInputMessage(inputPort, n - 2).value; - if (diff > 0) { - gain = diff; - loss = 0; - } else if (diff < 0) { - loss = -diff; - gain = 0; - } else { - loss = 0; - gain = 0; - } - averageGain = (prevAverageGain * (n - 2) + gain) / (n - 1); - averageLoss = (prevAverageLoss * (n - 2) + loss) / (n - 1); - } - - prevAverageGain = averageGain; - prevAverageLoss = averageLoss; - - if (averageLoss > 0) { - rs = averageGain / averageLoss; - - rsi = 100.0 - (100.0 / (1 + rs)); - } else - rsi = 100.0; - out.value = rsi; - - out.time = this->getDataInputLastMessage(inputPort).time; - - OperatorMessage outputMsgs; - PortMessage v; - v.push_back(out); - outputMsgs.emplace("o1", v); - return outputMsgs; - } - - private: - V averageGain; - V averageLoss; - V prevAverageGain; - V prevAverageLoss; - bool initialized = false; -}; - -} // namespace rtbot - -#endif // RELATIVESTRENGTHINDEX_H diff --git a/libs/finance/test/test_relative_strength_index.cpp b/libs/finance/test/test_relative_strength_index.cpp deleted file mode 100644 index 468398d8..00000000 --- a/libs/finance/test/test_relative_strength_index.cpp +++ /dev/null @@ -1,35 +0,0 @@ -#define CATCH_CONFIG_MAIN -#include - -#include - -#include "rtbot/finance/RelativeStrengthIndex.h" - -using namespace rtbot; -using namespace std; - -TEST_CASE("Relative Strength Index") { - auto rsi = RelativeStrengthIndex("rsi", 14); - vector values = {54.8, 56.8, 57.85, 59.85, 60.57, 61.1, 62.17, 60.6, 62.35, 62.15, 62.35, 61.45, 62.8, - 61.37, 62.5, 62.57, 60.8, 59.37, 60.35, 62.35, 62.17, 62.55, 64.55, 64.37, 65.3, 64.42, - 62.9, 61.6, 62.05, 60.05, 59.7, 60.9, 60.25, 58.27, 58.7, 57.72, 58.1, 58.2}; - - vector rsis = {0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 74.21384, 74.33552, - 65.87129, 59.93370, 62.43288, 66.96205, 66.18862, 67.05377, 71.22679, 70.36299, - 72.23644, 67.86486, 60.99822, 55.79821, 57.15964, 49.81579, 48.63810, 52.76154, - 50.40119, 43.95111, 45.57992, 42.54534, 44.09946, 44.52472}; - - SECTION("emits right values") { - for (int i = 0; i < values.size(); i++) { - rsi.receiveData(Message(i + 1, values.at(i))); - ProgramMessage emitted = rsi.executeData(); - - if (i < 14) { - REQUIRE(emitted.empty()); - } else { - REQUIRE(abs(emitted.find("rsi")->second.find("o1")->second.at(0).value - rsis.at(i)) <= 0.00001); - } - } - } -} \ No newline at end of file diff --git a/libs/std/include/rtbot/std/Composite.h b/libs/std/include/rtbot/std/Composite.h deleted file mode 100644 index fa87596c..00000000 --- a/libs/std/include/rtbot/std/Composite.h +++ /dev/null @@ -1,365 +0,0 @@ -#ifndef COMPOSITE_H -#define COMPOSITE_H - -// TODO: migrate to new Operator -/* -#include -#include - -#include "rtbot/Demultiplexer.h" -#include "rtbot/Input.h" -#include "rtbot/Join.h" -#include "rtbot/Operator.h" -#include "rtbot/Output.h" -#include "rtbot/finance/RelativeStrengthIndex.h" -#include "rtbot/std/Add.h" -#include "rtbot/std/AutoRegressive.h" -#include "rtbot/std/Constant.h" -#include "rtbot/std/CosineResampler.h" -#include "rtbot/std/Count.h" -#include "rtbot/std/CumulativeSum.h" -#include "rtbot/std/Difference.h" -#include "rtbot/std/Division.h" -#include "rtbot/std/EqualTo.h" -#include "rtbot/std/FiniteImpulseResponse.h" -#include "rtbot/std/GreaterThan.h" -#include "rtbot/std/HermiteResampler.h" -#include "rtbot/std/Identity.h" -#include "rtbot/std/LessThan.h" -#include "rtbot/std/Linear.h" -#include "rtbot/std/Minus.h" -#include "rtbot/std/MovingAverage.h" -#include "rtbot/std/PeakDetector.h" -#include "rtbot/std/Power.h" -#include "rtbot/std/Scale.h" -#include "rtbot/std/StandardDeviation.h" -#include "rtbot/std/TimeShift.h" -#include "rtbot/std/Variable.h" - -namespace rtbot { - -using namespace std; - -template -struct Composite : public Operator // TODO: improve from chain to graph -{ - Composite() = default; - - Composite(string const &id) : Operator(id) { this->input == nullptr; } - - string typeName() const override { return "Composite"; } - - virtual ~Composite() = default; - - string createInput(string id, size_t numPorts = 1) { - if (this->ops.count(id) == 0 && this->input == nullptr) { - this->input = make_shared>(id, numPorts); - vector dataI = this->input->getDataInputs(); - vector controlI = this->input->getControlInputs(); - for (int i = 0; i < dataI.size(); i++) this->addDataInput(dataI.at(i), 1); - for (int i = 0; i < controlI.size(); i++) this->addControlInput(controlI.at(i), 1); - this->ops.emplace(id, this->input); - } else if (this->ops.count(id) > 0) - throw std::runtime_error(typeName() + ": unique id is required"); - else if (this->input != nullptr) - throw std::runtime_error(typeName() + ": input operator already setup"); - return id; - } - - string createAdd(string id, V value) { - if (this->ops.count(id) == 0) { - this->ops.emplace(id, make_shared>(id, value)); - return id; - } else - throw std::runtime_error(typeName() + ": unique id is required"); - } - - string createAutoregressive(string id, vector const &coeff) { - if (this->ops.count(id) == 0) { - this->ops.emplace(id, make_shared>(id, coeff)); - return id; - } else - throw std::runtime_error(typeName() + ": unique id is required"); - } - - string createConstant(string id, V value) { - if (this->ops.count(id) == 0) { - this->ops.emplace(id, make_shared>(id, value)); - return id; - } else - throw std::runtime_error(typeName() + ": unique id is required"); - } - - string createCosineResampler(string id, T dt) { - if (this->ops.count(id) == 0) { - this->ops.emplace(id, make_shared>(id, dt)); - return id; - } else - throw std::runtime_error(typeName() + ": unique id is required"); - } - - string createCount(string id) { - if (this->ops.count(id) == 0) { - this->ops.emplace(id, make_shared>(id)); - return id; - } else - throw std::runtime_error(typeName() + ": unique id is required"); - } - - string createCumulativeSum(string id) { - if (this->ops.count(id) == 0) { - this->ops.emplace(id, make_shared>(id)); - return id; - } else - throw std::runtime_error(typeName() + ": unique id is required"); - } - - string createDifference(string id, bool useOldestTime = true) { - if (this->ops.count(id) == 0) { - this->ops.emplace(id, make_shared>(id, useOldestTime)); - return id; - } else - throw std::runtime_error(typeName() + ": unique id is required"); - } - - string createJoin(string id, size_t numPorts) { - if (this->ops.count(id) == 0) { - this->ops.emplace(id, make_shared>(id, numPorts)); - return id; - } else - throw std::runtime_error(typeName() + ": unique id is required"); - } - - string createDivision(string id) { - if (this->ops.count(id) == 0) { - this->ops.emplace(id, make_shared>(id)); - return id; - } else - throw std::runtime_error(typeName() + ": unique id is required"); - } - - string createMinus(string id) { - if (this->ops.count(id) == 0) { - this->ops.emplace(id, make_shared>(id)); - return id; - } else - throw std::runtime_error(typeName() + ": unique id is required"); - } - - string createLinear(string id, vector const &coeff) { - if (this->ops.count(id) == 0) { - this->ops.emplace(id, make_shared>(id, coeff)); - return id; - } else - throw std::runtime_error(typeName() + ": unique id is required"); - } - - string createEqualTo(string id, V value) { - if (this->ops.count(id) == 0) { - this->ops.emplace(id, make_shared>(id, value)); - return id; - } else - throw std::runtime_error(typeName() + ": unique id is required"); - } - - string createGreaterThan(string id, V value) { - if (this->ops.count(id) == 0) { - this->ops.emplace(id, make_shared>(id, value)); - return id; - } else - throw std::runtime_error(typeName() + ": unique id is required"); - } - - string createLessThan(string id, V value) { - if (this->ops.count(id) == 0) { - this->ops.emplace(id, make_shared>(id, value)); - return id; - } else - throw std::runtime_error(typeName() + ": unique id is required"); - } - - string createHermiteResampler(string id, T dt) { - if (this->ops.count(id) == 0) { - this->ops.emplace(id, make_shared>(id, dt)); - return id; - } else - throw std::runtime_error(typeName() + ": unique id is required"); - } - - string createIdentity(string id) { - if (this->ops.count(id) == 0) { - this->ops.emplace(id, make_shared>(id)); - return id; - } else - throw std::runtime_error(typeName() + ": unique id is required"); - } - - string createMovingAverage(string id, size_t n) { - if (this->ops.count(id) == 0) { - this->ops.emplace(id, make_shared>(id, n)); - return id; - } else - throw std::runtime_error(typeName() + ": unique id is required"); - } - - string createFiniteImpulseResponse(string id, vector coeff) { - if (this->ops.count(id) == 0) { - this->ops.emplace(id, make_shared>(id, coeff)); - return id; - } else - throw std::runtime_error(typeName() + ": unique id is required"); - } - - string createVariable(string id, V value = 0) { - if (this->ops.count(id) == 0) { - this->ops.emplace(id, make_shared>(id, value)); - return id; - } else - throw std::runtime_error(typeName() + ": unique id is required"); - } - - string createOutput(string id, size_t numPorts = 1) { - if (this->ops.count(id) == 0 && this->output == nullptr) { - this->output = make_shared>(id, numPorts); - vector outs = this->output->getOutputs(); - for (int i = 0; i < outs.size(); i++) this->addOutput(outs.at(i)); - this->ops.emplace(id, this->output); - } else if (this->ops.count(id) > 0) - throw std::runtime_error(typeName() + ": unique id is required"); - else if (this->output != nullptr) - throw std::runtime_error(typeName() + ": output operator already setup"); - - return id; - } - - string createPeakDetector(string id, size_t n) { - if (this->ops.count(id) == 0) { - this->ops.emplace(id, make_shared>(id, n)); - return id; - } else - throw std::runtime_error(typeName() + ": unique id is required"); - } - - string createStandardDeviation(string id, size_t n) { - if (this->ops.count(id) == 0) { - this->ops.emplace(id, make_shared>(id, n)); - return id; - } else - throw std::runtime_error(typeName() + ": unique id is required"); - } - - string createDemultiplexer(string id, size_t numOutputPorts = 2) { - if (this->ops.count(id) == 0) { - this->ops.emplace(id, make_shared>(id, numOutputPorts)); - return id; - } else - throw std::runtime_error(typeName() + ": unique id is required"); - } - - string createPower(string id, V value) { - if (this->ops.count(id) == 0) { - this->ops.emplace(id, make_shared>(id, value)); - return id; - } else - throw std::runtime_error(typeName() + ": unique id is required"); - } - - string createScale(string id, V value) { - if (this->ops.count(id) == 0) { - this->ops.emplace(id, make_shared>(id, value)); - return id; - } else - throw std::runtime_error(typeName() + ": unique id is required"); - } - - string createTimeShift(string id, T dt = 1, int times = 1) { - if (this->ops.count(id) == 0) { - this->ops.emplace(id, make_shared>(id, dt, times)); - return id; - } else - throw std::runtime_error(typeName() + ": unique id is required"); - } - - shared_ptr> getOperator(string id) { - if (this->ops.count(id) == 1) { - return this->ops.find(id)->second; - } else - throw std::runtime_error(typeName() + ": operator now found"); - } - - Operator *createInternalConnection(string operatorId, string childId, string outputPort = "", - string inputPort = "") { - if (this->ops.count(operatorId) == 0) - throw std::runtime_error(typeName() + ": operator " + operatorId + - " has not been added to the operator list, please use add[Operator] first"); - if (this->ops.count(childId) == 0) - throw std::runtime_error(typeName() + ": operator " + childId + - " has not been added to the operator list, please use add[Operator] first"); - auto op = this->ops.find(operatorId)->second; - auto child = this->ops.find(childId)->second; - auto childptr = op.get()->connect(child.get(), outputPort, inputPort); - if (childptr != nullptr) - return this; - else - throw std::runtime_error(typeName() + ": connection was not successful"); - } - - virtual void receiveData(Message msg, string inputPort = "") override { - if (this->input != nullptr) - this->input.get()->receiveData(msg, inputPort); - else - throw std::runtime_error(typeName() + ": the input operator have not been found"); - } - - virtual ProgramMessage executeData() override { - if (this->input != nullptr) - return this->input.get()->executeData(); - else - throw std::runtime_error(typeName() + ": the input operator have not been found"); - } - - virtual void receiveControl(Message msg, string inputPort = "") override { - if (this->input != nullptr) - this->input.get()->receiveControl(msg, inputPort); - else - throw std::runtime_error(typeName() + ": the input operator have not been found"); - } - - virtual ProgramMessage executeControl() override { - if (this->input != nullptr) - return this->input.get()->executeControl(); - else - throw std::runtime_error(typeName() + ": the input operator have not been found"); - } - - virtual OperatorMessage processData() override { return {}; } - - virtual OperatorMessage processControl() override { return {}; } - - virtual Operator *connect(Operator &child, string outputPort = "", string inputPort = "") override { - if (this->output != nullptr) - return this->output->connect(child, outputPort, inputPort); - else if (this->output == nullptr) - throw std::runtime_error(typeName() + ": output operator have not been found"); - return nullptr; - } - - virtual Operator *connect(Operator *child, string outputPort = "", string inputPort = "") override { - if (this->output != nullptr) - return this->output->connect(child, outputPort, inputPort); - else if (this->output == nullptr) - throw std::runtime_error(typeName() + ": output operator have not been found"); - return nullptr; - } - - private: - map>> ops; - shared_ptr> input; - shared_ptr> output; -}; - -} // namespace rtbot - -#endif // COMPOSITE_H - -*/ \ No newline at end of file