Initial commit

This commit is contained in:
torsten committed 2026-08-13 18:33:10 +02:00
commit b7d90b9afe
16245 files changed
+3396666

No files matched your search

@@ -0,0 +1,233 @@
/**
* @RDE_HEADER@
* Base class and factory for further ChartModel classes
* $Id$
* $HeadURL$
* $Author$
* Created by Hannes Baeuerle, SLSE, 2017-03-01
*/
#include "rep_abstract_model.h"
#include "rep_unit_power_model.h"
#include "rep_participant_distance_model.h"
#include "rep_charge_administration_model.h"
#include "rep_charge_resupply_model.h"
#include "rep_firings_model.h"
#include "rep_air_support_model.h"
#include "rep_mine_area_model.h"
#include "rep_nbc_model.h"
#include "rep_maintenance_model.h"
#include "rep_building_damage_model.h"
#include "rep_sanitation_material_model.h"
#include "rep_medevac_nine_liner_model.h"
#include "rep_treatment_model.h"
#include "rep_treatment_timeline_model.h"
#include <Plugins/ReportManagement/rep_data_plugin_interface.h>
#include <LtsUtilsCore/dds_vector.h>
using namespace ReportManagement;
// -----------------------------------------------------------------------------------------------------------------------------------------------
ReportManagement::AbstractModel *ReportManagement::AbstractModel::create(const ReportInfo &report, LtsSession::LtsSession *session, QObject *parent)
{
switch (report.reportType().underlying())
{
case ReportType::UnitPower:
return new UnitPowerModel(report, session, parent);
case ReportType::ParticipantDistance:
return new ParticipantDistanceModel(report, session, parent);
case ReportType::MineArea:
return new MineAreaModel(report, session, parent);
case ReportType::Nbc:
return new NbcModel(report, session, parent);
case ReportType::Firings:
case ReportType::ExplosiveDevice:
return new FiringsModel(report, session, parent);
case ReportType::AirSupport:
return new AirSupportModel(report, session, parent);
case ReportType::ChargeAdministration:
return new ChargeAdministrationModel(report, session, parent);
case ReportType::ChargeResupply:
return new ChargeResupplyModel(report, session, parent);
case ReportType::VehicleRepair:
case ReportType::Decontamination:
return new MaintenanceModel(report, session, parent);
case ReportType::BuildingDamage:
return new BuildingDamageModel(report, session, parent);
case ReportType::SanitationMaterial:
return new SanitationMaterialModel(report, session, parent);
case ReportType::MedevacNineLiner:
return new MedevacNineLinerModel(report, session, parent);
case ReportType::Treatment:
case ReportType::TreatmentPriority:
case ReportType::TreatmentChain:
return new TreatmentModel(report, session, parent);
case ReportType::TreatmentTimeline:
return new TreatmentTimelineModel(report, session, parent);
}
return nullptr;
}
// -----------------------------------------------------------------------------------------------------------------------------------------------
AbstractModel::AbstractModel(const ReportInfo &report, LtsSession::LtsSession *session, QObject *parent)
: QAbstractTableModel(parent)
, m_report(report)
, m_reportJsonArray(QJsonArray())
, m_requestHelper(new LtsUtils::RequestHelper(this))
, m_session(session)
{
}
// -----------------------------------------------------------------------------------------------------------------------------------------------
bool AbstractModel::getReportData(const ReportManagement::ReportInfo &report)
{
std::shared_ptr<ReportManagement::Interface::Ftc> ftc;
if (!m_session->getFtc<ReportManagement::DataInterface>(ftc))
return false;
std::vector<uint8_t> content;
std::function<void(const Core::FunctionReply &baseReply)> handleContent = [&](const Core::FunctionReply & baseReply)
{
const GetReportDataReply &reply = static_cast<const GetReportDataReply &>(baseReply);
content = reply.reportData();
};
if (!m_requestHelper->startSingleRequest([ = ]()
{
GetReportDataRequest req;
req.reportId(report.id());
req.reportType(report.reportType());
return ftc->getReportDataRequest(req, this);
}, handleContent))
{
return false;
}
QJsonDocument doc(QJsonDocument::fromBinaryData(LtsUtils::toQByteArray(content)));
if (doc.isNull() || doc.isEmpty())
return false;
m_reportJsonArray = doc.array(); // no main key here!
return true;
}
//----------------------------------------------------------------------------
bool AbstractProxyModel::filterAcceptsRow(int source_row, const QModelIndex &source_parent) const
{
if (m_groupId > 0 && sourceModel())
{
int groupId = sourceModel()->data(sourceModel()->index(source_row,0), Qt::EditRole).toInt();
return (m_groupId == groupId);
}
return QSortFilterProxyModel::filterAcceptsRow(source_row, source_parent);
}
// Treatment reports columns, from rep_treatment_model.h
enum Columns
{
PARTICIPANT = 0,
VITALITY = 1,
VULNERABILITY = 2,
TIME_VULNERABILITY = 3,
TIME_VITALITY = 4,
TIME_NINE_LINER = 5,
TIME_POSITION_CHANGED = 6,
TIME_ENTER_AREA = 7,
TIME_TREATMENT = 8,
DURATION_TREATMENT = 9,
GOLDEN_HOUR = 11,
SANITATION_PROCEDURES_TAKEN = 12,
SANITATION_RESULT = 13,
QUALIFICATION = 14,
SANITATION_EVALUATION = 15,
PRIORITY = 16,
PRIORITY_CORRECT = 17,
DURATION_NINE_LINER = 18,
DURATION_POSITION_CHANGED= 19,
DURATION_ENTER_AREA = 20,
FUNCTIONAL_AREA = 21,
PARTICIPANT_TYPE_NAME = 22,
PARTICIPANT_EQUIPMENT_NO = 23,
PARTICIPANT_NAME = 24,
PARTICIPANT_ID = 25,
PARTICIPANT_TYPE_ID = 26,
AREA_ID = 27,
#ifdef LTS_DEBUG
COUNT = 28
#else
COUNT = 22 // without last 6 columns
#endif
};
/*
enum TimelineColumns
{
EVENT_TIME = 0,
EVENT_TYPE = 1,
VULNERABILITY = 2,
VITALITY = 3,
AREA_NAME = 4,
PARTICIPANT_EQUIPMENT_NO = 5,
PARTICIPANT_NAME = 6,
PARTICIPANT_ID = 7,
PARTICIPANT_TYPE_ID = 8,
PARTICIPANT_TYPE_NAME = 9
};
*/
//----------------------------------------------------------------------------
bool AbstractProxyModel::filterAcceptsColumn(int source_column, const QModelIndex &source_parent) const
{
if (m_rt == ReportManagement::ReportType::TreatmentChain)
{
if (m_vis == VisualisationType::Table)
return !(source_column >= Columns::TIME_VITALITY &&
source_column <= Columns::PRIORITY_CORRECT); // hide columns
else
return (source_column >= Columns::DURATION_TREATMENT &&
source_column <= Columns::DURATION_NINE_LINER); // only duration columns
}
if (m_rt == ReportManagement::ReportType::TreatmentPriority) // hide these columns
return !(source_column == Columns::TIME_VITALITY ||
source_column == Columns::DURATION_TREATMENT ||
source_column == Columns::TIME_NINE_LINER ||
source_column == Columns::TIME_POSITION_CHANGED ||
source_column == Columns::TIME_ENTER_AREA ||
source_column == Columns::SANITATION_PROCEDURES_TAKEN ||
source_column == Columns::SANITATION_RESULT ||
source_column == Columns::SANITATION_EVALUATION ||
source_column >= Columns::DURATION_NINE_LINER);
/*
if (m_rt == ReportManagement::ReportType::Treatment && m_vis == VisualisationType::Table) // hide these columns
return !(//source_column == Columns::TIME_VULNERABILITY ||
//source_column == Columns::TIME_TREATMENT ||
source_column == Columns::TIME_VITALITY ||
source_column == Columns::VITALITY ||
source_column == Columns::SANITATION_RESULT ||
source_column == Columns::SANITATION_PROCEDURES_TAKEN ||
source_column == Columns::TIME_NINE_LINER ||
source_column == Columns::TIME_POSITION_CHANGED ||
//source_column == Columns::TIME_ENTER_AREA ||
source_column >= Columns::SANITATION_EVALUATION);
*/
if (m_rt == ReportManagement::ReportType::TreatmentTimeline && m_vis == VisualisationType::Line) // show only TimelineColumns::VITALITY
return (source_column == 3);
return QSortFilterProxyModel::filterAcceptsColumn(source_column, source_parent);
}
//----------------------------------------------------------------------------
void AbstractProxyModel::setFilterGroup(int groupId)
{
if (m_groupId == groupId)
return;
m_groupId = groupId;
invalidateFilter();
}
@@ -0,0 +1,81 @@
/**
* @RDE_HEADER@
* Base class and factory for further ChartModel classes
* $Id$
* $HeadURL$
* $Author$
* Created by Hannes Baeuerle, SLSE, 2017-03-01
*/
#pragma once
#include <QSet>
#include <QSortFilterProxyModel>
#include <QAbstractTableModel>
#include <QJsonDocument>
#include <QJsonObject>
#include <QJsonArray>
#include <QVariantList>
#include <QtGui/QBrush>
#include <ReportManagement/rep_dtc.h>
#include <ReportManagement/rep_ftc.h>
#include <LtsSession/lts_session.h>
#include <LtsUtilsGuiDds/request_helper.h>
namespace ReportManagement
{
class AbstractModel
: public QAbstractTableModel
, protected ReportManagement::Interface::Ftc::GetReportDataReplyHandler
{
Q_OBJECT
public: // methods
static AbstractModel *create(const ReportManagement::ReportInfo &report, LtsSession::LtsSession *session, QObject *parent = nullptr);
bool getReportData(const ReportManagement::ReportInfo &report);
virtual bool fetchInterfaces() = 0;
virtual void fillReportData() = 0;
protected: // methods
explicit AbstractModel(const ReportManagement::ReportInfo &report, LtsSession::LtsSession *session, QObject *parent);
void onGetReportDataReply(const GetReportDataReply &replyObject) override final { m_requestHelper->requestReply(replyObject); }
template<typename T, typename S>
void sumUp(T &dst, const S &src, int count)
{
for(int i = 0; i < count; ++i)
dst[i] += src[i];
}
protected: // attributes
ReportManagement::ReportInfo m_report;
QJsonArray m_reportJsonArray;
LtsUtils::RequestHelper *m_requestHelper;
LtsSession::LtsSession *m_session;
}; // class AbstractModel
// -------------------------------------------------------------------------------------
class AbstractProxyModel final : public QSortFilterProxyModel
{
Q_OBJECT
public:
using QSortFilterProxyModel::QSortFilterProxyModel;
void setFilterGroup(int groupId);
void setReportType(const ReportManagement::ReportType &rt) { m_rt = rt; }
void setReportVisualisation(const ReportManagement::VisualisationType &vis) { m_vis = vis; }
protected:
bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const override;
bool filterAcceptsColumn(int source_column, const QModelIndex &source_parent) const override;
private:
int m_groupId = 0;
ReportManagement::ReportType m_rt;
ReportManagement::VisualisationType m_vis;
};
} // namespace
@@ -0,0 +1,478 @@
/**
* @RDE_HEADER@
* Shows a report of combat power in form of curves
* $Id$
* $HeadURL$
* $Author$
*/
#include "rep_air_support_model.h"
#include <PluginInterfaces/gui_plugin_interface.h>
#include <Plugins/ProjectDataManagement/pdm_data_plugin_interface.h>
#include <Plugins/AreaEffectSimulation/aes_data_plugin_interface.h>
#include <Plugins/ReportManagement/rep_data_plugin_interface.h>
#include <ProjectDataManagement/pdm_translation.h>
#include <LtsSession/lts_session.h>
#include <ngltools/ngltools_dtg.h>
#include <QFont>
using namespace ReportManagement;
//----------------------------------------------------------------------------
AirSupportModel::AirSupportModel(const ReportInfo &report, LtsSession::LtsSession *session, QObject *parent)
: AbstractModel(report, session, parent)
, m_pdmDtc(nullptr)
, m_logger(getLogger("AirSupportModel"))
{
if (!fetchInterfaces())
return;
//#define TEST_DATA
#ifdef TEST_DATA
resultDataTable resData;
// charge type 371
resData.chargeTypeId = 371;
resData.startTime = 1513758640000;
resData.vulnerabilityState = ProjectDataManagement::VulnerabilityState::CatastrophicKill;
resData.hits = {9, 4, 4, 0};
m_dataTable.append(resData);
resData.chargeTypeId = 371;
resData.startTime = 1513758640000;
resData.vulnerabilityState = ProjectDataManagement::VulnerabilityState::MobilityKill;
resData.hits = {9, 4, 3, 1};
m_dataTable.append(resData);
resData.chargeTypeId = 371;
resData.startTime = 1513758640000;
resData.vulnerabilityState = ProjectDataManagement::VulnerabilityState::VisibleMobilityKill;
resData.hits = {2, 2, 2, 0};
m_dataTable.append(resData);
resData.chargeTypeId = 371;
resData.startTime = 1513758640000;
resData.vulnerabilityState = ProjectDataManagement::VulnerabilityState::NotReady; // total firings and hits on all VBGs
resData.hits = {20, 10, 9, 1};
m_dataTable.append(resData);
resultDataPie pieData;
pieData.chargeTypeId = 371;
pieData.startTime = 1513758640000;
pieData.hits = {20, 10, 9, 1};
m_dataPie.append(pieData);
// charge type 372
resData.chargeTypeId = 372;
resData.startTime = 1513758640000;
resData.vulnerabilityState = ProjectDataManagement::VulnerabilityState::CatastrophicKill;
resData.hits = {14, 4, 4, 0};
m_dataTable.append(resData);
resData.chargeTypeId = 372;
resData.startTime = 1513758640000;
resData.vulnerabilityState = ProjectDataManagement::VulnerabilityState::MobilityKill;
resData.hits = {4, 4, 3, 1};
m_dataTable.append(resData);
resData.chargeTypeId = 372;
resData.startTime = 1513758640000;
resData.vulnerabilityState = ProjectDataManagement::VulnerabilityState::VisibleMobilityKill;
resData.hits = {2, 2, 2, 0};
m_dataTable.append(resData);
resData.chargeTypeId = 372;
resData.startTime = 1513758640000;
resData.vulnerabilityState = ProjectDataManagement::VulnerabilityState::NotReady; // total firings and hits on all VBGs
resData.hits = {20, 10, 9, 1};
m_dataTable.append(resData);
pieData.chargeTypeId = 372;
pieData.startTime = 1513758640000;
pieData.hits = {20, 10, 9, 1};
m_dataPie.append(pieData);
resData.chargeTypeId = 0; // total
resData.startTime = 1513758640000;
resData.vulnerabilityState = ProjectDataManagement::VulnerabilityState::NotReady; // total firings and hits on all VBGs
resData.hits = {40, 20, 18, 2};
m_dataTable.append(resData);
#else
getReportData(report);
if (report.visualisationType() == VisualisationType::Table)
fillReportData();
else
fillPieData();
#endif
}
// -----------------------------------------------------------------------------------------------------
bool AirSupportModel::fetchInterfaces()
{
if (!m_session->getDtc<ProjectDataManagement::DataInterface>(m_pdmDtc))
{
ERROR_LOG(m_logger) << "Could not fetch PDM DTC Interface";
return false;
}
if (!m_session->getDtc<AreaEffectSimulation::DataInterface>(m_aesDtc))
{
ERROR_LOG(m_logger) << "Could not fetch PDM DTC Interface";
return false;
}
return true;
}
// -----------------------------------------------------------------------------------------------------
int AirSupportModel::rowCount(const QModelIndex &parent) const
{
if (m_report.visualisationType() == VisualisationType::Pie || m_report.visualisationType() == VisualisationType::Bar)
return parent.isValid() ? 0 : m_dataPie.count();
else
return parent.isValid() ? 0 : m_dataTable.count();
}
// -----------------------------------------------------------------------------------------------------
int AirSupportModel::columnCount(const QModelIndex &parent) const
{
if (m_report.visualisationType() == VisualisationType::Pie || m_report.visualisationType() == VisualisationType::Bar)
return parent.isValid() ? 0 : COUNT_PIE;
else
return parent.isValid() ? 0 : COUNT_TABLE;
}
// -----------------------------------------------------------------------------------------------------
QVariant AirSupportModel::data(const QModelIndex &index, int role) const
{
if (!index.isValid())
return QVariant();
if (m_report.visualisationType() == VisualisationType::Table)
{
const resultDataTable &displayInfo = m_dataTable[index.row()];
if (role == Qt::TextAlignmentRole)
{
switch (index.column())
{
case CHARGE_TYPE_ID:
case IMPACTS:
case HITS_TOTAL:
case HITS_ENEMY:
case HITS_FRIENDLY:
case HITS_BUILDING:
return Qt::AlignRight;
case START_TIME:
case CHARGE_TYPE_NAME:
case VULNERABILITY_STATE:
default:
return Qt::AlignLeft;
}
return Qt::AlignLeft;
}
if (role == Qt::FontRole)
{
QFont boldFont;
boldFont.setBold(true);
// total on charge type
if (displayInfo.chargeTypeId == 0 || displayInfo.vulnerabilityState == ProjectDataManagement::VulnerabilityState::NotReady)
return boldFont;
return QFont();
}
if (role == Qt::DisplayRole)
{
switch (index.column())
{
case CHARGE_TYPE_ID:
return (displayInfo.chargeTypeId > 0 ? displayInfo.chargeTypeId : QVariant());
case CHARGE_TYPE_NAME:
{
QString displayTypeName;
if (displayInfo.chargeTypeId > 0)
{
QString chargeTypeName = m_pdmDtc->trChargeTypeShortName(displayInfo.chargeTypeId);
if (displayInfo.vulnerabilityState == ProjectDataManagement::VulnerabilityState::NotReady)
displayTypeName = tr("Total [%1]").arg(chargeTypeName);
else
displayTypeName = chargeTypeName;
}
return (displayInfo.chargeTypeId > 0 ? displayTypeName : tr("TOTAL:"));
}
case START_TIME:
{
QString timeInterval = DTG::toStringMSec(displayInfo.startTime) + QStringLiteral(" - " ) + DTG::toStringMSec(displayInfo.endTime);
return (displayInfo.vulnerabilityState != ProjectDataManagement::VulnerabilityState::NotReady ? timeInterval : QVariant());
}
case IMPACTS:
return (displayInfo.hits[4] > 0 ? displayInfo.hits[4] : QVariant());
case HITS_BUILDING:
return (displayInfo.hits[0] > 0 ? displayInfo.hits[0] : QVariant());
case HITS_TOTAL:
return (displayInfo.hits[1] > 0 ? displayInfo.hits[1] : QVariant());
case HITS_ENEMY:
return displayInfo.hits[2];
case HITS_FRIENDLY:
return displayInfo.hits[3];
case VULNERABILITY_STATE:
return ((displayInfo.vulnerabilityState != ProjectDataManagement::VulnerabilityState::NotReady &&
displayInfo.vulnerabilityState != ProjectDataManagement::VulnerabilityState::CombatReady) ?
ProjectDataManagement::toString(displayInfo.vulnerabilityState): QVariant());
default:
return QVariant();
}
}
}
if (m_report.visualisationType() == VisualisationType::Pie || m_report.visualisationType() == VisualisationType::Bar)
{
const resultDataPie &pieInfo = m_dataPie[index.row()];
if (role == Qt::EditRole)
{
return pieInfo.chargeTypeId;
}
if (role == Qt::UserRole)
{
return pieInfo.chargeTypeId > 0 ? m_pdmDtc->trChargeTypeShortName(pieInfo.chargeTypeId) : QVariant();
}
if (role == Qt::DisplayRole)
{
switch (index.column())
{
case HITS_ENEMY_PIE:
return pieInfo.hits[2] > 0 ? pieInfo.hits[2] : QVariant();
case HITS_FRIENDLY_PIE:
return pieInfo.hits[3] > 0 ? pieInfo.hits[3] : QVariant();
case HITS_BUILDING_PIE:
return pieInfo.hits[0] > 0 ? pieInfo.hits[0] :QVariant();
case START_TIME_PIE:
return DTG::toStringMSec(pieInfo.startTime);
default:
return QVariant();
}
}
}
return QVariant();
}
// -----------------------------------------------------------------------------------------------------
QVariant AirSupportModel::headerData(int section, Qt::Orientation orientation, int role) const
{
if (orientation == Qt::Horizontal && role == Qt::FontRole)
{
QFont boldFont;
boldFont.setBold(true);
return boldFont;
}
if (orientation == Qt::Horizontal && role == Qt::DisplayRole)
{
if (m_report.visualisationType() == VisualisationType::Table)
{
switch (section)
{
case CHARGE_TYPE_ID:
return tr("Charge Id");
case CHARGE_TYPE_NAME:
return tr("Charge Type");
case VULNERABILITY_STATE:
return tr("Hit Effects");
case START_TIME:
return tr("Interval Start Time");
case IMPACTS:
return tr("Impacts");
case HITS_TOTAL:
return tr("Hits");
case HITS_ENEMY:
return tr("Enemy Forces Hits");
case HITS_FRIENDLY:
return tr("Own Force Hits");
case HITS_BUILDING:
return tr("Hit Buildings");
default:
return QVariant();
}
}
if (m_report.visualisationType() == VisualisationType::Pie || m_report.visualisationType() == VisualisationType::Bar)
{
switch (section)
{
case START_TIME_PIE:
return tr("Time");
case HITS_ENEMY_PIE:
return tr("Enemy Forces Hits");
case HITS_FRIENDLY_PIE:
return tr("Own Force Hits");
case HITS_BUILDING_PIE:
return tr("Buildings hits");
default:
return QVariant();
}
}
}
if (orientation == Qt::Vertical && role == Qt::DisplayRole && m_report.visualisationType() == VisualisationType::Bar)
{
return DTG::toStringMSec(m_dataPie[section].startTime);
}
return QAbstractTableModel::headerData(section, orientation, role);
}
// ------------------------------------------------------------------
void AirSupportModel::fillReportData()
{
DEBUG_LOG(m_logger) << "fillReportData(): m_reportJsonArray.size() = " << m_reportJsonArray.size();
int chargeTypeId = -1;
QMap<int, QVector<int> > sums;
QVector<int> bigTotal(5, 0);
resultDataTable resData;
for (const QJsonValue &arrVal : qAsConst(m_reportJsonArray))
{
const QJsonObject obj = arrVal.toObject();
resData.chargeTypeId = obj[QStringLiteral("charge_type_id")].toInt();
resData.startTime = obj[QStringLiteral("start_time")].toDouble();
resData.endTime = obj[QStringLiteral("end_time")].toDouble();
resData.hits[4] = obj[QStringLiteral("impacts")].toInt();
resData.vulnerabilityState = static_cast<ProjectDataManagement::VulnerabilityState::type>(obj[QStringLiteral("vulnerability_state")].toInt());
resData.hits[0] = obj[QStringLiteral("hits_buildings")].toInt();
resData.hits[3] = obj[QStringLiteral("hits_friendly_fire")].toInt();
resData.hits[2] = obj[QStringLiteral("hits")].toInt();
resData.hits[1] = resData.hits[2] + resData.hits[3] + resData.hits[0];
INFO_LOG(m_logger) << "Charge type id = " << resData.chargeTypeId;
INFO_LOG(m_logger) << "Start time = " << resData.startTime;
INFO_LOG(m_logger) << "VulnerabilityState = " << resData.vulnerabilityState;
INFO_LOG(m_logger) << "Hits = ("
<< resData.hits[0] << ", "
<< resData.hits[1] << ", "
<< resData.hits[2] << ", "
<< resData.hits[3] << ", "
<< resData.hits[4] << ")" ;
if (chargeTypeId != resData.chargeTypeId) // new chargeTypeId
{
DEBUG_LOG(m_logger) << "New chargeTypeId: " << resData.chargeTypeId;
if (chargeTypeId != -1) // total on chargeTypeId
{
resultDataTable totalChargeTypeId;
totalChargeTypeId.chargeTypeId = chargeTypeId;
totalChargeTypeId.startTime = 0;
totalChargeTypeId.vulnerabilityState = ProjectDataManagement::VulnerabilityState::NotReady;
totalChargeTypeId.hits = sums[chargeTypeId];
m_dataTable.append(std::move(totalChargeTypeId));
sumUp(bigTotal, sums[chargeTypeId], sums[chargeTypeId].size());
}
chargeTypeId = resData.chargeTypeId;
sums[chargeTypeId].append(resData.hits);
}
else
{
DEBUG_LOG(m_logger) << "Adding values to chargeType id: " << chargeTypeId;
resData.hits[4] = 0; // count impact only once
sumUp(sums[chargeTypeId], resData.hits, resData.hits.size());
}
m_dataTable.append(resData); // no std::move() - allocated outside loop
}
if (m_reportJsonArray.size() > 0)
{
// last total on charge type
resultDataTable totalChargeTypeId;
totalChargeTypeId.chargeTypeId = chargeTypeId;
totalChargeTypeId.startTime = 0;
totalChargeTypeId.vulnerabilityState = ProjectDataManagement::VulnerabilityState::NotReady;
totalChargeTypeId.hits = sums[chargeTypeId];
m_dataTable.append(std::move(totalChargeTypeId));
sumUp(bigTotal, sums[chargeTypeId], sums[chargeTypeId].size());
// big total
resultDataTable total;
total.chargeTypeId = 0;
total.startTime = 0;
total.vulnerabilityState = ProjectDataManagement::VulnerabilityState::NotReady;
total.hits = bigTotal;
m_dataTable.append(std::move(total));
}
}
// ------------------------------------------------------------------
void AirSupportModel::fillPieData()
{
DEBUG_LOG(m_logger) << "fillPieData(): m_reportJsonArray.size() = " << m_reportJsonArray.size();
QMap<QPair<int,double>, QVector<int> > sums;
resultDataPie resPieData;
for (const QJsonValue &arrVal : qAsConst(m_reportJsonArray))
{
const QJsonObject obj = arrVal.toObject();
resPieData.chargeTypeId = obj[QStringLiteral("charge_type_id")].toInt();
resPieData.startTime = obj[QStringLiteral("start_time")].toDouble();
resPieData.hits[0] = obj[QStringLiteral("hits_buildings")].toInt();
resPieData.hits[3] = obj[QStringLiteral("hits_friendly_fire")].toInt();
resPieData.hits[2] = obj[QStringLiteral("hits")].toInt();
resPieData.hits[1] = resPieData.hits[2] + resPieData.hits[3];
INFO_LOG(m_logger) << "Charge type id = " << resPieData.chargeTypeId;
INFO_LOG(m_logger) << "Start time = " << resPieData.startTime;
INFO_LOG(m_logger) << "Hits = ("
<< resPieData.hits[0] << ", "
<< resPieData.hits[1] << ", "
<< resPieData.hits[2] << ", "
<< resPieData.hits[3] << ")" ;
QPair<int,double> key;
key.first = resPieData.chargeTypeId;
key.second = resPieData.startTime;
if (!sums.contains(key))
sums[key].append({0,0,0,0,0});
// wäre folgendes nicht einfacher und sprechender? 'sums[key] += resPieData.hits'
for(int i = 0; i < resPieData.hits.size(); ++i)
sums[key][i] += resPieData.hits[i];
}
const auto &keyValues = sums.keys();
for (const auto &key : keyValues) // do not iterate on temporary
{
resultDataPie resPie;
resPie.chargeTypeId = key.first;
resPie.startTime = key.second;
resPie.hits = sums[key];
INFO_LOG(m_logger) << "ChargeType: " << resPie.chargeTypeId;
INFO_LOG(m_logger) << "StartTime: " << resPie.startTime;
for(int i = 0; i < resPie.hits.size(); ++i)
INFO_LOG(m_logger) << "Hits = ("
<< resPie.hits[0] << ", "
<< resPie.hits[1] << ", "
<< resPie.hits[2] << ", "
<< resPie.hits[3] << ")" ;
m_dataPie.append(std::move(resPie));
}
}
@@ -0,0 +1,84 @@
/**
* @RDE_HEADER@
* Shows report player distance
* $Id$
* $HeadURL$
* $Author$
*/
#pragma once
#include "rep_abstract_model.h"
#include <ReportManagement/logger.h>
#include <ProjectDataManagement/pdm_dtc.h>
#include <AreaEffectSimulation/aes_dtc.h>
//----------------------------------------------------------------------------
namespace ReportManagement
{
class AirSupportModel final : public AbstractModel
{
Q_OBJECT
friend class AbstractModel;
public:
int rowCount(const QModelIndex &parent = QModelIndex()) const override final;
int columnCount(const QModelIndex &parent = QModelIndex()) const override final;
QVariant data(const QModelIndex &index, int role) const override final;
QVariant headerData(int section, Qt::Orientation orientation, int role) const override final;
bool fetchInterfaces() override final;
private:
explicit AirSupportModel(const ReportManagement::ReportInfo &report, LtsSession::LtsSession *session, QObject *parent);
void fillReportData() override final;
void fillPieData();
enum ColumnsTable
{
CHARGE_TYPE_NAME = 0,
START_TIME = 1,
IMPACTS = 2,
HITS_TOTAL = 3,
VULNERABILITY_STATE = 4,
HITS_ENEMY = 5,
HITS_BUILDING = 6,
HITS_FRIENDLY = 7,
CHARGE_TYPE_ID = 8,
#ifdef LTS_DEBUG
COUNT_TABLE = 9
#else
COUNT_TABLE = 7 // without last column
#endif
};
enum ColumnsPie
{
HITS_ENEMY_PIE = 0,
HITS_FRIENDLY_PIE = 1,
HITS_BUILDING_PIE = 2,
START_TIME_PIE = 3,
COUNT_PIE = 3
};
struct resultDataPie
{
//int aesId = 0;
int chargeTypeId = 0;
qint64 startTime = 0;
qint64 endTime = 0;
QVector<int> hits = {0, 0, 0, 0, 0};
};
struct resultDataTable : public resultDataPie
{
//QString aesName;
ProjectDataManagement::VulnerabilityState vulnerabilityState = ProjectDataManagement::VulnerabilityState::NotReady;
};
QVector<resultDataTable> m_dataTable;
QVector<resultDataPie> m_dataPie;
std::shared_ptr<ProjectDataManagement::Interface::Dtc> m_pdmDtc;
std::shared_ptr<AreaEffectSimulation::Interface::Dtc> m_aesDtc;
LOGGER_T m_logger;
};
}
@@ -0,0 +1,202 @@
/**
* @RDE_HEADER@
* Shows a report of combat power in form of curves
* $Id$
* $HeadURL$
* $Author$
*/
#include "rep_building_damage_model.h"
#include <PluginInterfaces/gui_plugin_interface.h>
#include <Plugins/ReportManagement/rep_data_plugin_interface.h>
#include <Plugins/InfrastructureManagement/ism_data_plugin_interface.h>
#include <LtsSession/lts_session.h>
#include <ngltools/ngltools_dtg.h>
#include <QFont>
using namespace ReportManagement;
//----------------------------------------------------------------------------
BuildingDamageModel::BuildingDamageModel(const ReportInfo &report, LtsSession::LtsSession *session, QObject *parent)
: AbstractModel(report, session, parent)
, m_ismDtc(nullptr)
, m_logger(getLogger("BuildingDamageModel"))
{
if (!fetchInterfaces())
return;
//#define TEST_DATA
#ifdef TEST_DATA
resultData resData;
resData.buildingId = 301;
resData.timePoint = 1513758640000;
resData.damages[0] = 20;
resData.damages[1] = 20;
resData.damages[2] = 20;
resData.damages[3] = 20;
resData.damages[4] = 20;
m_data.append(resData);
resData.buildingId = 301;
resData.timePoint = 1513758650000;
resData.damages[0] = 10;
resData.damages[1] = 30;
resData.damages[2] = 20;
resData.damages[3] = 20;
resData.damages[4] = 20;
m_data.append(resData);
#else
getReportData(report);
fillReportData();
#endif
}
// -----------------------------------------------------------------------------------------------------
int BuildingDamageModel::rowCount(const QModelIndex &parent) const
{
return parent.isValid() ? 0 : m_data.count();
}
// -----------------------------------------------------------------------------------------------------
int BuildingDamageModel::columnCount(const QModelIndex &parent) const
{
return parent.isValid() ? 0 : COUNT;
}
// -----------------------------------------------------------------------------------------------------
QVariant BuildingDamageModel::data(const QModelIndex &index, int role) const
{
if (!index.isValid())
return QVariant();
const resultData &displayInfo = m_data[index.row()];
if (role == Qt::TextAlignmentRole)
{
switch (index.column())
{
case BUILDING_ID:
case DAMAGE_20:
case DAMAGE_40:
case DAMAGE_60:
case DAMAGE_80:
case DAMAGE_100:
return Qt::AlignRight;
case BUILDING_NAME:
case TIME_POINT:
case ROOM_COUNT:
default:
return Qt::AlignLeft;
}
}
if (role == Qt::DisplayRole)
{
switch (index.column())
{
case BUILDING_ID:
return displayInfo.buildingId;
case BUILDING_NAME:
return m_ismDtc->getBuildingDisplayName(displayInfo.buildingId);
case TIME_POINT:
return DTG::toStringMSec(displayInfo.timePoint);
case ROOM_COUNT:
return m_ismDtc->getBuildingRoomsCount(displayInfo.buildingId);
case DAMAGE_20:
return displayInfo.damages[0];
case DAMAGE_40:
return displayInfo.damages[1];
case DAMAGE_60:
return displayInfo.damages[2];
case DAMAGE_80:
return displayInfo.damages[3];
case DAMAGE_100:
return displayInfo.damages[4];
default:
return QVariant();
}
}
return QVariant();
}
// -----------------------------------------------------------------------------------------------------
QVariant BuildingDamageModel::headerData(int section, Qt::Orientation orientation, int role) const
{
if (orientation == Qt::Horizontal && role == Qt::FontRole)
{
QFont boldFont;
boldFont.setBold(true);
return boldFont;
}
if (!(orientation == Qt::Horizontal && role == Qt::DisplayRole))
return QVariant();
switch (section)
{
case BUILDING_ID:
return tr("Building Id");
case BUILDING_NAME:
return tr("Building Name");
case ROOM_COUNT:
return tr("#Rooms");
case TIME_POINT:
return tr("Timepoint (start/end)");
case DAMAGE_20:
return tr("Damage level 0-20%");
case DAMAGE_40:
return tr("Damage level 20-40%");
case DAMAGE_60:
return tr("Damage level 40-60%");
case DAMAGE_80:
return tr("Damage level 60-80%");
case DAMAGE_100:
return tr("Damage level 80-100%");
default:
return QVariant();
}
}
// ------------------------------------------------------------------
void BuildingDamageModel::fillReportData()
{
DEBUG_LOG(m_logger) << "fillReportData(): m_reportJsonArray.size() = " << m_reportJsonArray.size();
for (const QJsonValue &arrVal : qAsConst(m_reportJsonArray))
{
const QJsonObject obj = arrVal.toObject();
resultData resData;
resData.buildingId = obj[QStringLiteral("building_id")].toInt();
resData.timePoint = obj[QStringLiteral("time_point")].toDouble();
resData.damages[0] = obj[QStringLiteral("damage_20")].toInt();
resData.damages[1] = obj[QStringLiteral("damage_40")].toInt();
resData.damages[2] = obj[QStringLiteral("damage_60")].toInt();
resData.damages[3] = obj[QStringLiteral("damage_80")].toInt();
resData.damages[4] = obj[QStringLiteral("damage_100")].toInt();
resData.buildingDamagePercent = obj[QStringLiteral("damage_percent")].toInt();
INFO_LOG(m_logger) << "Building Id = " << resData.buildingId;
INFO_LOG(m_logger) << "Time point = " << resData.timePoint;
INFO_LOG(m_logger) << "Damages = " << resData.damages;
INFO_LOG(m_logger) << "Building Damage Percent = " << resData.buildingDamagePercent;
m_data.append(std::move(resData));
}
}
// -----------------------------------------------------------------------------------------------------
bool BuildingDamageModel::fetchInterfaces()
{
if (!m_session->getDtc<InfrastructureManagement::DataInterface>(m_ismDtc))
{
ERROR_LOG(m_logger) << "Could not fetch ISM DTC Interface";
return false;
}
return true;
}
@@ -0,0 +1,65 @@
/**
* @RDE_HEADER@
* Shows report player distance
* $Id$
* $HeadURL$
* $Author$
*/
#pragma once
#include "rep_abstract_model.h"
#include <ReportManagement/logger.h>
#include <InfrastructureManagement/ism_dtc.h>
//----------------------------------------------------------------------------
namespace ReportManagement
{
class BuildingDamageModel final : public AbstractModel
{
Q_OBJECT
friend class AbstractModel;
public:
int rowCount(const QModelIndex &parent = QModelIndex()) const override final;
int columnCount(const QModelIndex &parent = QModelIndex()) const override final;
QVariant data(const QModelIndex &index, int role) const override final;
QVariant headerData(int section, Qt::Orientation orientation, int role) const override final;
bool fetchInterfaces() override final;
private:
explicit BuildingDamageModel(const ReportManagement::ReportInfo &report, LtsSession::LtsSession *session, QObject *parent);
void fillReportData() override final;
enum Columns
{
BUILDING_NAME = 0,
TIME_POINT = 1,
ROOM_COUNT = 2,
DAMAGE_20 = 3,
DAMAGE_40 = 4,
DAMAGE_60 = 5,
DAMAGE_80 = 6,
DAMAGE_100 = 7,
BUILDING_ID = 8,
#ifdef LTS_DEBUG
COUNT = 9
#else
COUNT = 8 // without last column
#endif
};
struct resultData
{
int buildingId = 0;
int buildingDamagePercent = 0;
int damages[5] = {0,0,0,0,0};
qint64 timePoint = 0;
};
QVector<resultData> m_data;
std::shared_ptr<InfrastructureManagement::Interface::Dtc> m_ismDtc;
LOGGER_T m_logger;
};
}
@@ -0,0 +1,255 @@
/**
* @RDE_HEADER@
* Shows a report of combat power in form of curves
* $Id$
* $HeadURL$
* $Author$
*/
#include "rep_charge_administration_model.h"
#include <PluginInterfaces/gui_plugin_interface.h>
#include <Plugins/ProjectDataManagement/pdm_data_plugin_interface.h>
#include <Plugins/ReportManagement/rep_data_plugin_interface.h>
#include <ProjectDataManagement/pdm_translation.h>
#include <LtsSession/lts_session.h>
#include <QFont>
using namespace ReportManagement;
//----------------------------------------------------------------------------
ChargeAdministrationModel::ChargeAdministrationModel(const ReportInfo &report, LtsSession::LtsSession *session, QObject *parent)
: AbstractModel(report, session, parent)
, m_pdmDtc(nullptr)
, m_logger(getLogger("ChargeAdministrationModel"))
{
if (!fetchInterfaces())
return;
// #define TEST_DATA
#ifdef TEST_DATA
resultData resData;
resData.chargeTypeId = 371;
resData.charges[0] = 1000;
resData.charges[1] = 1000;
resData.charges[2] = 500;
resData.charges[3] = 1500;
m_data.append(resData);
resData.chargeTypeId = 372;
resData.charges[0] = 1000;
resData.charges[1] = 1000;
resData.charges[2] = 500;
resData.charges[3] = 1500;
m_data.append(resData);
resData.chargeTypeId = 0;
resData.charges[0] = 2000;
resData.charges[1] = 2000;
resData.charges[2] = 1000;
resData.charges[3] = 3000;
m_data.append(resData);
#else
getReportData(report);
fillReportData();
#endif
}
// -----------------------------------------------------------------------------------------------------
bool ChargeAdministrationModel::fetchInterfaces()
{
if (!m_session->getDtc<ProjectDataManagement::DataInterface>(m_pdmDtc))
{
ERROR_LOG(m_logger) << "Could not fetch PDM DTC Interface";
return false;
}
return true;
}
// -----------------------------------------------------------------------------------------------------
int ChargeAdministrationModel::rowCount(const QModelIndex &parent) const { return parent.isValid() ? 0 : m_data.count(); }
// -----------------------------------------------------------------------------------------------------
int ChargeAdministrationModel::columnCount(const QModelIndex &parent) const { return parent.isValid() ? 0 : COUNT; }
// -----------------------------------------------------------------------------------------------------
QVariant ChargeAdministrationModel::data(const QModelIndex &index, int role) const
{
if (!index.isValid())
return QVariant();
const resultData &displayInfo = m_data[index.row()];
if (role == Qt::TextAlignmentRole)
{
switch (index.column())
{
case CHARGE_TYPE_ID:
case GEAR_CLASS:
case CHARGE_START:
case CHARGE_END:
case CHARGE_RESUPPLIED:
case CHARGE_FIRED:
case CHARGE_PLANNED:
case CHARGE_AVAILABLE:
return Qt::AlignRight;
case CHARGE_TYPE_NAME:
default:
return Qt::AlignLeft;
}
return Qt::AlignLeft;
}
if (role == Qt::FontRole)
{
QFont boldFont;
boldFont.setBold(true);
// total
if (displayInfo.chargeTypeId == 0)
return boldFont;
return QFont();
}
if (role == Qt::DisplayRole)
{
switch (index.column())
{
case CHARGE_TYPE_ID:
return (displayInfo.chargeTypeId > 0 ? displayInfo.chargeTypeId : QVariant());
case EFFECT_SOURCE_ID:
return (displayInfo.effectSourceId.underlying() >= 0 ? ProjectDataManagement::toString(displayInfo.effectSourceId) : tr("Total:"));
case GEAR_CLASS:
return (displayInfo.chargeTypeId > 0 ? ProjectDataManagement::toString(m_pdmDtc->gearClassFromChargeTypeId(displayInfo.chargeTypeId)) : QVariant());
case CHARGE_TYPE_NAME:
return (displayInfo.chargeTypeId > 0 ? m_pdmDtc->trChargeTypeShortName(displayInfo.chargeTypeId, true) : tr("TOTAL:"));
case CHARGE_START:
return displayInfo.charges[0];
case CHARGE_RESUPPLIED:
return displayInfo.charges[1];
case CHARGE_END:
return displayInfo.charges[2];
case CHARGE_FIRED:
return displayInfo.charges[3];
case CHARGE_PLANNED:
return displayInfo.charges[4];
case CHARGE_AVAILABLE:
return displayInfo.charges[5];
default:
return QVariant();
}
}
return QVariant();
}
// -----------------------------------------------------------------------------------------------------
QVariant ChargeAdministrationModel::headerData(int section, Qt::Orientation orientation, int role) const
{
if (orientation == Qt::Horizontal && role == Qt::FontRole)
{
QFont boldFont;
boldFont.setBold(true);
return boldFont;
}
if (!(orientation == Qt::Horizontal && role == Qt::DisplayRole))
return QVariant();
switch (section)
{
case EFFECT_SOURCE_ID:
return tr("Effect Source Id");
case CHARGE_TYPE_ID:
return tr("Charge Id");
case GEAR_CLASS:
return tr("Gear Class");
case CHARGE_TYPE_NAME:
return tr("Charge Type");
case CHARGE_START:
return tr("Stock Start");
case CHARGE_RESUPPLIED:
return tr("Resupplied");
case CHARGE_END:
return tr("Total Stock");
case CHARGE_FIRED:
return tr("Used");
case CHARGE_PLANNED:
return tr("Planned");
case CHARGE_AVAILABLE:
return tr("Available");
default:
return QVariant();
}
}
// ------------------------------------------------------------------
void ChargeAdministrationModel::fillReportData()
{
DEBUG_LOG(m_logger) << "fillReportData(): m_reportJsonArray.size() = " << m_reportJsonArray.size();
int sums[6] = {0, 0, 0, 0, 0, 0};
int bigTotal[6] = {0, 0, 0, 0, 0, 0};
ProjectDataManagement::EffectSource effectSourceId = ProjectDataManagement::EffectSource::ES_Unknown;
for (const QJsonValue &arrVal : qAsConst(m_reportJsonArray))
{
const QJsonObject obj = arrVal.toObject();
resultData resData;
resData.chargeTypeId = obj[QStringLiteral("charge_type_id")].toInt();
resData.effectSourceId = static_cast<ProjectDataManagement::EffectSource::type>(obj[QStringLiteral("effect_source_id")].toInt());
resData.charges[0] = obj[QStringLiteral("charge_start")].toInt();
resData.charges[1] = obj[QStringLiteral("charge_resupplied")].toInt();
resData.charges[2] = obj[QStringLiteral("charge_end")].toInt();
resData.charges[3] = obj[QStringLiteral("charge_fired")].toInt();
resData.charges[4] = obj[QStringLiteral("charge_planned")].toInt();
resData.charges[5] = obj[QStringLiteral("charge_available")].toInt();
INFO_LOG(m_logger) << "Charge type id = " << resData.chargeTypeId;
INFO_LOG(m_logger) << "Effect Source id = " << resData.effectSourceId;
INFO_LOG(m_logger) << "Charges = (" << resData.charges[0] << ", " << resData.charges[1] << ", " << resData.charges[2] << ", " << resData.charges[3] << ", "
<< resData.charges[4] << ", " << resData.charges[5] << ")";
// if (resData.charges[0] != 0 || resData.charges[1] != 0 || resData.charges[2] != 0 || resData.charges[3] != 0)
if (effectSourceId != resData.effectSourceId)
{
DEBUG_LOG(m_logger) << "New effectSourceId: " << resData.effectSourceId;
if (effectSourceId != ProjectDataManagement::EffectSource::ES_Unknown)
{
resultData totalEffectSource;
totalEffectSource.effectSourceId = effectSourceId;
std::copy(std::begin(sums), std::end(sums), std::begin(totalEffectSource.charges));
m_data.append(std::move(totalEffectSource));
sumUp(bigTotal, totalEffectSource.charges, 6);
}
effectSourceId = resData.effectSourceId.underlying();
std::fill(std::begin(sums), std::end(sums), 0);
}
sumUp(sums, resData.charges, 6);
m_data.append(std::move(resData));
}
if (m_data.size() > 0) // total
{
// last total on effectSourceId
resultData totalEffectSource;
totalEffectSource.effectSourceId = effectSourceId;
totalEffectSource.chargeTypeId = -1;
std::copy(std::begin(sums), std::end(sums), std::begin(totalEffectSource.charges));
m_data.append(std::move(totalEffectSource));
sumUp(bigTotal, totalEffectSource.charges, 6);
// big total
resultData total;
total.effectSourceId = ProjectDataManagement::EffectSource::ES_Unknown;
total.chargeTypeId = -1;
std::copy(std::begin(bigTotal), std::end(bigTotal), std::begin(total.charges));
m_data.append(std::move(total));
}
}
@@ -0,0 +1,65 @@
/**
* @RDE_HEADER@
* Shows report player distance
* $Id$
* $HeadURL$
* $Author$
*/
#pragma once
#include "rep_abstract_model.h"
#include <ProjectDataManagement/pdm_dtc.h>
#include <ReportManagement/logger.h>
//----------------------------------------------------------------------------
namespace ReportManagement
{
class ChargeAdministrationModel final : public AbstractModel
{
Q_OBJECT
friend class AbstractModel;
public:
int rowCount(const QModelIndex &parent = QModelIndex()) const override final;
int columnCount(const QModelIndex &parent = QModelIndex()) const override final;
QVariant data(const QModelIndex &index, int role) const override final;
QVariant headerData(int section, Qt::Orientation orientation, int role) const override final;
bool fetchInterfaces() override final;
private:
explicit ChargeAdministrationModel(const ReportManagement::ReportInfo &report, LtsSession::LtsSession *session, QObject *parent);
void fillReportData() override final;
enum Columns
{
EFFECT_SOURCE_ID = 0,
GEAR_CLASS = 1,
CHARGE_TYPE_NAME = 2,
CHARGE_START = 3,
CHARGE_RESUPPLIED = 4,
CHARGE_END = 5,
CHARGE_PLANNED = 6,
CHARGE_AVAILABLE = 7,
CHARGE_FIRED = 8,
CHARGE_TYPE_ID = 9,
#ifdef LTS_DEBUG
COUNT = 10
#else
COUNT = 9 // without last column
#endif
};
struct resultData
{
ProjectDataManagement::EffectSource effectSourceId = ProjectDataManagement::EffectSource::get_default();
int chargeTypeId = 0;
int charges[6] = {0, 0, 0, 0, 0, 0};
};
QVector<resultData> m_data;
std::shared_ptr<ProjectDataManagement::Interface::Dtc> m_pdmDtc;
LOGGER_T m_logger;
};
} // namespace ReportManagement
@@ -0,0 +1,333 @@
/**
* @RDE_HEADER@
* Shows a report of combat power in form of curves
* $Id$
* $HeadURL$
* $Author$
*/
#include "rep_charge_resupply_model.h"
#include <PluginInterfaces/gui_plugin_interface.h>
#include <Plugins/ProjectDataManagement/pdm_data_plugin_interface.h>
#include <Plugins/ReportManagement/rep_data_plugin_interface.h>
#include <Plugins/ParticipantManagement/ppm_data_plugin_interface.h>
#include <LtsSession/lts_session.h>
#include <QFont>
using namespace ReportManagement;
//----------------------------------------------------------------------------
ChargeResupplyModel::ChargeResupplyModel(const ReportInfo &report, LtsSession::LtsSession *session, QObject *parent)
: AbstractModel(report, session, parent)
, m_logger(getLogger("ChargeResupplyModel"))
{
if (!fetchInterfaces())
return;
//#define TEST_DATA
#ifdef TEST_DATA
resultData resData;
resData.participantTypeId = 23;
resData.chargeTypeId = 371;
resData.charges[0] = 1000;
resData.charges[1] = 1000;
resData.charges[2] = 500;
resData.charges[3] = 1500;
resData.charges[4] = 1000;
m_data.append(resData);
resData.participantTypeId = 23;
resData.chargeTypeId = 372;
resData.charges[0] = 1000;
resData.charges[1] = 1000;
resData.charges[2] = 500;
resData.charges[3] = 1500;
resData.charges[4] = 1000;
m_data.append(resData);
resData.participantTypeId = 23;
resData.chargeTypeId = 0; // total on participant type
resData.charges[0] = 2000;
resData.charges[1] = 2000;
resData.charges[2] = 1000;
resData.charges[3] = 3000;
resData.charges[4] = 2000;
m_data.append(resData);
resData.participantTypeId = 32;
resData.chargeTypeId = 371;
resData.charges[0] = 1000;
resData.charges[1] = 1000;
resData.charges[2] = 500;
resData.charges[3] = 1500;
resData.charges[4] = 1000;
m_data.append(resData);
resData.participantTypeId = 32;
resData.chargeTypeId = 372;
resData.charges[0] = 1000;
resData.charges[1] = 1000;
resData.charges[2] = 500;
resData.charges[3] = 1500;
resData.charges[4] = 1000;
m_data.append(resData);
resData.participantTypeId = 32;
resData.chargeTypeId = 0; // total on participant type
resData.charges[0] = 2000;
resData.charges[1] = 2000;
resData.charges[2] = 1000;
resData.charges[3] = 3000;
resData.charges[4] = 2000;
m_data.append(resData);
resData.participantTypeId = 0; // total
resData.chargeTypeId = 0;
resData.charges[0] = 4000;
resData.charges[1] = 4000;
resData.charges[2] = 2000;
resData.charges[3] = 6000;
resData.charges[4] = 4000;
m_data.append(resData);
#else
getReportData(report);
fillReportData();
#endif
}
// -----------------------------------------------------------------------------------------------------
bool ChargeResupplyModel::fetchInterfaces()
{
if (!m_session->getDtc<ProjectDataManagement::DataInterface>(m_pdmDtc))
{
ERROR_LOG(m_logger) << "Could not fetch PDM DTC Interface";
return false;
}
if (!m_session->getDtc<ParticipantManagement::DataInterface>(m_ppmDtc))
{
ERROR_LOG(m_logger) << "Could not fetch PPM DTC Interface";
return false;
}
return true;
}
// -----------------------------------------------------------------------------------------------------
int ChargeResupplyModel::rowCount(const QModelIndex &parent) const
{
return parent.isValid() ? 0 : m_data.count();
}
// -----------------------------------------------------------------------------------------------------
int ChargeResupplyModel::columnCount(const QModelIndex &parent) const
{
return parent.isValid() ? 0 : COUNT;
}
// -----------------------------------------------------------------------------------------------------
QVariant ChargeResupplyModel::data(const QModelIndex &index, int role) const
{
if (!index.isValid())
return QVariant();
const resultData &displayInfo = m_data[index.row()];
if (role == Qt::TextAlignmentRole)
{
switch (index.column())
{
case CHARGE_TYPE_ID:
case PARTICIPANT_TYPE_ID:
case CHARGE_START:
case CHARGE_END:
case CHARGE_TAKEN:
#ifndef GUEZ_MODE
case CHARGE_GIVEN:
#endif
case CHARGE_FIRED:
return Qt::AlignRight;
case CHARGE_TYPE_NAME:
case PARTICIPANT_TYPE_NAME:
default:
return Qt::AlignLeft;
}
return Qt::AlignLeft;
}
if (role == Qt::FontRole)
{
QFont boldFont;
boldFont.setBold(true);
// total
if (displayInfo.chargeTypeId == 0)
return boldFont;
return QFont();
}
if (role == Qt::DisplayRole)
{
switch (index.column())
{
case PARTICIPANT_TYPE_ID:
return (displayInfo.participantTypeId > 0 ? displayInfo.participantTypeId : QVariant());
case CHARGE_TYPE_ID:
return (displayInfo.chargeTypeId > 0 ? displayInfo.chargeTypeId : QVariant());
case PARTICIPANT_TYPE_NAME:
{
QString displayTypeName;
if (displayInfo.participantTypeId > 0)
{
QString typeName = QString::fromStdString(m_ppmDtc->type(displayInfo.participantTypeId).name());
if (displayInfo.chargeTypeId == 0)
displayTypeName = tr("Total [%1]").arg(typeName);
else
displayTypeName = typeName;
}
return (displayInfo.participantTypeId > 0 ? displayTypeName : tr("TOTAL:"));
}
case CHARGE_TYPE_NAME:
return (displayInfo.chargeTypeId > 0 ? m_pdmDtc->trChargeTypeShortName(displayInfo.chargeTypeId, true)
: QVariant());
case CHARGE_START:
return displayInfo.charges[0];
case CHARGE_TAKEN:
return displayInfo.charges[1];
#ifndef GUEZ_MODE
case CHARGE_GIVEN:
return displayInfo.charges[2];
#endif
case CHARGE_END:
return displayInfo.charges[3];
case CHARGE_FIRED:
return displayInfo.charges[4];
default:
return QVariant();
}
}
return QVariant();
}
// -----------------------------------------------------------------------------------------------------
QVariant ChargeResupplyModel::headerData(int section, Qt::Orientation orientation, int role) const
{
if (orientation == Qt::Horizontal && role == Qt::FontRole)
{
QFont boldFont;
boldFont.setBold(true);
return boldFont;
}
if (!(orientation == Qt::Horizontal && role == Qt::DisplayRole))
return QVariant();
switch (section)
{
case CHARGE_TYPE_ID:
return tr("Charge Id");
case CHARGE_TYPE_NAME:
return tr("Charge Type");
case PARTICIPANT_TYPE_ID:
return tr("Type Id");
case PARTICIPANT_TYPE_NAME:
return tr("Type Name");
case CHARGE_START:
return tr("Stock Start");
case CHARGE_TAKEN:
return tr("Taken");
#ifndef GUEZ_MODE
case CHARGE_GIVEN:
return tr("Given");
#endif
case CHARGE_END:
return tr("Stock End");
case CHARGE_FIRED:
return tr("Charge Used");
default:
return QVariant();
}
}
// ------------------------------------------------------------------
void ChargeResupplyModel::fillReportData()
{
DEBUG_LOG(m_logger) << "fillReportData(): m_reportJsonArray.size() = " << m_reportJsonArray.size();
int participantTypeId = -1;
QMap<int, QVector<int> > sums;
QVector<int> bigTotal(5, 0);
for (const QJsonValue &arrVal : qAsConst(m_reportJsonArray))
{
const QJsonObject obj = arrVal.toObject();
resultData resData;
resData.participantTypeId = obj[QStringLiteral("participant_type_id")].toInt();
resData.chargeTypeId = obj[QStringLiteral("charge_type_id")].toInt();
resData.charges[0] = obj[QStringLiteral("charge_start")].toInt();
resData.charges[1] = obj[QStringLiteral("charge_taken")].toInt();
resData.charges[2] = obj[QStringLiteral("charge_given")].toInt();
resData.charges[3] = obj[QStringLiteral("charge_end")].toInt();
resData.charges[4] = obj[QStringLiteral("charge_fired")].toInt();
INFO_LOG(m_logger) << "Participant type id = " << resData.participantTypeId;
INFO_LOG(m_logger) << "Charge type id = " << resData.chargeTypeId;
INFO_LOG(m_logger) << "Charges = ("
<< resData.charges[0] << ", "
<< resData.charges[1] << ", "
<< resData.charges[2] << ", "
<< resData.charges[3] << ", "
<< resData.charges[4] << ")" ;
if (participantTypeId != resData.participantTypeId) // new Type
{
DEBUG_LOG(m_logger) << "New participant type id: " << resData.participantTypeId;
if (participantTypeId != -1) // total on type
{
resultData totalType;
totalType.participantTypeId = participantTypeId;
totalType.chargeTypeId = 0;
totalType.charges = sums[participantTypeId];
m_data.append(std::move(totalType));
sumUp(bigTotal, sums[participantTypeId], sums[participantTypeId].size());
}
participantTypeId = resData.participantTypeId;
sums[participantTypeId].append(resData.charges);
}
else
{
DEBUG_LOG(m_logger) << "Adding values to participant type id: " << participantTypeId;
sumUp(sums[participantTypeId], resData.charges, resData.charges.size());
}
m_data.append(std::move(resData));
}
if (m_reportJsonArray.size() > 0)
{
// last total on type
resultData totalType;
totalType.participantTypeId = participantTypeId;
totalType.chargeTypeId = 0;
totalType.charges = sums[participantTypeId];
m_data.append(std::move(totalType));
sumUp(bigTotal, sums[participantTypeId], sums[participantTypeId].size());
// big total
resultData total;
total.participantTypeId = 0;
total.chargeTypeId = 0;
total.charges = bigTotal;
m_data.append(std::move(total));
}
}
@@ -0,0 +1,70 @@
/**
* @RDE_HEADER@
* Shows report player distance
* $Id$
* $HeadURL$
* $Author$
*/
#pragma once
#include "rep_abstract_model.h"
#include <ReportManagement/logger.h>
#include <ProjectDataManagement/pdm_dtc.h>
#include <ParticipantManagement/ppm_dtc.h>
//----------------------------------------------------------------------------
namespace ReportManagement
{
class ChargeResupplyModel final : public AbstractModel
{
Q_OBJECT
friend class AbstractModel;
public:
int rowCount(const QModelIndex &parent = QModelIndex()) const override final;
int columnCount(const QModelIndex &parent = QModelIndex()) const override final;
QVariant data(const QModelIndex &index, int role) const override final;
QVariant headerData(int section, Qt::Orientation orientation, int role) const override final;
bool fetchInterfaces() override final;
private:
explicit ChargeResupplyModel(const ReportManagement::ReportInfo &report, LtsSession::LtsSession *session, QObject *parent);
void fillReportData() override final;
enum Columns
{
PARTICIPANT_TYPE_NAME = 0,
CHARGE_TYPE_NAME = 1,
CHARGE_START = 2,
CHARGE_TAKEN = 3,
#ifndef GUEZ_MODE
CHARGE_GIVEN = 4,
CHARGE_END = 5,
CHARGE_FIRED = 6,
CHARGE_TYPE_ID = 7,
PARTICIPANT_TYPE_ID = 8,
COUNT = 7 // without last 2 columns
#else
CHARGE_END = 4,
CHARGE_FIRED = 5,
CHARGE_TYPE_ID = 6,
PARTICIPANT_TYPE_ID = 7,
COUNT = 6 // without last 2 columns
#endif
};
struct resultData
{
int participantTypeId = 0;
int chargeTypeId = 0;
QVector<int> charges = {0, 0, 0, 0, 0};
};
QVector<resultData> m_data;
std::shared_ptr<ReportManagement::Interface::Ftc> m_ftc;
std::shared_ptr<ProjectDataManagement::Interface::Dtc> m_pdmDtc;
std::shared_ptr<ParticipantManagement::Interface::Dtc> m_ppmDtc;
LOGGER_T m_logger;
};
}
@@ -0,0 +1,460 @@
/**
* @RDE_HEADER@
* Shows a report of combat power in form of curves
* $Id$
* $HeadURL$
* $Author$
*/
#include "rep_firings_model.h"
#include <PluginInterfaces/gui_plugin_interface.h>
#include <Plugins/ProjectDataManagement/pdm_data_plugin_interface.h>
#include <Plugins/ReportManagement/rep_data_plugin_interface.h>
#include <ProjectDataManagement/pdm_translation.h>
#include <LtsSession/lts_session.h>
#include <ngltools/ngltools_dtg.h>
#include <QFont>
using namespace ReportManagement;
//----------------------------------------------------------------------------
FiringsModel::FiringsModel(const ReportInfo &report, LtsSession::LtsSession *session, QObject *parent)
: AbstractModel(report, session, parent)
, m_pdmDtc(nullptr)
, m_logger(getLogger("FiringsModel"))
{
if (!fetchInterfaces())
return;
//#define TEST_DATA
#ifdef TEST_DATA
resultDataTable resData;
// charge type 371
resData.chargeTypeId = 371;
resData.startTime = 1513758640000;
resData.vulnerabilityState = ProjectDataManagement::VulnerabilityState::CatastrophicKill;
resData.hits = {9, 4, 4, 0};
m_dataTable.append(resData);
resData.chargeTypeId = 371;
resData.startTime = 1513758640000;
resData.vulnerabilityState = ProjectDataManagement::VulnerabilityState::MobilityKill;
resData.hits = {9, 4, 3, 1};
m_dataTable.append(resData);
resData.chargeTypeId = 371;
resData.startTime = 1513758640000;
resData.vulnerabilityState = ProjectDataManagement::VulnerabilityState::VisibleMobilityKill;
resData.hits = {2, 2, 2, 0};
m_dataTable.append(resData);
resData.chargeTypeId = 371;
resData.startTime = 1513758640000;
resData.vulnerabilityState = ProjectDataManagement::VulnerabilityState::NotReady; // total firings and hits on all VBGs
resData.hits = {20, 10, 9, 1};
m_dataTable.append(resData);
resultDataPie pieData;
pieData.chargeTypeId = 371;
pieData.startTime = 1513758640000;
pieData.hits = {20, 10, 9, 1};
m_dataPie.append(pieData);
// charge type 372
resData.chargeTypeId = 372;
resData.startTime = 1513758640000;
resData.vulnerabilityState = ProjectDataManagement::VulnerabilityState::CatastrophicKill;
resData.hits = {14, 4, 4, 0};
m_dataTable.append(resData);
resData.chargeTypeId = 372;
resData.startTime = 1513758640000;
resData.vulnerabilityState = ProjectDataManagement::VulnerabilityState::MobilityKill;
resData.hits = {4, 4, 3, 1};
m_dataTable.append(resData);
resData.chargeTypeId = 372;
resData.startTime = 1513758640000;
resData.vulnerabilityState = ProjectDataManagement::VulnerabilityState::VisibleMobilityKill;
resData.hits = {2, 2, 2, 0};
m_dataTable.append(resData);
resData.chargeTypeId = 372;
resData.startTime = 1513758640000;
resData.vulnerabilityState = ProjectDataManagement::VulnerabilityState::NotReady; // total firings and hits on all VBGs
resData.hits = {20, 10, 9, 1};
m_dataTable.append(resData);
pieData.chargeTypeId = 372;
pieData.startTime = 1513758640000;
pieData.hits = {20, 10, 9, 1};
m_dataPie.append(pieData);
resData.chargeTypeId = 0; // total
resData.startTime = 1513758640000;
resData.vulnerabilityState = ProjectDataManagement::VulnerabilityState::NotReady; // total firings and hits on all VBGs
resData.hits = {40, 20, 18, 2};
m_dataTable.append(resData);
#else
getReportData(report);
if (report.visualisationType() == VisualisationType::Table)
fillReportData();
else
fillPieData();
#endif
}
// -----------------------------------------------------------------------------------------------------
bool FiringsModel::fetchInterfaces()
{
if (!m_session->getDtc<ProjectDataManagement::DataInterface>(m_pdmDtc))
{
ERROR_LOG(m_logger) << "Could not fetch PDM DTC Interface";
return false;
}
return true;
}
// -----------------------------------------------------------------------------------------------------
int FiringsModel::rowCount(const QModelIndex &parent) const
{
if (m_report.visualisationType() == VisualisationType::Pie || m_report.visualisationType() == VisualisationType::Bar)
return parent.isValid() ? 0 : m_dataPie.count();
else
return parent.isValid() ? 0 : m_dataTable.count();
}
// -----------------------------------------------------------------------------------------------------
int FiringsModel::columnCount(const QModelIndex &parent) const
{
if (m_report.visualisationType() == VisualisationType::Pie || m_report.visualisationType() == VisualisationType::Bar)
return parent.isValid() ? 0 : COUNT_PIE;
else
return parent.isValid() ? 0 : COUNT_TABLE;
}
// -----------------------------------------------------------------------------------------------------
QVariant FiringsModel::data(const QModelIndex &index, int role) const
{
if (!index.isValid())
return QVariant();
if (m_report.visualisationType() == VisualisationType::Table)
{
const resultDataTable &displayInfo = m_dataTable[index.row()];
if (role == Qt::TextAlignmentRole)
{
switch (index.column())
{
case CHARGE_TYPE_ID:
case FIRINGS:
case HITS_TOTAL:
case HITS_ENEMY:
case HITS_FRIENDLY:
return Qt::AlignRight;
case START_TIME:
case CHARGE_TYPE_NAME:
case VULNERABILITY_STATE:
default:
return Qt::AlignLeft;
}
return Qt::AlignLeft;
}
if (role == Qt::FontRole)
{
QFont boldFont;
boldFont.setBold(true);
// total on charge type
if (displayInfo.chargeTypeId == 0 || displayInfo.vulnerabilityState == ProjectDataManagement::VulnerabilityState::NotReady)
return boldFont;
return QFont();
}
if (role == Qt::DisplayRole)
{
switch (index.column())
{
case CHARGE_TYPE_ID:
return (displayInfo.chargeTypeId > 0 ? displayInfo.chargeTypeId : QVariant());
case CHARGE_TYPE_NAME:
{
QString displayTypeName;
if (displayInfo.chargeTypeId > 0)
{
QString chargeTypeName = m_pdmDtc->trChargeTypeShortName(displayInfo.chargeTypeId);
if (displayInfo.vulnerabilityState == ProjectDataManagement::VulnerabilityState::NotReady)
displayTypeName = tr("Total [%1]").arg(chargeTypeName);
else
displayTypeName = chargeTypeName;
}
return (displayInfo.chargeTypeId > 0 ? displayTypeName : tr("TOTAL:"));
}
case START_TIME:
return (displayInfo.vulnerabilityState != ProjectDataManagement::VulnerabilityState::NotReady ? DTG::toStringMSec(displayInfo.startTime) : QVariant());
case FIRINGS:
return (displayInfo.hits[0] > 0 ? displayInfo.hits[0] : QVariant());
case HITS_TOTAL:
return (displayInfo.hits[1] > 0 ? displayInfo.hits[1] : QVariant());
case HITS_ENEMY:
return displayInfo.hits[2];
case HITS_FRIENDLY:
return displayInfo.hits[3];
case VULNERABILITY_STATE:
return ((displayInfo.vulnerabilityState != ProjectDataManagement::VulnerabilityState::NotReady &&
displayInfo.vulnerabilityState != ProjectDataManagement::VulnerabilityState::CombatReady) ?
ProjectDataManagement::toString(displayInfo.vulnerabilityState): QVariant());
default:
return QVariant();
}
}
}
if (m_report.visualisationType() == VisualisationType::Pie || m_report.visualisationType() == VisualisationType::Bar)
{
const resultDataPie &pieInfo = m_dataPie[index.row()];
if (role == Qt::EditRole)
{
return pieInfo.chargeTypeId;
}
if (role == Qt::UserRole)
{
return pieInfo.chargeTypeId > 0 ? m_pdmDtc->trChargeTypeShortName(pieInfo.chargeTypeId) : QVariant();
}
if (role == Qt::DisplayRole)
{
switch (index.column())
{
case HITS_ENEMY_PIE:
return pieInfo.hits[2] > 0 ? pieInfo.hits[2] : QVariant();
case HITS_FRIENDLY_PIE:
return pieInfo.hits[3] > 0 ? pieInfo.hits[3] : QVariant();
case FIRE_WITHOUT_HIT:
return (pieInfo.hits[0] - pieInfo.hits[1]) > 0 ? (pieInfo.hits[0] - pieInfo.hits[1]) : QVariant(); // firings - hits total
case START_TIME_PIE:
return DTG::toStringMSec(pieInfo.startTime);
default:
return QVariant();
}
}
}
return QVariant();
}
// -----------------------------------------------------------------------------------------------------
QVariant FiringsModel::headerData(int section, Qt::Orientation orientation, int role) const
{
if (orientation == Qt::Horizontal && role == Qt::FontRole)
{
QFont boldFont;
boldFont.setBold(true);
return boldFont;
}
if (orientation == Qt::Horizontal && role == Qt::DisplayRole)
{
if (m_report.visualisationType() == VisualisationType::Table)
{
switch (section)
{
case CHARGE_TYPE_ID:
return tr("Charge Id");
case CHARGE_TYPE_NAME:
return tr("Charge Type");
case VULNERABILITY_STATE:
return tr("Hit Effects");
case START_TIME:
return tr("Interval Start Time");
case FIRINGS:
return tr("Firings");
case HITS_TOTAL:
return tr("Hits");
case HITS_ENEMY:
return tr("Enemy Forces Hits");
case HITS_FRIENDLY:
return tr("Own Force Hits");
default:
return QVariant();
}
}
if (m_report.visualisationType() == VisualisationType::Pie || m_report.visualisationType() == VisualisationType::Bar)
{
switch (section)
{
case START_TIME_PIE:
return tr("Time");
case HITS_ENEMY_PIE:
return tr("Enemy Forces Hits");
case HITS_FRIENDLY_PIE:
return tr("Own Force Hits");
case FIRE_WITHOUT_HIT:
return tr("Firings without hits");
default:
return QVariant();
}
}
}
if (orientation == Qt::Vertical && role == Qt::DisplayRole && m_report.visualisationType() == VisualisationType::Bar)
{
return DTG::toStringMSec(m_dataPie[section].startTime);
}
return QAbstractTableModel::headerData(section, orientation, role);
}
// ------------------------------------------------------------------
void FiringsModel::fillReportData()
{
DEBUG_LOG(m_logger) << "fillReportData(): m_reportJsonArray.size() = " << m_reportJsonArray.size();
int chargeTypeId = -1;
QMap<int, QVector<int> > sums;
QVector<int> bigTotal(4, 0);
resultDataTable resData;
for (const QJsonValue &arrVal : qAsConst(m_reportJsonArray))
{
const QJsonObject obj = arrVal.toObject();
resData.chargeTypeId = obj[QStringLiteral("charge_type_id")].toInt();
resData.startTime = obj[QStringLiteral("start_time")].toDouble();
resData.vulnerabilityState = static_cast<ProjectDataManagement::VulnerabilityState::type>(obj[QStringLiteral("vulnerability_state")].toInt());
resData.hits[0] = obj[QStringLiteral("firings")].toInt();
resData.hits[3] = obj[QStringLiteral("hits_friendly_fire")].toInt();
resData.hits[2] = obj[QStringLiteral("hits")].toInt();
resData.hits[1] = resData.hits[2] + resData.hits[3];
INFO_LOG(m_logger) << "Charge type id = " << resData.chargeTypeId;
INFO_LOG(m_logger) << "Start time = " << resData.startTime;
INFO_LOG(m_logger) << "VulnerabilityState = " << resData.vulnerabilityState;
INFO_LOG(m_logger) << "Hits = ("
<< resData.hits[0] << ", "
<< resData.hits[1] << ", "
<< resData.hits[2] << ", "
<< resData.hits[3] << ")" ;
if (chargeTypeId != resData.chargeTypeId) // new Charge Type
{
DEBUG_LOG(m_logger) << "New charge type id: " << resData.chargeTypeId;
if (chargeTypeId != -1) // total on type
{
resultDataTable totalChargeType;
totalChargeType.chargeTypeId = chargeTypeId;
totalChargeType.startTime = 0;
totalChargeType.vulnerabilityState = ProjectDataManagement::VulnerabilityState::NotReady;
totalChargeType.hits = sums[chargeTypeId];
m_dataTable.append(std::move(totalChargeType));
sumUp(bigTotal, sums[chargeTypeId], sums[chargeTypeId].size());
}
chargeTypeId = resData.chargeTypeId;
sums[chargeTypeId].append(resData.hits);
}
else
{
DEBUG_LOG(m_logger) << "Adding values to charge type id: " << chargeTypeId;
sumUp(sums[chargeTypeId], resData.hits, resData.hits.size());
}
m_dataTable.append(resData); // no std::move() - allocated outside loop
}
if (m_reportJsonArray.size() > 0)
{
// last total on charge type
resultDataTable totalChargeType;
totalChargeType.chargeTypeId = chargeTypeId;
totalChargeType.startTime = 0;
totalChargeType.vulnerabilityState = ProjectDataManagement::VulnerabilityState::NotReady;
totalChargeType.hits = sums[chargeTypeId];
m_dataTable.append(std::move(totalChargeType));
sumUp(bigTotal, sums[chargeTypeId], sums[chargeTypeId].size());
// big total
resultDataTable total;
total.chargeTypeId = 0;
total.startTime = 0;
total.vulnerabilityState = ProjectDataManagement::VulnerabilityState::NotReady;
total.hits = bigTotal;
m_dataTable.append(std::move(total));
}
}
// ------------------------------------------------------------------
void FiringsModel::fillPieData()
{
DEBUG_LOG(m_logger) << "fillPieData(): m_reportJsonArray.size() = " << m_reportJsonArray.size();
QMap<QPair<int,double>, QVector<int> > sums;
resultDataPie resPieData;
for (const QJsonValue &arrVal : qAsConst(m_reportJsonArray))
{
const QJsonObject obj = arrVal.toObject();
resPieData.chargeTypeId = obj[QStringLiteral("charge_type_id")].toInt();
resPieData.startTime = obj[QStringLiteral("start_time")].toDouble();
resPieData.hits[0] = obj[QStringLiteral("firings")].toInt();
resPieData.hits[3] = obj[QStringLiteral("hits_friendly_fire")].toInt();
resPieData.hits[2] = obj[QStringLiteral("hits")].toInt();
resPieData.hits[1] = resPieData.hits[2] + resPieData.hits[3];
INFO_LOG(m_logger) << "Charge type id = " << resPieData.chargeTypeId;
INFO_LOG(m_logger) << "Start time = " << resPieData.startTime;
INFO_LOG(m_logger) << "Hits = ("
<< resPieData.hits[0] << ", "
<< resPieData.hits[1] << ", "
<< resPieData.hits[2] << ", "
<< resPieData.hits[3] << ")" ;
QPair<int,double> key;
key.first = resPieData.chargeTypeId;
key.second = resPieData.startTime;
if (!sums.contains(key))
sums[key].append({0,0,0,0});
for(int i = 0; i < resPieData.hits.size(); ++i)
sums[key][i] += resPieData.hits[i];
}
for (auto key : sums.keys())
{
resultDataPie resPie;
resPie.chargeTypeId = key.first;
resPie.startTime = key.second;
resPie.hits = sums[key];
INFO_LOG(m_logger) << "ChargeType: " << resPie.chargeTypeId;
INFO_LOG(m_logger) << "StartTime: " << resPie.startTime;
for(int i = 0; i < resPie.hits.size(); ++i)
INFO_LOG(m_logger) << "Hits = ("
<< resPie.hits[0] << ", "
<< resPie.hits[1] << ", "
<< resPie.hits[2] << ", "
<< resPie.hits[3] << ")" ;
m_dataPie.append(std::move(resPie));
}
}
@@ -0,0 +1,78 @@
/**
* @RDE_HEADER@
* Shows report player distance
* $Id$
* $HeadURL$
* $Author$
*/
#pragma once
#include "rep_abstract_model.h"
#include <ReportManagement/logger.h>
#include <ProjectDataManagement/pdm_dtc.h>
//----------------------------------------------------------------------------
namespace ReportManagement
{
class FiringsModel final : public AbstractModel
{
Q_OBJECT
friend class AbstractModel;
public:
int rowCount(const QModelIndex &parent = QModelIndex()) const override final;
int columnCount(const QModelIndex &parent = QModelIndex()) const override final;
QVariant data(const QModelIndex &index, int role) const override final;
QVariant headerData(int section, Qt::Orientation orientation, int role) const override final;
bool fetchInterfaces() override final;
private:
explicit FiringsModel(const ReportManagement::ReportInfo &report, LtsSession::LtsSession *session, QObject *parent);
void fillReportData() override final;
void fillPieData();
enum ColumnsTable
{
CHARGE_TYPE_NAME = 0,
START_TIME = 1,
FIRINGS = 2,
HITS_TOTAL = 3,
VULNERABILITY_STATE = 4,
HITS_ENEMY = 5,
HITS_FRIENDLY = 6,
CHARGE_TYPE_ID = 7,
#ifdef LTS_DEBUG
COUNT_TABLE = 8
#else
COUNT_TABLE = 7 // without last column
#endif
};
enum ColumnsPie
{
HITS_ENEMY_PIE = 0,
HITS_FRIENDLY_PIE = 1,
FIRE_WITHOUT_HIT = 2,
START_TIME_PIE = 3,
COUNT_PIE = 3
};
struct resultDataPie
{
int chargeTypeId = 0;
qint64 startTime = 0;
QVector<int> hits = {0, 0, 0, 0};
};
struct resultDataTable : public resultDataPie
{
ProjectDataManagement::VulnerabilityState vulnerabilityState = ProjectDataManagement::VulnerabilityState::NotReady;
};
QVector<resultDataTable> m_dataTable;
QVector<resultDataPie> m_dataPie;
std::shared_ptr<ProjectDataManagement::Interface::Dtc> m_pdmDtc;
LOGGER_T m_logger;
};
}
@@ -0,0 +1,229 @@
/**
* @RDE_HEADER@
* Shows a report of combat power in form of curves
* $Id$
* $HeadURL$
* $Author$
*/
#include "rep_maintenance_model.h"
#include <PluginInterfaces/gui_plugin_interface.h>
#include <Plugins/ParticipantManagement/ppm_data_plugin_interface.h>
#include <Plugins/ReportManagement/rep_data_plugin_interface.h>
#include <LtsSession/lts_session.h>
#include <ngltools/ngltools_dtg.h>
#include <QFont>
using namespace ReportManagement;
//----------------------------------------------------------------------------
MaintenanceModel::MaintenanceModel(const ReportInfo &report, LtsSession::LtsSession *session, QObject *parent)
: AbstractModel(report, session, parent)
, m_ppmDtc(nullptr)
, m_logger(getLogger("ReportMaintenanceModel"))
{
if (!fetchInterfaces())
return;
//#define TEST_DATA
#ifdef TEST_DATA
resultData resData;
resData.participantTypeId = 23;
resData.participantId = 31;
resData.time_sanitation = 1513758639000;
resData.success_sanitation = false;
resData.time_event = 1513758640000;
resData.time_position = 1513758640010;
resData.time_vulnerability = 1513758640020;
resData.vitality = 80;
m_data.append(resData);
resData.participantTypeId = 23;
resData.participantId = 32;
resData.time_sanitation = 1513758639000;
resData.success_sanitation = true;
resData.time_event = 1513758640000;
resData.time_position = 1513758640010;
resData.time_vulnerability = 1513758640020;
resData.vitality = 80;
m_data.append(resData);
resData.participantTypeId = 23;
resData.participantId = 33;
resData.time_sanitation = 1513758639000;
resData.success_sanitation = true;
resData.time_event = 1513758640000;
resData.time_position = 1513758640010;
resData.time_vulnerability = 1513758640020;
resData.vitality = 80;
m_data.append(resData);
#else
getReportData(report);
fillReportData();
#endif
}
// -----------------------------------------------------------------------------------------------------
bool MaintenanceModel::fetchInterfaces()
{
if (!m_session->getDtc<ParticipantManagement::DataInterface>(m_ppmDtc))
{
ERROR_LOG(m_logger) << "Could not fetch PPM DTC Interface";
return false;
}
return true;
}
// -----------------------------------------------------------------------------------------------------
int MaintenanceModel::rowCount(const QModelIndex &parent) const
{
return parent.isValid() ? 0 : m_data.count();
}
// -----------------------------------------------------------------------------------------------------
int MaintenanceModel::columnCount(const QModelIndex &parent) const
{
return parent.isValid() ? 0 : COUNT;
}
// -----------------------------------------------------------------------------------------------------
QVariant MaintenanceModel::data(const QModelIndex &index, int role) const
{
if (!index.isValid())
return QVariant();
const resultData &displayInfo = m_data[index.row()];
if (role == Qt::TextAlignmentRole)
{
switch (index.column())
{
case PARTICIPANT_TYPE_ID:
case PARTICIPANT_ID:
case PARTICIPANT_EQUIPMENT_NO:
case TIME_EVENT:
case TIME_POSITION_CHANGED:
case TIME_VULNERABILITY:
return Qt::AlignRight;
case PARTICIPANT_TYPE_NAME:
case PARTICIPANT_NAME:
default:
return Qt::AlignLeft;
}
return Qt::AlignLeft;
}
if (role == Qt::FontRole)
{
QFont boldFont;
boldFont.setBold(true);
// total and subtotals
if (displayInfo.participantId == 0 || displayInfo.participantTypeId == 0)
return boldFont;
return QFont();
}
if (role == Qt::DisplayRole)
{
switch (index.column())
{
case PARTICIPANT_TYPE_ID:
return (displayInfo.participantTypeId > 0 ? displayInfo.participantTypeId : QVariant());
case PARTICIPANT_TYPE_NAME:
return (displayInfo.participantTypeId > 0 ? QString::fromStdString(m_ppmDtc->type(displayInfo.participantTypeId).name())
: QVariant());
case PARTICIPANT_ID:
return (displayInfo.participantId > 0 ? displayInfo.participantId
: QVariant());
case PARTICIPANT_EQUIPMENT_NO:
return (displayInfo.participantEqNo > 0 ? QString::number(displayInfo.participantEqNo) : QVariant());
case PARTICIPANT_NAME:
return (!displayInfo.participantName.isEmpty() ? displayInfo.participantName : QVariant());
case TIME_EVENT:
return (displayInfo.time_event > 0 ? DTG::toStringMSec(displayInfo.time_event)
: QVariant());
case TIME_POSITION_CHANGED:
return (displayInfo.time_position > 0 ? DTG::toStringMSec(displayInfo.time_position)
: QVariant());
case TIME_VULNERABILITY:
return (displayInfo.time_vulnerability > 0 ? DTG::toStringMSec(displayInfo.time_vulnerability)
: QVariant());
default:
return QVariant();
}
}
return QVariant();
}
// -----------------------------------------------------------------------------------------------------
QVariant MaintenanceModel::headerData(int section, Qt::Orientation orientation, int role) const
{
if (orientation == Qt::Horizontal && role == Qt::FontRole)
{
QFont boldFont;
boldFont.setBold(true);
return boldFont;
}
if (!(orientation == Qt::Horizontal && role == Qt::DisplayRole))
return QVariant();
switch (section)
{
case PARTICIPANT_TYPE_ID:
return tr("Type Id");
case PARTICIPANT_TYPE_NAME:
return tr("Type Name");
case PARTICIPANT_ID:
return tr("Participant Id");
case PARTICIPANT_EQUIPMENT_NO:
return tr("Equipment Number");
case PARTICIPANT_NAME:
return tr("Participant Name");
case TIME_EVENT:
return tr("Enter Functional Area");
case TIME_POSITION_CHANGED:
return tr("Position Changed");
case TIME_VULNERABILITY:
return tr("Vulnerability Changed");
default:
return QVariant();
}
}
// ------------------------------------------------------------------
void MaintenanceModel::fillReportData()
{
DEBUG_LOG(m_logger) << "fillReportData(): m_reportJsonArray.size() = " << m_reportJsonArray.size();
for (const QJsonValue &arrVal : qAsConst(m_reportJsonArray))
{
const QJsonObject obj = arrVal.toObject();
resultData resData;
resData.participantTypeId = obj[QStringLiteral("participant_type_id")].toInt();
resData.participantId = obj[QStringLiteral("participant_id")].toInt();
resData.participantName = obj[QStringLiteral("participant_name")].toString();
resData.participantEqNo = obj[QStringLiteral("participant_equipment_number")].toInt();
resData.time_event = obj[QStringLiteral("time_event")].toDouble();
resData.time_position = obj[QStringLiteral("time_position_changed")].toDouble();
resData.time_vulnerability = obj[QStringLiteral("time_vulnerability")].toDouble();
INFO_LOG(m_logger) << "Participant id = " << resData.participantId;
INFO_LOG(m_logger) << "Participant type id = " << resData.participantTypeId;
INFO_LOG(m_logger) << "Time event = " << resData.time_event;
INFO_LOG(m_logger) << "Time pos = " << resData.time_position;
INFO_LOG(m_logger) << "Time vulnerability = " << resData.time_vulnerability;
m_data.append(std::move(resData));
}
}
@@ -0,0 +1,62 @@
/**
* @RDE_HEADER@
* Shows report player distance
* $Id$
* $HeadURL$
* $Author$
*/
#pragma once
#include "rep_abstract_model.h"
#include <ReportManagement/logger.h>
#include <ParticipantManagement/ppm_dtc.h>
//----------------------------------------------------------------------------
namespace ReportManagement
{
class MaintenanceModel : public AbstractModel
{
Q_OBJECT
friend class AbstractModel;
public:
int rowCount(const QModelIndex &parent = QModelIndex()) const override final;
int columnCount(const QModelIndex &parent = QModelIndex()) const override final;
QVariant data(const QModelIndex &index, int role) const override final;
QVariant headerData(int section, Qt::Orientation orientation, int role) const override final;
bool fetchInterfaces() override final;
private:
explicit MaintenanceModel(const ReportManagement::ReportInfo &report, LtsSession::LtsSession *session, QObject *parent);
void fillReportData() override final;
enum Columns
{
PARTICIPANT_TYPE_NAME = 0,
PARTICIPANT_EQUIPMENT_NO = 1,
PARTICIPANT_NAME = 2,
TIME_EVENT = 3,
TIME_POSITION_CHANGED = 4,
TIME_VULNERABILITY = 5,
PARTICIPANT_ID = 6,
PARTICIPANT_TYPE_ID = 7,
COUNT = 8 // without 2 last columns
};
struct resultData
{
int participantTypeId = 0;
int participantId = 0;
int participantEqNo = 0;
QString participantName;
qint64 time_event = 0;
qint64 time_position = 0;
qint64 time_vulnerability = 0;
};
QVector<resultData> m_data;
std::shared_ptr<ParticipantManagement::Interface::Dtc> m_ppmDtc;
LOGGER_T m_logger;
};
}
@@ -0,0 +1,228 @@
/**
* @RDE_HEADER@
* Plugin Report Management: Report Sanitation Materials model
* $Id$
* $HeadURL$
* $Author$
* Created by Iuliana Ojog, 2020-06-22
*/
#include "rep_medevac_nine_liner_model.h"
#include <PluginInterfaces/gui_plugin_interface.h>
#include <Plugins/Evaluations/evl_data_plugin_interface.h>
#include <Plugins/ReportManagement/rep_data_plugin_interface.h>
#include <Evaluations/evl_translation.h>
#include <Services/Evaluations/san_category_line_json.h>
#include <LtsSession/lts_session.h>
#include <ngltools/ngltools_dtg.h>
#include <LtsCoordTrans/lts_coord_trans.h>
using namespace ReportManagement;
//----------------------------------------------------------------------------
MedevacNineLinerModel::MedevacNineLinerModel(const ReportInfo &report, LtsSession::LtsSession *session, QObject *parent)
: AbstractModel(report, session, parent)
, m_evlDtc(nullptr)
, m_logger(getLogger("MedevacNineLinerModel"))
{
if (!fetchInterfaces())
return;
//#define TEST_DATA
#ifdef TEST_DATA
resultData resData;
resData.nineLinerId = 1;
resData.lastModified = 12345678;
resData.callSign = QStringLiteral("Sign 1");
resData.position = QStringLiteral("Pos");
resData.line_3 = QStringLiteral("Line 3");
resData.line_4 = QStringLiteral("Line 4");
resData.line_5 = QStringLiteral("Line 5");
resData.line_6 = QStringLiteral("Line 6");
resData.line_7 = QStringLiteral("Line 7");
resData.line_8 = QStringLiteral("Line 8");
resData.line_9 = QStringLiteral("Line 9");
m_data.append(resData);
#else
getReportData(report);
fillReportData();
#endif
}
// -----------------------------------------------------------------------------------------------------
bool MedevacNineLinerModel::fetchInterfaces()
{
if (!m_session->getDtc<Evaluations::DataInterface>(m_evlDtc))
{
ERROR_LOG(m_logger) << "Could not fetch EVL DTC Interface";
return false;
}
return true;
}
// -----------------------------------------------------------------------------------------------------
int MedevacNineLinerModel::rowCount(const QModelIndex &parent) const
{
return parent.isValid() ? 0 : m_data.count();
}
// -----------------------------------------------------------------------------------------------------
int MedevacNineLinerModel::columnCount(const QModelIndex &parent) const
{
return parent.isValid() ? 0 : COUNT;
}
// -----------------------------------------------------------------------------------------------------
QVariant MedevacNineLinerModel::data(const QModelIndex &index, int role) const
{
if (!index.isValid())
return QVariant();
const resultData &displayInfo = m_data[index.row()];
if (role == Qt::TextAlignmentRole)
{
switch (index.column())
{
case NINE_LINER_ID:
return Qt::AlignRight;
default:
return Qt::AlignLeft;
}
return Qt::AlignLeft;
}
if (role == Qt::DisplayRole)
{
switch (index.column())
{
case NINE_LINER_ID:
return displayInfo.nineLinerId;
case LAST_MODIFIED:
return displayInfo.lastModified;
case CALL_SIGN:
return displayInfo.callSign;
case POSITION:
return displayInfo.position;
case LINE_3:
return displayInfo.line_3;
case LINE_4:
return displayInfo.line_4;
case LINE_5:
return displayInfo.line_5;
case LINE_6:
return displayInfo.line_6;
case LINE_7:
return displayInfo.line_7;
case LINE_8:
return displayInfo.line_8;
case LINE_9:
return displayInfo.line_9;
default:
return QVariant();
}
}
return QVariant();
}
// -----------------------------------------------------------------------------------------------------
QVariant MedevacNineLinerModel::headerData(int section, Qt::Orientation orientation, int role) const
{
if (!(orientation == Qt::Horizontal && role == Qt::DisplayRole))
return QVariant();
switch (section)
{
case NINE_LINER_ID:
return tr("NineLiner Id");
case LAST_MODIFIED:
return tr("Last modified");
case POSITION:
return tr("Line 1");
case CALL_SIGN:
return tr("Line 2");
case LINE_3:
return tr("Line 3");
case LINE_4:
return tr("Line 4");
case LINE_5:
return tr("Line 5");
case LINE_6:
return tr("Line 6");
case LINE_7:
return tr("Line 7");
case LINE_8:
return tr("Line 8");
case LINE_9:
return tr("Line 9");
default:
return QVariant();
}
}
// ------------------------------------------------------------------
void MedevacNineLinerModel::fillReportData()
{
ERROR_LOG(m_logger) << "fillReportData(): m_reportJsonArray.size() = " << m_reportJsonArray.size();
for (const QJsonValue &arrVal : qAsConst(m_reportJsonArray))
{
const QJsonObject obj = arrVal.toObject();
resultData resData;
resData.nineLinerId = obj[QStringLiteral("nine_liner_id")].toInt();
DEBUG_LOG(m_logger) << "Nine Liner id = " << resData.nineLinerId;
Evaluations::SanNineLiner crtNineLiner = m_evlDtc->sanNineLiner(resData.nineLinerId);
if (crtNineLiner.id() <= 0 )
continue;
resData.lastModified = DTG::toStringMSec(crtNineLiner.lastModified());
const Core::GeoPosition2D &pos = crtNineLiner.line1_position();
resData.position = LtsCoordTrans::mgrsFromGeographic(pos.lon(), pos.lat());
resData.callSign = QString::fromStdString(crtNineLiner.line2_RadioFrequencyCallSignSuffix());
// FromJson line 3 - 9
QVector<Evaluations::Database::SanCategoryLine> linesCategory = Evaluations::SanCategoryLine::fromJson(crtNineLiner.lines(), crtNineLiner.id());
INFO_LOG(m_logger) << "linesCategory size: " << linesCategory.size();
for (const Evaluations::Database::SanCategoryLine &cl : qAsConst(linesCategory))
{
switch (cl.line) {
case 3:
resData.line_3.append(QString::number(cl.amount)+cl.category+QStringLiteral(" "));
break;
case 4:
resData.line_4.append(QString::number(cl.amount)+cl.category+QStringLiteral(" "));
break;
case 5:
resData.line_5.append(QString::number(cl.amount)+cl.category+QStringLiteral(" "));
break;
case 6:
resData.line_6.append(cl.category+QStringLiteral(" "));
break;
case 7:
resData.line_7.append(cl.category+QStringLiteral(" "));
break;
case 8:
resData.line_8.append(QString::number(cl.amount)+cl.category+QStringLiteral(" "));
break;
case 9:
if (cl.category == QStringLiteral("None"))
resData.line_9.append(tr("None"));
else
resData.line_9.append(cl.category+QStringLiteral(" "));
break;
default:
break;
}
}
m_data.append(std::move(resData));
}
}
@@ -0,0 +1,74 @@
/**
* @RDE_HEADER@
* Plugin Report Management: Report Sanitation Materials model
* $Id$
* $HeadURL$
* $Author$
* Created by Iuliana Ojog, 2020-06-22
*/
#pragma once
#include "rep_abstract_model.h"
#include <ReportManagement/logger.h>
#include <Evaluations/evl_dtc.h>
//----------------------------------------------------------------------------
namespace ReportManagement
{
class MedevacNineLinerModel final : public AbstractModel
{
Q_OBJECT
friend class AbstractModel;
public:
int rowCount(const QModelIndex &parent = QModelIndex()) const override final;
int columnCount(const QModelIndex &parent = QModelIndex()) const override final;
QVariant data(const QModelIndex &index, int role) const override final;
QVariant headerData(int section, Qt::Orientation orientation, int role) const override final;
bool fetchInterfaces() override final;
private:
explicit MedevacNineLinerModel(const ReportManagement::ReportInfo &report, LtsSession::LtsSession *session, QObject *parent);
void fillReportData() override final;
enum Columns
{
LAST_MODIFIED = 0,
POSITION = 1,
CALL_SIGN = 2,
LINE_3 = 3,
LINE_4 = 4,
LINE_5 = 5,
LINE_6 = 6,
LINE_7 = 7,
LINE_8 = 8,
LINE_9 = 9,
NINE_LINER_ID = 10,
#ifdef LTS_DEBUG
COUNT = 11
#else
COUNT = 10 // without last column
#endif
};
struct resultData
{
int nineLinerId = 0;
QString lastModified;
QString position; // line 1
QString callSign; // line 2
QString line_3;
QString line_4;
QString line_5;
QString line_6;
QString line_7;
QString line_8;
QString line_9;
};
QVector<resultData> m_data;
std::shared_ptr<Evaluations::Interface::Dtc> m_evlDtc;
LOGGER_T m_logger;
};
}
@@ -0,0 +1,284 @@
/**
* @RDE_HEADER@
* Shows a report of combat power in form of curves
* $Id$
* $HeadURL$
* $Author$
*/
#include "rep_mine_area_model.h"
#include <PluginInterfaces/gui_plugin_interface.h>
#include <Plugins/ParticipantManagement/ppm_data_plugin_interface.h>
#include <Plugins/AreaEffectSimulation/aes_data_plugin_interface.h>
#include <Plugins/ReportManagement/rep_data_plugin_interface.h>
#include <LtsSession/lts_session.h>
#include <QFont>
using namespace ReportManagement;
//----------------------------------------------------------------------------
MineAreaModel::MineAreaModel(const ReportInfo &report, LtsSession::LtsSession *session, QObject *parent)
: AbstractModel(report, session, parent)
, m_ppmDtc(nullptr)
, m_logger(getLogger("MineAreaModel"))
{
if (!fetchInterfaces())
return;
//#define TEST_DATA
#ifdef TEST_DATA
resultData resData;
resData.mineAreaId = 1;
resData.participantTypeId = 23;
resData.hits = {2, 2, 0};
m_data.append(resData);
resData.mineAreaId = 1;
resData.participantTypeId = 32;
resData.hits = {2, 2, 0};
m_data.append(resData);
resData.mineAreaId = 1;
resData.participantTypeId = 0; // total on mine id
resData.hits = {4, 4, 0};
m_data.append(resData);
resData.mineAreaId = 2;
resData.participantTypeId = 23;
resData.hits = {2, 2, 0};
m_data.append(resData);
resData.mineAreaId = 2;
resData.participantTypeId = 32;
resData.hits = {2, 2, 0};
m_data.append(resData);
resData.mineAreaId = 2;
resData.participantTypeId = 0; // total on mine id
resData.hits = {4, 4, 0};
m_data.append(resData);
resData.mineAreaId = 0; // total
resData.participantTypeId = 0;
resData.hits = {8, 8, 0};
m_data.append(resData);
#else
getReportData(report);
fillReportData();
#endif
}
// -----------------------------------------------------------------------------------------------------
bool MineAreaModel::fetchInterfaces()
{
if (!m_session->getDtc<ParticipantManagement::DataInterface>(m_ppmDtc))
{
ERROR_LOG(m_logger) << "Could not fetch PPM DTC Interface";
return false;
}
return true;
}
// -----------------------------------------------------------------------------------------------------
int MineAreaModel::rowCount(const QModelIndex &parent) const
{
return parent.isValid() ? 0 : m_data.count();
}
// -----------------------------------------------------------------------------------------------------
int MineAreaModel::columnCount(const QModelIndex &parent) const
{
return parent.isValid() ? 0 : COUNT;
}
// -----------------------------------------------------------------------------------------------------
QVariant MineAreaModel::data(const QModelIndex &index, int role) const
{
if (!index.isValid())
return QVariant();
const resultData &displayInfo = m_data[index.row()];
if (role == Qt::TextAlignmentRole)
{
switch (index.column())
{
case PARTICIPANT_TYPE_ID:
case MINE_AREA_ID:
case HIT_TOTAL:
case HIT_ENEMY:
case HIT_OWN:
return Qt::AlignRight;
case PARTICIPANT_TYPE_NAME:
case MINE_AREA_NAME:
default:
return Qt::AlignLeft;
}
return Qt::AlignLeft;
}
if (role == Qt::FontRole)
{
QFont boldFont;
boldFont.setBold(true);
// total and subtotals
if (displayInfo.mineAreaId == 0 || displayInfo.participantTypeId == 0)
return boldFont;
return QFont();
}
if (role == Qt::DisplayRole)
{
switch (index.column())
{
case MINE_AREA_ID:
return (displayInfo.mineAreaId > 0 ? displayInfo.mineAreaId : QVariant());
case MINE_AREA_NAME:
{
QString displayName;
if (displayInfo.mineAreaId > 0)
{
QString mineName = displayInfo.mineAreaName;
if (displayInfo.participantTypeId == 0)
displayName = tr("Total [%1]").arg(mineName);
else
displayName = mineName;
}
return (displayInfo.mineAreaId > 0 ? displayName : tr("TOTAL:"));
}
case PARTICIPANT_TYPE_ID:
return (displayInfo.participantTypeId > 0 ? displayInfo.participantTypeId : QVariant());
case PARTICIPANT_TYPE_NAME:
return (displayInfo.participantTypeId > 0 ? QString::fromStdString(m_ppmDtc->type(displayInfo.participantTypeId).name())
: QVariant());
case HIT_TOTAL:
return displayInfo.hits[0];
case HIT_ENEMY:
return displayInfo.hits[1];
case HIT_OWN:
return displayInfo.hits[2];
default:
return QVariant();
}
}
return QVariant();
}
// -----------------------------------------------------------------------------------------------------
QVariant MineAreaModel::headerData(int section, Qt::Orientation orientation, int role) const
{
if (orientation == Qt::Horizontal && role == Qt::FontRole)
{
QFont boldFont;
boldFont.setBold(true);
return boldFont;
}
if (!(orientation == Qt::Horizontal && role == Qt::DisplayRole))
return QVariant();
switch (section)
{
case MINE_AREA_ID:
return tr("Mine Area Id");
case MINE_AREA_NAME:
return tr("Mine Area Name");
case PARTICIPANT_TYPE_ID:
return tr("Type Id");
case PARTICIPANT_TYPE_NAME:
return tr("Type Name");
case HIT_TOTAL:
return tr("Total hits");
case HIT_ENEMY:
return tr("Enemy forces");
case HIT_OWN:
return tr("Own forces");
default:
return QVariant();
}
}
// ------------------------------------------------------------------
void MineAreaModel::fillReportData()
{
DEBUG_LOG(m_logger) << "fillReportData(): m_reportJsonArray.size() = " << m_reportJsonArray.size();
int mineAreaId = -1;
QString mineAreaName;
QMap<int, QVector<int> > sums;
QVector<int> bigTotal(3, 0);
for (const QJsonValue &arrVal : qAsConst(m_reportJsonArray))
{
const QJsonObject obj = arrVal.toObject();
resultData resData;
resData.participantTypeId = obj[QStringLiteral("participant_type_id")].toInt();
resData.mineAreaId = obj[QStringLiteral("mine_area_id")].toInt();
resData.mineAreaName = obj[QStringLiteral("mine_area_name")].toString();
resData.hits[0] = obj[QStringLiteral("hit")].toInt();
resData.hits[2] = obj[QStringLiteral("hit_friendly_fire")].toInt();
resData.hits[1] = resData.hits[0] - resData.hits[2];
INFO_LOG(m_logger) << "Mine area id = " << resData.mineAreaId;
INFO_LOG(m_logger) << "Mine area name = " << resData.mineAreaName;
INFO_LOG(m_logger) << "Participant type id = " << resData.participantTypeId;
INFO_LOG(m_logger) << "Hits = ("
<< resData.hits[0] << ", "
<< resData.hits[1] << ", "
<< resData.hits[2] << ")" ;
if (mineAreaId != resData.mineAreaId) // new Mine area
{
if (mineAreaId != -1) // total on mine area
{
resultData totalType;
totalType.mineAreaId = mineAreaId;
totalType.mineAreaName = mineAreaName;
totalType.participantTypeId = 0;
totalType.hits = sums[mineAreaId];
m_data.append(std::move(totalType));
sumUp(bigTotal, sums[mineAreaId], sums[mineAreaId].size());
}
mineAreaId = resData.mineAreaId;
mineAreaName = resData.mineAreaName;
sums[mineAreaId] = resData.hits;
}
else
{
sumUp(sums[mineAreaId], resData.hits, resData.hits.size());
}
m_data.append(std::move(resData));
}
if (m_reportJsonArray.size() > 0)
{
// last total on mine area
resultData totalType;
totalType.mineAreaId = mineAreaId;
totalType.mineAreaName = mineAreaName;
totalType.participantTypeId = 0;
totalType.hits = sums[mineAreaId];
m_data.append(std::move(totalType));
sumUp(bigTotal, sums[mineAreaId], sums[mineAreaId].size());
// big total
resultData total;
total.mineAreaId = 0;
total.mineAreaName = QString();
total.participantTypeId = 0;
total.hits = bigTotal;
m_data.append(std::move(total));
}
}
@@ -0,0 +1,62 @@
/**
* @RDE_HEADER@
* Shows report player distance
* $Id$
* $HeadURL$
* $Author$
*/
#pragma once
#include "rep_abstract_model.h"
#include <ReportManagement/logger.h>
#include <ParticipantManagement/ppm_dtc.h>
//----------------------------------------------------------------------------
namespace ReportManagement
{
class MineAreaModel final : public AbstractModel
{
Q_OBJECT
friend class AbstractModel;
public:
int rowCount(const QModelIndex &parent = QModelIndex()) const override final;
int columnCount(const QModelIndex &parent = QModelIndex()) const override final;
QVariant data(const QModelIndex &index, int role) const override final;
QVariant headerData(int section, Qt::Orientation orientation, int role) const override final;
bool fetchInterfaces() override final;
private:
explicit MineAreaModel(const ReportManagement::ReportInfo &report, LtsSession::LtsSession *session, QObject *parent);
void fillReportData() override final;
enum Columns
{
MINE_AREA_NAME = 0,
PARTICIPANT_TYPE_NAME = 1,
HIT_TOTAL = 2,
HIT_ENEMY = 3,
HIT_OWN = 4,
PARTICIPANT_TYPE_ID = 5,
MINE_AREA_ID = 6,
#ifdef LTS_DEBUG
COUNT = 7
#else
COUNT = 5 // without last 2 columns
#endif
};
struct resultData
{
int mineAreaId = 0;
int participantTypeId = 0;
QString mineAreaName;
QVector<int> hits = {0, 0, 0};
};
QVector<resultData> m_data;
std::shared_ptr<ParticipantManagement::Interface::Dtc> m_ppmDtc;
LOGGER_T m_logger;
};
}
@@ -0,0 +1,341 @@
/**
* @RDE_HEADER@
* Shows a report of combat power in form of curves
* $Id$
* $HeadURL$
* $Author$
*/
#include "rep_nbc_model.h"
#include <PluginInterfaces/gui_plugin_interface.h>
#include <Plugins/ParticipantManagement/ppm_data_plugin_interface.h>
#include <Plugins/AreaEffectSimulation/aes_data_plugin_interface.h>
#include <Plugins/ReportManagement/rep_data_plugin_interface.h>
#include <Plugins/ProjectDataManagement/pdm_data_plugin_interface.h>
#include <LtsSession/lts_session.h>
#include <QFont>
using namespace ReportManagement;
//----------------------------------------------------------------------------
NbcModel::NbcModel(const ReportInfo &report, LtsSession::LtsSession *session, QObject *parent)
: AbstractModel(report, session, parent)
, m_ppmDtc(nullptr)
, m_pdmDtc(nullptr)
, m_logger(getLogger("NbcModel"))
{
if (!fetchInterfaces())
return;
//#define TEST_DATA
#ifdef TEST_DATA
resultData resData;
resData.nbcId = 3;
resData.partyId = 2;
resData.participantTypeId = 23;
resData.hits = {2, 0};
m_data.append(resData);
resData.nbcId = 3;
resData.partyId = 2;
resData.participantTypeId = 32;
resData.hits = {2, 0};
m_data.append(resData);
resData.nbcId = 3;
resData.partyId = 2;
resData.participantTypeId = 0; // total on nbc id and party id
resData.hits = {4, 0};
m_data.append(resData);
resData.nbcId = 3;
resData.partyId = 3;
resData.participantTypeId = 23;
resData.hits = {2, 0};
m_data.append(resData);
resData.nbcId = 3;
resData.partyId = 3;
resData.participantTypeId = 32;
resData.hits = {2, 0};
m_data.append(resData);
resData.nbcId = 3;
resData.partyId = 3;
resData.participantTypeId = 0; // total on nbc id and party id
resData.hits = {4, 0};
m_data.append(resData);
resData.nbcId = 3;
resData.partyId = 0;
resData.participantTypeId = 0; // total on nbc id
resData.hits = {8, 0};
m_data.append(resData);
resData.nbcId = 4;
resData.partyId = 2;
resData.participantTypeId = 23;
resData.hits = {2, 0};
m_data.append(resData);
resData.nbcId = 4;
resData.partyId = 2;
resData.participantTypeId = 32;
resData.hits = {2, 0};
m_data.append(resData);
resData.nbcId = 4;
resData.partyId = 2;
resData.participantTypeId = 0; // total on nbc id and party id
resData.hits = {4, 0};
m_data.append(resData);
resData.nbcId = 0; // total
resData.partyId = 0;
resData.participantTypeId = 0;
resData.hits = {12, 0};
m_data.append(resData);
#else
getReportData(report);
fillReportData();
#endif
}
// -----------------------------------------------------------------------------------------------------
bool NbcModel::fetchInterfaces()
{
if (!m_session->getDtc<ParticipantManagement::DataInterface>(m_ppmDtc))
{
ERROR_LOG(m_logger) << "Could not fetch PPM DTC Interface";
return false;
}
if (!m_session->getDtc<ProjectDataManagement::DataInterface>(m_pdmDtc))
{
ERROR_LOG(m_logger) << "Could not fetch PDM DTC Interface";
return false;
}
return true;
}
// -----------------------------------------------------------------------------------------------------
int NbcModel::rowCount(const QModelIndex &parent) const
{
return parent.isValid() ? 0 : m_data.count();
}
// -----------------------------------------------------------------------------------------------------
int NbcModel::columnCount(const QModelIndex &parent) const
{
return parent.isValid() ? 0 : COUNT;
}
// -----------------------------------------------------------------------------------------------------
QVariant NbcModel::data(const QModelIndex &index, int role) const
{
if (!index.isValid())
return QVariant();
const resultData &displayInfo = m_data[index.row()];
if (role == Qt::TextAlignmentRole)
{
switch (index.column())
{
case EVENT_ID:
case PARTY_ID:
case PARTICIPANT_TYPE_ID:
case HITS:
case PROTECTED:
return Qt::AlignRight;
case EVENT_NAME:
case CHARGE_TYPE_NAME:
case PARTY_NAME:
case PARTICIPANT_TYPE_NAME:
default:
return Qt::AlignLeft;
}
return Qt::AlignLeft;
}
if (role == Qt::FontRole)
{
QFont boldFont;
boldFont.setBold(true);
// total and subtotals
if (displayInfo.nbcId == 0 || displayInfo.participantTypeId == 0 || displayInfo.partyId < 0)
return boldFont;
return QFont();
}
if (role == Qt::DisplayRole)
{
switch (index.column())
{
case EVENT_ID:
return (displayInfo.nbcId > 0 ? displayInfo.nbcId : QVariant());
case EVENT_NAME:
{
QString displayName;
if (displayInfo.nbcId > 0)
{
QString eventName = displayInfo.nbcName;
if (displayInfo.participantTypeId == 0)
displayName = tr("Total [%1]").arg(eventName);
else
displayName = eventName;
}
return (displayInfo.nbcId > 0 ? displayName : tr("TOTAL:"));
}
case CHARGE_TYPE_ID:
return (displayInfo.chargeTypeId > 0 ? displayInfo.chargeTypeId : QVariant());
case CHARGE_TYPE_NAME:
return displayInfo.chargeTypeId > 0 ? m_pdmDtc->trChargeTypeShortName(displayInfo.chargeTypeId, true) : QVariant();
case PARTY_ID:
return (displayInfo.partyId >= 0 ? QVariant(displayInfo.partyId) : QVariant());
case PARTY_NAME:
return (displayInfo.partyId > 0 ? QString::fromStdString(m_ppmDtc->party(displayInfo.partyId).name())
: QVariant());
case PARTICIPANT_TYPE_ID:
return (displayInfo.participantTypeId > 0 ? displayInfo.participantTypeId : QVariant());
case PARTICIPANT_TYPE_NAME:
return (displayInfo.participantTypeId > 0 ? QString::fromStdString(m_ppmDtc->type(displayInfo.participantTypeId).name())
: QVariant());
case HITS:
return displayInfo.hits[0];
case PROTECTED:
return displayInfo.hits[1];
default:
return QVariant();
}
}
return QVariant();
}
// -----------------------------------------------------------------------------------------------------
QVariant NbcModel::headerData(int section, Qt::Orientation orientation, int role) const
{
if (orientation == Qt::Horizontal && role == Qt::FontRole)
{
QFont boldFont;
boldFont.setBold(true);
return boldFont;
}
if (!(orientation == Qt::Horizontal && role == Qt::DisplayRole))
return QVariant();
switch (section)
{
case EVENT_ID:
return tr("Event Id");
case EVENT_NAME:
return tr("Event Name");
case CHARGE_TYPE_ID:
return tr("Charge Type Id");
case CHARGE_TYPE_NAME:
return tr("Charge Type");
case PARTICIPANT_TYPE_ID:
return tr("Type Id");
case PARTICIPANT_TYPE_NAME:
return tr("Type Name");
case HITS:
return tr("Total hits");
case PROTECTED:
return tr("Protected");
case PARTY_ID:
return tr("Party Id");
case PARTY_NAME:
return tr("Party Name");
default:
return QVariant();
}
}
// ------------------------------------------------------------------
void NbcModel::fillReportData()
{
DEBUG_LOG(m_logger) << "fillReportData(): m_reportJsonArray.size() = " << m_reportJsonArray.size();
int nbcId = -1;
QString nbcName;
QMap<int, QVector<int> > sums;
QVector<int> bigTotal(3, 0);
for (const QJsonValue &arrVal : qAsConst(m_reportJsonArray))
{
const QJsonObject obj = arrVal.toObject();
resultData resData;
resData.nbcId = obj[QStringLiteral("nbc_id")].toInt();
resData.nbcName = obj[QStringLiteral("nbc_name")].toString();
resData.chargeTypeId = obj[QStringLiteral("charge_type_id")].toInt();
resData.partyId = obj[QStringLiteral("party_id")].toInt();
resData.participantTypeId = obj[QStringLiteral("participant_type_id")].toInt();
resData.hits[0] = obj[QStringLiteral("hit")].toInt();
resData.hits[1] = obj[QStringLiteral("protection")].toInt();
INFO_LOG(m_logger) << "Nbc id = " << resData.nbcId;
INFO_LOG(m_logger) << "Nbc name = " << resData.nbcName;
INFO_LOG(m_logger) << "Participant type id = " << resData.participantTypeId;
INFO_LOG(m_logger) << "Hits = ("
<< resData.hits[0] << ", "
<< resData.hits[1];
if (nbcId != resData.nbcId) // new NBC field
{
if (nbcId != -1) // total on NBC id
{
resultData totalType;
totalType.nbcId = nbcId;
totalType.nbcName = nbcName;
totalType.chargeTypeId = 0;
totalType.participantTypeId = 0;
totalType.hits = sums[nbcId];
m_data.append(std::move(totalType));
sumUp(bigTotal, sums[nbcId], sums[nbcId].size());
}
nbcId = resData.nbcId;
nbcName = resData.nbcName;
sums[nbcId] = resData.hits;
}
else
{
sumUp(sums[nbcId], resData.hits, resData.hits.size());
}
m_data.append(std::move(resData));
}
if (m_reportJsonArray.size() > 0)
{
// last total on NBC id
resultData totalType;
totalType.nbcId = nbcId;
totalType.nbcName = nbcName;
totalType.chargeTypeId = 0;
totalType.participantTypeId = 0;
totalType.hits = sums[nbcId];
m_data.append(std::move(totalType));
sumUp(bigTotal, sums[nbcId], sums[nbcId].size());
// big total
resultData total;
total.nbcId = 0;
total.nbcName = QString();
total.chargeTypeId = 0;
total.participantTypeId = 0;
total.hits = bigTotal;
m_data.append(std::move(total));
}
}
@@ -0,0 +1,69 @@
/**
* @RDE_HEADER@
* Shows report player distance
* $Id$
* $HeadURL$
* $Author$
*/
#pragma once
#include "rep_abstract_model.h"
#include <ReportManagement/logger.h>
#include <ParticipantManagement/ppm_dtc.h>
#include <ProjectDataManagement/pdm_dtc.h>
//----------------------------------------------------------------------------
namespace ReportManagement
{
class NbcModel final : public AbstractModel
{
Q_OBJECT
friend class AbstractModel;
public:
int rowCount(const QModelIndex &parent = QModelIndex()) const override final;
int columnCount(const QModelIndex &parent = QModelIndex()) const override final;
QVariant data(const QModelIndex &index, int role) const override final;
QVariant headerData(int section, Qt::Orientation orientation, int role) const override final;
bool fetchInterfaces() override final;
private:
explicit NbcModel(const ReportManagement::ReportInfo &report, LtsSession::LtsSession *session, QObject *parent);
void fillReportData() override final;
enum Columns
{
EVENT_NAME = 0,
CHARGE_TYPE_NAME = 1,
PARTY_NAME = 2,
PARTICIPANT_TYPE_NAME = 3,
HITS = 4,
PROTECTED = 5,
PARTICIPANT_TYPE_ID = 6,
PARTY_ID = 7,
CHARGE_TYPE_ID = 8,
EVENT_ID = 9,
#ifdef LTS_DEBUG
COUNT = 10
#else
COUNT = 6 // without last 4 columns
#endif
};
struct resultData
{
int nbcId = 0;
int chargeTypeId = 0;
int partyId = 0;
int participantTypeId = 0;
QString nbcName;
QVector<int> hits = {0, 0};
};
QVector<resultData> m_data;
std::shared_ptr<ParticipantManagement::Interface::Dtc> m_ppmDtc;
std::shared_ptr<ProjectDataManagement::Interface::Dtc> m_pdmDtc;
LOGGER_T m_logger;
};
}
@@ -0,0 +1,265 @@
/**
* @RDE_HEADER@
* Shows a report of combat power in form of curves
* $Id$
* $HeadURL$
* $Author$
*/
#include "rep_participant_distance_model.h"
#include <PluginInterfaces/gui_plugin_interface.h>
#include <Plugins/ParticipantManagement/ppm_data_plugin_interface.h>
#include <Plugins/ReportManagement/rep_data_plugin_interface.h>
#include <LtsSession/lts_session.h>
#include <QFont>
using namespace ReportManagement;
//----------------------------------------------------------------------------
ParticipantDistanceModel::ParticipantDistanceModel(const ReportInfo &report, LtsSession::LtsSession *session, QObject *parent)
: AbstractModel(report, session, parent)
, m_ppmDtc(nullptr)
, m_logger(getLogger("ParticipantDistanceModel"))
{
if (!fetchInterfaces())
return;
//#define TEST_DATA
#ifdef TEST_DATA
resultData resData;
resData.participantTypeId = 23;
resData.participantId = 18;
resData.distance = 2000.50;
m_data.append(resData);
resData.participantTypeId = 23;
resData.participantId = 19;
resData.distance = 1200.50;
m_data.append(resData);
resData.participantTypeId = 23;
resData.participantId = 0; // total on type 23
resData.distance = 3201.00;
m_data.append(resData);
resData.participantTypeId = 32;
resData.participantId = 5;
resData.distance = 1500.25;
m_data.append(resData);
resData.participantTypeId = 32;
resData.participantId = 6;
resData.distance = 1000.75;
m_data.append(resData);
resData.participantTypeId = 32;
resData.participantId = 0; // total on type 32
resData.distance = 2501.00;
m_data.append(resData);
resData.participantTypeId = 0; // big total
resData.participantId = 0;
resData.distance = 5702.00;
m_data.append(resData);
#else
getReportData(report);
fillReportData();
#endif
}
// -----------------------------------------------------------------------------------------------------
bool ParticipantDistanceModel::fetchInterfaces()
{
if (!m_session->getDtc<ParticipantManagement::DataInterface>(m_ppmDtc))
{
ERROR_LOG(m_logger) << "Could not fetch PPM DTC Interface";
return false;
}
return true;
}
// -----------------------------------------------------------------------------------------------------
int ParticipantDistanceModel::rowCount(const QModelIndex &parent) const
{
return parent.isValid() ? 0 : m_data.count();
}
// -----------------------------------------------------------------------------------------------------
int ParticipantDistanceModel::columnCount(const QModelIndex &parent) const
{
return parent.isValid() ? 0 : COUNT;
}
// -----------------------------------------------------------------------------------------------------
QVariant ParticipantDistanceModel::data(const QModelIndex &index, int role) const
{
if (!index.isValid())
return QVariant();
const resultData &displayInfo = m_data[index.row()];
if (role == Qt::TextAlignmentRole)
{
switch (index.column())
{
case PARTICIPANT_TYPE_ID:
case PARTICIPANT_ID:
case PARTICIPANT_EQUIPMENT_NO:
case DISTANCE:
return Qt::AlignRight;
case PARTICIPANT_TYPE_NAME:
case PARTICIPANT_NAME:
default:
return Qt::AlignLeft;
}
return Qt::AlignLeft;
}
if (role == Qt::FontRole)
{
QFont boldFont;
boldFont.setBold(true);
// total and subtotals
if (displayInfo.participantId == 0 || displayInfo.participantTypeId == 0)
return boldFont;
return QFont();
}
if (role == Qt::DisplayRole)
{
switch (index.column())
{
case PARTICIPANT_TYPE_ID:
return (displayInfo.participantTypeId > 0 ? displayInfo.participantTypeId : QVariant());
case PARTICIPANT_TYPE_NAME:
{
QString displayTypeName;
if (displayInfo.participantTypeId > 0)
{
QString typeName = QString::fromStdString(m_ppmDtc->type(displayInfo.participantTypeId).name());
if (displayInfo.participantId == 0)
displayTypeName = tr("Total [%1]").arg(typeName);
else
displayTypeName = typeName;
}
return (displayInfo.participantTypeId > 0 ? displayTypeName : tr("TOTAL:"));
}
case PARTICIPANT_EQUIPMENT_NO:
// return (displayInfo.participantId > 0 && m_ppmDtc->participant(displayInfo.participantId).equipmentNumber().is_set() ? m_ppmDtc->participant(displayInfo.participantId).equipmentNumber().get() : QVariant());
return (displayInfo.participantEqNo > 0 ? QString::number(displayInfo.participantEqNo) : QVariant());
case PARTICIPANT_ID:
return (displayInfo.participantId > 0 ? displayInfo.participantId : QVariant());
case PARTICIPANT_NAME:
// return (displayInfo.participantId > 0 ? QString::fromStdString(m_ppmDtc->participant(displayInfo.participantId).name())
// : QVariant());
return (!displayInfo.participantName.isEmpty() ? displayInfo.participantName : QVariant());
case DISTANCE:
return QString::number(displayInfo.distance); //, 'f', 2);
default:
return QVariant();
}
}
return QVariant();
}
// -----------------------------------------------------------------------------------------------------
QVariant ParticipantDistanceModel::headerData(int section, Qt::Orientation orientation, int role) const
{
if (orientation == Qt::Horizontal && role == Qt::FontRole)
{
QFont boldFont;
boldFont.setBold(true);
return boldFont;
}
if (!(orientation == Qt::Horizontal && role == Qt::DisplayRole))
return QVariant();
switch (section)
{
case PARTICIPANT_TYPE_ID:
return tr("Type Id");
case PARTICIPANT_TYPE_NAME:
return tr("Type Name");
case PARTICIPANT_ID:
return tr("Participant Id");
case PARTICIPANT_EQUIPMENT_NO:
return tr("Equipment Number");
case PARTICIPANT_NAME:
return tr("Participant Name");
case DISTANCE:
return tr("Covered Distance [m]");
default:
return QVariant();
}
}
// ------------------------------------------------------------------
void ParticipantDistanceModel::fillReportData()
{
DEBUG_LOG(m_logger) << "fillReportData(): m_reportJsonArray.size() = " << m_reportJsonArray.size();
int participantTypeId = -1;
long bigTotal = 0;
QHash<int, long> sums;
for (const QJsonValue &arrVal : qAsConst(m_reportJsonArray))
{
const QJsonObject obj = arrVal.toObject();
resultData resData;
resData.participantTypeId = obj[QStringLiteral("participant_type_id")].toInt();
resData.participantId = obj[QStringLiteral("participant_id")].toInt();
resData.participantName = obj[QStringLiteral("participant_name")].toString();
resData.participantEqNo = obj[QStringLiteral("participant_equipment_number")].toInt();
resData.distance = obj[QStringLiteral("distance")].toDouble();
INFO_LOG(m_logger) << "Participant id = " << resData.participantId;
INFO_LOG(m_logger) << "Participant type id = " << resData.participantTypeId;
INFO_LOG(m_logger) << "Participant distance = " << resData.distance;
if (participantTypeId != resData.participantTypeId) // new Type
{
if (participantTypeId != -1) // total on type
{
resultData totalType;
totalType.participantTypeId = participantTypeId;
totalType.participantId = 0;
totalType.distance = sums[participantTypeId];
m_data.append(std::move(totalType));
bigTotal += sums[participantTypeId];
}
participantTypeId = resData.participantTypeId;
sums[participantTypeId] = resData.distance;
}
else
sums[participantTypeId] += resData.distance;
m_data.append(std::move(resData));
}
if (m_reportJsonArray.size() > 0)
{
// last total on type
resultData totalType;
totalType.participantTypeId = participantTypeId;
totalType.participantId = 0;
totalType.distance = sums[participantTypeId];
m_data.append(std::move(totalType));
bigTotal += sums[participantTypeId];
// big total
resultData total;
total.participantTypeId = 0;
total.participantId = 0;
total.distance = bigTotal;
m_data.append(std::move(total));
}
}
@@ -0,0 +1,62 @@
/**
* @RDE_HEADER@
* Shows report player distance
* $Id$
* $HeadURL$
* $Author$
*/
#pragma once
#include "rep_abstract_model.h"
#include <ReportManagement/logger.h>
#include <ParticipantManagement/ppm_dtc.h>
//----------------------------------------------------------------------------
namespace ReportManagement
{
class ParticipantDistanceModel final : public AbstractModel
{
Q_OBJECT
friend class AbstractModel;
public:
int rowCount(const QModelIndex &parent = QModelIndex()) const override final;
int columnCount(const QModelIndex &parent = QModelIndex()) const override final;
QVariant data(const QModelIndex &index, int role) const override final;
QVariant headerData(int section, Qt::Orientation orientation, int role) const override final;
bool fetchInterfaces() override final;
private:
explicit ParticipantDistanceModel(const ReportManagement::ReportInfo &report, LtsSession::LtsSession *session, QObject *parent);
void fillReportData() override final;
enum Columns
{
PARTICIPANT_TYPE_NAME = 0,
PARTICIPANT_EQUIPMENT_NO = 1,
PARTICIPANT_NAME = 2,
DISTANCE = 3,
PARTICIPANT_ID = 4,
PARTICIPANT_TYPE_ID = 5,
#ifdef LTS_DEBUG
COUNT = 6
#else
COUNT = 4 // without last 2 columns
#endif
};
struct resultData
{
int participantTypeId = 0;
int participantId = 0;
int participantEqNo = 0;
qint64 distance = 0;
QString participantName;
};
QVector<resultData> m_data;
std::shared_ptr<ParticipantManagement::Interface::Dtc> m_ppmDtc;
LOGGER_T m_logger;
};
}
@@ -0,0 +1,382 @@
/**
* @RDE_HEADER@
* Plugin Report Management: Report Sanitation Materials model
* $Id$
* $HeadURL$
* $Author$
* Created by Iuliana Ojog, 2020-06-22
*/
#include "rep_sanitation_material_model.h"
#include <PluginInterfaces/gui_plugin_interface.h>
#include <Plugins/ProjectDataManagement/pdm_data_plugin_interface.h>
#include <Plugins/ReportManagement/rep_data_plugin_interface.h>
#include <ProjectDataManagement/pdm_translation.h>
#include <ParticipantManagement/ppm_translation.h>
#include <LtsSession/lts_session.h>
#include <QFont>
using namespace ReportManagement;
//----------------------------------------------------------------------------
SanitationMaterialModel::SanitationMaterialModel(const ReportInfo &report, LtsSession::LtsSession *session, QObject *parent)
: AbstractModel(report, session, parent)
, m_pdmDtc(nullptr)
, m_logger(getLogger("SanitationMaterialModel"))
{
if (!fetchInterfaces())
return;
//#define TEST_DATA
#ifdef TEST_DATA
resultData resData;
resData.uniqueId = 123;
resData.qualification = 1;
resData.materialId = 1;
resData.amounts[0] = 1000;
resData.amounts[1] = 1000;
resData.amounts[2] = 500;
resData.amounts[3] = 1500;
m_data.append(resData);
resData.uniqueId = 123;
resData.qualification = 2;
resData.materialId = 2;
resData.amounts[0] = 1000;
resData.amounts[1] = 1000;
resData.amounts[2] = 500;
resData.amounts[3] = 1500;
m_data.append(resData);
//total on unique id 123
resData.uniqueId = 123;
resData.qualification = 0;
resData.materialId = 0;
resData.amounts[0] = 2000;
resData.amounts[1] = 2000;
resData.amounts[2] = 1000;
resData.amounts[3] = 3000;
m_data.append(resData);
resData.uniqueId = 321;
resData.qualification = 2;
resData.materialId = 3;
resData.amounts[0] = 1000;
resData.amounts[1] = 1000;
resData.amounts[2] = 500;
resData.amounts[3] = 1500;
m_data.append(resData);
//total on unique id 321
resData.uniqueId = 321;
resData.qualification = 0;
resData.materialId = 0;
resData.amounts[0] = 1000;
resData.amounts[1] = 1000;
resData.amounts[2] = 500;
resData.amounts[3] = 1500;
m_data.append(resData);
// grand total
resData.uniqueId = 0;
resData.qualification = 0;
resData.materialId = 0;
resData.amounts[0] = 3000;
resData.amounts[1] = 3000;
resData.amounts[2] = 1500;
resData.amounts[3] = 4500;
m_data.append(resData);
#else
getReportData(report);
fillReportData();
#endif
}
// -----------------------------------------------------------------------------------------------------
bool SanitationMaterialModel::fetchInterfaces()
{
if (!m_session->getDtc<ProjectDataManagement::DataInterface>(m_pdmDtc))
{
ERROR_LOG(m_logger) << "Could not fetch PDM DTC Interface";
return false;
}
return true;
}
// -----------------------------------------------------------------------------------------------------
int SanitationMaterialModel::rowCount(const QModelIndex &parent) const
{
return parent.isValid() ? 0 : m_data.count();
}
// -----------------------------------------------------------------------------------------------------
int SanitationMaterialModel::columnCount(const QModelIndex &parent) const
{
return parent.isValid() ? 0 : COUNT;
}
// -----------------------------------------------------------------------------------------------------
QVariant SanitationMaterialModel::data(const QModelIndex &index, int role) const
{
if (!index.isValid())
return QVariant();
const resultData &displayInfo = m_data[index.row()];
if (role == Qt::TextAlignmentRole)
{
switch (index.column())
{
case MATERIAL_ID:
case AMOUNT_START:
case AMOUNT_RESUPPLIED:
case AMOUNT_END:
case AMOUNT_USED:
case DURATION:
return Qt::AlignRight;
case MATERIAL_NAME:
default:
return Qt::AlignLeft;
}
return Qt::AlignLeft;
}
if (role == Qt::FontRole)
{
QFont boldFont;
boldFont.setBold(true);
// total
if (displayInfo.materialId == 0 || displayInfo.qualification == 0 || displayInfo.uniqueId == 0)
return boldFont;
return QFont();
}
if (role == Qt::DisplayRole)
{
switch (index.column())
{
case UNIQUE_ID:
{
QString tot, uq;
if (displayInfo.uniqueId > 0)
{
uq = QStringLiteral("%1").arg(displayInfo.uniqueId, 2, 16, QLatin1Char('0')); // hex value
if (displayInfo.qualification == 0)
tot = tr("Total [%1]").arg(uq);
else
tot = uq;
}
// else
// tot = tr("TOTAL:");
return tot;
}
case QUALIFICATION:
return (displayInfo.qualification > 0 ? ParticipantManagement::toString(static_cast<ParticipantManagement::Qualification_def::type>(displayInfo.qualification)) : QVariant());
case MATERIAL_ID:
return (displayInfo.materialId > 0 ? displayInfo.materialId : QVariant());
case MATERIAL_NAME:
return (displayInfo.materialId > 0 ? ProjectDataManagement::trSanitationMaterialName(m_pdmDtc->sanitationMaterial(displayInfo.materialId).name())
: tr("TOTAL:"));
case AMOUNT_START:
return displayInfo.amounts[0];
case AMOUNT_RESUPPLIED:
return displayInfo.materialId > 0 ? displayInfo.amounts[1] : QVariant();
case AMOUNT_END:
return displayInfo.amounts[2];
case AMOUNT_USED:
return displayInfo.materialId > 0 ? displayInfo.amounts[3] : QVariant();
case DURATION:
return LtsWidgets::readableDuration(displayInfo.duration);
default:
return QVariant();
}
}
return QVariant();
}
// -----------------------------------------------------------------------------------------------------
QVariant SanitationMaterialModel::headerData(int section, Qt::Orientation orientation, int role) const
{
if (orientation == Qt::Horizontal && role == Qt::FontRole)
{
QFont boldFont;
boldFont.setBold(true);
return boldFont;
}
if (!(orientation == Qt::Horizontal && role == Qt::DisplayRole))
return QVariant();
switch (section)
{
case UNIQUE_ID:
return tr("Unique Id");
case MATERIAL_ID:
return tr("Material Id");
case MATERIAL_NAME:
return tr("Material");
case AMOUNT_START:
return tr("Stock Start");
case AMOUNT_RESUPPLIED:
return tr("Resupplied");
case AMOUNT_END:
return tr("Stock End");
case AMOUNT_USED:
return tr("Amount Used");
case QUALIFICATION:
return tr("Qualification");
case DURATION:
return tr("No stock duration");
default:
return QVariant();
}
}
// ------------------------------------------------------------------
void SanitationMaterialModel::fillReportData()
{
DEBUG_LOG(m_logger) << "fillReportData(): m_reportJsonArray.size() = " << m_reportJsonArray.size();
/*
int uniqueId = -1;
QMap<int, QVector<int> > sums;
QVector<int> bigTotal(4, 0);
*/
// totals per material id
QMap<int, QVector<int> > totals;
for (const QJsonValue &arrVal : qAsConst(m_reportJsonArray))
{
const QJsonObject obj = arrVal.toObject();
resultData resData;
resData.uniqueId = obj[QStringLiteral("sanitation_unique_id")].toInt();
resData.qualification = obj[QStringLiteral("qualification")].toInt();
resData.materialId = obj[QStringLiteral("material_id")].toInt();
resData.amounts[0] = obj[QStringLiteral("amount_start")].toInt();
resData.amounts[1] = obj[QStringLiteral("amount_resupplied")].toInt();
resData.amounts[2] = obj[QStringLiteral("amount_end")].toInt();
resData.amounts[3] = obj[QStringLiteral("amount_used")].toInt();
resData.duration = obj[QStringLiteral("duration")].toDouble();
ERROR_LOG(m_logger) << "Unique id = " << resData.uniqueId;
ERROR_LOG(m_logger) << "qualification = " << resData.qualification;
ERROR_LOG(m_logger) << "Material id = " << resData.materialId;
ERROR_LOG(m_logger) << "Duration with no stock = " << resData.duration;
ERROR_LOG(m_logger) << "Amounts = ("
<< resData.amounts[0] << ", "
<< resData.amounts[1] << ", "
<< resData.amounts[2] << ", "
<< resData.amounts[3] << ")" ;
/*
if (uniqueId != resData.uniqueId) // new UniqueId
{
if (uniqueId != -1) // total on UniqueId
{
resultData totalUniqueId;
totalUniqueId.uniqueId = uniqueId;
totalUniqueId.materialId = 0;
totalUniqueId.qualification = 0;
totalUniqueId.amounts = sums[uniqueId];
m_data.append(std::move(totalUniqueId));
sumUp(bigTotal, sums[uniqueId], sums[uniqueId].size());
}
uniqueId = resData.uniqueId;
sums[uniqueId] = resData.amounts;
}
else
{
sumUp(sums[uniqueId], resData.amounts, resData.amounts.size());
}
*/
if (!totals.keys().contains(resData.materialId))
totals[resData.materialId] = resData.amounts;
else
sumUp(totals[resData.materialId], resData.amounts, resData.amounts.size());
m_data.append(std::move(resData));
}
if (m_reportJsonArray.size() > 0)
{
resultData total;
total.uniqueId = 0;
total.materialId = 0;
total.qualification = 0;
m_data.append(std::move(total));
// totals on material ids
for (auto matId : totals.keys())
{
resultData totalMatId;
totalMatId.uniqueId = 0;
totalMatId.materialId = matId;
totalMatId.qualification = 0;
totalMatId.amounts = totals[matId];
DEBUG_LOG(m_logger) << "Totals per material id = " << matId << " : "
<< totalMatId.amounts[0] << ", "
<< totalMatId.amounts[1] << ", "
<< totalMatId.amounts[2] << ", "
<< totalMatId.amounts[3];
m_data.append(std::move(totalMatId));
}
}
/*
if (m_reportJsonArray.size() > 0)
{
// last total on UniqueId
resultData totalUniqueId;
totalUniqueId.uniqueId = uniqueId;
totalUniqueId.materialId = 0;
totalUniqueId.qualification = 0;
totalUniqueId.amounts = sums[uniqueId];
m_data.append(std::move(totalUniqueId));
sumUp(bigTotal, sums[uniqueId], sums[uniqueId].size());
// big total
resultData total;
total.uniqueId = 0;
total.materialId = 0;
total.qualification = 0;
total.amounts = bigTotal;
m_data.append(std::move(total));
}
*/
}
/* tried, does not work
QSize SanitationMaterialModel::span(const QModelIndex &index) const
{
if (!index.isValid())
return QSize();
const int row = index.row();
const int column = index.column();
ERROR_LOG(m_logger) << "Spanning row, col = " << row << ", " << column;
if (row < rowCount() - 1)
{
if (m_data[row].uniqueId == m_data[row + 1].uniqueId)
{
if (m_data[row].qualification == m_data[row + 1].qualification)
{
return QSize(1, 3);
}
return QSize(1, 2);
}
}
return QSize();
}
*/
@@ -0,0 +1,67 @@
/**
* @RDE_HEADER@
* Plugin Report Management: Report Sanitation Materials model
* $Id$
* $HeadURL$
* $Author$
* Created by Iuliana Ojog, 2020-06-22
*/
#pragma once
#include "rep_abstract_model.h"
#include <ReportManagement/logger.h>
#include <ProjectDataManagement/pdm_dtc.h>
//----------------------------------------------------------------------------
namespace ReportManagement
{
class SanitationMaterialModel final : public AbstractModel
{
Q_OBJECT
friend class AbstractModel;
public:
int rowCount(const QModelIndex &parent = QModelIndex()) const override final;
int columnCount(const QModelIndex &parent = QModelIndex()) const override final;
QVariant data(const QModelIndex &index, int role) const override final;
QVariant headerData(int section, Qt::Orientation orientation, int role) const override final;
bool fetchInterfaces() override final;
// QSize span(const QModelIndex &index) const override;
private:
explicit SanitationMaterialModel(const ReportManagement::ReportInfo &report, LtsSession::LtsSession *session, QObject *parent);
void fillReportData() override final;
enum Columns
{
UNIQUE_ID = 0,
QUALIFICATION = 1,
MATERIAL_NAME = 2,
AMOUNT_RESUPPLIED = 3,
AMOUNT_USED = 4,
DURATION = 5,
AMOUNT_START = 6,
AMOUNT_END = 7,
MATERIAL_ID = 8,
#ifdef LTS_DEBUG
COUNT = 5
#else
COUNT = 5 // without last columns
#endif
};
struct resultData
{
int materialId = 0;
int uniqueId = 0;
int qualification = 0;
QVector<int> amounts = {0, 0, 0, 0};
double duration = 0;
};
QVector<resultData> m_data;
std::shared_ptr<ProjectDataManagement::Interface::Dtc> m_pdmDtc;
LOGGER_T m_logger;
};
}
File diff suppressed because it is too large. Load diff
@@ -0,0 +1,261 @@
/**
* @RDE_HEADER@
* Shows report player distance
* $Id$
* $HeadURL$
* $Author$
*/
#pragma once
#include "rep_abstract_model.h"
#include <ReportManagement/logger.h>
#include <ParticipantManagement/ppm_dtc.h>
#include <ProjectDataManagement/pdm_dtc.h>
//----------------------------------------------------------------------------
namespace ReportManagement
{
class TreatmentModel : public AbstractModel
{
Q_OBJECT
friend class AbstractModel;
public:
int rowCount(const QModelIndex &parent = QModelIndex()) const override final;
int columnCount(const QModelIndex &parent = QModelIndex()) const override final;
QVariant data(const QModelIndex &index, int role) const override final;
QVariant headerData(int section, Qt::Orientation orientation, int role) const override final;
bool fetchInterfaces() override final;
int getAmountInjuryTotal() { return m_amountInjuryTotal; }
private:
explicit TreatmentModel(const ReportManagement::ReportInfo &report, LtsSession::LtsSession *session, QObject *parent);
void fillReportData() override final;
void fillParticipantMap();
int getParticipantKey(int participantId);
// recursive
void findTroupId(QSet<int> &partIds, int key);
QString getUnitName(int participantId);
enum Columns
{
PARTICIPANT = 0,
VITALITY = 1,
VULNERABILITY = 2,
TIME_VULNERABILITY = 3,
TIME_VITALITY = 4,
TIME_NINE_LINER = 5,
TIME_POSITION_CHANGED = 6,
TIME_ENTER_AREA = 7,
TIME_TREATMENT = 8,
DURATION_TREATMENT = 9,
INBETWEEN_10_MINUTES = 10,
GOLDEN_HOUR = 11,
SANITATION_PROCEDURES_TAKEN = 12,
SANITATION_RESULT = 13,
QUALIFICATION = 14,
SANITATION_EVALUATION = 15,
PRIORITY = 16,
PRIORITY_CORRECT = 17,
DURATION_NINE_LINER = 18,
DURATION_POSITION_CHANGED= 19,
DURATION_ENTER_AREA = 20,
FUNCTIONAL_AREA = 21,
PARTICIPANT_TYPE_NAME = 22,
PARTICIPANT_EQUIPMENT_NO = 23,
PARTICIPANT_NAME = 24,
PARTICIPANT_ID = 25,
PARTICIPANT_TYPE_ID = 26,
AREA_ID = 27,
#ifdef LTS_DEBUG
COUNT = 28
#else
COUNT = 22 // without last 6 columns
#endif
};
enum ColumnsTable
{
T_PARTICIPANT = 0,
T_PARTICIPANT_NAME = 1,
AMOUNT_LIGHT_WOUNDED = 2,
AMOUNT_MEDIUM_WOUNDED = 3,
AMOUNT_HEAVY_WOUNDED = 4,
AMOUNT_KIA = 5,
AMOUNT_KIA_AFTER_WIA = 6,
AMOUNT_INJURY_TOTAL = 7,
AMOUNT_TREATED = 8,
AMOUNT_PLATIN = 9,
AMOUNT_GOLDEN_HOUR = 10,
AMOUNT_OPTIMAL_TREATED = 11,
AMOUNT_RS_PLATIN = 12,
AMOUNT_RS_GOLDEN_HOUR = 13,
AMOUNT_ENTER_RESCUE_STATION_TREATED = 14,
AMOUNT_ENTER_RESCUE_STATION_NOT_TREATED = 15,
T_PARTICIPANT_ID = 16,
#ifdef LTS_DEBUG
COUNT_TABLE = 17
#else
COUNT_TABLE = 16 // without participantId
#endif
};
struct resultData
{
int participantTypeId = 0;
int participantId = 0;
int participantEqNo = 0;
QString participantName;
qint64 timeVulnerability = 0;
qint64 timeVitality = 0;
qint64 timeNineLiner = 0;
qint64 timePositionChanged = 0;
qint64 timeEnterArea = 0;
qint64 timeTreatment = 0;
qint64 timeTreatmentVulnerability;
bool inbetween10Minutes;
bool goldenHour;
int sanitationResult = 0;
int sanitationEvaluation = 0;
qint64 sanitationProceduresTaken = 0;
int qualification = 0;
bool optimalTreated = false;
int priority = 0;
bool priority_correct = true;
int vulnerability = 0;
int vulnerabilityState = 0;
int vitality = 0;
int areaId = 0;
QString areaName;
bool kiaAfterWia;
};
struct resultDataTable
{
int participantId = 0;
QString participantName;
int amountLightlyWounded = 0;
int amountMediumWounded = 0;
int amountHeavyWounded = 0;
int amountInjuryTotal = 0;
int amountKIA = 0;
int amountKIAAfterWIA = 0;
int amountTreated = 0;
int amountPlatin = 0;
int amountGoldenHour = 0;
int amountRsPlatin = 0;
int amountRsGoldenHour = 0;
int amountEnterRescueStationNotTreated = 0;
int amountEnterRescueStationTreated = 0;
int amountOptimalTreated = 0;
};
/* Columns Pie show the results based on PPM enum
<enumeration name="SanitationResult">
<attribute key="deprecatedNA" value="-1"/>
<attribute key="NoEffect" value="0"/>
<attribute key="Unhandled" value="1"/>
<attribute key="Insufficient" value="2"/>
<attribute key="Sufficient" value="3"/>
<attribute key="Optimal" value="4"/>
</enumeration>
enum ColumnsPie
{
PIE_NoEffect = 0,
PIE_Unhandled = 1,
PIE_Insufficient = 2,
PIE_Sufficient = 3,
PIE_Optimal = 4,
COUNT_PIE = 5
};
*/
enum ColumnsPie
{
PIE_platin, // inbetween 10 min
PIE_goldenHour, // inbetween 1h
PIE_enterRescueArea,
PIE_KIA,
PIE_notEnteredRecueArea,
PIE_total,
PIE_enterRescueAreaPlatin,
PIE_enterRescueAreaGoldenHour,
PIE_optimalTreated,
COUNT_PIE = 4 // without total/enterRsPlatin/enterRsGh/NotEnteredRS
};
struct resultDataPie
{
int groupId = 0;
QVector<int> results = {0, 0, 0, 0, 0, 0};
};
/* Columns PieEvaluation show the results based on PPM enum
<enumeration name="SanitationEvaluation">
<attribute key="NotApplicable" value="-1"/>
<attribute key="Okay" value="0"/>
<attribute key="PartlyWrong" value="1"/>
<attribute key="Wrong" value="2"/>
</enumeration>
*/
enum ColumnsPieEvaluation
{
PIE_Okay = 0,
PIE_PartlyWrong = 1,
PIE_Wrong = 2,
COUNT_PIE_EVAL = 3
};
struct resultDataPieEvaluation
{
int groupId = 0;
QVector<int> results = {0, 0, 0};
};
enum ColumnsPiePriority
{
WRONG = 0,
RIGHT = 1,
COUNT_PIE_PRIORITY = 2
};
struct resultDataPiePriority
{
int groupId = 0;
QVector<int> results = {0, 0};
};
void countVulnerabilityState( int key, const resultData &data);
int m_amountInjuryTotal = 0;
// QMap<troupId, QSet<participantId>
QMap<int,QSet<int>> m_participantMap;
// QMap<participantId, SuperiorId>
QMap<int,int> m_partSuperiorMap;
// QMap<troupId, QMap<VulnerabilityState, QSet<participantId>>>
QMap<int,QMap<int,QSet<int>>> m_vulnerabilityMap;
// QMap<troupId, QMap<TreatmentInterval, QSet<participantId>>>
QMap<int,QMap<int,QSet<int>>> m_treatmentIntervalMap;
//QMap<troupId,QSet<participantId>>
QMap<int,QSet<int>> m_rescueStationTreated;
//QMap<troupId,QSet<participantId>>
QMap<int,QSet<int>> m_rescueStationNotTreated;
//QMap<troupId,QSet<participantId>>
QMap<int,QSet<int>> m_treatmentAmount;
QVector<resultData> m_data;
QVector<resultDataTable> m_dataTable;
QVector<resultDataPie> m_dataPie;
QVector<resultDataPieEvaluation> m_dataPieEval;
QVector<resultDataPiePriority> m_dataPiePriority;
QMap<int, resultDataPieEvaluation> m_bars;
std::shared_ptr<ParticipantManagement::Interface::Dtc> m_ppmDtc;
std::shared_ptr<ProjectDataManagement::Interface::Dtc> m_pdmDtc;
LOGGER_T m_logger;
};
}
@@ -0,0 +1,397 @@
/**
* @RDE_HEADER@
* Shows a report of combat power in form of curves
* $Id$
* $HeadURL$
* $Author$
*/
#include "rep_treatment_timeline_model.h"
#include <PluginInterfaces/gui_plugin_interface.h>
#include <Plugins/ParticipantManagement/ppm_data_plugin_interface.h>
#include <Plugins/ProjectDataManagement/pdm_data_plugin_interface.h>
#include <Plugins/ReportManagement/rep_data_plugin_interface.h>
#include <ProjectDataManagement/pdm_to_string.h>
#include <ParticipantManagement/ppm_translation.h>
#include <ReportManagement/rep_translation.h>
#include <LtsSession/lts_session.h>
#include <ngltools/ngltools_dtg.h>
using namespace ReportManagement;
//----------------------------------------------------------------------------
TreatmentTimelineModel::TreatmentTimelineModel(const ReportInfo &report, LtsSession::LtsSession *session, QObject *parent)
: AbstractModel(report, session, parent)
, m_ppmDtc(nullptr)
, m_pdmDtc(nullptr)
, m_logger(getLogger("ReportTreatmentTimelineModel"))
{
if (!fetchInterfaces())
return;
//#define TEST_DATA
#ifdef TEST_DATA
resultData resData;
resData.groupId = 5; //participantId
resData.participantTypeId = 55;
resData.participantId = 5;
resData.participantEqNo = 781;
resData.participantName = QStringLiteral("Soldat 781");
resData.eventTypeId = ReportManagement::EventType::VBGChanged;
resData.eventTime = 1513758640000;
resData.vulnerability = 460942;
resData.vitality = 90;
resData.properties = QString();
m_data.append(resData);
resData.groupId = 5; //participantId
resData.participantTypeId = 55;
resData.participantId = 5;
resData.participantEqNo = 781;
resData.participantName = QStringLiteral("Soldat 781");
resData.eventTypeId = ReportManagement::EventType::VitalityChanged;
resData.eventTime = 1513758641000;
resData.vitality = 60;
resData.vulnerability = 460942;
resData.properties = QString();
m_data.append(resData);
resData.groupId = 5; //participantId
resData.participantTypeId = 55;
resData.participantId = 5;
resData.participantEqNo = 781;
resData.participantName = QStringLiteral("Soldat 781");
resData.eventTypeId = ReportManagement::EventType::NineLinerSet;
resData.eventTime = 1513758642000;
resData.vitality = 60;
resData.vulnerability = 460942;
resData.properties = QString();
m_data.append(resData);
resData.groupId = 5; //participantId
resData.participantTypeId = 55;
resData.participantId = 5;
resData.participantEqNo = 781;
resData.participantName = QStringLiteral("Soldat 781");
resData.eventTypeId = ReportManagement::EventType::TransportInitiated;
resData.eventTime = 1513758645000;
resData.vitality = 70;
resData.vulnerability = 460942;
resData.properties = QString();
m_data.append(resData);
resData.groupId = 5; //participantId
resData.participantTypeId = 55;
resData.participantId = 5;
resData.participantEqNo = 781;
resData.participantName = QStringLiteral("Soldat 781");
resData.eventTypeId = ReportManagement::EventType::PositionChanged;
resData.eventTime = 1513758646000;
resData.vitality = 70;
resData.vulnerability = 460942;
resData.properties = QString();
m_data.append(resData);
resData.groupId = 5; //participantId
resData.participantTypeId = 55;
resData.participantId = 5;
resData.participantEqNo = 781;
resData.participantName = QStringLiteral("Soldat 781");
resData.eventTypeId = ReportManagement::EventType::EnterFunctionalArea;
resData.eventTime = 1513758647000;
resData.vitality = 70;
resData.vulnerability = 460942;
std::string json = R"({"area_id": 1, "area_name": "test area"})";
resData.properties = QString::fromStdString(json);
m_data.append(resData);
resData.groupId = 5; //participantId
resData.participantTypeId = 55;
resData.participantId = 5;
resData.participantEqNo = 781;
resData.participantName = QStringLiteral("Soldat 781");
resData.eventTypeId = ReportManagement::EventType::Treatment;
resData.eventTime = 1513758648000;
resData.vitality = 70;
resData.vulnerability = 460942;
resData.properties = QString();
m_data.append(resData);
resData.groupId = 5; //participantId
resData.participantTypeId = 55;
resData.participantId = 5;
resData.participantEqNo = 781;
resData.participantName = QStringLiteral("Soldat 781");
resData.eventTypeId = ReportManagement::EventType::Treatment;
resData.eventTime = 1513758649000;
resData.vitality = 100;
resData.vulnerability = 460942;
resData.properties = QString();
m_data.append(resData);
#else
getReportData(report);
fillReportData();
#endif
}
// -----------------------------------------------------------------------------------------------------
bool TreatmentTimelineModel::fetchInterfaces()
{
if (!m_session->getDtc<ParticipantManagement::DataInterface>(m_ppmDtc))
{
ERROR_LOG(m_logger) << "Could not fetch PPM DTC Interface";
return false;
}
if (!m_session->getDtc<ProjectDataManagement::DataInterface>(m_pdmDtc))
{
ERROR_LOG(m_logger) << "Could not fetch PDM DTC Interface";
return false;
}
return true;
}
// -----------------------------------------------------------------------------------------------------
int TreatmentTimelineModel::rowCount(const QModelIndex &parent) const
{
return parent.isValid() ? 0 : m_data.count();
}
// -----------------------------------------------------------------------------------------------------
int TreatmentTimelineModel::columnCount(const QModelIndex &parent) const
{
return parent.isValid() ? 0 : COUNT;
}
// -----------------------------------------------------------------------------------------------------
QVariant TreatmentTimelineModel::data(const QModelIndex &index, int role) const
{
if (!index.isValid())
return QVariant();
if (m_report.visualisationType() == VisualisationType::Table || m_report.visualisationType() == VisualisationType::Line)
{
const resultData &displayInfo = m_data[index.row()];
if (role == Qt::TextAlignmentRole)
{
return Qt::AlignLeft;
}
else if (role == Qt::DisplayRole)
{
switch (index.column())
{
case PARTICIPANT_TYPE_ID:
return (displayInfo.participantTypeId > 0 ? displayInfo.participantTypeId : QVariant());
case PARTICIPANT_TYPE_NAME:
return (displayInfo.participantTypeId > 0 ? QString::fromStdString(m_ppmDtc->type(displayInfo.participantTypeId).name())
: QVariant());
case PARTICIPANT_ID:
return (displayInfo.participantId > 0 ? displayInfo.participantId
: QVariant());
case PARTICIPANT_EQUIPMENT_NO:
return (displayInfo.participantEqNo > 0 ? QString::number(displayInfo.participantEqNo) : QVariant());
case PARTICIPANT_NAME:
return (!displayInfo.participantName.isEmpty() ? displayInfo.participantName : QVariant());
case EVENT_TIME:
return (displayInfo.eventTime > 0 ? DTG::toStringMSec(displayInfo.eventTime)
: QVariant());
case EVENT_TYPE:
{
QString event = ReportManagement::toString(displayInfo.eventTypeId);
if (displayInfo.eventTypeId == ReportManagement::EventType::EnterFunctionalArea && displayInfo.properties.size() > 0)
event += QStringLiteral("\n") + getAreaName(displayInfo.properties);
if (displayInfo.eventTypeId == ReportManagement::EventType::Treatment && displayInfo.properties.size() > 0)
event += QStringLiteral("\n") + getSanProcs(displayInfo.properties);
return event;
}
case VITALITY:
{
if (m_report.visualisationType() == VisualisationType::Line)
return displayInfo.vitality;
else
{
QString vit = QString::number(displayInfo.vitality);
vit += QStringLiteral(" %");
return vit;
}
}
case VULNERABILITY:
{
QString vbg = ProjectDataManagement::toString(static_cast<ProjectDataManagement::VulnerabilityState::type>(displayInfo.vulnerabilityState));
if (displayInfo.vulnerability > 0)
vbg += QStringLiteral("\n") + m_pdmDtc->trVulnerabilityKindName(displayInfo.vulnerability, ProjectDataManagement::VulnerabilityClass::SoldierInjuries);
return vbg;
}
case AREA_NAME:
if (displayInfo.eventTypeId == ReportManagement::EventType::EnterFunctionalArea && displayInfo.properties.size() > 0)
return getAreaName(displayInfo.properties);
else
return QVariant();
default:
return QVariant();
}
}
else if (role == Qt::UserRole)
{
if (m_report.groupByParty() && displayInfo.participantId > 0)
{
QString part = tr("Participant: %1 - %2").arg(displayInfo.participantEqNo).arg(displayInfo.participantName);
return part;
}
}
else if (role == Qt::EditRole)
{
return displayInfo.participantId;
}
else if (role == Qt::ForegroundRole || role == Qt::BackgroundRole)
{
if (m_report.visualisationType() == VisualisationType::Line)
return eventColor(displayInfo.eventTypeId);
}
else if (role == Qt::UserRole + 1)
{
if (m_report.visualisationType() == VisualisationType::Line)
return displayInfo.eventTypeId.underlying();
}
}
return QVariant();
}
// -----------------------------------------------------------------------------------------------------
QVariant TreatmentTimelineModel::headerData(int section, Qt::Orientation orientation, int role) const
{
if (orientation == Qt::Horizontal && role == Qt::DisplayRole)
{
switch (section)
{
case PARTICIPANT_TYPE_ID:
return tr("Type Id");
case PARTICIPANT_TYPE_NAME:
return tr("Type Name");
case PARTICIPANT_ID:
return tr("Participant Id");
case PARTICIPANT_EQUIPMENT_NO:
return tr("Eqpt.No");
case PARTICIPANT_NAME:
return tr("Participant Name");
case VITALITY:
return tr("Vitality");
case VULNERABILITY:
return tr("Vulnerability");
case EVENT_TIME:
return tr("Event time");
case EVENT_TYPE:
return tr("Event type");
case AREA_NAME:
return tr("Functional Area");
}
}
if (orientation == Qt::Vertical && m_report.visualisationType() == VisualisationType::Line)
{
if (role == Qt::BackgroundRole)
{
return eventColor(m_data[section].eventTypeId);
}
else if (role == Qt::TextAlignmentRole)
{
return Qt::AlignRight;
}
else if (role == Qt::DisplayRole)
{
// QString event = DTG::toStringMSec(m_data[section].eventTime) + QStringLiteral("\n");
// event += ReportManagement::toString(m_data[section].eventTypeId);
// return event;
return DTG::toStringMSec(m_data[section].eventTime);
}
}
return QVariant();
}
// ------------------------------------------------------------------
void TreatmentTimelineModel::fillReportData()
{
DEBUG_LOG(m_logger) << "fillReportData(): m_reportJsonArray.size() = " << m_reportJsonArray.size();
for (const QJsonValue &arrVal : qAsConst(m_reportJsonArray))
{
const QJsonObject obj = arrVal.toObject();
resultData resData;
resData.participantTypeId = obj[QStringLiteral("participant_type_id")].toInt();
resData.participantId = obj[QStringLiteral("participant_id")].toInt();
resData.participantName = obj[QStringLiteral("participant_name")].toString();
resData.participantEqNo = obj[QStringLiteral("participant_equipment_number")].toInt();
resData.vitality = obj[QStringLiteral("vitality")].toInt();
resData.vulnerability = obj[QStringLiteral("vulnerability")].toInt();
resData.vulnerabilityState = obj[QStringLiteral("vulnerability_state")].toInt();
resData.eventTime = obj[QStringLiteral("event_time")].toDouble();
resData.eventTypeId = static_cast<ReportManagement::EventType::type>(obj[QStringLiteral("event_type_id")].toInt());
resData.properties = obj[QStringLiteral("properties")].toString();
DEBUG_LOG(m_logger) << "Participant type id = " << resData.participantTypeId;
DEBUG_LOG(m_logger) << "Participant id = " << resData.participantId;
DEBUG_LOG(m_logger) << "Event type = " << resData.eventTypeId;
DEBUG_LOG(m_logger) << "Event time = " << resData.eventTime;
DEBUG_LOG(m_logger) << "Properties = " << resData.properties;
m_data.append(std::move(resData));
}
}
// ------------------------------------------------------------------
QString TreatmentTimelineModel::getAreaName(const QString& properties) const
{
DEBUG_LOG(m_logger) << "getAreaName from " << properties;
QJsonDocument doc = QJsonDocument::fromJson(properties.toUtf8());
const QJsonObject obj = doc.object();
//const int area_id = obj[QStringLiteral("area_id")].toInt();
QString area_name = obj[QStringLiteral("area_name")].toString();
return area_name;
}
// ------------------------------------------------------------------
QColor TreatmentTimelineModel::eventColor(ReportManagement::EventType eventTypeId) const
{
DEBUG_LOG(m_logger) << "eventColor for event type " << eventTypeId;
switch (eventTypeId.underlying())
{
case ReportManagement::EventType::VBGChanged: return QColor(Qt::red);
case ReportManagement::EventType::VitalityChanged: return QColor(Qt::green);
case ReportManagement::EventType::NineLinerSet: return QColor(Qt::darkYellow);
case ReportManagement::EventType::Treatment: return QColor(Qt::blue);
case ReportManagement::EventType::TransportRequested: return QColor(Qt::darkGray);
case ReportManagement::EventType::TransportInitiated: return QColor(Qt::magenta);
case ReportManagement::EventType::EnterFunctionalArea: return QColor(Qt::darkCyan);
case ReportManagement::EventType::VitalityReset: return QColor(Qt::darkGreen);
case ReportManagement::EventType::SetInjury: return QColor(Qt::darkRed);
case ReportManagement::EventType::VBGSet: return QColor(Qt::black);
}
return QColor(Qt::black);
}
// ------------------------------------------------------------------
QString TreatmentTimelineModel::getSanProcs(const QString& properties) const
{
DEBUG_LOG(m_logger) << "getSanProcs from " << properties;
QString sanProcs;
QJsonDocument doc = QJsonDocument::fromJson(properties.toUtf8());
const QJsonObject obj = doc.object();
qint64 procTaken = obj[QStringLiteral("san_procs")].toDouble();
if (procTaken > 0)
sanProcs = m_pdmDtc->sanitationProceduresList(procTaken).join(QLatin1String(", "));
return sanProcs;
}
@@ -0,0 +1,77 @@
/**
* @RDE_HEADER@
* Shows report player distance
* $Id$
* $HeadURL$
* $Author$
*/
#pragma once
#include "rep_abstract_model.h"
#include <ReportManagement/logger.h>
#include <ParticipantManagement/ppm_dtc.h>
#include <ProjectDataManagement/pdm_dtc.h>
//----------------------------------------------------------------------------
namespace ReportManagement
{
class TreatmentTimelineModel : public AbstractModel
{
Q_OBJECT
friend class AbstractModel;
public:
int rowCount(const QModelIndex &parent = QModelIndex()) const override final;
int columnCount(const QModelIndex &parent = QModelIndex()) const override final;
QVariant data(const QModelIndex &index, int role) const override final;
QVariant headerData(int section, Qt::Orientation orientation, int role) const override final;
bool fetchInterfaces() override final;
private:
explicit TreatmentTimelineModel(const ReportManagement::ReportInfo &report, LtsSession::LtsSession *session, QObject *parent);
void fillReportData() override final;
QString getAreaName(const QString &properties) const;
QColor eventColor(ReportManagement::EventType eventTypeId) const;
QString getSanProcs(const QString &properties) const;
enum Columns
{
EVENT_TIME = 0,
EVENT_TYPE = 1,
VULNERABILITY = 2,
VITALITY = 3,
AREA_NAME = 4,
PARTICIPANT_EQUIPMENT_NO = 5,
PARTICIPANT_NAME = 6,
PARTICIPANT_ID = 7,
PARTICIPANT_TYPE_ID = 8,
PARTICIPANT_TYPE_NAME = 9,
#ifdef LTS_DEBUG
COUNT = 10
#else
COUNT = 4 // without last columns
#endif
};
struct resultData
{
int groupId = 0;
int participantTypeId = 0;
int participantId = 0;
int participantEqNo = 0;
QString participantName;
int vulnerability = 0;
int vulnerabilityState = 0;
int vitality = 0;
ReportManagement::EventType eventTypeId = ReportManagement::EventType::VBGChanged;
qint64 eventTime = 0;
QString properties;
};
QVector<resultData> m_data;
std::shared_ptr<ParticipantManagement::Interface::Dtc> m_ppmDtc;
std::shared_ptr<ProjectDataManagement::Interface::Dtc> m_pdmDtc;
LOGGER_T m_logger;
};
}
@@ -0,0 +1,220 @@
/**
* @RDE_HEADER@
* ChartModel for detailed unit power data
* $Id$
* $HeadURL$
* $Author$
* Created by Hannes Baeuerle, SLSE, 2017-03-01
*/
#include "rep_unit_power_model.h"
#include <ProjectDataManagement/pdm_to_string.h>
#include <Plugins/ReportManagement/rep_data_plugin_interface.h>
#include <Plugins/ProjectDataManagement/pdm_data_plugin_interface.h>
#include <Plugins/ParticipantManagement/ppm_data_plugin_interface.h>
#include <ngltools/ngltools_dtg.h>
#include <QFont>
using namespace ReportManagement;
// -----------------------------------------------------------------------------------------------------------------------------------------------
UnitPowerModel::UnitPowerModel(const ReportInfo &report, LtsSession::LtsSession *session, QObject *parent)
: AbstractModel(report, session, parent)
, m_ppmDtc(nullptr)
, m_logger(getLogger("UnitPowerModel"))
{
if (!fetchInterfaces())
return;
//#define TEST_DATA
#ifdef TEST_DATA
resultData resData;
resData.groupId = 32;
resData.startTime = 1513758640000;
resData.ready = 110;
resData.notReady = 110;
resData.notReadyVbgs = {10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10};
m_data.append(resData);
resData.groupId = 33;
resData.startTime = 1513758640000;
resData.ready = 50;
resData.notReady = 220;
resData.notReadyVbgs = {20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20};
m_data.append(resData);
#else
getReportData(report);
fillReportData();
#endif
}
// -----------------------------------------------------------------------------------------------------
bool UnitPowerModel::fetchInterfaces()
{
if (!m_session->getDtc<ParticipantManagement::DataInterface>(m_ppmDtc))
{
ERROR_LOG(m_logger) << "Could not fetch PPM DTC Interface";
return false;
}
return true;
}
// -----------------------------------------------------------------------------------------------------------------------------------------------
int UnitPowerModel::rowCount(const QModelIndex &parent) const
{
return parent.isValid() ? 0 : m_data.count();
}
// -----------------------------------------------------------------------------------------------------------------------------------------------
int UnitPowerModel::columnCount(const QModelIndex &parent) const
{
return parent.isValid() ? 0 : COUNT;
}
// -----------------------------------------------------------------------------------------------------------------------------------------------
QVariant UnitPowerModel::data(const QModelIndex &index, int role) const
{
if (!index.isValid())
return QVariant();
const resultData &displayInfo = m_data[index.row()];
if (role == Qt::DisplayRole)
{
switch (index.column())
{
case COMBAT_READY:
return displayInfo.ready;
case NOT_READY:
return displayInfo.notReady;
case LIGHT_DAMAGE:
return displayInfo.notReadyVbgs[0];
case MEDIUM_DAMAGE:
return displayInfo.notReadyVbgs[1];
case HEAVY_DAMAGE:
return displayInfo.notReadyVbgs[2];
case MOBILITY_KILL:
return displayInfo.notReadyVbgs[3];
case VISIBLE_MOBILITY_KILL:
return displayInfo.notReadyVbgs[4];
case WEAPON_SYSTEM_DAMAGE:
return displayInfo.notReadyVbgs[5];
case VISIBLE_WEAPON_SYSTEM_DAMAGE:
return displayInfo.notReadyVbgs[6];
case CATASTROPHIC_KILL:
return displayInfo.notReadyVbgs[7];
case TEMPORARY_SEVERANCE:
return displayInfo.notReadyVbgs[8];
case NEAR_MISS:
return displayInfo.notReadyVbgs[9];
case HIT_WITH_NO_EFFECT:
return displayInfo.notReadyVbgs[10];
case START_TIME:
return DTG::toStringMSec(displayInfo.startTime);
default:
return QVariant();
}
}
else if (role == Qt::UserRole)
{
if (!m_report.groupByParty() && displayInfo.groupId > 0)
return QString::fromStdString(m_ppmDtc->type(displayInfo.groupId).name()).trimmed();
else
return QVariant();
}
else if (role == Qt::EditRole)
{
return displayInfo.groupId;
}
return QVariant();
}
// -----------------------------------------------------------------------------------------------------------------------------------------------
QVariant UnitPowerModel::headerData(int section, Qt::Orientation orientation, int role) const
{
if (orientation == Qt::Horizontal && role == Qt::DisplayRole)
{
switch (section)
{
case COMBAT_READY:
return ProjectDataManagement::toString(ProjectDataManagement::VulnerabilityState::CombatReady);
case NOT_READY:
return ProjectDataManagement::toString(ProjectDataManagement::VulnerabilityState::NotReady);
case LIGHT_DAMAGE:
return ProjectDataManagement::toString(ProjectDataManagement::VulnerabilityState::LightDamage);
case MEDIUM_DAMAGE:
return ProjectDataManagement::toString(ProjectDataManagement::VulnerabilityState::MediumDamage);
case HEAVY_DAMAGE:
return ProjectDataManagement::toString(ProjectDataManagement::VulnerabilityState::HeavyDamage);
case MOBILITY_KILL:
return ProjectDataManagement::toString(ProjectDataManagement::VulnerabilityState::MobilityKill);
case VISIBLE_MOBILITY_KILL:
return ProjectDataManagement::toString(ProjectDataManagement::VulnerabilityState::VisibleMobilityKill);
case WEAPON_SYSTEM_DAMAGE:
return ProjectDataManagement::toString(ProjectDataManagement::VulnerabilityState::WeaponSystemDamage);
case VISIBLE_WEAPON_SYSTEM_DAMAGE:
return ProjectDataManagement::toString(ProjectDataManagement::VulnerabilityState::VisibleWeaponSystemDamage);
case CATASTROPHIC_KILL:
return ProjectDataManagement::toString(ProjectDataManagement::VulnerabilityState::CatastrophicKill);
case TEMPORARY_SEVERANCE:
return ProjectDataManagement::toString(ProjectDataManagement::VulnerabilityState::TemporarySeverance);
case NEAR_MISS:
return ProjectDataManagement::toString(ProjectDataManagement::VulnerabilityState::NearMiss);
case HIT_WITH_NO_EFFECT:
return ProjectDataManagement::toString(ProjectDataManagement::VulnerabilityState::HitWithNoEffect);
case START_TIME:
return tr("Time");
default:
return QVariant();
}
}
if (orientation == Qt::Vertical && role == Qt::DisplayRole &&
(m_report.visualisationType() == VisualisationType::Bar || m_report.visualisationType() == VisualisationType::Line))
{
return DTG::toStringMSec(m_data[section].startTime);
}
return QAbstractTableModel::headerData(section, orientation, role);
}
// ------------------------------------------------------------------
void UnitPowerModel::fillReportData()
{
DEBUG_LOG(m_logger) << "fillReportData(): m_reportJsonArray.size() = " << m_reportJsonArray.size();
for (const QJsonValue &arrVal : qAsConst(m_reportJsonArray))
{
const QJsonObject obj = arrVal.toObject();
resultData resData;
resData.groupId = obj[QStringLiteral("group_id")].toInt();
resData.ready = obj[QStringLiteral("ready")].toInt();
resData.notReady = obj[QStringLiteral("not_ready")].toInt();
resData.startTime = obj[QStringLiteral("start_time")].toDouble();
resData.notReadyVbgs[0] = obj[QStringLiteral("vulnerability_state1")].toInt();
resData.notReadyVbgs[1] = obj[QStringLiteral("vulnerability_state2")].toInt();
resData.notReadyVbgs[2] = obj[QStringLiteral("vulnerability_state3")].toInt();
resData.notReadyVbgs[3] = obj[QStringLiteral("vulnerability_state4")].toInt();
resData.notReadyVbgs[4] = obj[QStringLiteral("vulnerability_state5")].toInt();
resData.notReadyVbgs[5] = obj[QStringLiteral("vulnerability_state6")].toInt();
resData.notReadyVbgs[6] = obj[QStringLiteral("vulnerability_state7")].toInt();
resData.notReadyVbgs[7] = obj[QStringLiteral("vulnerability_state8")].toInt();
resData.notReadyVbgs[8] = obj[QStringLiteral("vulnerability_state9")].toInt();
resData.notReadyVbgs[9] = obj[QStringLiteral("vulnerability_state10")].toInt();
resData.notReadyVbgs[10] = obj[QStringLiteral("vulnerability_state11")].toInt();
INFO_LOG(m_logger) << "Group id = " << resData.groupId;
INFO_LOG(m_logger) << "Ready = " << resData.ready;
INFO_LOG(m_logger) << "Not ready = " << resData.notReady;
INFO_LOG(m_logger) << "Start time = " << resData.startTime;
m_data.append(std::move(resData));
}
}
@@ -0,0 +1,89 @@
/**
* @RDE_HEADER@
* ChartModel for detailed unit power data
* $Id$
* $HeadURL$
* $Author$
* Created by Hannes Baeuerle, SLSE, 2017-03-01
*/
#pragma once
#include "rep_abstract_model.h"
#include <ReportManagement/logger.h>
#include <ParticipantManagement/ppm_dtc.h>
namespace ReportManagement
{
enum UnitPowerColumns
{
COMBAT_READY = 0,
LIGHT_DAMAGE = 1,
MEDIUM_DAMAGE = 2,
HEAVY_DAMAGE = 3,
MOBILITY_KILL = 4,
VISIBLE_MOBILITY_KILL = 5,
WEAPON_SYSTEM_DAMAGE = 6,
VISIBLE_WEAPON_SYSTEM_DAMAGE = 7,
CATASTROPHIC_KILL = 8,
TEMPORARY_SEVERANCE = 9,
NOT_READY = 10,
// hidden columns
NEAR_MISS = 11,
HIT_WITH_NO_EFFECT = 12,
START_TIME = 13,
COUNT = 11
};
/* PDM Enum VulnerabilityState:
CombatReady = 0,
LightDamage = 1,
MediumDamage = 2,
HeavyDamage = 3,
MobilityKill = 4,
VisibleMobilityKill = 5,
WeaponSystemDamage = 6,
VisibleWeaponSystemDamage = 7,
CatastrophicKill = 8,
TemporarySeverance = 9,
NearMiss = 10,
HitWithNoEffect = 11,
NotReady = 99
*/
class UnitPowerModel : public AbstractModel
{
Q_OBJECT
friend class AbstractModel;
public:
int rowCount(const QModelIndex &parent = QModelIndex()) const override final;
int columnCount(const QModelIndex &parent = QModelIndex()) const override final;
QVariant data(const QModelIndex &index, int role) const override final;
QVariant headerData(int section, Qt::Orientation orientation, int role) const override final;
bool fetchInterfaces() override final;
private: // methods
explicit UnitPowerModel(const ReportManagement::ReportInfo &report, LtsSession::LtsSession *session, QObject *parent);
void fillReportData() override final;
private: //other
struct resultData
{
int groupId = 0;
int ready = 0;
int notReady = 0;
qint64 startTime = 0;
QVector<int> notReadyVbgs = {0,0,0,0,0,0,0,0,0,0,0};
};
QVector<resultData> m_data;
private: // attributes
std::shared_ptr<ParticipantManagement::Interface::Dtc> m_ppmDtc;
LOGGER_T m_logger;
};
}