rawmerge.hpp: start implementation of merge
This commit is contained in:
parent
7316d59c2c
commit
1ee05c03a2
@ -89,9 +89,8 @@ public:
|
||||
}
|
||||
|
||||
// provide/set new raw file
|
||||
void set_file(std::string rawfile)
|
||||
void set_file(std::string rawfile, bool showlog = false)
|
||||
{
|
||||
std::cout<<"raw_eater::set_file "<<rawfile<<"\n";
|
||||
// set file
|
||||
rawfile_ = rawfile;
|
||||
|
||||
@ -101,7 +100,7 @@ public:
|
||||
datmes_.clear();
|
||||
|
||||
// do setup and conversion
|
||||
setup_and_conversion(true);
|
||||
setup_and_conversion(showlog);
|
||||
}
|
||||
|
||||
// set up and conversion
|
||||
|
@ -25,6 +25,9 @@ private:
|
||||
std::vector<std::vector<double>> channels_;
|
||||
std::vector<double> timeseries_;
|
||||
|
||||
// timestep of original timeseries
|
||||
double dt_;
|
||||
|
||||
// temporal unit and channel meta data
|
||||
std::string temp_unit_;
|
||||
std::vector<std::string> channel_names_;
|
||||
@ -49,33 +52,108 @@ public:
|
||||
|
||||
}
|
||||
|
||||
// get list of channel names
|
||||
std::vector<std::string> get_channel_names()
|
||||
{
|
||||
return this->channel_names_;
|
||||
}
|
||||
|
||||
// get unified timeseries
|
||||
std::vector<double> get_time_series()
|
||||
{
|
||||
return this->timeseries_;
|
||||
}
|
||||
|
||||
// get array representation i-th channel
|
||||
std::vector<double> get_channel(long unsigned int chidx)
|
||||
{
|
||||
return chidx >= 0 && chidx < this->channels_.size() ?
|
||||
this->channels_[chidx] : std::vector<double>();
|
||||
}
|
||||
|
||||
// add a single channel and its associated time series
|
||||
bool add_channel(std::string rawfile)
|
||||
bool add_channel(std::string rawfile, bool log = false)
|
||||
{
|
||||
// set raw file and perform conversion
|
||||
this->set_file(rawfile);
|
||||
this->set_file(rawfile,false);
|
||||
|
||||
// show channel name, unit, timestep, time unit, etc.
|
||||
if ( log )
|
||||
{
|
||||
std::cout<<this->get_name()<<" ["<<this->get_unit()<<"]"<<"\n";
|
||||
std::cout<<"Time ["<<this->get_temp_unit()<<"]"<<"\n";
|
||||
for ( unsigned long int i = 0; i < 5; i++ ) std::cout<<this->get_time()[i]<<"\n";
|
||||
for ( unsigned long int i = 0; i < 5; i++ ) std::cout<<this->get_data()[i]<<"\n";
|
||||
std::cout<<"lenght of channel "<<this->get_time().size()<<"\n";
|
||||
std::cout<<"\n";
|
||||
}
|
||||
|
||||
// add first/initial time series (and channel data)
|
||||
if ( timeseries_.size() == 0 && channels_.size() == 0 )
|
||||
if ( this->get_valid() && timeseries_.size() == 0 && channels_.size() == 0 )
|
||||
{
|
||||
std::cout<<"adding first channel\n";
|
||||
std::cout<<"adding initial channel "<<rawfile<<"\n\n";
|
||||
|
||||
// insert timeseries and its unit
|
||||
timeseries_ = this->get_time();
|
||||
temp_unit_ = this->get_temp_unit();
|
||||
this->timeseries_ = this->get_time();
|
||||
this->temp_unit_ = this->get_temp_unit();
|
||||
|
||||
// get timestep size
|
||||
this->dt_ = this->get_dt();
|
||||
|
||||
// insert channel data and its meta data
|
||||
channels_.push_back(this->get_data());
|
||||
channel_names_.push_back(this->get_name() + std::string(" [")
|
||||
this->channels_.push_back(this->get_data());
|
||||
this->channel_names_.push_back(this->get_name() + std::string(" [")
|
||||
+ this->get_unit() + std::string("]"));
|
||||
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
// TODO check consistency of time series, time unit, channels....
|
||||
std::cout<<"adding next channel "<<rawfile<<"\n\n";
|
||||
|
||||
// check consistency of temporal unit
|
||||
if ( this->get_temp_unit() == this->temp_unit_ )
|
||||
{
|
||||
// get time series
|
||||
std::vector<double> ts = this->get_time();
|
||||
|
||||
// compare start/end of timeseries (define tolerance)
|
||||
double deltat = 10*this->dt_;
|
||||
if ( ( this->timeseries_[0] - ts[0] < deltat )
|
||||
&& ( this->timeseries_.back() - ts.back() < deltat ) )
|
||||
{
|
||||
// submerge channels and their time series
|
||||
// TODO
|
||||
// this->merge_channels(this.timeseries_,this)
|
||||
|
||||
// insert channel data and its meta data
|
||||
this->channels_.push_back(this->get_data());
|
||||
this->channel_names_.push_back(this->get_name() + std::string(" [")
|
||||
+ this->get_unit() + std::string("]"));
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
// refuse to merge due to inconsistent start of timeseries
|
||||
std::cerr<<"rawmerge: add_channel '"<<rawfile
|
||||
<<"' : inconsistent start of time series, i.e. "
|
||||
<<timeseries_[0]<<" vs. "<<ts[0]<<"\n";
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// refuse to merge due to different temporal units
|
||||
std::cerr<<"rawmerge: add_channel '"<<rawfile
|
||||
<<"' : inconsistent time units\n";
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// print all data to file
|
||||
void write_table(std::string filename, char delimiter = ',', int precision = 6, int width = 25)
|
||||
|
@ -33,7 +33,9 @@ int main(int argc, char* argv[])
|
||||
// raw_eater eatraw(rawfile,true);
|
||||
|
||||
// declare instance of "raw_merger"
|
||||
raw_merger eatmea(rawfile);
|
||||
raw_merger eatmea;
|
||||
eatmea.add_channel(rawfile,true);
|
||||
eatmea.add_channel("smp/VehicleSpeed_HS.raw",true);
|
||||
|
||||
//eatraw.show_markers();
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user