##// END OF EJS Templates
Added basic cache tests for new VC...
Added basic cache tests for new VC Signed-off-by: Alexis Jeandet <alexis.jeandet@member.fsf.org>

File last commit:

r10:1c3b4c2c9c11
r11:d2d15e1be6f5
Show More
VariableController2.cpp
190 lines | 6.6 KiB | text/x-c | CppLexer
/ src / Variable / VariableController2.cpp
First init from SciQLop Core module...
r0 #include "Variable/VariableController2.h"
Added DateTimeRange unit Tests...
r6 #include "Variable/VariableSynchronizationGroup2.h"
Basic serial variable creation and update...
r2 #include <Common/containers.h>
#include <Common/debug.h>
#include <Data/DataProviderParameters.h>
Many fixes plus implemented var synchronization...
r9 #include <Data/DateTimeRangeHelper.h>
#include <Variable/VariableCacheStrategyFactory.h>
First init from SciQLop Core module...
r0
Basic serial variable creation and update...
r2 class VariableController2::VariableController2Private
First init from SciQLop Core module...
r0 {
Many fixes plus implemented var synchronization...
r9 QMap<QUuid,std::shared_ptr<Variable>> _variables;
Basic serial variable creation and update...
r2 QMap<QUuid,std::shared_ptr<IDataProvider>> _providers;
Added DateTimeRange unit Tests...
r6 QMap<QUuid,std::shared_ptr<VariableSynchronizationGroup2>> _synchronizationGroups;
Many fixes plus implemented var synchronization...
r9 std::unique_ptr<VariableCacheStrategy> _cacheStrategy;
Added more features in DateTimeRange to prepare variable synchronization...
r8 bool p_contains(std::shared_ptr<Variable> variable)
{
return _providers.contains(variable->ID());
}
bool v_contains(std::shared_ptr<Variable> variable)
{
return SciQLop::containers::contains(this->_variables, variable);
}
bool sg_contains(std::shared_ptr<Variable> variable)
{
return _synchronizationGroups.contains(variable->ID());
}
Many fixes plus implemented var synchronization...
r9
void _changeRange(std::shared_ptr<Variable> var, DateTimeRange r)
{
auto provider = _providers[var->ID()];
Added basic usage of cache in VC, not tested yet...
r10 DateTimeRange newCacheRange;
std::vector<DateTimeRange> missingRanges;
if(DateTimeRangeHelper::hasnan(var->cacheRange()))
{
newCacheRange = _cacheStrategy->computeRange(r,r);
missingRanges = {newCacheRange};
}
else
{
newCacheRange = _cacheStrategy->computeRange(var->cacheRange(),r);
missingRanges = newCacheRange - var->cacheRange();
}
Many fixes plus implemented var synchronization...
r9 for(auto range:missingRanges)
{
auto data = provider->getData(DataProviderParameters{{range},var->metadata()});
var->mergeDataSeries(data);
}
Added basic usage of cache in VC, not tested yet...
r10 var->setCacheRange(r);
Many fixes plus implemented var synchronization...
r9 var->setRange(r);
}
First init from SciQLop Core module...
r0 public:
VariableController2Private(QObject* parent=Q_NULLPTR)
Many fixes plus implemented var synchronization...
r9 :_cacheStrategy(VariableCacheStrategyFactory::createCacheStrategy(CacheStrategy::Proportional))
Basic serial variable creation and update...
r2 {
Q_UNUSED(parent);
}
First init from SciQLop Core module...
r0 ~VariableController2Private() = default;
Basic serial variable creation and update...
r2
Added basic usage of cache in VC, not tested yet...
r10 std::shared_ptr<Variable> createVariable(const QString &name, const QVariantHash &metadata, std::shared_ptr<IDataProvider> provider)
First init from SciQLop Core module...
r0 {
Basic serial variable creation and update...
r2 auto newVar = std::make_shared<Variable>(name,metadata);
Many fixes plus implemented var synchronization...
r9 this->_variables[newVar->ID()] = newVar;
Basic serial variable creation and update...
r2 this->_providers[newVar->ID()] = provider;
Added DateTimeRange unit Tests...
r6 this->_synchronizationGroups[newVar->ID()] = std::make_shared<VariableSynchronizationGroup2>(newVar->ID());
Basic serial variable creation and update...
r2 return newVar;
}
void deleteVariable(std::shared_ptr<Variable> variable)
{
Added more features in DateTimeRange to prepare variable synchronization...
r8 /*
* Removing twice a var is ok but a var without provider has to be a hard error
* this means we got the var controller in an inconsistent state
*/
if(v_contains(variable))
Many fixes plus implemented var synchronization...
r9 this->_variables.remove(variable->ID());
Added more features in DateTimeRange to prepare variable synchronization...
r8 if(p_contains(variable))
this->_providers.remove(variable->ID());
else
Many fixes plus implemented var synchronization...
r9 SCIQLOP_ERROR(VariableController2Private, "No provider found for given variable");
Basic serial variable creation and update...
r2 }
void changeRange(std::shared_ptr<Variable> variable, DateTimeRange r)
{
Added more features in DateTimeRange to prepare variable synchronization...
r8 if(p_contains(variable))
Basic serial variable creation and update...
r2 {
Added basic usage of cache in VC, not tested yet...
r10 if(!DateTimeRangeHelper::hasnan(r))
Many fixes plus implemented var synchronization...
r9 {
auto transformation = DateTimeRangeHelper::computeTransformation(variable->range(),r);
auto group = _synchronizationGroups[variable->ID()];
if(std::holds_alternative<DateTimeRangeTransformation>(transformation))
{
for(auto varId:group->variables())
{
auto var = _variables[varId];
auto newRange = var->range().transform(std::get<DateTimeRangeTransformation>(transformation));
_changeRange(var,newRange);
}
}
else // force new range to all variables -> may be weird if more than one var in the group
// @TODO ensure that there is no side effects
{
for(auto varId:group->variables())
{
auto var = _variables[varId];
_changeRange(var,r);
}
}
}
else
{
SCIQLOP_ERROR(VariableController2Private, "Invalid range containing NaN");
}
Basic serial variable creation and update...
r2 }
else
{
Many fixes plus implemented var synchronization...
r9 SCIQLOP_ERROR(VariableController2Private, "No provider found for given variable");
Basic serial variable creation and update...
r2 }
}
Added more features in DateTimeRange to prepare variable synchronization...
r8 void synchronize(std::shared_ptr<Variable> var, std::shared_ptr<Variable> with)
{
if(v_contains(var) && v_contains(with))
{
if(sg_contains(var) && sg_contains(with))
{
auto dest_group = this->_synchronizationGroups[with->ID()];
this->_synchronizationGroups[var->ID()] = dest_group;
dest_group->addVariable(var->ID());
}
else
{
Many fixes plus implemented var synchronization...
r9 SCIQLOP_ERROR(VariableController2Private, "At least one of the given variables isn't in a sync group");
Added more features in DateTimeRange to prepare variable synchronization...
r8 }
}
else
{
Many fixes plus implemented var synchronization...
r9 SCIQLOP_ERROR(VariableController2Private, "At least one of the given variables is not found");
Added more features in DateTimeRange to prepare variable synchronization...
r8 }
}
Basic serial variable creation and update...
r2
Many fixes plus implemented var synchronization...
r9 const std::set<std::shared_ptr<Variable>> variables()
Basic serial variable creation and update...
r2 {
Many fixes plus implemented var synchronization...
r9 std::set<std::shared_ptr<Variable>> vars;
for(auto var:_variables.values())
{
vars.insert(var);
}
return vars;
First init from SciQLop Core module...
r0 }
Basic serial variable creation and update...
r2
First init from SciQLop Core module...
r0 };
VariableController2::VariableController2()
:impl{spimpl::make_unique_impl<VariableController2Private>()}
{}
std::shared_ptr<Variable> VariableController2::createVariable(const QString &name, const QVariantHash &metadata, std::shared_ptr<IDataProvider> provider, const DateTimeRange &range)
{
Added basic usage of cache in VC, not tested yet...
r10 auto var = impl->createVariable(name, metadata, provider);
Basic serial variable creation and update...
r2 emit variableAdded(var);
Added basic usage of cache in VC, not tested yet...
r10 if(!DateTimeRangeHelper::hasnan(range))
Many fixes plus implemented var synchronization...
r9 impl->changeRange(var,range);
else
SCIQLOP_ERROR(VariableController2, "Creating a variable with default constructed DateTimeRange is an error");
Basic serial variable creation and update...
r2 return var;
}
void VariableController2::deleteVariable(std::shared_ptr<Variable> variable)
{
impl->deleteVariable(variable);
emit variableDeleted(variable);
}
void VariableController2::changeRange(std::shared_ptr<Variable> variable, DateTimeRange r)
{
impl->changeRange(variable, r);
}
Many fixes plus implemented var synchronization...
r9 const std::set<std::shared_ptr<Variable> > VariableController2::variables()
Basic serial variable creation and update...
r2 {
return impl->variables();
First init from SciQLop Core module...
r0 }
Added more features in DateTimeRange to prepare variable synchronization...
r8 void VariableController2::synchronize(std::shared_ptr<Variable> var, std::shared_ptr<Variable> with)
{
impl->synchronize(var, with);
}