~smartboyhw/ubuntu/raring/calligra/2.6.0-0ubuntu1

« back to all changes in this revision

Viewing changes to plan/plugins/schedulers/tj/PlanTJScheduler.cpp

  • Committer: Package Import Robot
  • Author(s): Philip Muškovac
  • Date: 2012-10-23 21:09:16 UTC
  • mfrom: (1.1.13)
  • Revision ID: package-import@ubuntu.com-20121023210916-m82w6zxnxhaxz7va
Tags: 1:2.5.90-0ubuntu1
* New upstream alpha release (LP: #1070436)
  - Add libkactivities-dev and libopenimageio-dev to build-depends
  - Add kubuntu_build_calligraactive.diff to build calligraactive by default
  - Add package for calligraauthor and move files that are shared between
    calligrawords and calligraauthor to calligrawords-common
* Document the patches
* Remove numbers from patches so they follow the same naming scheme as
  the rest of our patches.
* calligra-data breaks replaces krita-data (<< 1:2.5.3) (LP: #1071686)

Show diffs side-by-side

added added

removed removed

Lines of Context:
55
55
#define PROGRESS_MAX_VALUE 100
56
56
 
57
57
 
58
 
PlanTJScheduler::PlanTJScheduler( Project *project, ScheduleManager *sm, QObject *parent )
 
58
PlanTJScheduler::PlanTJScheduler( Project *project, ScheduleManager *sm, ulong granularity, QObject *parent )
59
59
    : SchedulerThread( project, sm, parent ),
60
60
    result( -1 ),
61
61
    m_schedule( 0 ),
62
62
    m_recalculate( false ),
63
63
    m_usePert( false ),
64
 
    m_backward( false )
 
64
    m_backward( false ),
 
65
    m_granularity( granularity )
65
66
{
66
67
    TJ::TJMH.reset();
67
68
    connect(&TJ::TJMH, SIGNAL(message(int, const QString&, TJ::CoreAttributes*)), this, SLOT(slotMessage(int, const QString&, TJ::CoreAttributes*)));
142
143
 
143
144
        m_schedule->setPhaseName( 0, i18nc( "@info/plain" , "Init" ) );
144
145
        if ( ! m_backward && locale() ) {
145
 
            logDebug( m_project, 0, QString( "Schedule project using TJ Scheduler, starting at %1" ).arg( QDateTime::currentDateTime().toString() ), 0 );
 
146
            logDebug( m_project, 0, QString( "Schedule project using TJ Scheduler, starting at %1, granularity %2" ).arg( QDateTime::currentDateTime().toString() ).arg( locale()->formatDuration( m_granularity ) ), 0 );
146
147
            if ( m_recalculate ) {
147
148
                logInfo( m_project, 0, i18nc( "@info/plain" , "Re-calculate project from start time: %1", locale()->formatDateTime( m_project->constraintStartTime() ) ), 0 );
148
149
            } else {
151
152
            logInfo( m_project, 0, i18nc( "@info/plain" , "Project target finish time: %1", locale()->formatDateTime( m_project->constraintEndTime() ) ), 0 );
152
153
        }
153
154
        if ( m_backward && locale() ) {
154
 
            logDebug( m_project, 0, QString( "Schedule project backward using TJ Scheduler, starting at %1" ).arg( locale()->formatDateTime( QDateTime::currentDateTime() ) ), 0 );
 
155
            logDebug( m_project, 0, QString( "Schedule project backward using TJ Scheduler, starting at %1, granularity %2" ).arg( locale()->formatDateTime( QDateTime::currentDateTime() ) ).arg( locale()->formatDuration( m_granularity ) ), 0 );
155
156
            logInfo( m_project, 0, i18nc( "@info/plain" , "Schedule project from end time: %1", locale()->formatDateTime( m_project->constraintEndTime() ) ), 0 );
156
157
        }
157
158
 
209
210
        }
210
211
        return false;
211
212
    }
212
 
    DebugCtrl.setDebugLevel(5);
 
213
    DebugCtrl.setDebugLevel(0);
213
214
    DebugCtrl.setDebugMode(PSDEBUG+TSDEBUG);
214
215
 
215
216
    return m_tjProject->scheduleScenario( sc );
218
219
bool PlanTJScheduler::kplatoToTJ()
219
220
{
220
221
    m_tjProject = new TJ::Project();
 
222
    m_tjProject->setScheduleGranularity( m_granularity / 1000 );
221
223
    m_tjProject->setNow( m_project->constraintStartTime().toTime_t() );
222
224
    m_tjProject->setStart( m_project->constraintStartTime().toTime_t() );
223
225
    m_tjProject->setEnd( m_project->constraintEndTime().toTime_t() );
224
 
    m_tjProject->setScheduleGranularity( 300 ); //5 minutes
225
226
 
226
227
    m_tjProject->setDailyWorkingHours( m_project->standardWorktime()->day() );
227
228
 
287
288
}
288
289
 
289
290
// static
290
 
TJ::Interval PlanTJScheduler::toTJInterval( const QDateTime &start, const QDateTime &end ) {
291
 
    TJ::Interval ti( start.toTime_t(), end.addSecs( - 1).toTime_t() );
 
291
TJ::Interval PlanTJScheduler::toTJInterval( const QDateTime &start, const QDateTime &end, ulong granularity ) {
 
292
    int secs = QTime( 0, 0, 0 ).secsTo( start.time() );
 
293
    secs -= secs % granularity;
 
294
    QDateTime s( start.date(), QTime( 0, 0, 0 ).addSecs( secs ) );
 
295
    secs = QTime( 0, 0, 0 ).secsTo( end.time() );
 
296
    secs -= secs % granularity;
 
297
    QDateTime e( end.date(), QTime( 0, 0, 0 ).addSecs( secs ) );
 
298
    TJ::Interval ti( s.toTime_t(), e.addSecs( -1 ).toTime_t() );
292
299
    return ti;
293
300
}
294
301
 
295
302
// static
296
 
TJ::Interval PlanTJScheduler::toTJInterval( const QTime &start, const QTime &end ) {
297
 
    time_t s = QTime( 0, 0, 0 ).secsTo( start );
298
 
    time_t e = ( end == QTime( 0, 0, 0 ) ) ? 86399 : QTime( 0, 0, 0 ).secsTo( end );
 
303
TJ::Interval PlanTJScheduler::toTJInterval( const QTime &start, const QTime &end, ulong granularity ) {
 
304
    int secs = QTime( 0, 0, 0 ).secsTo( start );
 
305
    time_t s =  secs - ( secs % granularity );
 
306
    secs = ( end == QTime( 0, 0, 0 ) ) ? 86399 : QTime( 0, 0, 0 ).secsTo( end );
 
307
    time_t e = secs - ( secs % granularity ) - 1;
299
308
    TJ::Interval ti( s, e );
300
309
    return ti;
301
310
}
302
311
 
 
312
ulong PlanTJScheduler::tjGranularity() const
 
313
{
 
314
    return m_tjProject->getScheduleGranularity();
 
315
}
 
316
 
303
317
bool PlanTJScheduler::kplatoFromTJ()
304
318
{
305
319
    MainSchedule *cs = static_cast<MainSchedule*>( m_project->currentSchedule() );
512
526
    }
513
527
    foreach ( CalendarDay *day, lst ) {
514
528
        if ( day->state() == CalendarDay::NonWorking ) {
515
 
            res->addVacation( new TJ::Interval( toTJInterval( QDateTime( day->date() ), QDateTime( day->date().addDays( 1 ) ) ) ) );
 
529
            res->addVacation( new TJ::Interval( toTJInterval( QDateTime( day->date() ), QDateTime( day->date().addDays( 1 ) ), tjGranularity() ) ) );
516
530
        } else if ( day->state() == CalendarDay::Working ) {
517
531
            TJ::Shift *shift = new TJ::Shift( m_tjProject, r->id() + day->date().toString( Qt::ISODate ), r->name(), 0, QString(), 0 );
518
532
            foreach ( TimeInterval *ti, day->timeIntervals() ) {
519
533
                QList<TJ::Interval*> ivs;
520
 
                ivs << new TJ::Interval( toTJInterval( ti->startTime(), ti->endTime() ) );
 
534
                ivs << new TJ::Interval( toTJInterval( ti->startTime(), ti->endTime(), tjGranularity() ) );
521
535
                shift->setWorkingHours( day->date().dayOfWeek() - 1, ivs );
522
536
            }
523
 
            TJ::Interval period = toTJInterval( day->start(), day->end() );
 
537
            TJ::Interval period = toTJInterval( day->start(), day->end(), tjGranularity() );
524
538
            TJ::ShiftSelection *sl = new TJ::ShiftSelection( period, shift );
525
539
            res->addShift( sl );
526
540
        }
527
541
    }
528
 
    if ( m_project->constraintStartTime() < r->availableFrom() ) {
529
 
        res->addVacation( new TJ::Interval( toTJInterval( m_project->constraintStartTime(), r->availableFrom() ) ) );
 
542
    if ( m_project->startTime() < r->availableFrom() ) {
 
543
        res->addVacation( new TJ::Interval( toTJInterval( m_project->startTime(), r->availableFrom(), tjGranularity() ) ) );
530
544
    }
531
 
    if ( r->availableUntil().isValid() && m_project->constraintEndTime() > r->availableUntil() ) {
532
 
        res->addVacation( new TJ::Interval( toTJInterval( r->availableUntil(), m_project->constraintEndTime() ) ) );
 
545
    if ( m_project->endTime() > r->availableUntil() ) {
 
546
        res->addVacation( new TJ::Interval( toTJInterval( r->availableUntil(), m_project->startTime(), tjGranularity() ) ) );
533
547
    }
534
548
    m_resourcemap[res] = r;
535
549
//     if ( locale() ) { logDebug( m_project, 0, "Added resource: " + r->name() ); }
670
684
            logDebug( task, 0, QString( "FNL: set specified end: %1").arg( TJ::time2ISO( task->constraintEndTime().toTime_t() ) ) );
671
685
            break;
672
686
        }
673
 
        case Node::FixedInterval:
 
687
        case Node::FixedInterval: {
674
688
            job->setPriority( 700 );
675
 
            job->setSpecifiedStart( 0, task->constraintStartTime().toTime_t() );
676
 
            job->setSpecifiedEnd( 0, task->constraintEndTime().toTime_t() - 1 );
677
 
            logDebug( task, 0, QString( "FI: set specified: %1 - %2").arg( TJ::time2ISO( task->constraintStartTime().toTime_t() ) ).arg( TJ::time2ISO( task->constraintEndTime().toTime_t() ) ) );
 
689
            TJ::Interval i( toTJInterval( task->constraintStartTime(), task->constraintEndTime(), tjGranularity() ) );
 
690
            job->setSpecifiedPeriod( 0, i );
 
691
            // estimate not allowed
 
692
            job->setDuration( 0, 0.0 );
 
693
            job->setLength( 0, 0.0 );
 
694
            job->setEffort( 0, 0.0 );
 
695
            logDebug( task, 0, QString( "FI: set specified: %1 - %2 -> %3 - %4 (%5)")
 
696
                      .arg( TJ::time2ISO( task->constraintStartTime().toTime_t() ) )
 
697
                      .arg( TJ::time2ISO( task->constraintEndTime().toTime_t() ) )
 
698
                      .arg( TJ::time2ISO( i.getStart() ) )
 
699
                      .arg( TJ::time2ISO( i.getEnd() ) )
 
700
                      .arg( tjGranularity() ) );
678
701
            break;
 
702
        }
679
703
        default:
680
704
            if ( locale() ) logWarning( task, 0, i18nc( "@info/plain", "Unhandled time constraint type" ) );
681
705
            break;
699
723
        job->setDuration( 0, 0.0 );
700
724
        return;
701
725
    }
702
 
    if ( task->estimate()->type() == Estimate::Type_Duration && task->estimate()->calendar() == 0 ) {
703
 
        job->setDuration( 0, task->estimate()->value( Estimate::Use_Expected, m_usePert ).toDouble( Duration::Unit_d ) );
704
 
        return;
705
 
    }
706
 
    if ( task->estimate()->type() == Estimate::Type_Duration && task->estimate()->calendar() != 0 ) {
707
 
        job->setLength( 0, task->estimate()->value( Estimate::Use_Expected, m_usePert ).toDouble( Duration::Unit_d ) );
708
 
        return;
709
 
    }
710
 
    if ( task->constraint() == Node::FixedInterval ) {
711
 
        job->setSpecifiedPeriod( 0, toTJInterval( task->constraintStartTime(), task->constraintEndTime() ) );
712
 
    }
713
 
    if ( m_recalculate && task->completion().isStarted() ) {
714
 
        job->setEffort( 0, task->completion().remainingEffort().toDouble( Duration::Unit_d ) );
715
 
    } else {
716
 
        Estimate *estimate = task->estimate();
717
 
        double e = estimate->scale( estimate->value( Estimate::Use_Expected, m_usePert ), Duration::Unit_d, estimate->scales() );
718
 
        job->setEffort( 0, e );
 
726
    // Note: FI tasks can never have an estimate set (duration, length or effort)
 
727
    if ( task->constraint() != Node::FixedInterval ) {
 
728
        if ( task->estimate()->type() == Estimate::Type_Duration && task->estimate()->calendar() == 0 ) {
 
729
            job->setDuration( 0, task->estimate()->value( Estimate::Use_Expected, m_usePert ).toDouble( Duration::Unit_d ) );
 
730
            return;
 
731
        }
 
732
        if ( task->estimate()->type() == Estimate::Type_Duration && task->estimate()->calendar() != 0 ) {
 
733
            job->setLength( 0, task->estimate()->value( Estimate::Use_Expected, m_usePert ).toDouble( Duration::Unit_d ) );
 
734
            return;
 
735
        }
 
736
        if ( m_recalculate && task->completion().isStarted() ) {
 
737
            job->setEffort( 0, task->completion().remainingEffort().toDouble( Duration::Unit_d ) );
 
738
        } else {
 
739
            Estimate *estimate = task->estimate();
 
740
            double e = estimate->scale( estimate->value( Estimate::Use_Expected, m_usePert ), Duration::Unit_d, estimate->scales() );
 
741
            job->setEffort( 0, e );
 
742
        }
719
743
    }
720
744
    if ( task->requests().isEmpty() ) {
721
745
        return;