merge with upstream

This commit is contained in:
Travis Hunter 2023-05-04 16:40:20 -06:00
parent 10c552e086
commit 42298ca801
4 changed files with 64 additions and 1 deletions

View File

@ -4,6 +4,8 @@
/// \cond
// C headers
// C++ headers
#include <boost/property_tree/ptree.hpp>
#include <boost/property_tree/xml_parser.hpp>
// 3rd party headers
#include <boost/property_tree/ptree.hpp>
#include <boost/property_tree/xml_parser.hpp>

View File

@ -74,4 +74,4 @@ private:
} // namespace utils
#endif // UTILS_MOTORMODELDATABASE_H
#endif // UTILS_MOTORMODELDATABASE_H

View File

@ -4,6 +4,7 @@
// C++ headers
// 3rd party headers
#include <json/json.h>
#include <optional>
/// \endcond
// qtrocket headers
@ -25,6 +26,58 @@ ThrustCurveAPI::~ThrustCurveAPI()
}
std::optional<ThrustCurve> ThrustCurveAPI::getThrustCurve(const std::string& id)
{
std::stringstream endpoint;
endpoint << hostname << "api/v1/download.json?motorId=" << id << "&data=samples";
std::vector<std::string> extraHeaders = {};
std::string res = curlConnection.get(endpoint.str(), extraHeaders);
model::MotorModel mm;
if(!res.empty())
{
try
{
Json::Reader reader;
Json::Value jsonResult;
reader.parse(res, jsonResult);
std::vector<std::pair<double, double>> samples;
for(Json::ValueConstIterator iter = jsonResult["results"].begin();
iter != jsonResult["results"].end();
++iter)
{
// if there are more than 1 items in the results list, we only want the RASP data
// Otherwise just take whatever is there
if(std::next(iter) != jsonResult["results"].end())
{
if( (*iter)["format"].asString() != "RASP")
continue;
}
for(Json::ValueConstIterator samplesIter = (*iter)["samples"].begin();
samplesIter != (*iter)["samples"].end();
++samplesIter)
{
samples.push_back(std::make_pair((*samplesIter)["time"].asDouble(),
(*samplesIter)["thrust"].asDouble()));
}
}
return ThrustCurve(samples);
}
catch(const std::exception& e)
{
std::string err("Unable to parse JSON from Thrustcurve motor data request. Error: ");
err += e.what();
Logger::getInstance()->error(err);
}
}
return std::nullopt;
}
model::MotorModel ThrustCurveAPI::getMotorData(const std::string& motorId)
{
@ -227,6 +280,11 @@ std::vector<model::MotorModel> ThrustCurveAPI::searchMotors(const SearchCriteria
mm.type = model::MotorModel::MotorType(model::MotorModel::MOTORTYPE::HYBRID);
motorModel.moveMetaData(std::move(mm));
auto tc = getThrustCurve(mm.motorIdTC);
if(tc)
{
motorModel.addThrustCurve(*tc);
}
retVal.push_back(motorModel);
}
}

View File

@ -7,6 +7,7 @@
// C++ headers
#include <map>
#include <string>
#include <optional>
// 3rd party headers
/// \endcond
@ -91,6 +92,8 @@ private:
const std::string hostname;
CurlConnection curlConnection;
std::optional<ThrustCurve> getThrustCurve(const std::string& id);
// no extra headers, but CurlConnection library wants them
const std::vector<std::string> extraHeaders{};
};