Migrated old visualization of the bidding round statuses with donut charts from the legacy BeetRound project.
This commit is contained in:
@ -291,6 +291,18 @@ void TableModel::onRowCountChanged(const QModelIndex& parent, int first, int las
|
||||
}
|
||||
emit rowCountChanged();
|
||||
emit nExpectedBiddingsChanged();
|
||||
|
||||
emit nPlacedBiddingsChanged(1);
|
||||
emit nPlacedBiddingsChanged(2);
|
||||
emit nPlacedBiddingsChanged(3);
|
||||
|
||||
emit biddingSumChanged(1);
|
||||
emit biddingSumChanged(2);
|
||||
emit biddingSumChanged(3);
|
||||
|
||||
emit biddingAverageChanged(1);
|
||||
emit biddingAverageChanged(2);
|
||||
emit biddingAverageChanged(3);
|
||||
}
|
||||
|
||||
int TableModel::nExpectedBiddings() const {
|
||||
@ -303,6 +315,35 @@ int TableModel::nExpectedBiddings() const {
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
int TableModel::nPlacedBiddings1() const { return nPlacedBiddings(Bidding1Role); }
|
||||
int TableModel::nPlacedBiddings2() const { return nPlacedBiddings(Bidding2Role); }
|
||||
int TableModel::nPlacedBiddings3() const { return nPlacedBiddings(Bidding3Role); }
|
||||
|
||||
int TableModel::biddingSum1() const { return biddingSum(Bidding1Role); }
|
||||
int TableModel::biddingSum2() const { return biddingSum(Bidding2Role); }
|
||||
int TableModel::biddingSum3() const { return biddingSum(Bidding3Role); }
|
||||
|
||||
qreal TableModel::biddingAverage1() const {
|
||||
const UserRoles biddingRole = Bidding1Role;
|
||||
const qreal averageBidding = averageBiddingAmount(biddingRole);
|
||||
qInfo() << "average calculation (1):" << averageBidding;
|
||||
return averageBidding;
|
||||
}
|
||||
|
||||
qreal TableModel::biddingAverage2() const {
|
||||
const UserRoles biddingRole = Bidding2Role;
|
||||
const qreal averageBidding = averageBiddingAmount(biddingRole);
|
||||
qInfo() << "average calculation (2):" << averageBidding;
|
||||
return averageBidding;
|
||||
}
|
||||
qreal TableModel::biddingAverage3() const {
|
||||
const UserRoles biddingRole = Bidding3Role;
|
||||
const qreal averageBidding = averageBiddingAmount(biddingRole);
|
||||
qInfo() << "average calculation (3):" << averageBidding;
|
||||
return averageBidding;
|
||||
}
|
||||
|
||||
void TableModel::execInsertItems(const int firstRow, const QList<ModelItemValues> valueList) {
|
||||
const int nRows = valueList.size();
|
||||
qDebug() << "Inserting" << nRows << "items...";
|
||||
@ -339,7 +380,37 @@ void TableModel::execEditItemData(const int row, const QMap<int, QVariant>& chan
|
||||
emit dataChanged(firstIndex, lastIndex, roles.toVector());
|
||||
|
||||
// NEXT check which roles are changed & trigger only changed properties
|
||||
emit nExpectedBiddingsChanged();
|
||||
if (roles.contains(BiddingTypeRole) || roles.contains(ShareAmountRole)) {
|
||||
emit nExpectedBiddingsChanged();
|
||||
}
|
||||
if (roles.contains(ShareAmountRole) || roles.contains(ShareTypeRole)) {
|
||||
emit nPlacedBiddingsChanged(1);
|
||||
emit nPlacedBiddingsChanged(2);
|
||||
emit nPlacedBiddingsChanged(3);
|
||||
emit biddingSumChanged(1);
|
||||
emit biddingSumChanged(2);
|
||||
emit biddingSumChanged(3);
|
||||
emit biddingAverageChanged(1);
|
||||
emit biddingAverageChanged(2);
|
||||
emit biddingAverageChanged(3);
|
||||
} else {
|
||||
/// no changes to share amount or type, but maybe to the biddings:
|
||||
if (roles.contains(Bidding1Role)) {
|
||||
emit nPlacedBiddingsChanged(1);
|
||||
emit biddingSumChanged(1);
|
||||
emit biddingAverageChanged(1);
|
||||
}
|
||||
if (roles.contains(Bidding2Role)) {
|
||||
emit nPlacedBiddingsChanged(2);
|
||||
emit biddingSumChanged(2);
|
||||
emit biddingAverageChanged(2);
|
||||
}
|
||||
if (roles.contains(Bidding3Role)) {
|
||||
emit nPlacedBiddingsChanged(3);
|
||||
emit biddingSumChanged(3);
|
||||
emit biddingAverageChanged(3);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -435,3 +506,64 @@ bool TableModel::isItemEqualToItemValues(const QModelIndex& itemIndex,
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
int TableModel::nPlacedBiddings(const UserRoles biddingRole) const {
|
||||
int result = 0;
|
||||
for (auto i = m_items.begin(), end = m_items.end(); i != end; ++i) {
|
||||
int localBidding = (*i)->data(biddingRole).toInt();
|
||||
if (localBidding > 0) {
|
||||
result++;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
int TableModel::biddingSum(const UserRoles biddingRole) const {
|
||||
int result = 0;
|
||||
for (auto i = m_items.begin(), end = m_items.end(); i != end; ++i) {
|
||||
result += (*i)->data(biddingRole).toInt();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
qreal TableModel::averageBiddingAmount(const UserRoles biddingRole) const {
|
||||
qInfo() << "Calculating average bidding for role:" << ROLE_NAMES.value(biddingRole);
|
||||
const qreal localTotalSharesWithBiddings = totalSharesWithBiddings(biddingRole);
|
||||
|
||||
if (localTotalSharesWithBiddings <= 0) {
|
||||
qInfo() << "No biddings found. Aborting calculation...";
|
||||
return 0;
|
||||
}
|
||||
|
||||
const qreal localTotalBiddingAmount = biddingSum(biddingRole);
|
||||
const qreal alternateBiddingAverage = localTotalBiddingAmount / localTotalSharesWithBiddings;
|
||||
qDebug() << "Total bidding amount:" << localTotalBiddingAmount;
|
||||
qDebug() << "Total bidding shares:" << localTotalSharesWithBiddings;
|
||||
return alternateBiddingAverage;
|
||||
}
|
||||
|
||||
qreal TableModel::totalSharesWithBiddings(const UserRoles biddingRole) const {
|
||||
qreal result = 0;
|
||||
for (auto i = m_items.begin(), end = m_items.end(); i != end; ++i) {
|
||||
const qreal bidding = (*i)->data(biddingRole).toReal();
|
||||
const qreal shareAmount = (*i)->data(ShareAmountRole).toReal();
|
||||
const QString shareType = (*i)->data(ShareTypeRole).toString();
|
||||
const bool isValid = bidding != 0 && shareAmount != 0;
|
||||
if (isValid) {
|
||||
// qInfo() << "Including entry in bidding average calculation. MailRole:"
|
||||
// << (*i)->data(MailRole);
|
||||
// qreal bidForWholeShare = 0;
|
||||
if (shareType == "bezahlt") {
|
||||
result += shareAmount;
|
||||
} else if (shareType == "teils/teils") {
|
||||
result += shareAmount / 2;
|
||||
} else {
|
||||
qInfo() << "Share type not 'bezahlt' nor 'teils/teils'. Will be ignored..";
|
||||
qDebug() << "Share type:" << shareType;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
qInfo() << "Biddings exist for " << result << "shares!";
|
||||
return result;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user