GCBM
growthcurvetransform.h
Go to the documentation of this file.
1 #ifndef MOJA_MODULES_CBM_GROWTHCURVETRANSFORM_H_
2 #define MOJA_MODULES_CBM_GROWTHCURVETRANSFORM_H_
3 
4 #include "moja/datarepository/iproviderrelationalinterface.h"
5 #include "moja/flint/ilandunitcontroller.h"
6 #include "moja/flint/itransform.h"
7 
8 #include <Poco/LRUCache.h>
9 #include <Poco/ThreadLocal.h>
10 
11 namespace moja {
12 namespace modules {
13 namespace cbm {
14 
15 class GrowthCurveTransform : public flint::ITransform {
16 public:
17  void configure(DynamicObject config,
18  const flint::ILandUnitController& landUnitController,
19  datarepository::DataRepository& dataRepository) override;
20 
21  void controllerChanged(const flint::ILandUnitController& controller) override;
22  const DynamicVar& value() const override;
23 
24 private:
25  const flint::ILandUnitController* _landUnitController;
26  datarepository::DataRepository* _dataRepository;
27  std::shared_ptr<datarepository::IProviderRelationalInterface> _provider;
28  mutable const flint::IVariable* _csetVar;
29  mutable DynamicVar _value;
30  mutable Poco::ThreadLocal<Poco::LRUCache<std::string, DynamicVar>> _cache;
31 
32  const std::string buildSql(const DynamicObject& classifierSet) const;
33  const std::string buildDebuggingInfo(const DynamicObject& classifierSet) const;
34 
35  const std::string _baseSql = R"(
36  SELECT growth_curve_id
37  FROM (
38  SELECT
39  gccv.growth_curve_id AS growth_curve_id,
40  SUM(CASE
41  WHEN c.name IN (%1%) THEN
42  CASE
43  WHEN cv.value LIKE '?' THEN 1
44  %2%
45  ELSE -1000
46  END
47  ELSE -1000
48  END
49  ) AS score
50  FROM growth_curve_classifier_value gccv
51  INNER JOIN classifier_value cv
52  ON gccv.classifier_value_id = cv.id
53  INNER JOIN classifier c
54  ON cv.classifier_id = c.id
55  GROUP BY gccv.growth_curve_id
56  ) AS growth_curve_ranking
57  WHERE score > 0
58  ORDER BY score DESC
59  LIMIT 1
60  )";
61 
62  const std::string _matchSql = "WHEN c.name LIKE '%1%' AND cv.value LIKE '%2%' THEN 4 ";
63 };
64 
65 }}}
66 
67 #endif // MOJA_MODULES_CBM_GROWTHCURVETRANSFORM_H_
moja::modules::cbm::GrowthCurveTransform::_matchSql
const std::string _matchSql
Definition: growthcurvetransform.h:62
moja::modules::cbm
Definition: ageclasshelper.cpp:12
moja::modules::cbm::GrowthCurveTransform::_value
DynamicVar _value
Definition: growthcurvetransform.h:29
moja::modules::cbm::GrowthCurveTransform::buildDebuggingInfo
const std::string buildDebuggingInfo(const DynamicObject &classifierSet) const
Definition: growthcurvetransform.cpp:88
moja::modules::cbm::GrowthCurveTransform::_landUnitController
const flint::ILandUnitController * _landUnitController
Definition: growthcurvetransform.h:25
moja::modules::cbm::GrowthCurveTransform::_cache
Poco::ThreadLocal< Poco::LRUCache< std::string, DynamicVar > > _cache
Definition: growthcurvetransform.h:30
moja::modules::cbm::GrowthCurveTransform::configure
void configure(DynamicObject config, const flint::ILandUnitController &landUnitController, datarepository::DataRepository &dataRepository) override
Definition: growthcurvetransform.cpp:27
moja::modules::cbm::GrowthCurveTransform
Definition: growthcurvetransform.h:15
moja::modules::cbm::GrowthCurveTransform::controllerChanged
void controllerChanged(const flint::ILandUnitController &controller) override
Definition: growthcurvetransform.cpp:49
moja::modules::cbm::GrowthCurveTransform::_baseSql
const std::string _baseSql
Definition: growthcurvetransform.h:35
moja::modules::cbm::GrowthCurveTransform::_dataRepository
datarepository::DataRepository * _dataRepository
Definition: growthcurvetransform.h:26
moja::modules::cbm::GrowthCurveTransform::value
const DynamicVar & value() const override
Definition: growthcurvetransform.cpp:111
moja::modules::cbm::GrowthCurveTransform::_provider
std::shared_ptr< datarepository::IProviderRelationalInterface > _provider
Definition: growthcurvetransform.h:27
moja::modules::cbm::GrowthCurveTransform::buildSql
const std::string buildSql(const DynamicObject &classifierSet) const
Definition: growthcurvetransform.cpp:65
moja::modules::cbm::GrowthCurveTransform::_csetVar
const flint::IVariable * _csetVar
Definition: growthcurvetransform.h:28
moja
Definition: ageclasshelper.cpp:10