void WorkInfoCacheTester::fullDay()
{
    Calendar cal("Test");
    QDate wdate(2012,1,2);

    QTime t1(0,0,0);
    DateTime wdt1(wdate, t1);
    DateTime wdt2(wdate.addDays( 1 ), t1);
    long length = ( wdt2 - wdt1 ).milliseconds();
    CalendarDay *day = new CalendarDay(wdate, CalendarDay::Working);
    day->addInterval(TimeInterval(t1, length));
    cal.addDay(day);
    QVERIFY(cal.findDay(wdate) == day);

    Resource r;
    r.setCalendar( &cal );
    const Resource::WorkInfoCache &wic = r.workInfoCache();
    QVERIFY( ! wic.isValid() );

    r.calendarIntervals( wdt1, wdt2 );
    qDebug()<<wic.intervals.map();
    QCOMPARE( wic.intervals.map().count(), 1 );

    day = new CalendarDay(wdt2.date(), CalendarDay::Working);
    day->addInterval(TimeInterval(t1, length));
    cal.addDay(day);

    r.calendarIntervals( wdt1, DateTime( wdt2.addDays( 2 ) ) );
    qDebug()<<wic.intervals.map();
    QCOMPARE( wic.intervals.map().count(), 2 );
}
/******************************************************************************
* Calculates the largest time interval containing the given time during
* which the controller's value does not change.
******************************************************************************/
TimeInterval KeyframeController::validityInterval(TimePoint time)
{
	OVITO_ASSERT(areKeysSorted());
	if(keys().empty())
		return TimeInterval::infinite();
	else if(time <= keys().front()->time())
		return TimeInterval(TimeNegativeInfinity(), keys().front()->time());
	else if(time >= keys().back()->time())
		return TimeInterval(keys().back()->time(), TimePositiveInfinity());
	else
		return TimeInterval(time);
}
Beispiel #3
0
/**  Returns an intersection of this interval with \a ti
     @param ti :: Time interval
     @return A valid time interval if this interval intersects with \a ti or
             an empty interval otherwise.
 */
TimeInterval TimeInterval::intersection(const TimeInterval& ti)const
{
    if (!isValid() || !ti.isValid()) return TimeInterval();

    DateAndTime t1 = begin();
    if (ti.begin() > t1) t1 = ti.begin();

    DateAndTime t2 = end();
    if (ti.end() < t2) t2 = ti.end();

    return t1 < t2? TimeInterval(t1,t2) : TimeInterval();

}
void CalendarTester::testSingleDay() {
    Calendar t("Test");
    QDate wdate(2006,1,2);
    DateTime before = DateTime(wdate.addDays(-1), QTime());
    DateTime after = DateTime(wdate.addDays(1), QTime());
    QTime t1(8,0,0);
    QTime t2(10,0,0);
    DateTime wdt1(wdate, t1);
    DateTime wdt2(wdate, t2);
    int length = t1.msecsTo( t2 );
    CalendarDay *day = new CalendarDay(wdate, CalendarDay::Working);
    day->addInterval(TimeInterval(t1, length));
    t.addDay(day);
    QVERIFY(t.findDay(wdate) == day);
    
    QVERIFY(t.hasInterval(after, DateTime( after.addDays(1))) == false);
    QVERIFY(t.hasInterval(before, DateTime(before.addDays(-1))) == false);
    
    QVERIFY(t.hasInterval(after, before) == false);
    QVERIFY(t.hasInterval(before, after));
    
    QVERIFY((t.firstAvailableAfter(after, DateTime(after.addDays(10)))).isValid() == false);
    QVERIFY((t.firstAvailableBefore(before, DateTime(before.addDays(-10)))).isValid() == false);
    
    QCOMPARE(t.firstAvailableAfter(before,after), wdt1);
    QCOMPARE(t.firstAvailableBefore(after, before), wdt2);
    
    Duration e(0, 2, 0);
    QCOMPARE((t.effort(before, after)).toString(), e.toString());
}
void WorkInfoCacheTester::addBefore()
{
    Calendar cal("Test");
    QDate wdate(2012,1,2);
    DateTime before = DateTime(wdate.addDays(-1), QTime());
    DateTime after = DateTime(wdate.addDays(1), QTime());
    QTime t1(8,0,0);
    QTime t2(10,0,0);
    QTime t3(12,0,0);
    QTime t4(14,0,0);
    DateTime wdt1(wdate, t1);
    DateTime wdt2(wdate, t2);
    int length = t1.msecsTo( t2 );
    CalendarDay *day = new CalendarDay(wdate, CalendarDay::Working);
    day->addInterval(TimeInterval(t1, length));
    length = t3.msecsTo( t4 );
    day->addInterval(TimeInterval(t3, length));
    cal.addDay(day);
    QVERIFY(cal.findDay(wdate) == day);

    Resource r;
    r.setCalendar( &cal );
    const Resource::WorkInfoCache &wic = r.workInfoCache();
    QVERIFY( ! wic.isValid() );

    r.calendarIntervals( before, after );
    qDebug()<<wic.intervals.map();
    QCOMPARE( wic.intervals.map().count(), 2 );

    wdt1 = wdt1.addDays( 1 );
    wdt2 = wdt2.addDays( 1 );
    day = new CalendarDay(wdt1.date(), CalendarDay::Working);
    day->addInterval(TimeInterval(t1, length));
    cal.addDay(day);

    // wdate: 8-10, 12-14
    // wdate+1: 8-10
    r.calendarIntervals( DateTime( wdate.addDays( 1 ), t1 ), DateTime( wdate.addDays( 1 ), t2 ) );
    qDebug()<<wic.intervals.map();
    QCOMPARE( wic.intervals.map().count(), 1 );

    r.calendarIntervals( DateTime( wdate, t3 ), DateTime( wdate, t4 ) );
    QCOMPARE( wic.intervals.map().count(), 2 );

    r.calendarIntervals( DateTime( wdate, t1 ), DateTime( wdate, t2 ) );
    QCOMPARE( wic.intervals.map().count(), 3 );
}
void CalendarTester::testTimezone()
{
    Calendar t("Test");
    QDate wdate(2006,1,2);
    DateTime before = DateTime(wdate.addDays(-1), QTime());
    DateTime after = DateTime(wdate.addDays(1), QTime());
    QTime t1(8,0,0);
    QTime t2(10,0,0);
    DateTime wdt1(wdate, t1);
    DateTime wdt2(wdate, t2);
    int length = t1.msecsTo( t2 );
    CalendarDay *day = new CalendarDay(wdate, CalendarDay::Working);
    day->addInterval(TimeInterval(t1, length));
    t.addDay(day);
    Debug::print( &t, "Time zone testing" );
    QVERIFY(t.findDay(wdate) == day);

    // local zone: Europe/Berlin ( 1 hours from London )
    KTimeZone lo = KSystemTimeZones::zone("Europe/London");
    QVERIFY( lo.isValid() );
    KDateTime dt1 = KDateTime( wdate, t1, lo ).addSecs( -2 * 3600 );
    KDateTime dt2 = KDateTime( wdate, t2, lo ).addSecs( 0 * 3600 );

    qDebug()<<KDateTime( wdt1 )<<KDateTime( wdt2 );
    qDebug()<<dt1<<dt2<<"("<<dt1.toLocalZone()<<dt2.toLocalZone()<<")";
    QCOMPARE(t.firstAvailableAfter( DateTime( dt1 ), after ), wdt1 );
    QCOMPARE(t.firstAvailableBefore( DateTime( dt2 ), before ), wdt2 );

    Duration e(0, 2, 0);
    QCOMPARE( t.effort( DateTime( dt1 ), DateTime( dt2 ) ).toString(), e.toString() );

    // local zone: Europe/Berlin ( 9 hours from America/Los_Angeles )
    KTimeZone la = KSystemTimeZones::zone("America/Los_Angeles");
    QVERIFY( la.isValid() );
    KDateTime dt3 = KDateTime( wdate, t1, la ).addSecs( -10 * 3600 );
    KDateTime dt4 = KDateTime( wdate, t2, la ).addSecs( -8 * 3600 );

    qDebug()<<KDateTime( wdt1 )<<KDateTime( wdt2 );
    qDebug()<<dt3<<dt4<<"("<<dt3.toLocalZone()<<dt4.toLocalZone()<<")";
    QCOMPARE(t.firstAvailableAfter( DateTime( dt3 ), after ), wdt1 );
    QCOMPARE(t.firstAvailableBefore( DateTime( dt4 ), before ), wdt2 );

    QCOMPARE( t.effort( DateTime( dt3 ), DateTime( dt4 ) ).toString(), e.toString() );

    QString s = "Test Cairo:";
    qDebug()<<s;
    // local zone: Europe/Berlin ( 1 hour from cairo )
    KTimeZone ca = KSystemTimeZones::zone("Africa/Cairo");
    KDateTime dt5 = KDateTime( wdate, t1, ca ).addSecs( 0 * 3600 );
    KDateTime dt6 = KDateTime( wdate, t2, ca ).addSecs( 2 * 3600 );

    qDebug()<<KDateTime( wdt1 )<<KDateTime( wdt2 );
    qDebug()<<dt5<<dt6<<"("<<dt5.toLocalZone()<<dt6.toLocalZone()<<")";
    QCOMPARE(t.firstAvailableAfter( DateTime( dt5 ), after ), wdt1 );
    QCOMPARE(t.firstAvailableBefore( DateTime( dt6 ), before ), wdt2 );

    QCOMPARE( t.effort( DateTime( dt5 ), DateTime( dt6 ) ).toString(), e.toString() );
}
bool AsyncPluginImpl::Start() {
  if (libusb_init(&m_context)) {
    OLA_WARN << "Failed to init libusb";
    return false;
  }

  OLA_DEBUG << "libusb debug level set to " << m_debug_level;
  libusb_set_debug(m_context, m_debug_level);

  m_use_hotplug = HotplugSupported();
  OLA_INFO << "HotplugSupported returned " << m_use_hotplug;
  if (m_use_hotplug) {
#ifdef HAVE_LIBUSB_HOTPLUG_API
    m_usb_thread.reset(new LibUsbHotplugThread(
          m_context, hotplug_callback, this));
#else
    OLA_FATAL << "Mismatch between m_use_hotplug and "
      " HAVE_LIBUSB_HOTPLUG_API";
    return false;
#endif
  } else {
    m_usb_thread.reset(new LibUsbSimpleThread(m_context));
  }
  m_usb_adaptor.reset(new AsyncronousLibUsbAdaptor(m_usb_thread.get()));

  // Setup the factories.
  m_widget_factories.push_back(new AnymauDMXFactory(m_usb_adaptor.get()));
  m_widget_factories.push_back(
      new EuroliteProFactory(m_usb_adaptor.get()));
  m_widget_factories.push_back(
      new JaRuleFactory(m_plugin_adaptor, m_usb_adaptor.get()));
  m_widget_factories.push_back(
      new ScanlimeFadecandyFactory(m_usb_adaptor.get()));
  m_widget_factories.push_back(new SunliteFactory(m_usb_adaptor.get()));
  m_widget_factories.push_back(new VellemanK8062Factory(m_usb_adaptor.get()));

  // If we're using hotplug, this starts the hotplug thread.
  if (!m_usb_thread->Init()) {
    STLDeleteElements(&m_widget_factories);
    m_usb_adaptor.reset();
    m_usb_thread.reset();
    return false;
  }

  if (!m_use_hotplug) {
    // Either we don't support hotplug or the setup failed.
    // As poor man's hotplug, we call libusb_get_device_list periodically to
    // check for new devices.
    m_scan_timeout = m_plugin_adaptor->RegisterRepeatingTimeout(
        TimeInterval(5, 0),
        NewCallback(this, &AsyncPluginImpl::ScanUSBDevices));

    // Call it immediately now.
    ScanUSBDevices();
  }

  return true;
}
void CalendarTester::workIntervals()
{
    Calendar t("Test");
    QDate wdate(2006,1,2);
    DateTime before = DateTime(wdate.addDays(-1), QTime());
    DateTime after = DateTime(wdate.addDays(1), QTime());
    QTime t1(8,0,0);
    QTime t2(10,0,0);
    DateTime wdt1( wdate, t1 );
    DateTime wdt2( wdate, t2 );
    int length = t1.msecsTo( t2 );
    CalendarDay *day = new CalendarDay(wdate, CalendarDay::Working);
    day->addInterval( TimeInterval( t1, length ) );
    t.addDay(day);
    QVERIFY(t.findDay(wdate) == day);
    
    AppointmentIntervalList lst = t.workIntervals( before, after, 100. );
    QCOMPARE( lst.map().count(), 1 );
    QCOMPARE( wdate, lst.map().values().first().startTime().date() );
    QCOMPARE( t1, lst.map().values().first().startTime().time() );
    QCOMPARE( wdate, lst.map().values().first().endTime().date() );
    QCOMPARE( t2, lst.map().values().first().endTime().time() );
    QCOMPARE( 100., lst.map().values().first().load() );
    
    QTime t3( 12, 0, 0 );
    day->addInterval( TimeInterval( t3, length ) );
    
    lst = t.workIntervals( before, after, 100. );
    Debug::print( lst );
    QCOMPARE( lst.map().count(), 2 );
    QCOMPARE( wdate, lst.map().values().first().startTime().date() );
    QCOMPARE( t1, lst.map().values().first().startTime().time() );
    QCOMPARE( wdate, lst.map().values().first().endTime().date() );
    QCOMPARE( t2, lst.map().values().first().endTime().time() );
    QCOMPARE( 100., lst.map().values().first().load() );
    
    QCOMPARE( wdate, lst.map().values().at( 1 ).startTime().date() );
    QCOMPARE( t3, lst.map().values().at( 1 ).startTime().time() );
    QCOMPARE( wdate, lst.map().values().at( 1 ).endTime().date() );
    QCOMPARE( t3.addMSecs( length ), lst.map().values().at( 1 ).endTime().time() );
    QCOMPARE( 100., lst.map().values().at( 1 ).load() );
}
void CalendarTester::workIntervalsFullDays()
{
    Calendar t("Test");
    QDate wdate(2006,1,2);
    DateTime before = DateTime(wdate.addDays(-1), QTime());
    DateTime after = DateTime(wdate.addDays(10), QTime());

    CalendarDay *day = new CalendarDay( wdate, CalendarDay::Working );
    day->addInterval( TimeInterval( QTime( 0, 0, 0), 24*60*60*1000 ) );
    t.addDay(day);

    QCOMPARE( day->numIntervals(), 1 );
    QVERIFY( day->intervalAt( 0 )->endsMidnight() );

    DateTime start = day->start();
    DateTime end = day->end();

    QCOMPARE( t.workIntervals( start, end, 100. ).map().count(), 1 );
    QCOMPARE( t.workIntervals( before, after, 100. ).map().count(), 1 );

    day = new CalendarDay( wdate.addDays( 1 ), CalendarDay::Working );
    day->addInterval( TimeInterval( QTime( 0, 0, 0), 24*60*60*1000 ) );
    t.addDay( day );

    end = day->end();

    QCOMPARE( t.workIntervals( start, end, 100. ).map().count(), 2 );
    QCOMPARE( t.workIntervals( before, after, 100. ).map().count(), 2 );

    day = new CalendarDay( wdate.addDays( 2 ), CalendarDay::Working );
    day->addInterval( TimeInterval( QTime( 0, 0, 0), 24*60*60*1000 ) );
    t.addDay( day );

    end = day->end();

    QCOMPARE( t.workIntervals( start, end, 100. ).map().count(), 3 );
    QCOMPARE( t.workIntervals( before, after, 100. ).map().count(), 3 );

}
Beispiel #10
0
/******************************************************************************
* This is called when new animation settings have been loaded.
******************************************************************************/
void ActionManager::onAnimationSettingsReplaced(AnimationSettings* newAnimationSettings)
{
	disconnect(_autoKeyModeChangedConnection);
	disconnect(_autoKeyModeToggledConnection);
	disconnect(_animationIntervalChangedConnection);
	QAction* autoKeyModeAction = getAction(ACTION_AUTO_KEY_MODE_TOGGLE);
	if(newAnimationSettings) {
		autoKeyModeAction->setEnabled(true);
		autoKeyModeAction->setChecked(newAnimationSettings->autoKeyMode());
		_autoKeyModeChangedConnection = connect(newAnimationSettings, &AnimationSettings::autoKeyModeChanged, autoKeyModeAction, &QAction::setChecked);
		_autoKeyModeToggledConnection = connect(autoKeyModeAction, &QAction::toggled, newAnimationSettings, &AnimationSettings::setAutoKeyMode);
		_animationIntervalChangedConnection = connect(newAnimationSettings, &AnimationSettings::intervalChanged, this, &ActionManager::onAnimationIntervalChanged);
		onAnimationIntervalChanged(newAnimationSettings->animationInterval());
	}
	else {
		autoKeyModeAction->setEnabled(false);
		onAnimationIntervalChanged(TimeInterval(0));
	}
}
void CalendarTester::testWeekdays() {
    Calendar t("Test");
    QDate wdate(2006,1,4); // wednesday
    DateTime before = DateTime(wdate.addDays(-2), QTime());
    DateTime after = DateTime(wdate.addDays(2), QTime());
    QTime t1(8,0,0);
    QTime t2(10,0,0);
    int length = t1.msecsTo( t2 );

    CalendarDay *wd1 = t.weekday(Qt::Wednesday);
    QVERIFY(wd1 != 0);
    
    wd1->setState(CalendarDay::Working);
    wd1->addInterval(TimeInterval(t1, length));

    QCOMPARE(t.firstAvailableAfter(before, after), DateTime(QDate(2006, 1, 4), QTime(8,0,0)));
    QCOMPARE((t.firstAvailableBefore(after, before)), DateTime(QDate(2006, 1, 4), QTime(10,0,0)));
    
    QCOMPARE(t.firstAvailableAfter(after, DateTime(QDate(QDate(2006,1,14)), QTime())), DateTime(QDate(2006, 1, 11), QTime(8,0,0)));
    QCOMPARE(t.firstAvailableBefore(before, DateTime(QDate(2005,12,25), QTime())), DateTime(QDate(2005, 12, 28), QTime(10,0,0)));
}
void WorkInfoCacheTester::timeZone()
{
    Calendar cal("Test");
    // local zone: Europe/Berlin ( 9 hours from America/Los_Angeles )
    KTimeZone la = KSystemTimeZones::zone("America/Los_Angeles");
    QVERIFY( la.isValid() );
    cal.setTimeZone( la );

    QDate wdate(2012,1,2);
    DateTime before = DateTime(wdate.addDays(-1), QTime());
    DateTime after = DateTime(wdate.addDays(1), QTime());
    QTime t1(14,0,0); // 23 LA
    QTime t2(16,0,0); // 01 LA next day
    DateTime wdt1(wdate, t1);
    DateTime wdt2(wdate, t2);
    int length = t1.msecsTo( t2 );
    CalendarDay *day = new CalendarDay(wdate, CalendarDay::Working);
    day->addInterval(TimeInterval(t1, length));
    cal.addDay(day);
    QVERIFY(cal.findDay(wdate) == day);

    Debug::print( &cal, "America/Los_Angeles" );
    Resource r;
    r.setCalendar( &cal );
    const Resource::WorkInfoCache &wic = r.workInfoCache();
    QVERIFY( ! wic.isValid() );

    r.calendarIntervals( before, after );
    qDebug()<<wic.intervals.map();
    QCOMPARE( wic.intervals.map().count(), 2 );

    QCOMPARE( wic.intervals.map().value( wdate ).startTime(), DateTime( wdate, QTime( 23, 0, 0 ) ) );
    QCOMPARE( wic.intervals.map().value( wdate ).endTime(), DateTime( wdate.addDays( 1 ), QTime( 0, 0, 0 ) ) );

    wdate = wdate.addDays( 1 );
    QCOMPARE( wic.intervals.map().value( wdate ).startTime(), DateTime( wdate, QTime( 0, 0, 0 ) ) );
    QCOMPARE( wic.intervals.map().value( wdate ).endTime(), DateTime( wdate, QTime( 1, 0, 0 ) ) );
}
Beispiel #13
0
    YETI_Result TaskManager::stop_all_tasks()
    {
        {
            AutoLock lock(m_tasks_lock_);

            m_stopping_ = true;

            if (m_queue_) {
                Queue<int>* queue = m_queue_;
                m_queue_ = NULL;
                delete queue;
            }  

            List<ThreadTask *>::iterator task = m_tasks_.get_first_item();
            while (task) {
                (*task)->Stop(false);
                ++task;
            }
        }

        YETI_Cardinal num_running_tasks;
        do {
            {
                AutoLock lock(m_tasks_lock_);
                num_running_tasks = m_tasks_.get_item_count();
            }

            if (num_running_tasks == 0) 
                break; 

            System::sleep(TimeInterval(0.05));
        } while (1);

        m_stopping_ = false;
        return YETI_SUCCESS;
    }
Beispiel #14
0
bool SelectPoller::Poll(TimeoutManager *timeout_manager,
                        const TimeInterval &poll_interval) {
  int maxsd;
  fd_set r_fds, w_fds;
  TimeStamp now;
  TimeInterval sleep_interval = poll_interval;
  struct timeval tv;

  maxsd = 0;
  FD_ZERO(&r_fds);
  FD_ZERO(&w_fds);
  m_clock->CurrentTime(&now);

  TimeInterval next_event_in = timeout_manager->ExecuteTimeouts(&now);
  if (!next_event_in.IsZero()) {
    sleep_interval = std::min(next_event_in, sleep_interval);
  }

  // Adding descriptors should be the last thing we do, they may have changed
  // due to timeouts above.
  bool closed_descriptors = AddDescriptorsToSet(&r_fds, &w_fds, &maxsd);
  // If there are closed descriptors, set the timeout to something
  // very small (1ms). This ensures we at least make a pass through the
  // descriptors.
  if (closed_descriptors) {
    sleep_interval = std::min(sleep_interval, TimeInterval(0, 1000));
  }

  // take care of stats accounting
  if (m_wake_up_time.IsSet()) {
    TimeInterval loop_time = now - m_wake_up_time;
    OLA_DEBUG << "ss process time was " << loop_time.ToString();
    if (m_loop_time)
      (*m_loop_time) += loop_time.AsInt();
    if (m_loop_iterations)
      (*m_loop_iterations)++;
  }

  sleep_interval.AsTimeval(&tv);
  switch (select(maxsd + 1, &r_fds, &w_fds, NULL, &tv)) {
    case 0:
      // timeout
      m_clock->CurrentTime(&m_wake_up_time);
      timeout_manager->ExecuteTimeouts(&m_wake_up_time);

      if (closed_descriptors) {
        // there were closed descriptors before the select() we need to deal
        // with them.
        FD_ZERO(&r_fds);
        FD_ZERO(&w_fds);
        CheckDescriptors(&r_fds, &w_fds);
      }
      return true;
    case -1:
      if (errno == EINTR)
        return true;
      OLA_WARN << "select() error, " << strerror(errno);
      return false;
    default:
      m_clock->CurrentTime(&m_wake_up_time);
      CheckDescriptors(&r_fds, &w_fds);
      m_clock->CurrentTime(&m_wake_up_time);
      timeout_manager->ExecuteTimeouts(&m_wake_up_time);
  }

  return true;
}
void MPointCreator::ProcessPoints(
                         const MHTRouteCandidate::PointData& rData1,
                         const MHTRouteCandidate::RouteSegment& rSegment1,
                         const MHTRouteCandidate::PointData& rData2,
                         std::vector<const SimpleLine*>& vecCurvesBetweenPoints)
{
    Point Pt1(false);
    if (rData1.GetPointProjection() != NULL)
        Pt1 = *(rData1.GetPointProjection());
    else
        Pt1 = rData1.GetPointGPS();

    Point Pt2(false);
    if (rData2.GetPointProjection() != NULL)
        Pt2 = *(rData2.GetPointProjection());
    else
        Pt2 = rData2.GetPointGPS();

    if (AlmostEqual(Pt1, Pt2))
    {
        Interval<Instant> TimeInterval(rData1.GetTime(),
                                       rData2.GetTime(),
                                       true,
                                       rData1.GetTime() == rData2.GetTime());

        AttributePtr<UPoint> pUPoint(new UPoint(TimeInterval, Pt1, Pt1));
        m_pResMPoint->Add(*pUPoint);

        assert(vecCurvesBetweenPoints.size() == 0);
    }
    else
    {
        const shared_ptr<IMMNetworkSection>& pSection1 = rData1.GetSection();
        const shared_ptr<IMMNetworkSection>& pSection2 = rData2.GetSection();

        if (pSection1 == NULL || !pSection1->IsDefined() ||
            pSection2 == NULL || !pSection2->IsDefined())
        {
            // at least one point is offroad

            Interval<Instant> TimeInterval(
                                          rData1.GetTime(),
                                          rData2.GetTime(),
                                          true,
                                          rData1.GetTime() == rData2.GetTime());

            AttributePtr<UPoint> pUPoint(new UPoint(TimeInterval, Pt1, Pt2));
            m_pResMPoint->Add(*pUPoint);
        }
        else if (pSection1 == pSection2) // Same section
        {
            const SimpleLine* pSectionCurve = pSection1->GetCurve();

            AttributePtr<SimpleLine> pSubline(new SimpleLine(0));
            MMUtil::SubLine(pSectionCurve,
                            Pt1,
                            Pt2,
                            pSection1->GetCurveStartsSmaller(),
                            m_dNetworkScale,
                            *pSubline);

            if (pSubline->IsDefined() &&
                pSubline->StartPoint().IsDefined() &&
                pSubline->EndPoint().IsDefined())
            {
                Interval<Instant> TimeInterval(
                                          rData1.GetTime(),
                                          rData2.GetTime(),
                                          true,
                                          rData1.GetTime() == rData2.GetTime());

                //assert(AlmostEqual(Pt1, pSubline->StartPoint()));

                ProcessCurve(*pSubline, TimeInterval);
            }
        }
        else // different sections
        {
            // Calculate total length of curves

            const SimpleLine* pSection1Curve = pSection1->GetCurve();

            AttributePtr<SimpleLine> pSubline1(new SimpleLine(0));
            MMUtil::SubLine(pSection1Curve,
                            Pt1,
                            !rSegment1.HasUTurn() ? pSection1->GetEndPoint() :
                                                    pSection1->GetStartPoint(),
                            pSection1->GetCurveStartsSmaller(),
                            m_dNetworkScale,
                            *pSubline1);

            double dLenCurve1 = MMUtil::CalcLengthCurve(pSubline1.get(),
                                                        m_dNetworkScale);


            const SimpleLine* pSection2Curve = pSection2->GetCurve();

            AttributePtr<SimpleLine> pSubline2(new SimpleLine(0));
            MMUtil::SubLine(pSection2Curve,
                            pSection2->GetStartPoint(),
                            Pt2,
                            pSection2->GetCurveStartsSmaller(),
                            m_dNetworkScale,
                            *pSubline2);

            double dLenCurve2 = MMUtil::CalcLengthCurve(pSubline2.get(),
                                                        m_dNetworkScale);


            double dLength = dLenCurve1 + dLenCurve2;


            const size_t nCurves = vecCurvesBetweenPoints.size();
            for (size_t i = 0; i < nCurves; ++i)
            {
                dLength += MMUtil::CalcLengthCurve(vecCurvesBetweenPoints[i],
                                                   m_dNetworkScale);
            }

            // Total time
            DateTime Duration = rData2.GetTime() - rData1.GetTime();
            Duration.Abs();

            // Process first curve

            DateTime TimeEnd(rData1.GetTime());

            if (!pSubline1 ||
                AlmostEqual(dLenCurve1, 0.0))
            {
                Interval<Instant> TimeInterval(rData1.GetTime(),
                                               TimeEnd,
                                               true, true);
                AttributePtr<UPoint> pUPoint(new UPoint(TimeInterval,
                                                        Pt1, Pt1));
                m_pResMPoint->Add(*pUPoint);
            }
            else
            {
                TimeEnd = rData1.GetTime() +
                           DateTime(datetime::durationtype,
                                    (uint64_t)(((Duration.millisecondsToNull()
                                                / dLength) * dLenCurve1) + .5));
                Interval<Instant> TimeInterval(rData1.GetTime(),
                                               TimeEnd,
                                               true,
                                               rData1.GetTime() == TimeEnd);
                ProcessCurve(*pSubline1, TimeInterval, dLenCurve1);
            }

            // Process curves in between

            for (size_t i = 0; i < nCurves; ++i)
            {
                const SimpleLine* pCurve = vecCurvesBetweenPoints[i];
                if (pCurve == NULL)
                    continue;

                double dLenCurve = MMUtil::CalcLengthCurve(pCurve,
                                                           m_dNetworkScale);
                if (AlmostEqual(dLenCurve, 0.0))
                    continue;

                DateTime TimeStart = TimeEnd;
                TimeEnd = TimeStart +
                          DateTime(datetime::durationtype,
                                    (uint64_t)(((Duration.millisecondsToNull()
                                                / dLength) * dLenCurve) + .5));

                Interval<Instant> TimeInterval(TimeStart,
                                               TimeEnd,
                                               true, false);

                ProcessCurve(*pCurve, TimeInterval, dLenCurve);
            }

            // Process last curve

            if (!pSubline2 ||
                AlmostEqual(dLenCurve2, 0.0))
            {
                DateTime TimeStart = TimeEnd;
                TimeEnd = rData2.GetTime();
                Interval<Instant> TimeInterval(TimeStart,
                                               TimeEnd,
                                               true, true);
                AttributePtr<UPoint> pUPoint(new UPoint(TimeInterval,
                                                        Pt2, Pt2));
                m_pResMPoint->Add(*pUPoint);
            }
            else
            {
                assert(TimeEnd.millisecondsToNull() <=
                       rData2.GetTime().millisecondsToNull());
                DateTime TimeStart = TimeEnd;
                TimeEnd = rData2.GetTime();
                Interval<Instant> TimeInterval(TimeStart,
                                               TimeEnd,
                                               true, false);
                ProcessCurve(*pSubline2, TimeInterval, dLenCurve2);
            }
        }
    }
}
Beispiel #16
0
TimeInterval TimeInterval::operator*(unsigned int i) const {
  return TimeInterval(m_interval * i);
}
Beispiel #17
0
int OnlineSession::run(istream *in, ostream *out, bool interactive)
{
    map<string, int> commands;
    prepareCommands(commands);

    int res = 0;
    int count = 0;

    int cmd;
    string command;

    string sarg1, sarg2;
    int iarg1, iarg2, iarg3, iarg4, iarg5, iarg6, iarg7;
    double darg1;
    double *dparg1;
    TimeSeriesSet *t;

    clock_t time;

    res = 0;

    while (!in->eof()) {

        if (res != 0)
            *out << "Command returned with status " << res << "." << endl;

        if (interactive) {
            int width = out->width();
            *out << "[";

            out->width(3);
            *out << count;
            out->width(width);

            *out << "] > ";
            out->flush();
        }

        *in >> command;
        time = clock();

        if (command.size() > 0) {
            cmd = commands[command];
        }

        if (command.size() <= 0 || in->eof()) {
            cmd = _EXIT;
            *out << endl;
        }

        if (cmd == 0) {
            *out << "Unknown command '" << command << "'. Type 'help' for help." << endl;
            res = 1;
            count++;
            continue;
        }

        try {
            res = 0;
            switch (cmd) {
            case _EXIT:
                *out << "Quitting..." << endl;

                return iarg1;

            case _HELP:
                _print_help(out);

                break;

            case _LOAD_TSS:
                *in >> sarg1;

                *out << "Loading Time Series Set from file '" << sarg1 << "'." << endl;

                res = loadDataSet(new TimeSeriesSet(sarg1.c_str()));
                if (res >= 0) {
                    *out << "Dataset successfully loaded. Index: " << res << endl;
                    res = 0;
                } else {
                    *out << "Failed to load dataset." << endl;
                }

                break;

            case _SAVE_TSS:
                *in >> iarg1;
                *in >> sarg2;

                checkIndex(iarg1);
                t = dataSets[iarg1];
                *out << "Saving Time Series Set " << iarg1 << ":" << t->name << " to file '" << sarg2 << "'." << endl;

                res = saveDataSet(iarg1, sarg2.c_str());
                if (res == 0)
                    *out << "Dataset successfully saved." << endl;

                break;

            case _OLOAD_TSS:
                *in >> sarg1;
                *in >> iarg1 >> iarg2 >> iarg3;

                *out << "Loading Time Series Set from file '" << sarg1 << "' with N=" << iarg1 << ", L=" << iarg2 << ", and D=" << iarg3 << "." << endl;

                res = loadDataSet(new TimeSeriesSet(sarg1.c_str(), iarg1, iarg2, iarg3));
                if (res >= 0) {
                    *out << "Dataset successfully loaded. Index: " << res << endl;
                    res = 0;
                } else {
                    *out << "Failed to load dataset." << endl;
                }

                break;

            case _OSAVE_TSS:
                *in >> iarg1;
                *in >> sarg2;

                checkIndex(iarg1);
                t = dataSets[iarg1];

                *out << "Saving Time Series Set " << iarg1 << ":" << t->name << " to file '" << sarg2 << "'." << endl;
                res = saveDataSet(iarg1, sarg2.c_str(), true);
                if (res == 0)
                    *out << "Dataset successfully saved." << endl;
                break;

            case _DROP_TSS:
                *in >> iarg1;

                checkIndex(iarg1);
                t = dataSets[iarg1];
                *out << "Dropping Time Series Set " << iarg1 << ":" << t->name << "." << endl;

                res = dropDataSet(iarg1);

                break;

            case _RAND_TSS:
                *in >> iarg1 >> iarg2 >> iarg3;

                *out << "Generating random Time Series Set with N=" << iarg1 << ", L=" << iarg2 << ", and range=" << iarg3 << "." << endl;

                res = loadDataSet(&TimeSeriesSet::randomSet(iarg1, iarg2, iarg3));
                if (res >= 0) {
                    *out << "Dataset successfully loaded. Index: " << res << endl;
                    res = 0;
                } else {
                    *out << "Failed to load dataset." << endl;
                }

                break;

            case _LIST_TSS:
                printDataSets(out);
                break;

            case _NORM_TSS:
                *in >> iarg1;

                checkIndex(iarg1);
                t = dataSets[iarg1];
                *out << "Normalizing Time Series Set " << iarg1 << ":" << t->name << "." << endl;

                res = normalizeDataSet(iarg1);

                break;

            case _KSIM_TSS:
                *in >> iarg1 >> iarg2 >> iarg3 >> iarg4 >> iarg5 >> iarg6 >> iarg7;

                checkIndex(iarg1);
                checkIndex(iarg2);
                t = dataSets[iarg1];
                *out << "Getting the kSimilar for Time Series Set " << iarg1 << ":" << t->name;
                t = dataSets[iarg2];
                *out << ", query string at " << iarg3 << " in dataset " << iarg2 << ":" << t->name;
                *out << " in interval [" << iarg4 << "," << iarg5 << "] with k=" << iarg6 << " and strict="
                     << iarg7 << "." << endl;

                dparg1 = t->getInterval(iarg3,TimeInterval(iarg4, iarg5)).getData();
                kSimilar(iarg1, vector<double>(dparg1, dparg1 + (iarg5 - iarg4 + 1)),
                         TimeInterval(iarg4, iarg5), iarg6, iarg7);

                break;

            case _OUTLIER_TSS:
                *in >> iarg1 >> iarg2 >> iarg3;

                checkIndex(iarg1);
                t = dataSets[iarg1];
                *out << "Gettind dominant outlier on Time Series Set " << iarg1 << ":" << t->name
                     << " in the range [" << iarg2 << ", " << iarg3 << "]." << endl;

                dominantOutlier(iarg1, TimeInterval(iarg2, iarg3));

                break;

            case _GROUP_TSS:
                *in >> iarg1;

                checkIndex(iarg1);
                t = dataSets[iarg1];

                *out << ((groupings[iarg1] != NULL)?"Regrouping":"Grouping") << " Time Series Set "
                     << iarg1 << ":" << t->name << " with ST " << defaultST << "." << endl;

                genGrouping(iarg1, defaultST);

                break;

            case _NGROUP_TSS:
                *in >> iarg1;

                checkIndex(iarg1);
                t = dataSets[iarg1];

                *out << ((groupings[iarg1] != NULL)?"Regrouping":"Grouping") << " Time Series Set "
                     << iarg1 << ":" << t->name << " with ST " << defaultST << " (naive)." << endl;

                genNaiveGrouping(iarg1, defaultST);

                break;

            case _GROUP_ST_TSS:
                *in >> iarg1;
                *in >> darg1;

                checkIndex(iarg1);
                t = dataSets[iarg1];
                *out << ((groupings[iarg1]  == NULL)?"Grouping":"Regrouping") << " Time Series Set "
                     << iarg1 << ":" << t->name << " with ST " << darg1 << "." << endl;

                genGrouping(iarg1, darg1);

                break;

            case _NGROUP_ST_TSS:
                *in >> iarg1;
                *in >> darg1;

                checkIndex(iarg1);
                t = dataSets[iarg1];
                *out << ((groupings[iarg1]  == NULL)?"Grouping":"Regrouping") << " Time Series Set "
                     << iarg1 << ":" << t->name << " with ST " << darg1 << " (naive)." << endl;

                genNaiveGrouping(iarg1, darg1);

                break;

            case _LOAD_GROUP_TSS:
                *in >> iarg1;
                *in >> sarg1;

                checkIndex(iarg1);
                t = dataSets[iarg1];
                *out << "Loading grouping data for Time Series Set "
                     << iarg1 << ":" << t->name << " at " << sarg1 << "." << endl;

                res = loadGrouping(iarg1, sarg1.c_str());

                break;

            case _SAVE_GROUP_TSS:
                *in >> iarg1;
                *in >> sarg1;

                checkIndex(iarg1);
                t = dataSets[iarg1];
                *out << "Saving grouping data for Time Series Set "
                     << iarg1 << ":" << t->name << " to " << sarg1 << "." << endl;

                res = saveGrouping(iarg1, sarg1.c_str());

                break;

            case _DROP_GROUP_TSS:
                *in >> iarg1;

                checkIndex(iarg1);
                t = dataSets[iarg1];
                *out << "Dropping grouping data for Time Series Set "
                     << iarg1 << ":" << t->name << "." << endl;

                dropGrouping(iarg1);

                break;

            case _DESC_TSS:
                *in >> iarg1;

                checkIndex(iarg1);
                t = dataSets[iarg1];
                t->printDesc(out);

                break;

            case _PRINT_TSS:
                *in >> iarg1;

                checkIndex(iarg1);
                t = dataSets[iarg1];
                t->printData(out);

                break;

            case _DEBUG:
                *in >> iarg1;

                *out << "Setting debug to " << iarg1 << "." << endl;
                debug = iarg1;

                break;

            case _SET_DEF_ST:
                *in >> darg1;

                *out << "Setting default ST to " << darg1 << "." << endl;

                defaultST = darg1;

                break;

            case _GET_DEF_ST:
                *out << "default ST = " << defaultST << "." << endl;

                break;
            }

        } catch (exception &e) {
            *out << "Caught exception attempting operation:" << endl;
            *out << e.what() << endl;
        }

        time = clock() - time;
        (*out) << "Command used " << ((float)time/CLOCKS_PER_SEC) << " seconds." << endl << endl;

        count++;
    }

    return 0;
}
Beispiel #18
0
static TimeInterval entangledTime(int strength) {
  return TimeInterval(max(5, 30 - strength / 2));
}
Beispiel #19
0
void ProjectTester::team()
{
    Project project;
    project.setName( "P1" );
    project.setId( project.uniqueNodeId() );
    project.registerNodeId( &project );
    DateTime targetstart = DateTime( QDate( 2010, 5, 1 ), QTime(0,0,0) );
    DateTime targetend = DateTime( targetstart.addDays( 7 ) );
    project.setConstraintStartTime( targetstart );
    project.setConstraintEndTime( targetend);

    Calendar *c = new Calendar("Test");
    QTime t1(8,0,0);
    int length = 8*60*60*1000; // 8 hours

    for ( int i = 1; i <= 7; ++i ) {
        CalendarDay *wd1 = c->weekday(i);
        wd1->setState(CalendarDay::Working);
        wd1->addInterval(TimeInterval(t1, length));
    }
    project.addCalendar( c );

    Task *task1 = project.createTask();
    task1->setName( "T1" );
    project.addTask( task1, &project );
    task1->estimate()->setUnit( Duration::Unit_d );
    task1->estimate()->setExpectedEstimate( 2.0 );
    task1->estimate()->setType( Estimate::Type_Effort );

    QString s = "One team with one resource --------";
    qDebug()<<endl<<"Testing:"<<s;
    ResourceGroup *g = new ResourceGroup();
    project.addResourceGroup( g );
    Resource *r1 = new Resource();
    r1->setName( "R1" );
    r1->setCalendar( c );
    project.addResource( g, r1 );

    Resource *r2 = new Resource();
    r2->setName( "Team member" );
    r2->setCalendar( c );
    project.addResource( g, r2 );

    Resource *team = new Resource();
    team->setType( Resource::Type_Team );
    team->setName( "Team" );
    team->addTeamMemberId( r2->id() );
    project.addResource( g, team );
    
    ResourceGroupRequest *gr = new ResourceGroupRequest( g );
    task1->addRequest( gr );
    ResourceRequest *tr = new ResourceRequest( team, 100 );
    gr->addResourceRequest( tr );

    ScheduleManager *sm = project.createScheduleManager( "Team" );
    project.addScheduleManager( sm );
    sm->createSchedules();

    {
        KPlatoRCPSPlugin rcps( 0, QVariantList() );
        rcps.calculate( project, sm, true/*nothread*/ );
    }

//     Debug::print( r1, s);
//     Debug::print( r2, s);
     Debug::print( team, s, false);
     Debug::print( &project, task1, s);
//     Debug::printSchedulingLog( *sm, s );

    DateTime expectedEndTime = targetstart + Duration( 1, 16, 0 );
    QCOMPARE( task1->endTime(), expectedEndTime );

    s = "One team with one resource + one resource --------";
    qDebug()<<endl<<"Testing:"<<s;

    ResourceRequest *rr1 = new ResourceRequest( r1, 100 );
    gr->addResourceRequest( rr1 );

    sm = project.createScheduleManager( "Team + Resource" );
    project.addScheduleManager( sm );
    sm->createSchedules();

    {
        KPlatoRCPSPlugin rcps( 0, QVariantList() );
        rcps.calculate( project, sm, true/*nothread*/ );
    }

//     Debug::print( r1, s);
//     Debug::print( r2, s);
     Debug::print( team, s, false);
     Debug::print( &project, task1, s);
//     Debug::printSchedulingLog( *sm, s );
    expectedEndTime = targetstart + Duration( 0, 16, 0 );
    QCOMPARE( task1->endTime(), expectedEndTime );

    s = "One team with one resource + one resource, resource available too late --------";
    qDebug()<<endl<<"Testing:"<<s;
    
    r1->setAvailableFrom( targetend );
    r1->setAvailableUntil( targetend.addDays( 7 ) );

    sm = project.createScheduleManager( "Team + Resource not available" );
    project.addScheduleManager( sm );
    sm->createSchedules();
    
    {
        KPlatoRCPSPlugin rcps( 0, QVariantList() );
        rcps.calculate( project, sm, true/*nothread*/ );
    }

    Debug::print( r1, s);
//    Debug::print( r2, s);
    Debug::print( team, s, false);
    Debug::print( &project, task1, s);
    Debug::printSchedulingLog( *sm, s );
    expectedEndTime = targetstart + Duration( 1, 16, 0 );
    QCOMPARE( task1->endTime(), expectedEndTime );

    s = "One team with two resources --------";
    qDebug()<<endl<<"Testing:"<<s;
    
    r1->removeRequests();
    team->addTeamMemberId( r1->id() );
    r1->setAvailableFrom( targetstart );
    r1->setAvailableUntil( targetend );

    sm = project.createScheduleManager( "Team with 2 resources" );
    project.addScheduleManager( sm );
    sm->createSchedules();

    {
        KPlatoRCPSPlugin rcps( 0, QVariantList() );
        rcps.calculate( project, sm, true/*nothread*/ );
    }

//    Debug::print( r1, s);
//    Debug::print( r2, s);
    Debug::print( team, s, false);
    Debug::print( &project, task1, s);
    Debug::printSchedulingLog( *sm, s );
    expectedEndTime = targetstart + Duration( 0, 16, 0 );
    QCOMPARE( task1->endTime(), expectedEndTime );

    s = "One team with two resources, one resource unavailable --------";
    qDebug()<<endl<<"Testing:"<<s;
    
    r1->setAvailableFrom( targetend );
    r1->setAvailableUntil( targetend.addDays( 2 ) );

    sm = project.createScheduleManager( "Team, one unavailable resource" );
    project.addScheduleManager( sm );
    sm->createSchedules();

    {
        KPlatoRCPSPlugin rcps( 0, QVariantList() );
        rcps.calculate( project, sm, true/*nothread*/ );
    }

    Debug::print( r1, s);
//    Debug::print( r2, s);
    Debug::print( team, s, false);
    Debug::print( &project, task1, s);
    Debug::printSchedulingLog( *sm, s );
    expectedEndTime = targetstart + Duration( 1, 16, 0 );
    QCOMPARE( task1->endTime(), expectedEndTime );

}
Beispiel #20
0
void OnlineSession::kSimilar(int dbindex, vector<double> qdata, TimeInterval interval, int k, int strict)
{
    if (groupings[dbindex] == NULL)
        genGrouping(dbindex, defaultST);

    TimeSeriesGrouping *t = groupings[dbindex];

    int slen = dataSets[dbindex]->seqLength;
    int ilen = interval.length();

    TimeSeriesIntervalEnvelope eqdata(TimeSeriesInterval(qdata.data(), TimeInterval(0, qdata.size() - 1)));

    double gb;
    int bsfStart = 0, bsfEnd = 0, bsfIndex = -1;
    double bsf = INF;

    if (strict == 0) {
        for (int i = 0; i < slen; i++) {
            if (debug) {
                cout << "Searching groups from start=" << i << ", bsf=" << bsf << endl;
            }
            for (int j = i; j < slen; j++) {
                int k = t->groups[i * slen + j].getBestGroup(eqdata, &gb, bsf);
                if (k < 0)
                    continue;
                if (gb < bsf) {
                    bsf = gb;
                    bsfStart = i;
                    bsfEnd = j;
                    bsfIndex = k;
                }
            }
        }
    } else if (strict == 1) {
        for (int i = 0; i + ilen - 1 < slen; i++) {
            if (debug)
                cout << "Searching groups from start=" << i << endl;
            int j = i + (ilen - 1);
            int k = t->groups[i * slen + j].getBestGroup(eqdata, &gb, bsf);
            if (k < 0)
                continue;
            if (gb < bsf) {
                bsf = gb;
                bsfStart = i;
                bsfEnd = j;
                bsfIndex = k;
            }
        }
    } else {
        bsfStart = interval.start;
        bsfEnd = interval.end;
        bsfIndex = t->groups[bsfStart * slen + bsfEnd].getBestGroup(eqdata, &gb, bsf);
        if (bsfIndex >= 0)
            bsf = gb;
    }

    if (bsf == INF || bsfIndex < 0) {
        cerr << "kSimilar: Failed to find similar objects. No suitable candidate group centroids." << endl;
        return;
    }

    cout << "Found most similar interval and group: " << bsfIndex << "@"
         << "[" << bsfStart << "," << bsfEnd << "]" << endl;

    vector<kSim> sim = t->groups[bsfStart * slen + bsfEnd].groups[bsfIndex]->getSortedSimilar(eqdata, k);

    cout << "Discovered k similar points:" << endl;
    for (unsigned int i = 0; i < sim.size(); i++) {

        cout << "Series " << sim[i].index << ", interval [" << bsfStart << "," << bsfEnd
             << "] is at distance " << sim[i].distance << "." << endl;

        TimeSeriesInterval interval = (*t->groups[bsfStart * slen + bsfEnd].groups[bsfIndex]->slice)[sim[i].index];

        for (int j = 0; j < interval.length(); j++) {
            cout << interval[j] << " ";
        }
        cout << endl;
    }
}
int32 UnFbx::FFbxImporter::GetMaxSampleRate(TArray<FbxNode*>& SortedLinks, TArray<FbxNode*>& NodeArray)
{
	int32 MaxStackResampleRate = 0;

	int32 AnimStackCount = Scene->GetSrcObjectCount<FbxAnimStack>();
	for( int32 AnimStackIndex = 0; AnimStackIndex < AnimStackCount; AnimStackIndex++)
	{
		FbxAnimStack* CurAnimStack = Scene->GetSrcObject<FbxAnimStack>(AnimStackIndex);

		FbxTimeSpan AnimStackTimeSpan = GetAnimationTimeSpan(SortedLinks[0], CurAnimStack);

		double AnimStackStart = AnimStackTimeSpan.GetStart().GetSecondDouble();
		double AnimStackStop = AnimStackTimeSpan.GetStop().GetSecondDouble();

		FbxAnimLayer* AnimLayer = (FbxAnimLayer*)CurAnimStack->GetMember(0);

		for(int32 LinkIndex = 0; LinkIndex < SortedLinks.Num(); ++LinkIndex)
		{
			FbxNode* CurrentLink = SortedLinks[LinkIndex];

			FbxAnimCurve* Curves[6];

			Curves[0] = CurrentLink->LclTranslation.GetCurve(AnimLayer, FBXSDK_CURVENODE_COMPONENT_X, false);
			Curves[1] = CurrentLink->LclTranslation.GetCurve(AnimLayer, FBXSDK_CURVENODE_COMPONENT_Y, false);
			Curves[2] = CurrentLink->LclTranslation.GetCurve(AnimLayer, FBXSDK_CURVENODE_COMPONENT_Z, false);
			Curves[3] = CurrentLink->LclRotation.GetCurve(AnimLayer, FBXSDK_CURVENODE_COMPONENT_X, false);
			Curves[4] = CurrentLink->LclRotation.GetCurve(AnimLayer, FBXSDK_CURVENODE_COMPONENT_Y, false);
			Curves[5] = CurrentLink->LclRotation.GetCurve(AnimLayer, FBXSDK_CURVENODE_COMPONENT_Z, false);

			for(int32 CurveIndex = 0; CurveIndex < 6; ++CurveIndex)
			{
				FbxAnimCurve* CurrentCurve = Curves[CurveIndex];
				if(CurrentCurve)
				{
					int32 KeyCount = CurrentCurve->KeyGetCount();

					FbxTimeSpan TimeInterval(FBXSDK_TIME_INFINITE,FBXSDK_TIME_MINUS_INFINITE);
					bool bValidTimeInterval = CurrentCurve->GetTimeInterval(TimeInterval);

 					if(KeyCount > 1 && bValidTimeInterval)
					{
						double KeyAnimLength = TimeInterval.GetDuration().GetSecondDouble();
						double KeyAnimStart = TimeInterval.GetStart().GetSecondDouble();
						double KeyAnimStop = TimeInterval.GetStop().GetSecondDouble();

						if(KeyAnimLength != 0.0)
						{
							// 30 fps animation has 31 keys because it includes index 0 key for 0.0 second
							int32 NewRate = FPlatformMath::RoundToInt((KeyCount-1) / KeyAnimLength);
							MaxStackResampleRate = FMath::Max(NewRate, MaxStackResampleRate);
						}
					}
				}
			}
		}
	}

	// Make sure we're not hitting 0 for samplerate
	if ( MaxStackResampleRate != 0 )
	{
		return MaxStackResampleRate;
	}

	return DEFAULT_SAMPLERATE;
}
Beispiel #22
0
const TimeInterval TimeStamp::operator-(const TimeStamp &other) const {
  return TimeInterval(m_tv - other.m_tv);
}
int OnlineSession::run(istream &in, bool interactive)
{
    map<string, int> commands;
    _prepareCommands(commands);

    int res = 0;
    int count = 0;

    int cmd;
    string command;

    string sarg1, sarg2;
    int iarg1, iarg2, iarg3, iarg4, iarg5, iarg6, iarg7, iarg8;
    SeriesDistanceMetric *metric;
    double darg1;
    GroupableTimeSeriesSet *t;

    clock_t time;

    res = 0;

    while (!in.eof()) {

        if (res != 0)
            getout() << "Command returned with status " << res << "." << endl;

        if (interactive) {
            int width = getout().width();
            getout() << "[";

            getout().width(3);
            getout() << count;
            getout().width(width);

            getout() << "] > ";
            getout().flush();
        }

        in >> command;

        if (command.size() > 0 && !in.eof()) {
            cmd = commands[command];
        } else {
            cmd = _EXIT;
            getout() << endl;
        }

        time = clock();

        try {
            res = 0;

            switch (cmd) {
            case 0:
                getout() << "Unknown command '" << command << "'. Type 'help' for help." << endl;

                res = 1;
                break;

            case _EXIT:
                getout() << "Quitting..." << endl;

                return 0;

            case _HELP:
                _print_help(getout());

                break;

            case _DEBUG:
                in >> iarg1;

                getout() << "Setting verbosity to " << iarg1 << "." << endl;

                verbosity = iarg1;

                break;

            case _LOAD_TSS:
                in >> sarg1;

                getout() << "Loading Time Series Set from file '" << sarg1 << "'." << endl;

                res = loaddb(sarg1.c_str());
                if (res == 0) {
                    getout() << "Dataset successfully loaded. Index: " << datasets.size()-1 << endl;
                } else {
                    getout() << "Failed to load dataset." << endl;
                }

                break;

            case _SAVE_TSS:
                in >> iarg1;
                in >> sarg2;

                checkIndex(iarg1);
                t = datasets[iarg1];
                getout() << "Saving Time Series Set " << iarg1 << ":" << t->getName() << " to file '" << sarg2 << "'." << endl;

                res = savedb(iarg1, sarg2.c_str());
                if (res == 0)
                    getout() << "Dataset successfully saved." << endl;
                else
                    getout() << "Failed to save dataset." << endl;

                break;

            case _OLOAD_TSS:
                in >> sarg1;
                in >> iarg1 >> iarg2 >> iarg3;

                getout() << "Loading Time Series Set from file '" << sarg1 << "' with N=" << iarg1 << ", L=" << iarg2 << ", and D=" << iarg3 << "." << endl;

                res = loadolddb(sarg1.c_str(), iarg1, iarg2, iarg3);
                if (res == 0) {
                    getout() << "Dataset successfully loaded. Index: " << datasets.size()-1 << endl;
                } else {
                    getout() << "Failed to load dataset." << endl;
                }

                break;

            case _OSAVE_TSS:
                in >> iarg1;
                in >> sarg2;

                checkIndex(iarg1);
                t = datasets[iarg1];

                getout() << "Saving Time Series Set " << iarg1 << ":" << t->getName() << " to file '" << sarg2 << "'." << endl;

                res = saveolddb(iarg1, sarg2.c_str());
                if (res == 0)
                    getout() << "Dataset successfully saved." << endl;
                else
                    getout() << "Failed to save dataset." << endl;

                break;

            case _DROP_TSS:
                in >> iarg1;

                checkIndex(iarg1);
                t = datasets[iarg1];
                getout() << "Dropping Time Series Set " << iarg1 << ":" << t->getName() << "." << endl;

                killdb(iarg1);

                break;

            case _RAND_TSS:
                in >> iarg1 >> iarg2 >> iarg3;

                getout() << "Generating random Time Series Set with N=" << iarg1 << ", L=" << iarg2 << ", and range=" << iarg3 << "." << endl;

                res = randdb(iarg3, iarg1, iarg2);
                if (res == 0)
                    getout() << "Dataset successfully loaded. Index: " << datasets.size()-1 << endl;
                else
                    getout() << "Failed to load dataset." << endl;

                break;

            case _LIST_TSS:

                res = printdbs();

                break;

            case _NORM_TSS:
                in >> iarg1;

                checkIndex(iarg1);
                t = datasets[iarg1];
                getout() << "Normalizing Time Series Set " << iarg1 << ":" << t->getName() << "." << endl;

                t->normalize();

                break;

            case _KSIM_TSS:
                in >> iarg1 >> iarg2 >> iarg3 >> iarg4 >> iarg5 >> iarg6;

                checkIndex(iarg1);
                checkIndex(iarg2);
                t = datasets[iarg1];
                getout() << "Searching similar sequences for Time Series Set " << iarg1 << ":" << t->getName();
                t = datasets[iarg2];
                getout() << ", query string at " << iarg3 << " in dataset " << iarg2 << ":" << t->getName();
                getout() << " in interval [" << iarg4 << "," << iarg5 << "] with strategy="
                     << iarg6 << "." << endl;

                similar(iarg1, iarg2, iarg3, TimeInterval(iarg4, iarg5), iarg6);

                break;

            case _OUTLIER_TSS:
                in >> iarg1 >> iarg2;

                checkIndex(iarg1);
                t = datasets[iarg1];
                getout() << "Searching for outlier group in dataset " << iarg1 << ":" << t->getName() << " for length=" << iarg2 << "." << endl;

                outlier(iarg1, iarg2);

                break;

            case _TSS_DIST:
                in >> iarg1 >> iarg2 >> iarg3 >> iarg4;
                in >> iarg5 >> iarg6 >> iarg7 >> iarg8;
                in >> sarg1;

                checkIndex(iarg1);
                checkIndex(iarg5);

                metric = getDistMetric(sarg1.c_str());
                if (metric == NULL) {
                    getout() << "Unknown method: " << sarg1.c_str() << endl;
                    res = -1;
                    break;
                }

                getout() << "Using distance metric " << metric->name << " to find distance:" << endl;
                getout() << "A: DB:" << iarg1 << ", " << iarg2 << "@[" << iarg3 << "," << iarg4 << "]." << endl;
                getout() << "B: DB:" << iarg5 << ", " << iarg6 << "@[" << iarg7 << "," << iarg8 << "]." << endl;
                getout() << "Distance: " << printdist(iarg1, iarg5,
                                                      iarg2, iarg6,
                                                      TimeInterval(iarg3, iarg4), TimeInterval(iarg7, iarg8),
                                                      metric) << endl;

                break;

            case _LS_DIST:

                printDistMetrics();

                break;

            case _GROUP_TSS:
                in >> iarg1;

                checkIndex(iarg1);
                t = datasets[iarg1];

                getout() << "Generating new grouping for Time Series Set "
                     << iarg1 << ":" << t->getName() << " with ST " << defaultST << "." << endl;

                res = initdbgroups(iarg1, defaultST);

                break;

            case _GROUP_ST_TSS:
                in >> iarg1;
                in >> darg1;

                checkIndex(iarg1);
                t = datasets[iarg1];
                getout() << "Generating new grouping for Time Series Set "
                     << iarg1 << ":" << t->getName() << " with ST " << darg1 << "." << endl;

                res = initdbgroups(iarg1, darg1);

                break;

            case _LOAD_GROUP_TSS:
                in >> iarg1;
                in >> sarg1;

                checkIndex(iarg1);
                t = datasets[iarg1];
                getout() << "Loading grouping data for Time Series Set "
                     << iarg1 << ":" << t->getName() << " at " << sarg1 << "." << endl;

                res = loaddbgroups(iarg1, sarg1.c_str());

                break;

            case _SAVE_GROUP_TSS:
                in >> iarg1;
                in >> sarg1;

                checkIndex(iarg1);
                t = datasets[iarg1];
                getout() << "Saving grouping data for Time Series Set "
                     << iarg1 << ":" << t->getName() << " to " << sarg1 << "." << endl;

                res = savedbgroups(iarg1, sarg1.c_str());

                break;

            case _DROP_GROUP_TSS:
                in >> iarg1;

                checkIndex(iarg1);
                t = datasets[iarg1];
                getout() << "Dropping grouping data for Time Series Set "
                     << iarg1 << ":" << t->getName() << "." << endl;

                res = killdbgroups(iarg1);

                break;

            case _DESC_TSS:
                in >> iarg1;

                checkIndex(iarg1);
                res = descdb(iarg1);

                break;

            case _PRINT_TSS:
                in >> iarg1;

                checkIndex(iarg1);
                res = printdb(iarg1);

                break;

            case _PRINT_INTERVAL:
                in >> iarg1 >> iarg2 >> iarg3 >> iarg4;

                checkIndex(iarg1);
                res = printint(iarg1, iarg2, TimeInterval(iarg3, iarg4));

                break;

            case _SET_DEF_ST:
                in >> darg1;

                getout() << "Setting default ST to " << darg1 << "." << endl;

                res = setST(darg1);

                break;

            case _GET_DEF_ST:
                getout() << "default ST = " << getST() << "." << endl;

                break;

            case _SET_DEF_R:
                in >> iarg1;

                getout() << "Setting default R constraint to " << iarg1 << "." << endl;

                res = setR(iarg1);

                break;

            case _GET_DEF_R:
                getout() << "default R = " << getR() << "." << endl;

                break;
            }

        } catch (exception &e) {
            getout() << "Caught exception attempting operation:" << endl;
            getout() << e.what() << endl;
        }

        time = clock() - time;
        getout() << "Command used " << ((float)time/CLOCKS_PER_SEC) << " seconds." << endl << endl;

        count++;
    }

    return 0;
}