Example #1
0
void
cluster_helper_c::create_tags_for_track_statistics(KaxTags &tags,
                                                   std::string const &writing_app,
                                                   boost::posix_time::ptime const &writing_date) {
  auto writing_date_str = !writing_date.is_not_a_date_time() ? mtx::date_time::to_string(writing_date, "%Y-%m-%d %H:%M:%S") : "1970-01-01 00:00:00";

  for (auto const &ptzr : g_packetizers) {
    auto track_uid    = ptzr.packetizer->get_uid();
    auto const &stats = m->track_statistics[track_uid];
    auto bps          = stats.get_bits_per_second();
    auto duration     = stats.get_duration();

    mtx::tags::remove_simple_tags_for<KaxTagTrackUID>(tags, track_uid, "BPS");
    mtx::tags::remove_simple_tags_for<KaxTagTrackUID>(tags, track_uid, "DURATION");
    mtx::tags::remove_simple_tags_for<KaxTagTrackUID>(tags, track_uid, "NUMBER_OF_FRAMES");
    mtx::tags::remove_simple_tags_for<KaxTagTrackUID>(tags, track_uid, "NUMBER_OF_BYTES");

    auto tag = mtx::tags::find_tag_for<KaxTagTrackUID>(tags, track_uid, mtx::tags::Movie, true);

    mtx::tags::set_target_type(*tag, mtx::tags::Movie, "MOVIE");

    mtx::tags::set_simple(*tag, "BPS",              to_string(bps ? *bps : 0));
    mtx::tags::set_simple(*tag, "DURATION",         format_timecode(duration ? *duration : 0));
    mtx::tags::set_simple(*tag, "NUMBER_OF_FRAMES", to_string(stats.get_num_frames()));
    mtx::tags::set_simple(*tag, "NUMBER_OF_BYTES",  to_string(stats.get_num_bytes()));

    mtx::tags::set_simple(*tag, "_STATISTICS_WRITING_APP",      writing_app);
    mtx::tags::set_simple(*tag, "_STATISTICS_WRITING_DATE_UTC", writing_date_str);
    mtx::tags::set_simple(*tag, "_STATISTICS_TAGS",             "BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES");
  }

  m->track_statistics.clear();
}
void readTag( const std::string& tag, Session& session, const boost::posix_time::ptime& snapshotTime ){
  IOVProxy proxy;
  if( snapshotTime.is_not_a_date_time() ) proxy = session.readIov( tag );
  else proxy = session.readIov( tag, snapshotTime );
  std::cout <<"> iov loaded size="<<proxy.loadedSize()<<std::endl;
  std::cout <<"> iov sequence size="<<proxy.sequenceSize()<<std::endl;
  IOVProxy::Iterator iovIt = proxy.find( 107 );
  if( iovIt == proxy.end() ){
    std::cout <<">[0] not found!"<<std::endl;
  } else {
    cond::Iov_t val = *iovIt;
    std::cout <<"#[0] iov since="<<val.since<<" till="<<val.till<<" pid="<<val.payloadId<<std::endl;
    boost::shared_ptr<std::string> pay0 = session.fetchPayload<std::string>( val.payloadId );
    std::cout <<"#[0] payload="<<*pay0<<std::endl;
  }
  iovIt = proxy.find( 235 );
  if( iovIt == proxy.end() ){
    std::cout <<">[1] not found!"<<std::endl;
  } else {
    cond::Iov_t val = *iovIt;
    std::cout <<"#[1] iov since="<<val.since<<" till="<<val.till<<" pid="<<val.payloadId<<std::endl;
    boost::shared_ptr<std::string> pay0 = session.fetchPayload<std::string>( val.payloadId );
    std::cout <<"#[1] payload="<<*pay0<<std::endl;
  }
}
Example #3
0
/** Sets the date and time using a boost::posix_time::ptime
 *
 * @param _ptime :: boost::posix_time::ptime date and time.
 */
void DateAndTime::set_from_ptime(boost::posix_time::ptime _ptime) {
  if (_ptime.is_special()) {
    // --- SPECIAL VALUES! ----
    if (_ptime.is_infinity() || _ptime.is_pos_infinity())
      _nanoseconds = MAX_NANOSECONDS;
    if (_ptime.is_neg_infinity())
      _nanoseconds = MIN_NANOSECONDS;
    if (_ptime.is_not_a_date_time())
      _nanoseconds = MIN_NANOSECONDS;
  } else {
    _nanoseconds =
        nanosecondsFromDuration(_ptime - DateAndTimeHelpers::GPS_EPOCH);

    // Check for overflow
    if (_nanoseconds < 0) {
      if (_ptime.date().year() >= 1990) {
        // nanoseconds is negative despite the year being higher than 1990
        // ... means overflow occured
        this->setToMaximum();
      }
    } else if (_nanoseconds > 0) {
      if (_ptime.date().year() < 1990) {
        // Nanoseconds is positive but the year is below 1990 = it should be
        // negative!
        this->setToMinimum();
      }
    }
  }
}
std::vector<DateTimeEventsManager::EventStartTimePair> DateTimeEventsManager::GetEventsNearestStartTime() const
{
	std::vector<EventStartTimePair> result;

	const std::vector<DateTimeEvent*> dateTimeEvents = GetDateTimeEvents();
	for (auto it = dateTimeEvents.begin(); it != dateTimeEvents.end(); ++it)
	{
		DateTimeEvent* event = *it;

		const boost::posix_time::ptime eventStartTime = GetEventStartTime(event);

		// Skip once events in the past.
		if (eventStartTime.is_not_a_date_time())
		{
			continue;
		}

		result.push_back(std::make_pair(event, eventStartTime));
	}

	std::sort(result.begin(), result.end(),
		boost::bind(&EventStartTimePair::second, _1) < boost::bind(&EventStartTimePair::second, _2));

	return result;
}
Example #5
0
boost::posix_time::ptime ptime_truncate_milliseconds(const boost::posix_time::ptime &t)
{
	if(t.is_not_a_date_time())
		return t;

	boost::posix_time::time_duration time = t.time_of_day();
	return boost::posix_time::ptime(t.date(), boost::posix_time::time_duration(time.hours(), time.minutes(), time.seconds()));
}
Example #6
0
static QString boostTimeToQString(const boost::posix_time::ptime &boostDate) {
  if (boostDate.is_not_a_date_time()) return "";
  struct std::tm tm;
  try {
    tm = boost::posix_time::to_tm(boostDate);
  } catch(std::exception e) {
      return "";
  }
  const time_t t = mktime(&tm);
  const QDateTime dt = QDateTime::fromTime_t(t);
  return dt.toString(Qt::DefaultLocaleLongDate);
}
Example #7
0
 void update( const boost::posix_time::ptime& t, bool commit = false )
 {
     //std::cerr << "--> a: t_: " << ( t_ ? boost::posix_time::to_iso_string( *t_ ) : "none" ) << " t: " << boost::posix_time::to_iso_string( t ) << " commit: " << commit << std::endl;
     switch( how_ )
     {
         case first:
             if( !t_ ) { t_ = t; }
             break;
         case last:
             if( commit ) { t_ = t; }
             break;
         case max:
             if( !t_ ) { t_ = t; }
             if( t_->is_not_a_date_time() ) { break; }
             if( t.is_not_a_date_time() ) { t_ = boost::posix_time::not_a_date_time; } else if( *t_ < t ) { t_ = t; }
             break;
         case mean:
             if( t.is_special() || t.is_not_a_date_time() ) { break; }
             if( t_ && t_->is_not_a_date_time() ) { break; }
             if( t_ ) { ++count_; t_ = *t_ + ( t - *t_ ) / count_; }
             else { count_ = 1; t_ = t; }
             break;
         case middle:
             if( !t_ ) { t_ = t; }
             if( !commit ) { break; }
             if( t.is_special() || t.is_not_a_date_time() ) { t_ = boost::posix_time::not_a_date_time; }
             if( !t_->is_not_a_date_time() ) { t_ = *t_ + ( t - *t_ ) / 2; }
             break;
         case min:
             if( !t_ ) { t_ = t; }
             if( t_->is_not_a_date_time() ) { break; }
             if( t.is_not_a_date_time() ) { t_ = boost::posix_time::not_a_date_time; } else if( *t_ > t ) { t_ = t; }
             break;
     }
     //std::cerr << "--> b: t_: " << ( t_ ? boost::posix_time::to_iso_string( *t_ ) : "none" ) << std::endl << std::endl;
 }
Example #8
0
void
PreparedStatement::bind(size_t param, const boost::posix_time::ptime &value)
{
    if (value.is_not_a_date_time()) {
        bind(param, Null());
        return;
    }
    ensure(param);
    m_paramValues[param - 1].resize(8);
    long long ticks = (value - postgres_epoch).total_microseconds();
    *(long long *)&m_paramValues[param - 1][0] = byteswapOnLittleEndian(*(long long *)&ticks);
    m_params[param - 1] = m_paramValues[param - 1].c_str();
    m_paramLengths[param - 1] = m_paramValues[param - 1].size();
    m_paramFormats[param - 1] = 1;
    setType(param, TIMESTAMPOID);
}
Example #9
0
void HistoryManager::appendEntryToFile(std::ofstream &os, bool isSent, const boost::posix_time::ptime &saveTime, const std::string &content)
{
    if(saveTime.is_not_a_date_time())
        return;
    if(os.tellp() != 0)
        os << std::endl;
    os << "[" << FormattingUtils::dateToStr(saveTime) << "]";
    if(isSent)
    {
        os << "-S-";
    }
    else
    {
        os << "-R-";
    }
    os << content;
}
Example #10
0
double getAlpha(
    boost::posix_time::ptime& tstamp_prev,
    double max_life)
{
    auto now = boost::posix_time::microsec_clock::universal_time();
    double alpha = 1.0;  // Default is 100% opacity.
    if (!tstamp_prev.is_not_a_date_time()) 
    {
        // alpha = min {delta_t, max_life} / max_life
        auto tdelta = now - tstamp_prev;
        alpha = tdelta.total_nanoseconds()/1000000000.;
        alpha = std::min(alpha, max_life);
        alpha /= max_life;
    }
    tstamp_prev = now;
    return alpha;
}
boost::posix_time::ptime FileEndpoint::seek(boost::posix_time::ptime seek){
    std::ifstream::pos_type position = 0;
    boost::posix_time::ptime timestamp;
    try{
        in_file_stream.clear();
        if(!seek.is_not_a_date_time()){
            std::string line;
            while(std::getline(in_file_stream, line)){
                std::istringstream iss(line);
                boost::posix_time::time_input_facet *timefacet = new boost::posix_time::time_input_facet(timestamp_format.c_str());
                iss.imbue(std::locale(iss.getloc(), timefacet));
                iss >> timestamp;
                if(timestamp>seek){
                    break;
                }
                position = in_file_stream.tellg();
            }
        }
        in_file_stream.clear();
        in_file_stream.seekg(position);
    }catch (std::ifstream::failure e){
Example #12
0
bool ptime_is_valid(const boost::posix_time::ptime &t)
{
	return (t.is_not_a_date_time() == false);
}
Example #13
0
    TimeMap::TimeMap(boost::posix_time::ptime startDate) {
        if (startDate.is_not_a_date_time())
          throw std::invalid_argument("Input argument not properly initialized.");

        m_timeList.push_back( boost::posix_time::ptime(startDate) );
    }