unix timestamp
This commit is contained in:
parent
9887381d74
commit
a307da51aa
@ -106,6 +106,27 @@ void tdm_ripper::parse_structure()
|
|||||||
group_id_.push_back(anode.attribute("id").value());
|
group_id_.push_back(anode.attribute("id").value());
|
||||||
group_name_.push_back(anode.child_value("name"));
|
group_name_.push_back(anode.child_value("name"));
|
||||||
num_channels_group_.push_back(numchann);
|
num_channels_group_.push_back(numchann);
|
||||||
|
|
||||||
|
// get time-stamp
|
||||||
|
pugi::xml_node insatt = anode.child("instance_attributes");
|
||||||
|
std::pair<std::string,std::string> startstop;
|
||||||
|
for ( pugi::xml_node bnode: insatt.children() )
|
||||||
|
{
|
||||||
|
assert( std::string(bnode.name()).compare("double_attribute") == 0 );
|
||||||
|
if ( std::string(bnode.attribute("name").value()).compare("Starttime") == 0 )
|
||||||
|
{
|
||||||
|
startstop.first = bnode.child_value();
|
||||||
|
}
|
||||||
|
else if ( std::string(bnode.attribute("name").value()).compare("Stoptime") == 0 )
|
||||||
|
{
|
||||||
|
startstop.second = bnode.child_value();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
assert ( false && "unexpected attribute name" );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
group_timestamp_.push_back(startstop);
|
||||||
}
|
}
|
||||||
if ( numchann == 0 ) num_empty_groups_++;
|
if ( numchann == 0 ) num_empty_groups_++;
|
||||||
}
|
}
|
||||||
@ -289,8 +310,10 @@ void tdm_ripper::list_groups(std::ostream& gout, int width, int maxshow)
|
|||||||
gout<<std::setw(width)<<"group id";
|
gout<<std::setw(width)<<"group id";
|
||||||
gout<<std::setw(width)<<"group name";
|
gout<<std::setw(width)<<"group name";
|
||||||
gout<<std::setw(width)<<"num channels";
|
gout<<std::setw(width)<<"num channels";
|
||||||
|
gout<<std::setw(2*width)<<"start time";
|
||||||
|
gout<<std::setw(2*width)<<"stop time";
|
||||||
gout<<"\n";
|
gout<<"\n";
|
||||||
gout<<std::setfill('-')<<std::setw(4*width+1)<<"\n";
|
gout<<std::setfill('-')<<std::setw(8*width+1)<<"\n";
|
||||||
gout<<std::setfill(' ');
|
gout<<std::setfill(' ');
|
||||||
|
|
||||||
for ( int i = 0; i < num_groups_ && i < maxshow; i++ )
|
for ( int i = 0; i < num_groups_ && i < maxshow; i++ )
|
||||||
@ -299,6 +322,8 @@ void tdm_ripper::list_groups(std::ostream& gout, int width, int maxshow)
|
|||||||
gout<<std::setw(width)<<group_id_[i];
|
gout<<std::setw(width)<<group_id_[i];
|
||||||
gout<<std::setw(width)<<group_name_[i];
|
gout<<std::setw(width)<<group_name_[i];
|
||||||
gout<<std::setw(width)<<num_channels_group_[i];
|
gout<<std::setw(width)<<num_channels_group_[i];
|
||||||
|
gout<<std::setw(2*width)<<time_stamp(i,true);
|
||||||
|
gout<<std::setw(2*width)<<time_stamp(i,false);
|
||||||
gout<<"\n";
|
gout<<"\n";
|
||||||
}
|
}
|
||||||
gout<<"\n\n";
|
gout<<"\n\n";
|
||||||
@ -311,6 +336,8 @@ void tdm_ripper::list_groups(std::ostream& gout, int width, int maxshow)
|
|||||||
gout<<std::setw(width)<<group_id_[i];
|
gout<<std::setw(width)<<group_id_[i];
|
||||||
gout<<std::setw(width)<<group_name_[i];
|
gout<<std::setw(width)<<group_name_[i];
|
||||||
gout<<std::setw(width)<<num_channels_group_[i];
|
gout<<std::setw(width)<<num_channels_group_[i];
|
||||||
|
gout<<std::setw(2*width)<<time_stamp(i,true);
|
||||||
|
gout<<std::setw(2*width)<<time_stamp(i,false);
|
||||||
gout<<"\n";
|
gout<<"\n";
|
||||||
}
|
}
|
||||||
gout<<"\n\n";
|
gout<<"\n\n";
|
||||||
|
@ -32,10 +32,10 @@ class tdm_ripper
|
|||||||
int num_channels_, num_groups_;
|
int num_channels_, num_groups_;
|
||||||
std::vector<std::string> channel_id_, inc_id_, units_, channel_name_;
|
std::vector<std::string> channel_id_, inc_id_, units_, channel_name_;
|
||||||
std::vector<std::string> group_id_, group_name_;
|
std::vector<std::string> group_id_, group_name_;
|
||||||
|
std::vector<std::pair<std::string,std::string>> group_timestamp_;
|
||||||
std::vector<int> num_channels_group_;
|
std::vector<int> num_channels_group_;
|
||||||
std::vector<int> channels_group_;
|
std::vector<int> channels_group_;
|
||||||
std::vector<int> channel_ext_;
|
std::vector<int> channel_ext_;
|
||||||
// evtl. get group time_stamp of .tdm file in the unix format, i.e. #seconds since 01.01.0000 with average year having 365+97/400 = 365.2425 days
|
|
||||||
|
|
||||||
// minimum/maximum value in particular channel (is provided in .tdm file as float)
|
// minimum/maximum value in particular channel (is provided in .tdm file as float)
|
||||||
std::vector<std::pair<double,double>> minmax_;
|
std::vector<std::pair<double,double>> minmax_;
|
||||||
@ -248,6 +248,52 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// evtl. get group time_stamp of .tdm file given in unix format
|
||||||
|
std::string unix_timestamp(std::string unixts)
|
||||||
|
{
|
||||||
|
// average year of Gregorian calender
|
||||||
|
const double avgdaysofyear = 365 + 1./4 - 1./100 + 1./400;
|
||||||
|
|
||||||
|
// std::tm epochStart = {};
|
||||||
|
// epochStart.tm_sec = 0;
|
||||||
|
// epochStart.tm_min = 0;
|
||||||
|
// epochStart.tm_hour = 0;
|
||||||
|
// epochStart.tm_mday = 1;
|
||||||
|
// epochStart.tm_mon = 0;
|
||||||
|
// epochStart.tm_year = 2040;
|
||||||
|
// epochStart.tm_wday = 0;
|
||||||
|
// epochStart.tm_yday = 0;
|
||||||
|
// epochStart.tm_isdst = -1;
|
||||||
|
// std::time_t epochtst = std::mktime(&epochStart);
|
||||||
|
|
||||||
|
// convert string to long int = number of second since 0000/01/01 00:00
|
||||||
|
long int ts = atol(unixts.c_str());
|
||||||
|
|
||||||
|
// int year = (int)floor((double)ts/(avgdaysofyear*86400));
|
||||||
|
// int month = (int)floor((ts-year*avgdaysofyear*86400)/(30*86400));
|
||||||
|
// int day = (int)floor((ts-year*avgdaysofyear*86400-month*30*86400)/86400);
|
||||||
|
// int daysec = ts-year*avgdaysofyear*86400-month*30*86400-day*86400;
|
||||||
|
// int hour = (int)floor(daysec/3600.);
|
||||||
|
// int mins = (int)floor((daysec-hour*3600)/60.);
|
||||||
|
// int secs = (int)floor((daysec-hour*3600-mins*60));
|
||||||
|
|
||||||
|
// return std::to_string(year)+"-"+std::to_string(month)+"-"+std::to_string(day)
|
||||||
|
// +" "+std::to_string(hour)+":"+std::to_string(mins)+":"+std::to_string(secs);
|
||||||
|
|
||||||
|
// use STL to convert timestamp
|
||||||
|
// std::time_t tstime = std::time_t(ts)-epochtst;
|
||||||
|
std::time_t tstime = ts - 1970*avgdaysofyear*86400;
|
||||||
|
return std::ctime(&tstime);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string time_stamp(int groupid, bool startstop = true)
|
||||||
|
{
|
||||||
|
assert( groupid >= 0 && groupid < num_groups_ );
|
||||||
|
|
||||||
|
return startstop ? unix_timestamp(group_timestamp_[groupid].first)
|
||||||
|
: unix_timestamp(group_timestamp_[groupid].second);
|
||||||
|
}
|
||||||
|
|
||||||
void list_datatypes();
|
void list_datatypes();
|
||||||
|
|
||||||
// convert array of chars to single integer or floating point double
|
// convert array of chars to single integer or floating point double
|
||||||
|
Loading…
x
Reference in New Issue
Block a user