Skip to content
This repository was archived by the owner on Sep 30, 2024. It is now read-only.

Commit 1196806

Browse files
committed
fixed schedule & stats
1 parent 09e5561 commit 1196806

File tree

8 files changed

+68
-43
lines changed

8 files changed

+68
-43
lines changed

src/rammanagerwidgets/schedulemanagerwidget.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ ScheduleManagerWidget::ScheduleManagerWidget(QWidget *parent) : QWidget(parent)
1717
m_scheduleFilter = new RamScheduleFilterProxyModel();
1818
m_scheduleFilter->setSourceModel( m_schedule );
1919
ui_table->setModel( m_scheduleFilter );
20-
//ui_table->setModel( m_schedule );
2120

2221
connectEvents();
2322
}
@@ -197,7 +196,6 @@ void ScheduleManagerWidget::assignStep(RamObject *stepObj)
197196
this->update();
198197

199198
m_project->freezeEstimation(false);
200-
m_project->computeEstimation();
201199
}
202200

203201
void ScheduleManagerWidget::filterUser(RamObject *user, bool filter)

src/ramobjectmodels/ramabstractobjectmodel.cpp

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -158,14 +158,7 @@ void RamAbstractObjectModel::insertObject(int row, QString uuid, QString data)
158158
{
159159
// Add to list
160160
if (!m_objectUuids.contains(uuid)) m_objectUuids.insert(row, uuid);
161-
// Insert in lookup tables
162-
QHash<QString, QMultiHash<QString, QString>>::iterator i = m_lookUpTables.begin();
163-
while (i != m_lookUpTables.end())
164-
{
165-
QString lookUpValue = getLookUpValue(i.key(), data);
166-
i.value().insert(lookUpValue, uuid);
167-
i++;
168-
}
161+
insertObjectInLookUp(uuid, data);
169162
}
170163

171164
void RamAbstractObjectModel::removeObject(QString uuid)
@@ -182,19 +175,9 @@ void RamAbstractObjectModel::updateObject(QString uuid, QString data)
182175
QJsonObject dataObj = doc.object();
183176

184177
// Update lookup tables
185-
QHash<QString, QMultiHash<QString, QString>>::iterator i = m_lookUpTables.begin();
186-
while (i != m_lookUpTables.end())
187-
{
188-
QString lookUpValue = getLookUpValue(i.key(), data);
189-
190-
QStringList lookup = i.value().values(lookUpValue);
191-
if (!lookup.contains(uuid))
192-
{
193-
removeObjectFromLookUp(uuid);
194-
i.value().insert(lookUpValue, uuid);
195-
}
196-
i++;
197-
}
178+
removeObjectFromLookUp(uuid);
179+
insertObjectInLookUp(uuid, data);
180+
return;
198181
}
199182

200183
void RamAbstractObjectModel::moveObjects(int from, int count, int to)
@@ -234,3 +217,15 @@ void RamAbstractObjectModel::removeObjectFromLookUp(QString uuid)
234217
i++;
235218
}
236219
}
220+
221+
void RamAbstractObjectModel::insertObjectInLookUp(QString uuid, QString data)
222+
{
223+
// Insert in lookup tables
224+
QHash<QString, QMultiHash<QString, QString>>::iterator i = m_lookUpTables.begin();
225+
while (i != m_lookUpTables.end())
226+
{
227+
QString lookUpValue = getLookUpValue(i.key(), data);
228+
i.value().insert(lookUpValue, uuid);
229+
i++;
230+
}
231+
}

src/ramobjectmodels/ramabstractobjectmodel.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ class RamAbstractObjectModel : public QAbstractTableModel, public RamAbstractDat
6666
QString getLookUpValue(QString key, QString data);
6767
// Remove an object from the lookup table
6868
void removeObjectFromLookUp(QString uuid);
69+
// Adds an object to the lookup table
70+
void insertObjectInLookUp(QString uuid, QString data);
6971

7072
// === Attributes ===
7173

src/ramobjectmodels/ramscheduletablemodel.cpp

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -218,27 +218,35 @@ QVariant RamScheduleTableModel::data(const QModelIndex &index, int role) const
218218
foreach(RamObject *entryObj, entries)
219219
{
220220
RamScheduleEntry *entry = RamScheduleEntry::c(entryObj);
221-
RamStep *entryStep = entry->step();
222-
if (!entryStep)
223-
{
224-
entry->remove();
225-
continue;
226-
}
227-
RamProject *entryProj = entryStep->project();
221+
RamProject *entryProj = entry->project();
228222
if (!entryProj) continue;
229223
// For current project only
230224
if (!entryProj->is(currentProject)) continue;
231225

232226
if (!foundEntry)
233227
{
234228
foundEntry = entry;
235-
continue;
229+
break;
236230
}
237-
238-
// In case there are several entries, remove the other ones
239-
entry->remove();
240231
}
241232

233+
// try without lookup, just in case
234+
if (!foundEntry)
235+
for (int i = 0; i < user->schedule()->count(); i++) {
236+
RamScheduleEntry *entry = RamScheduleEntry::c( user->schedule()->get(i) );
237+
RamProject *entryProj = entry->project();
238+
if (!entryProj) continue;
239+
// For current project only
240+
if (!entryProj->is(currentProject)) continue;
241+
if (entry->date() != date) continue;
242+
243+
if (!foundEntry)
244+
{
245+
foundEntry = entry;
246+
break;
247+
}
248+
}
249+
242250
if (foundEntry)
243251
{
244252
// Add AMP/PM Info to entry data

src/ramobjectmodels/statisticsmodel.cpp

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,17 +52,20 @@ QVariant StatisticsModel::data(const QModelIndex &index, int role) const
5252
{
5353
int row = index.row();
5454

55-
RamStep *step = RamStep::c( m_project->steps()->get( row ) );
55+
if (!m_project) return QVariant();
56+
57+
RamStep *step = RamStep::c( m_project->steps()->get(row) );
5658
if (!step) return QVariant();
5759

58-
QVector<float> userStats = step->stats(m_user);
60+
QVector<float> userStats = m_statsPerStep.value(step->uuid(), QVector<float>(5));
5961
float estimation = userStats.at(0);
6062
float daysSpent = userStats.at(1);
6163
float assigned = userStats.at(2);
6264
float needed = estimation - daysSpent;
6365
float futureUnassigned = needed - userStats.at(3);
6466
float unassignedDays = estimation - assigned;
6567
float completion = 100;
68+
float latenessRatio = userStats.at(4);
6669
if (estimation > 0)
6770
completion = daysSpent / estimation * 100;
6871

@@ -112,7 +115,6 @@ QVariant StatisticsModel::data(const QModelIndex &index, int role) const
112115
}
113116
if (role == Qt::ForegroundRole)
114117
{
115-
float latenessRatio = step->latenessRatio();
116118
QColor timeColor;
117119
if ( latenessRatio < -0.05 ) timeColor = QColor(44,98,230);
118120
else if ( latenessRatio < -0.01 ) timeColor = QColor(50,100,186);
@@ -132,18 +134,18 @@ QVariant StatisticsModel::data(const QModelIndex &index, int role) const
132134
"\nCompletion: " %
133135
QString::number( completion, 'f', 0) %
134136
" %\nLateness: " %
135-
QString::number( (step->latenessRatio() -1) * 100, 'f', 0) %
137+
QString::number( (latenessRatio -1) * 100, 'f', 0) %
136138
" %");
137139

138140
if (role == Qt::StatusTipRole) return QString( step->shortName() % " | " % step->name() %
139141
" | Completion: " %
140142
QString::number( completion ) %
141143
" % | Lateness: " %
142-
QString::number( (step->latenessRatio() -1) * 100, 'f', 0) %
144+
QString::number( (latenessRatio -1) * 100, 'f', 0) %
143145
" %");
144146

145147
if (role == Qt::UserRole) return completion;
146-
if (role == Qt::UserRole +1) return step->latenessRatio();
148+
if (role == Qt::UserRole +1) return latenessRatio;
147149
if (role == Qt::UserRole +2) return estimation;
148150
if (role == Qt::UserRole +3) return QVariant();
149151
if (role == Qt::UserRole +4) return assigned;
@@ -185,6 +187,17 @@ void StatisticsModel::removeStep(const QModelIndex &parent, int first, int last)
185187

186188
void StatisticsModel::estimationComputed()
187189
{
190+
m_statsPerStep.clear();
191+
192+
// Cache data to improve perf
193+
if (m_project)
194+
for (int i = 0; i < m_project->steps()->rowCount(); i++) {
195+
RamStep *step = RamStep::c( m_project->steps()->get(i) );
196+
QVector<float> s = step->stats(m_user);
197+
s << step->latenessRatio();
198+
m_statsPerStep.insert(step->uuid(), s);
199+
}
200+
188201
emit dataChanged(createIndex(0,0), createIndex(rowCount()-1, 0));
189202
}
190203

src/ramobjectmodels/statisticsmodel.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ private slots:
3434
RamProject *m_project = nullptr;
3535
RamUser *m_user = nullptr;
3636

37+
QHash<QString, QVector<float>> m_statsPerStep; // step userstats + step lateness ratio
38+
3739
// Connect submodels and relay events
3840
void connectEvents();
3941
};

src/ramobjects/ramproject.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -540,6 +540,8 @@ void RamProject::freezeEstimation(bool frozen)
540540
if (!step) continue;
541541
step->freezeEstimation(frozen);
542542
}
543+
544+
if (!frozen) this->computeEstimation();
543545
}
544546

545547
// PROTECTED //

src/ramobjects/ramscheduleentry.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ RamScheduleEntry::RamScheduleEntry(RamUser *user, RamStep *step, QDateTime date)
3333
QJsonObject d = data();
3434
d.insert("user", user->uuid());
3535
d.insert("step", step->uuid());
36+
3637
RamProject *proj = step->project();
3738
if (proj) d.insert("project", proj->uuid());
3839

@@ -47,8 +48,13 @@ RamScheduleEntry::RamScheduleEntry(RamUser *user, RamStep *step, QDateTime date)
4748
RamProject *RamScheduleEntry::project() const
4849
{
4950
QString projUuid = getData("project").toString();
50-
if (projUuid != "") return RamProject::get( projUuid );
51-
else return nullptr;
51+
if (projUuid == "") {
52+
// Try with the step
53+
RamStep *s = this->step();
54+
if (s) return s->project();
55+
}
56+
57+
return RamProject::get( projUuid );
5258
}
5359

5460
RamScheduleEntry::RamScheduleEntry(QString uuid):
@@ -91,7 +97,6 @@ void RamScheduleEntry::setStep(RamStep *newStep)
9197
if (currentStep)
9298
{
9399
disconnect(currentStep, nullptr, this, nullptr);
94-
disconnect(this, nullptr, currentStep, nullptr);
95100
}
96101

97102
insertData("step", newStep->uuid());

0 commit comments

Comments
 (0)