Initial commit
This commit is contained in:
commit
b7d90b9afe
16245 files changed
+3396666
No files matched your search
@@ -0,0 +1,165 @@
|
||||
/**
|
||||
* Handler for report charge administration
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
* Created by Hanna E. Rathje, SLSE, 2016-12-20
|
||||
*/
|
||||
|
||||
#include "handler_report_data.h"
|
||||
|
||||
#include <ngldb/dbtransaction.h>
|
||||
#include <ngldb/nsqlquery.h>
|
||||
|
||||
#include <QVariant>
|
||||
|
||||
using namespace ReportManagement;
|
||||
|
||||
// ------------------------------------------------------------------------------------------------------------------
|
||||
bool HandlerReportData::generateChargeAdminResult(const CreateModifyReportRequest &request, int reportId)
|
||||
{
|
||||
INFO_LOG(m_logger) << "Start generateChargeAdminResult ";
|
||||
|
||||
DBTransaction trans(m_db->database());
|
||||
NSqlQuery q(m_db->database());
|
||||
|
||||
q.prepare(QLatin1String("INSERT INTO rep_charge_administration (report_id, effect_source_id, charge_type_id ) VALUES (:reportId, :effectSourceId, :chargeTypeId )"));
|
||||
q.bindValue(QLatin1String(":reportId"), reportId);
|
||||
|
||||
for (auto it1 = request.effectSources().begin(); it1 != request.effectSources().end(); ++it1)
|
||||
{
|
||||
ProjectDataManagement::EffectSource effectSourceId = *it1;
|
||||
q.bindValue(QLatin1String(":effectSourceId"), effectSourceId.underlying());
|
||||
|
||||
for (auto it2 = request.chargeTypeIds().begin(); it2 != request.chargeTypeIds().end(); ++it2)
|
||||
{
|
||||
int chargeTypeId = *it2;
|
||||
if (chargeTypeId == 0)
|
||||
continue; // skip 0
|
||||
|
||||
q.bindValue(QLatin1String(":chargeTypeId"), chargeTypeId);
|
||||
DEBUG_LOG(m_logger) << " Inserting chargeTypeId " << chargeTypeId;
|
||||
if (!q.exec())
|
||||
{
|
||||
ERROR_LOG(m_logger) << "Error inserting report id, effectSourceId, chargeTypeId = " << reportId << " , " << effectSourceId << " , " << chargeTypeId;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!calculateStock(chargeTypeId, effectSourceId, request.startTime(), request.endTime(), request.partyId(), reportId))
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
trans.commit();
|
||||
|
||||
INFO_LOG(m_logger) << " END generateChargeAdminResult";
|
||||
return true;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------------------------
|
||||
bool HandlerReportData::calculateStock(int chargeTypeId, const ProjectDataManagement::EffectSource &es, qint64 startTime, qint64 endTime, int partyId, int reportId)
|
||||
{
|
||||
ChargeTypeData chargeData;
|
||||
chargeData.chargeTypeId = chargeTypeId;
|
||||
chargeData.effectSourceId = es;
|
||||
|
||||
NSqlQuery qSelect(m_db->database());
|
||||
NSqlQuery qInit(m_db->database());
|
||||
NSqlQuery qUpdate(m_db->database());
|
||||
QString stmt = QLatin1String("SELECT amount, planned, used, sample_time, charge_type_id "
|
||||
" FROM rec_charge_administration "
|
||||
" WHERE effect_source_id = ")
|
||||
+ QString::number(es.underlying()) + QLatin1String(" AND sample_time > 0 AND sample_time < ") + QString::number(startTime)
|
||||
+ QLatin1String(" AND party_id = ") + QString::number(partyId) + QLatin1String(" AND charge_type_id = ") + QString::number(chargeTypeId)
|
||||
+ QLatin1String(" ORDER BY sample_time DESC LIMIT 1");
|
||||
|
||||
DEBUG_LOG(m_logger) << "Start Statement: " << stmt;
|
||||
|
||||
if (!qInit.exec(stmt))
|
||||
{
|
||||
ERROR_LOG(m_logger) << "Error while selecting start-data for chargeTypeId " << chargeTypeId << ", stmt='" << stmt << "'";
|
||||
return false;
|
||||
}
|
||||
if (!qInit.next()) // not found a valid record
|
||||
{
|
||||
INFO_LOG(m_logger) << "No start entry for chargeTypeId " << chargeTypeId << ", assuming 0";
|
||||
// return true;
|
||||
chargeData.chargeQuantity = 0;
|
||||
chargeData.chargeQuantityStart = 0;
|
||||
chargeData.usedCharge = 0;
|
||||
chargeData.usedChargeStart = 0;
|
||||
chargeData.chargeAddition = 0;
|
||||
chargeData.chargePlanned = 0;
|
||||
// chargeData.chargeAvailable = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
qInit.first();
|
||||
chargeData.chargeQuantity = qInit.value(0).toInt(); // + qInit.value(1).toInt();
|
||||
chargeData.chargeQuantityStart = chargeData.chargeQuantity;
|
||||
chargeData.usedCharge = qInit.value(2).toInt();
|
||||
chargeData.chargePlanned = qInit.value(1).toInt();
|
||||
chargeData.usedChargeStart = chargeData.usedCharge;
|
||||
chargeData.chargeAddition = 0;
|
||||
// chargeData.chargeAvailable = chargeData.chargeQuantityStart - chargeData.usedChargeStart;
|
||||
}
|
||||
|
||||
DEBUG_LOG(m_logger) << "START chargeTypeId = " << QString::number(chargeTypeId) << " , "
|
||||
<< " effectSourceId = " << es << "chargeQuantityStart = " << chargeData.chargeQuantityStart << " , "
|
||||
<< "usedChargeStart = " << chargeData.usedChargeStart;
|
||||
|
||||
stmt = QLatin1String("SELECT charge_type_id, amount, planned, used, amount_changed_by_operator "
|
||||
" FROM rec_charge_administration "
|
||||
" WHERE sample_time >= ")
|
||||
+ QString::number(startTime) + QLatin1String(" AND sample_time <= ") + QString::number(endTime) + QLatin1String(" AND party_id = ") + QString::number(partyId)
|
||||
+ QLatin1String(" AND charge_type_id = ") + QString::number(chargeTypeId) + QLatin1String(" AND effect_source_id = ") + QString::number(es.underlying())
|
||||
+ QLatin1String(" ORDER BY sample_time ");
|
||||
|
||||
if (!qSelect.exec(stmt))
|
||||
{
|
||||
ERROR_LOG(m_logger) << "Error while selecting charge-data for chargeTypeId " << chargeTypeId;
|
||||
return false;
|
||||
}
|
||||
|
||||
DEBUG_LOG(m_logger) << "Select statement: " << stmt;
|
||||
|
||||
while (qSelect.next())
|
||||
{
|
||||
int quantity = qSelect.value(1).toInt(); // + qSelect.value(2).toInt();
|
||||
|
||||
chargeData.chargeQuantity = quantity;
|
||||
chargeData.usedCharge = qSelect.value(3).toInt();
|
||||
chargeData.chargePlanned = qSelect.value(2).toInt();
|
||||
chargeData.chargeAddition = chargeData.chargeQuantity + chargeData.usedCharge - chargeData.chargeQuantityStart;
|
||||
|
||||
DEBUG_LOG(m_logger) << "CALCULATING for chargeTypeId = " << QString::number(chargeData.chargeTypeId) << " quantity = " << quantity << " , "
|
||||
<< " munQuantity = " << chargeData.chargeQuantity << " , "
|
||||
<< " munAddition = " << chargeData.chargeAddition << " , "
|
||||
<< " usedMunition = " << chargeData.usedCharge << " , "
|
||||
<< " planned = " << chargeData.chargePlanned;
|
||||
}
|
||||
|
||||
DEBUG_LOG(m_logger) << "UPDATING stock for chargeTypeId: " << chargeData.chargeTypeId << " values: " << chargeData.chargeQuantityStart << " , "
|
||||
<< chargeData.chargeAddition << " , " << chargeData.chargeQuantity << " , " << chargeData.usedCharge - chargeData.usedChargeStart << " , "
|
||||
<< chargeData.chargePlanned << " , " << chargeData.chargeQuantity - chargeData.chargePlanned;
|
||||
|
||||
stmt = QLatin1String("UPDATE rep_charge_administration SET "
|
||||
" charge_start = ")
|
||||
+ QString::number(chargeData.chargeQuantityStart) + QLatin1String(", ") + QLatin1String(" charge_resupplied = ") + QString::number(chargeData.chargeAddition)
|
||||
+ QLatin1String(", ") + QLatin1String(" charge_end = ") + QString::number(chargeData.chargeQuantity) + QLatin1String(", ") + QLatin1String(" charge_fired = ")
|
||||
+ QString::number(chargeData.usedCharge - chargeData.usedChargeStart) + QLatin1String(", ") + QLatin1String(" charge_planned = ")
|
||||
+ QString::number(chargeData.chargePlanned) + QLatin1String(", ") + QLatin1String(" charge_available = ")
|
||||
+ QString::number(chargeData.chargeQuantity - chargeData.chargePlanned) + QLatin1String(" WHERE report_id = ") + QString::number(reportId)
|
||||
+ QLatin1String(" AND charge_type_id = ") + QString::number(chargeData.chargeTypeId) + QLatin1String(" AND effect_source_id = ")
|
||||
+ QString::number(es.underlying());
|
||||
|
||||
DEBUG_LOG(m_logger) << "Update statement: " << stmt;
|
||||
|
||||
if (!qUpdate.exec(stmt))
|
||||
{
|
||||
ERROR_LOG(m_logger) << "Error while updating stock for chargeTypeId " << chargeTypeId;
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
/**
|
||||
* Handler for report Medevan 9Liner
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
* Created by Hanna E. Rathje, SLSE, 2020-09-15
|
||||
*/
|
||||
|
||||
#include "handler_report_data.h"
|
||||
#include <LtsCoordTrans/lts_coord_trans.h>
|
||||
|
||||
#include <ngldb/nsqlquery.h>
|
||||
#include <ngldb/dbtransaction.h>
|
||||
|
||||
#include <QVariant>
|
||||
|
||||
using namespace ReportManagement;
|
||||
|
||||
// ------------------------------------------------------------------------------------------------------------------
|
||||
bool HandlerReportData::generateMedevacNineLinerResult(const CreateModifyReportRequest &request, int reportId)
|
||||
{
|
||||
INFO_LOG(m_logger) << "Start generateMedevacNineLinerResult ";
|
||||
|
||||
LtsCoordTrans::UtmCoordinate coord(LtsCoordTrans::UtmCoordinate::fromGeographic(request.cornerBottomLeft().lon(),
|
||||
request.cornerBottomLeft().lat()));
|
||||
|
||||
DBTransaction trans(m_db->database());
|
||||
|
||||
QString insertStmt = QLatin1String("INSERT INTO rep_san_nine_liner ( report_id, nine_liner_id ) values (:reportId, :nineLinerId)");
|
||||
NSqlQuery qInsert(m_db->database());
|
||||
|
||||
if (!qInsert.prepare(insertStmt))
|
||||
{
|
||||
ERROR_LOG(m_logger) << "Eror while preparing insert into rep_san_nine_liner";
|
||||
return false;
|
||||
}
|
||||
|
||||
NSqlQuery q(m_db->database());
|
||||
q.setForwardOnly(false);
|
||||
|
||||
QString stmt = QLatin1String("SELECT id FROM san_nine_liner WHERE last_modified >= ") + QString::number(request.startTime()) +
|
||||
QLatin1String(" AND last_modified <= ") + QString::number(request.endTime());
|
||||
|
||||
|
||||
if (request.width() > 0 && request.height() > 0)
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "#### Filtering data on geographic position";
|
||||
|
||||
double x1 = coord.x + request.height();
|
||||
double y1 = coord.y + request.width();
|
||||
DEBUG_LOG(m_logger) << "#### (x,x1,y,y1) = (" << coord.x << "," << x1 << "," << coord.y << "," << y1 << ")";
|
||||
|
||||
stmt += QLatin1String(" AND position_x_m >= ") + QString::number(coord.x);
|
||||
stmt += QLatin1String(" AND position_x_m <= ") + QString::number(x1);
|
||||
stmt += QLatin1String(" AND position_y_m >= ") + QString::number(coord.y);
|
||||
stmt += QLatin1String(" AND position_y_m <= ") + QString::number(y1);
|
||||
|
||||
// QLatin1String(" AND position_x_m >= ") + QString::number(coord.x) +
|
||||
// QLatin1String(" AND position_x_m <= ") + QString::number(coord.x) + QLatin1String( " + ") + QString::number(request.height()) +
|
||||
// QLatin1String(" AND position_y_m >= ") + QString::number(coord.y) +
|
||||
// QLatin1String(" AND position_y_m <= ") + QString::number(coord.y) + QLatin1String( " + ") + QString::number(request.width());
|
||||
}
|
||||
|
||||
INFO_LOG(m_logger) << "stmt: " << stmt;
|
||||
|
||||
if (!q.exec(stmt))
|
||||
{
|
||||
ERROR_LOG(m_logger) << "Error while selecting sanNineLiners for area (x) " << request.cornerBottomLeft().lon() << ", (y)" << request.cornerBottomLeft().lat()
|
||||
<< " width: " << request.width() << ", height: " << request.height();
|
||||
ERROR_LOG(m_logger) << "stmt: " << stmt;
|
||||
return false;
|
||||
}
|
||||
|
||||
while(q.next())
|
||||
{
|
||||
int nineLinerId = q.value(0).toInt();
|
||||
qInsert.bindValue(QStringLiteral(":reportId"), reportId);
|
||||
qInsert.bindValue(QStringLiteral(":nineLinerId"), nineLinerId);
|
||||
|
||||
if (!qInsert.exec())
|
||||
{
|
||||
ERROR_LOG(m_logger) << "Error while inserting nineLinerId " << q.value(0).toInt() << ", reportId: " << reportId;
|
||||
trans.rollback();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
trans.commit();
|
||||
|
||||
INFO_LOG(m_logger) << "generateMedevacNineLinerResult";
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,301 @@
|
||||
/**
|
||||
* Handler for report AirSupport
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
* Created by Hanna E. Rathje, SLSE, 2016-12-20
|
||||
*/
|
||||
|
||||
#include "handler_report_data.h"
|
||||
|
||||
#include <ngldb/nsqlquery.h>
|
||||
#include <ngldb/dbtransaction.h>
|
||||
|
||||
using namespace ReportManagement;
|
||||
|
||||
bool HandlerReportData::generateAirSupportResult(const CreateModifyReportRequest &request, int reportId)
|
||||
{
|
||||
INFO_LOG(m_logger) << "Start generateAirSupportResult - reportId: " << reportId;
|
||||
|
||||
if (request.chargeTypeIds().size() <= 0 || request.participantTypes().size() <= 0)
|
||||
{
|
||||
ERROR_LOG(m_logger) << "No elements selected to generate the report";
|
||||
DEBUG_LOG(m_logger) << "request.chargeTypeIds().size()" << request.chargeTypeIds().size();
|
||||
DEBUG_LOG(m_logger) << "request.participantTypes().size()" << request.participantTypes().size();
|
||||
return false;
|
||||
}
|
||||
|
||||
DBTransaction trans(m_db->database());
|
||||
NSqlQuery qSelect1(m_db->database());
|
||||
NSqlQuery qSelect2(m_db->database());
|
||||
NSqlQuery qInsert(m_db->database());
|
||||
QString stmtInsert, stmtSelect1, stmtSelect2;
|
||||
|
||||
stmtSelect1 = QStringLiteral("SELECT max(impacts), aes_id, charge_type_id "
|
||||
" FROM rep_air_support_impact_data "
|
||||
" WHERE party_id = :partyId AND "
|
||||
" (event_time BETWEEN :startTime AND :endTime) "
|
||||
" GROUP BY aes_id, charge_type_id");
|
||||
|
||||
if (!qSelect1.prepare(stmtSelect1))
|
||||
{
|
||||
ERROR_LOG(m_logger) << "Error preparing select1 statement: " << stmtSelect1;
|
||||
return false;
|
||||
}
|
||||
|
||||
stmtSelect2 = QStringLiteral("SELECT vulnerability_state, hit, hit_friendly_fire, hit_building "
|
||||
" FROM rep_air_support_data "
|
||||
" WHERE aes_party_id = :aesPartyId AND "
|
||||
" (event_time BETWEEN :startTime AND :endTime) AND "
|
||||
" charge_type_id = :chargeId AND ");
|
||||
|
||||
if (request.participantTypes().size() > 0)
|
||||
{
|
||||
const QString pTypeIdsStr = intVecToString(request.participantTypes());
|
||||
stmtSelect2 += QStringLiteral(" participant_type_id IN (%1) ").arg(pTypeIdsStr);
|
||||
}
|
||||
|
||||
stmtSelect2 += QStringLiteral(" ORDER BY vulnerability_state");
|
||||
|
||||
if (!qSelect2.prepare(stmtSelect2))
|
||||
{
|
||||
ERROR_LOG(m_logger) << "Error preparing select2 statement: " << stmtSelect2;
|
||||
return false;
|
||||
}
|
||||
|
||||
stmtInsert = QStringLiteral("INSERT INTO rep_air_support_result (report_id, start_time, end_time, "
|
||||
" charge_type_id, impacts, vulnerability_state, hits, hits_friendly_fire, hits_buildings) "
|
||||
"VALUES (:reportId, :start, :end, :chargeTypeId, :impacts, :vbg, :hit, :hit_ff, :hit_buildings )");
|
||||
|
||||
if (!qInsert.prepare(stmtInsert))
|
||||
{
|
||||
ERROR_LOG(m_logger) << "Error preparing stmt: " << stmtInsert;
|
||||
return false;
|
||||
}
|
||||
|
||||
qInsert.bindValue(QStringLiteral(":reportId"), reportId);
|
||||
|
||||
qSelect1.bindValue(QStringLiteral(":partyId"), request.partyId());
|
||||
qSelect1.bindValue(QStringLiteral(":startTime"), request.startTime());
|
||||
qSelect1.bindValue(QStringLiteral(":endTime"), request.endTime());
|
||||
|
||||
if (!qSelect1.exec())
|
||||
{
|
||||
ERROR_LOG(m_logger) << "Error executing stmt: " << stmtSelect1;
|
||||
return false;
|
||||
}
|
||||
|
||||
DEBUG_LOG(m_logger) << "stmtSelect1: " << stmtSelect1;
|
||||
DEBUG_LOG(m_logger) << "partyId: " << request.partyId();
|
||||
DEBUG_LOG(m_logger) << "startTime: " << request.startTime();
|
||||
DEBUG_LOG(m_logger) << "endTime: " << request.endTime();
|
||||
|
||||
// QMap<chargeTypeId, impacts>
|
||||
QMap<int,int> impactDataMap;
|
||||
|
||||
while (qSelect1.next())
|
||||
{
|
||||
int chargeTypeId = qSelect1.value(2).toInt();
|
||||
if (!impactDataMap.contains(chargeTypeId))
|
||||
impactDataMap.insert(chargeTypeId, 0);
|
||||
|
||||
impactDataMap[chargeTypeId] += qSelect1.value(0).toInt();
|
||||
}
|
||||
|
||||
stmtSelect1 = QStringLiteral("SELECT min(event_time), charge_type_id "
|
||||
" FROM rep_air_support_impact_data "
|
||||
" WHERE party_id = :partyId AND "
|
||||
" (event_time BETWEEN :startTime AND :endTime) "
|
||||
" GROUP BY charge_type_id");
|
||||
|
||||
if (!qSelect1.prepare(stmtSelect1))
|
||||
{
|
||||
ERROR_LOG(m_logger) << "Error preparing select1 statement: " << stmtSelect1;
|
||||
return false;
|
||||
}
|
||||
|
||||
qSelect1.bindValue(QStringLiteral(":partyId"), request.partyId());
|
||||
qSelect1.bindValue(QStringLiteral(":startTime"), request.startTime());
|
||||
qSelect1.bindValue(QStringLiteral(":endTime"), request.endTime());
|
||||
|
||||
if (!qSelect1.exec())
|
||||
{
|
||||
ERROR_LOG(m_logger) << "Error executing stmt1: " << stmtSelect1;
|
||||
return false;
|
||||
}
|
||||
|
||||
DEBUG_LOG(m_logger) << "stmtSelect1: " << stmtSelect1;
|
||||
DEBUG_LOG(m_logger) << "partyId: " << request.partyId();
|
||||
DEBUG_LOG(m_logger) << "startTime: " << request.startTime();
|
||||
DEBUG_LOG(m_logger) << "endTime: " << request.endTime();
|
||||
|
||||
// QMap<chargeTypeId, eventTime>
|
||||
QMap<int,qint64> minEventTimeMap;
|
||||
|
||||
while (qSelect1.next())
|
||||
{
|
||||
int chargeTypeId = qSelect1.value(1).toInt();
|
||||
qint64 eventTime = qSelect1.value(0).toLongLong();
|
||||
minEventTimeMap.insert(chargeTypeId, eventTime);
|
||||
DEBUG_LOG(m_logger) << "chargeTypeId: " << chargeTypeId << ", min eventTime: " << eventTime;
|
||||
}
|
||||
|
||||
stmtSelect1 = QStringLiteral("SELECT max(event_time), charge_type_id "
|
||||
" FROM rep_air_support_impact_data "
|
||||
" WHERE party_id = :partyId AND "
|
||||
" (event_time BETWEEN :startTime AND :endTime) "
|
||||
" GROUP BY charge_type_id");
|
||||
|
||||
if (!qSelect1.prepare(stmtSelect1))
|
||||
{
|
||||
ERROR_LOG(m_logger) << "Error preparing select1 statement: " << stmtSelect1;
|
||||
return false;
|
||||
}
|
||||
|
||||
qSelect1.bindValue(QStringLiteral(":partyId"), request.partyId());
|
||||
qSelect1.bindValue(QStringLiteral(":startTime"), request.startTime());
|
||||
qSelect1.bindValue(QStringLiteral(":endTime"), request.endTime());
|
||||
|
||||
if (!qSelect1.exec())
|
||||
{
|
||||
ERROR_LOG(m_logger) << "Error executing stmt1: " << stmtSelect1;
|
||||
return false;
|
||||
}
|
||||
|
||||
DEBUG_LOG(m_logger) << "stmtSelect1: " << stmtSelect1;
|
||||
DEBUG_LOG(m_logger) << "partyId: " << request.partyId();
|
||||
DEBUG_LOG(m_logger) << "startTime: " << request.startTime();
|
||||
DEBUG_LOG(m_logger) << "endTime: " << request.endTime();
|
||||
|
||||
// QMap<chargeTypeId, eventTime>
|
||||
QMap<int,qint64> maxEventTimeMap;
|
||||
|
||||
while (qSelect1.next())
|
||||
{
|
||||
int chargeTypeId = qSelect1.value(1).toInt();
|
||||
qint64 eventTime = qSelect1.value(0).toLongLong();
|
||||
maxEventTimeMap.insert(chargeTypeId, eventTime);
|
||||
DEBUG_LOG(m_logger) << "chargeTypeId: " << chargeTypeId << ", max eventTime: " << eventTime;
|
||||
}
|
||||
|
||||
for ( auto itI = impactDataMap.begin(); itI != impactDataMap.end(); ++itI)
|
||||
{
|
||||
int chargeTypeId = itI.key();
|
||||
int impacts = itI.value();
|
||||
|
||||
DEBUG_LOG(m_logger) << "ChargeTypeId = " << chargeTypeId;
|
||||
DEBUG_LOG(m_logger) << "Impacts = " << impacts;
|
||||
|
||||
// use only requested chargeTypeIds
|
||||
if (std::find(request.chargeTypeIds().begin(), request.chargeTypeIds().end(), chargeTypeId) == request.chargeTypeIds().end() || chargeTypeId == 0)
|
||||
{
|
||||
WARNING_LOG(m_logger) << "ChargeTypeId " << chargeTypeId << " not found in list";
|
||||
continue;
|
||||
}
|
||||
|
||||
QElapsedTimer timeoutTimer;
|
||||
timeoutTimer.start();
|
||||
|
||||
qint64 t1;
|
||||
t1 = request.startTime();
|
||||
while (t1 <= request.endTime())
|
||||
{
|
||||
checkElapsedTimer(timeoutTimer);
|
||||
qint64 t2 = qMin(qMax(t1, t1 + request.intervalTime() - 1), request.endTime());
|
||||
if (request.intervalTime() == 0) // || request.visualisationType() == VisualisationType::Table)
|
||||
t2 = request.endTime();
|
||||
|
||||
qInsert.bindValue(QStringLiteral(":start"), t1);
|
||||
qInsert.bindValue(QStringLiteral(":end"), t2);
|
||||
qInsert.bindValue(QStringLiteral(":chargeTypeId"), chargeTypeId);
|
||||
|
||||
DEBUG_LOG(m_logger) << " Inserting: reportId, start, end, interval, name = " << reportId << " , " << t1 << " , " << t2 << " , "
|
||||
<< request.intervalTime();
|
||||
|
||||
qSelect2.bindValue(QStringLiteral(":aesPartyId"), request.partyId());
|
||||
qSelect2.bindValue(QStringLiteral(":chargeId"), chargeTypeId);
|
||||
qSelect2.bindValue(QStringLiteral(":startTime"), t1);
|
||||
qSelect2.bindValue(QStringLiteral(":endTime"), t2);
|
||||
|
||||
DEBUG_LOG(m_logger) << "stmtSelect2: " << stmtSelect2;
|
||||
DEBUG_LOG(m_logger) << "startTime: " << t1;
|
||||
DEBUG_LOG(m_logger) << "endTime: " << t2;
|
||||
DEBUG_LOG(m_logger) << "aesPartyId: " << request.partyId();
|
||||
DEBUG_LOG(m_logger) << "chargeTypeId: " << chargeTypeId;
|
||||
|
||||
QMap<int, QVector<int>> vbgMap;
|
||||
|
||||
if (!qSelect2.exec())
|
||||
{
|
||||
ERROR_LOG(m_logger) << "Error executing stmt2: " << stmtSelect2;
|
||||
return false;
|
||||
}
|
||||
|
||||
while (qSelect2.next())
|
||||
{
|
||||
int vbg = qSelect2.value(0).toInt();
|
||||
DEBUG_LOG(m_logger) << "# vbg: " << vbg;
|
||||
|
||||
if (!vbgMap.contains(vbg))
|
||||
vbgMap.insert(vbg, {0, 0, 0});
|
||||
if (vbg == ProjectDataManagement::VulnerabilityState_def::CombatReady ||
|
||||
vbg == ProjectDataManagement::VulnerabilityState_def::NearMiss ||
|
||||
vbg == ProjectDataManagement::VulnerabilityState_def::HitWithNoEffect)
|
||||
continue;
|
||||
|
||||
vbgMap[vbg][0] += qSelect2.value(1).toInt(); // hits
|
||||
vbgMap[vbg][1] += qSelect2.value(2).toInt(); // hits ff
|
||||
vbgMap[vbg][2] += qSelect2.value(3).toInt(); // hits buildings
|
||||
}
|
||||
|
||||
for (auto it = vbgMap.begin(); it != vbgMap.end(); ++it)
|
||||
{
|
||||
qInsert.bindValue(QStringLiteral(":vbg"), it.key());
|
||||
qInsert.bindValue(QStringLiteral(":impacts"), impacts);
|
||||
qInsert.bindValue(QStringLiteral(":hit"), it.value()[0]);
|
||||
qInsert.bindValue(QStringLiteral(":hit_ff"), it.value()[1]);
|
||||
qInsert.bindValue(QStringLiteral(":hit_buildings"), it.value()[2]);
|
||||
|
||||
if (minEventTimeMap.contains(chargeTypeId))
|
||||
qInsert.bindValue(QStringLiteral(":start"), minEventTimeMap.value(chargeTypeId));
|
||||
if (maxEventTimeMap.contains(chargeTypeId))
|
||||
qInsert.bindValue(QStringLiteral(":end"), maxEventTimeMap.value(chargeTypeId));
|
||||
|
||||
DEBUG_LOG(m_logger) << " Inserting report id, charge type id = " << reportId << ", " << chargeTypeId;
|
||||
DEBUG_LOG(m_logger) << " Inserting vbg, hits, hits ff, hit building = " << it.key() << ", " << it.value()[0] << " , " << it.value()[1] << " , " << it.value()[2];
|
||||
|
||||
if (!qInsert.exec())
|
||||
{
|
||||
ERROR_LOG(m_logger) << "Error inserting report id, charge type id, VBG = " << reportId << ", " << chargeTypeId << " , " << it.key();
|
||||
trans.rollback();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (vbgMap.isEmpty())
|
||||
{
|
||||
qInsert.bindValue(QStringLiteral(":vbg"),ProjectDataManagement::VulnerabilityState_def::NearMiss);
|
||||
qInsert.bindValue(QStringLiteral(":impacts"), impacts);
|
||||
qInsert.bindValue(QStringLiteral(":hit"), 0);
|
||||
qInsert.bindValue(QStringLiteral(":hit_ff"), 0);
|
||||
qInsert.bindValue(QStringLiteral(":hit_buildings"), 0);
|
||||
DEBUG_LOG(m_logger) << " Inserting report id, vbg = near miss, charge type id = " << reportId << ", " << chargeTypeId;
|
||||
|
||||
if (!qInsert.exec())
|
||||
{
|
||||
ERROR_LOG(m_logger) << "Error inserting report id, charge type id = " << reportId << " , " << chargeTypeId;
|
||||
trans.rollback();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
t1 += request.intervalTime();
|
||||
if (request.intervalTime() == 0) // || request.visualisationType() == VisualisationType::Table)
|
||||
break;
|
||||
}
|
||||
}
|
||||
trans.commit();
|
||||
|
||||
INFO_LOG(m_logger) << " END generateAirSupportResult";
|
||||
return true;
|
||||
}
|
||||
+167
@@ -0,0 +1,167 @@
|
||||
/**
|
||||
* Handler for report building damage
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
* Created by Hanna E. Rathje, SLSE, 2016-12-20
|
||||
*/
|
||||
|
||||
#include "handler_report_data.h"
|
||||
|
||||
#include <ngldb/nsqlquery.h>
|
||||
#include <ngldb/dbtransaction.h>
|
||||
|
||||
#include <QJsonDocument>
|
||||
|
||||
using namespace ReportManagement;
|
||||
//----------------------------------------------------------------------------
|
||||
bool HandlerReportData::generateBuildingDamageResult(const CreateModifyReportRequest &request, int reportId)
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "Start generateBuildingDamageResult";
|
||||
|
||||
DBTransaction trans(m_db->database());
|
||||
NSqlQuery qSelect(m_db->database());
|
||||
NSqlQuery qInsert(m_db->database());
|
||||
|
||||
// selecting last building state known for a certain timepoint
|
||||
QString stmtSelect = QStringLiteral("SELECT sample_time, structure_element_id, damage_percent, room_states "
|
||||
"FROM rec_building_state "
|
||||
"WHERE id = :buildingId AND sample_time <= :timePoint "
|
||||
"ORDER by sample_time DESC LIMIT 1");
|
||||
|
||||
DEBUG_LOG(m_logger) << "Statement: " << stmtSelect;
|
||||
|
||||
if (!qSelect.prepare(stmtSelect))
|
||||
{
|
||||
ERROR_LOG(m_logger) << "Error preparing select statement: " << stmtSelect;
|
||||
return false;
|
||||
}
|
||||
|
||||
m_buildingDamageData.clear();
|
||||
|
||||
// in chargeTypeIds are saved buildingIds
|
||||
for (auto it = request.chargeTypeIds().begin(); it != request.chargeTypeIds().end(); ++it)
|
||||
{
|
||||
BuildingDamageData bdDataStart, bdDataEnd;
|
||||
int buildingId = *it;
|
||||
DEBUG_LOG(m_logger) << " Building id " << buildingId;
|
||||
|
||||
if (buildingId == 0) // ignore 0, means all buildings are selected for this report
|
||||
continue;
|
||||
|
||||
bdDataStart.buildingId = buildingId;
|
||||
bdDataStart.timePoint = request.startTime();
|
||||
|
||||
bdDataEnd.buildingId = buildingId;
|
||||
bdDataEnd.timePoint = request.endTime();
|
||||
|
||||
qSelect.bindValue(QStringLiteral(":buildingId"), bdDataStart.buildingId);
|
||||
|
||||
// select start data from DB
|
||||
qSelect.bindValue(QStringLiteral(":timePoint"), bdDataStart.timePoint);
|
||||
DEBUG_LOG(m_logger) << "Timepoint Start: " << bdDataStart.timePoint;
|
||||
|
||||
if (!qSelect.exec())
|
||||
{
|
||||
ERROR_LOG(m_logger) << "Error selecting start data report data for report id = " << reportId;
|
||||
return false;
|
||||
}
|
||||
if (!qSelect.next()) // not found a valid record
|
||||
WARNING_LOG(m_logger) << "No start data for report id = " << reportId;
|
||||
|
||||
bdDataStart.buildingDamagePercent = qSelect.value(2).toDouble();
|
||||
bdDataStart.roomStates = qSelect.value(3).toByteArray();
|
||||
readRoomStates(bdDataStart);
|
||||
|
||||
// select end data from DB
|
||||
qSelect.bindValue(QStringLiteral(":timePoint"), bdDataEnd.timePoint);
|
||||
DEBUG_LOG(m_logger) << "Timepoint End: " << bdDataEnd.timePoint;
|
||||
|
||||
if (!qSelect.exec())
|
||||
{
|
||||
ERROR_LOG(m_logger) << "Error selecting end data report data for report id = " << reportId;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!qSelect.next()) // not found a valid record
|
||||
WARNING_LOG(m_logger) << "No end data for report id = " << reportId;
|
||||
|
||||
bdDataEnd.buildingDamagePercent = qSelect.value(2).toDouble();
|
||||
bdDataEnd.roomStates = qSelect.value(3).toByteArray();
|
||||
readRoomStates(bdDataEnd);
|
||||
|
||||
m_buildingDamageData.append(bdDataStart);
|
||||
m_buildingDamageData.append(bdDataEnd);
|
||||
}
|
||||
|
||||
QString stmtInsert = QStringLiteral("INSERT INTO rep_building_damage_result (report_id, building_id, time_point, damage_20, damage_40, damage_60, damage_80, damage_100, damage_percent)"
|
||||
" values (:reportId, :bldId, :time, :damage20, :damage40, :damage60, :damage80, :damage100, :damage)");
|
||||
|
||||
if (!qInsert.prepare(stmtInsert))
|
||||
{
|
||||
ERROR_LOG(m_logger) << "Error preparing statement: " << stmtInsert;
|
||||
return false;
|
||||
}
|
||||
|
||||
qInsert.bindValue(QStringLiteral(":reportId"), reportId);
|
||||
|
||||
for (const BuildingDamageData &bdData : qAsConst(m_buildingDamageData))
|
||||
{
|
||||
qInsert.bindValue(QStringLiteral(":bldId"), bdData.buildingId);
|
||||
qInsert.bindValue(QStringLiteral(":time"), bdData.timePoint);
|
||||
qInsert.bindValue(QStringLiteral(":damage20"), bdData.damages[0]);
|
||||
qInsert.bindValue(QStringLiteral(":damage40"), bdData.damages[1]);
|
||||
qInsert.bindValue(QStringLiteral(":damage60"), bdData.damages[2]);
|
||||
qInsert.bindValue(QStringLiteral(":damage80"), bdData.damages[3]);
|
||||
qInsert.bindValue(QStringLiteral(":damage100"), bdData.damages[4]);
|
||||
qInsert.bindValue(QStringLiteral(":damage"), bdData.buildingDamagePercent);
|
||||
|
||||
DEBUG_LOG(m_logger) << "Statement: " << stmtInsert;
|
||||
|
||||
if (!qInsert.exec())
|
||||
{
|
||||
ERROR_LOG(m_logger) << "Error inserting report data for report id = " << reportId;
|
||||
trans.rollback();
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
trans.commit();
|
||||
|
||||
DEBUG_LOG(m_logger) << " END generateBuildingDamageResult";
|
||||
return true;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
void HandlerReportData::readRoomStates(BuildingDamageData &bdd)
|
||||
{
|
||||
const QJsonArray roomStates(QJsonDocument::fromJson(bdd.roomStates).array());
|
||||
if (roomStates.size() == 0)
|
||||
{
|
||||
WARNING_LOG(m_logger) << "RoomStates empty!";
|
||||
return;
|
||||
}
|
||||
|
||||
for (const QJsonValue &val : roomStates)
|
||||
{
|
||||
const QJsonObject obj(val.toObject());
|
||||
double roomDamage = obj[QStringLiteral("damagePercent")].toDouble();
|
||||
|
||||
DEBUG_LOG(m_logger) << "Room id: " << obj[QStringLiteral("id")].toInt();
|
||||
DEBUG_LOG(m_logger) << "Room damage: " << roomDamage;
|
||||
|
||||
if (roomDamage > 0 && roomDamage <= 20)
|
||||
bdd.damages[0]++;
|
||||
else if (roomDamage > 20 && roomDamage <= 40)
|
||||
bdd.damages[1]++;
|
||||
else if (roomDamage > 40 && roomDamage <= 60)
|
||||
bdd.damages[2]++;
|
||||
else if (roomDamage > 60 && roomDamage <= 80)
|
||||
bdd.damages[3]++;
|
||||
else if (roomDamage > 80 && roomDamage <= 100)
|
||||
bdd.damages[4]++;
|
||||
else
|
||||
WARNING_LOG(m_logger) << "Invalid room damage percent " << roomDamage << " for building id = " << bdd.buildingId;
|
||||
}
|
||||
}
|
||||
+597
@@ -0,0 +1,597 @@
|
||||
/**
|
||||
* Handler for report charge resupply
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
* Created by Hanna E. Rathje, SLSE, 2016-12-20
|
||||
*/
|
||||
|
||||
#include "handler_report_data.h"
|
||||
|
||||
#include <ngldb/nsqlquery.h>
|
||||
#include <ngldb/dbtransaction.h>
|
||||
|
||||
#include <QVariant>
|
||||
#include <QSet>
|
||||
|
||||
using namespace ReportManagement;
|
||||
|
||||
bool HandlerReportData::generateChargeResupplyResult(const CreateModifyReportRequest &request, int reportId)
|
||||
{
|
||||
INFO_LOG(m_logger) << "Start generateChargeResupplyResult";
|
||||
|
||||
DBTransaction trans(m_db->database());
|
||||
NSqlQuery q(m_db->database());
|
||||
|
||||
m_crPartMap.clear();
|
||||
m_crGear.clear();
|
||||
|
||||
QElapsedTimer timeoutTimer;
|
||||
timeoutTimer.start();
|
||||
|
||||
// find all gears used by the selected players (in the given time period and with the given charge)
|
||||
QSet<int> usedGears;
|
||||
{
|
||||
QString stmt = QLatin1String("SELECT DISTINCT gear_id FROM rep_charge_resupply_data "
|
||||
" WHERE (event_time BETWEEN ") + QString::number(request.startTime()) + QLatin1String(" AND ") + QString::number(request.endTime()) + QLatin1String(") ");
|
||||
|
||||
stmt += QLatin1String(" AND charge_type_id != 0");
|
||||
|
||||
if (request.chargeTypeIds().size() > 0)
|
||||
{
|
||||
const QString chargeTypeIds = intVecToString(request.chargeTypeIds());
|
||||
stmt += QLatin1String(" AND (charge_type_id IN (") + chargeTypeIds + QLatin1String(") OR charge_type_id < 0) ");
|
||||
}
|
||||
|
||||
if (request.participantIds().size() > 0)
|
||||
{
|
||||
const QString participants = intVecToString(request.participantIds());
|
||||
stmt += QStringLiteral(" AND participant_id IN (%1)").arg(participants);
|
||||
}
|
||||
|
||||
DEBUG_LOG(m_logger) << " stmt: " << stmt;
|
||||
|
||||
if (!q.exec(stmt))
|
||||
{
|
||||
ERROR_LOG(m_logger) << "Couldn't select gears ";
|
||||
return false;
|
||||
}
|
||||
while (q.next())
|
||||
usedGears += q.value(0).toInt();
|
||||
|
||||
}
|
||||
if (usedGears.isEmpty())
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "No used gears for this report";
|
||||
return true;
|
||||
}
|
||||
|
||||
// select all events with the gears in the given time period
|
||||
{
|
||||
QString stmt = QLatin1String("SELECT party_id, event_time, participant_id, participant_type_id, charge_type_id, gear_type_id, "
|
||||
"gear_id, charge_fired, charge_remain FROM rep_charge_resupply_data "
|
||||
" WHERE (event_time BETWEEN ") + QString::number(request.startTime()) + QLatin1String(" AND ") + QString::number(request.endTime()) + QLatin1String(") ");
|
||||
|
||||
stmt += QLatin1String(" AND charge_type_id != 0 ");
|
||||
|
||||
// for gears with more than one possible charge
|
||||
if (request.chargeTypeIds().size() > 0)
|
||||
{
|
||||
const QString chargeTypeIds = intVecToString(request.chargeTypeIds());
|
||||
stmt += QLatin1String(" AND (charge_type_id IN (") + chargeTypeIds + QLatin1String(") OR charge_type_id < 0) ");
|
||||
}
|
||||
|
||||
// used gears
|
||||
{
|
||||
QStringList strList;
|
||||
strList.reserve(usedGears.size());
|
||||
for (int gearId : qAsConst(usedGears))
|
||||
strList += QString::number(gearId);
|
||||
QString gears = strList.join(QLatin1String(", "));
|
||||
stmt += QLatin1String(" AND gear_id IN (") + gears + QLatin1String(")");
|
||||
}
|
||||
|
||||
if (request.participantIds().size() > 0)
|
||||
{
|
||||
const QString participants = intVecToString(request.participantIds());
|
||||
stmt += QStringLiteral(" AND participant_id IN (%1)").arg(participants);
|
||||
}
|
||||
|
||||
stmt += QLatin1String(" ORDER BY event_time");
|
||||
DEBUG_LOG(m_logger) << " stmt: " << stmt;
|
||||
|
||||
if (!q.exec(stmt))
|
||||
{
|
||||
ERROR_LOG(m_logger) << "Couldn't fetch data from Table rep_charge_resupply_data";
|
||||
return false;
|
||||
}
|
||||
|
||||
Database::RepChargeResupplyData data;
|
||||
while (q.next())
|
||||
{
|
||||
checkElapsedTimer(timeoutTimer);
|
||||
int i = 0;
|
||||
data.partyId = q.value(i++).toInt();
|
||||
data.eventTime = q.value(i++).toLongLong();
|
||||
data.participantId = q.value(i++).toInt();
|
||||
data.participantTypeId = q.value(i++).toInt();
|
||||
data.chargeTypeId = q.value(i++).toInt();
|
||||
data.gearTypeId = q.value(i++).toInt();
|
||||
data.gearId = q.value(i++).toInt();
|
||||
data.chargeFired = q.value(i++).toInt();
|
||||
data.chargeRemain = q.value(i++).toInt();
|
||||
|
||||
DEBUG_LOG(m_logger) << "Raw data: Time: " << data.eventTime <<
|
||||
", Participant: " << data.participantId <<
|
||||
", P-Type: T" << data.participantTypeId <<
|
||||
", Gear: " << data.gearId <<
|
||||
", ChargeType: C" << data.chargeTypeId <<
|
||||
", Fired: " << data.chargeFired <<
|
||||
", Remain: " << data.chargeRemain;
|
||||
|
||||
m_crPartMap[data.participantId][data.gearId][data.chargeTypeId][data.eventTime] = data;
|
||||
|
||||
DEBUG_LOG(m_logger) << "m_crPart[P" << data.participantId <<
|
||||
"][G" << data.gearId <<
|
||||
"][C" << data.chargeTypeId <<
|
||||
"][T" << data.eventTime <<
|
||||
"]. ";
|
||||
|
||||
m_crGear[data.gearId][data.participantId].append(data);
|
||||
}
|
||||
}
|
||||
|
||||
if (m_logger.isDebugEnabled())
|
||||
{
|
||||
for (auto cIt1 = m_crGear.cbegin() ; cIt1 != m_crGear.cend(); ++cIt1)
|
||||
{
|
||||
const participant_map2_t &plMap = cIt1.value();
|
||||
|
||||
for (auto cIt2 = plMap.cbegin(); cIt2 != plMap.cend(); ++cIt2)
|
||||
{
|
||||
const QVector<Database::RepChargeResupplyData> &vecData = cIt2.value();
|
||||
for (const Database::RepChargeResupplyData &dd : vecData)
|
||||
{
|
||||
checkElapsedTimer(timeoutTimer);
|
||||
DEBUG_LOG(m_logger) << "m_crGear[G" << cIt1.key() <<
|
||||
"][P" << cIt2.key() <<
|
||||
"] data = "
|
||||
"Time: " << dd.eventTime <<
|
||||
", Participant: " << dd.participantId <<
|
||||
", P-Type: T" << dd.participantTypeId <<
|
||||
", Gear: " << dd.gearId <<
|
||||
", ChargeType: C" << dd.chargeTypeId <<
|
||||
", Fired: " << dd.chargeFired <<
|
||||
", Remain: " << dd.chargeRemain;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Alle Teilnehmer, die in der angegebenen Zeit kein Telegramm erzeugt haben, hier
|
||||
// hinzufügen
|
||||
for (const int participantId : request.participantIds())
|
||||
{
|
||||
if (!m_crPartMap.contains(participantId))
|
||||
{
|
||||
checkElapsedTimer(timeoutTimer);
|
||||
// letzte Waffenzuordnung & Munitionsvorat holen und in m_crPartMap / m_crGear eintragen
|
||||
getLastGearSetting(participantId, request.chargeTypeIds(), request.startTime());
|
||||
}
|
||||
}
|
||||
|
||||
// Remove all weapons that were only in one hand
|
||||
{
|
||||
QMap<int, participant_map2_t>::iterator it = m_crGear.begin();
|
||||
QMap<int, participant_map2_t>::iterator end = m_crGear.end();
|
||||
while (it != end)
|
||||
{
|
||||
const participant_map2_t &p = it.value();
|
||||
if (p.count() <= 1 || it.key() <= 0) // remove gearId (-1, 0) - turm / wanne and no gearId
|
||||
it = m_crGear.erase(it);
|
||||
else
|
||||
++it;
|
||||
}
|
||||
}
|
||||
|
||||
// Now examine the remaining weapons:
|
||||
for (const participant_map2_t &p : qAsConst(m_crGear))
|
||||
{
|
||||
QMap<time_t, Database::RepChargeResupplyData> temp;
|
||||
for (const QVector<Database::RepChargeResupplyData> &datas : p)
|
||||
{
|
||||
for (const Database::RepChargeResupplyData &d : datas)
|
||||
temp.insert(d.eventTime, d);
|
||||
}
|
||||
|
||||
int p_before = temp.begin().value().participantId;
|
||||
int pt_before = temp.begin().value().participantTypeId;
|
||||
|
||||
for (const Database::RepChargeResupplyData &d : qAsConst(temp))
|
||||
{
|
||||
if (p_before != d.participantId)
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "Inserting new Dummy Telegram for dropped weapon";
|
||||
Database::RepChargeResupplyData dNew = d;
|
||||
dNew.chargeRemain = 0;
|
||||
dNew.participantId = p_before;
|
||||
dNew.participantTypeId = pt_before;
|
||||
const charge_type_map_t &ctmap = m_crPartMap[dNew.participantId][dNew.gearId];
|
||||
|
||||
for (auto it = ctmap.cbegin(); it != ctmap.end(); ++it)
|
||||
{
|
||||
checkElapsedTimer(timeoutTimer);
|
||||
const int &chargeTypeId = it.key();
|
||||
|
||||
dNew.chargeTypeId = chargeTypeId;
|
||||
dNew.chargeRemain = 0;
|
||||
dNew.chargeFired = -1; // drop indicator
|
||||
m_crPartMap[dNew.participantId][dNew.gearId][chargeTypeId][dNew.eventTime] = dNew;
|
||||
DEBUG_LOG(m_logger) << "+Raw data: Time: " << dNew.eventTime <<
|
||||
", Participant: " << dNew.participantId <<
|
||||
", P-Type: T" << dNew.participantTypeId <<
|
||||
", Gear: " << dNew.gearId <<
|
||||
", ChargeType: C" << dNew.chargeTypeId <<
|
||||
", Fired: " << dNew.chargeFired <<
|
||||
", Remain: " << dNew.chargeRemain;
|
||||
}
|
||||
|
||||
DEBUG_LOG(m_logger) << "Inserting new Dummy Telegram for picked up gear";
|
||||
dNew = d;
|
||||
dNew.chargeRemain = 0;
|
||||
const charge_type_map_t &ctMap2 = m_crPartMap[dNew.participantId][dNew.gearId];
|
||||
|
||||
for (auto it = ctMap2.cbegin(); it != ctMap2.end(); ++it)
|
||||
{
|
||||
checkElapsedTimer(timeoutTimer);
|
||||
const int &chargeTypeId = it.key();
|
||||
|
||||
dNew.chargeTypeId = chargeTypeId;
|
||||
dNew.chargeRemain = 0;
|
||||
dNew.chargeFired = 0;
|
||||
m_crPartMap[dNew.participantId][dNew.gearId][chargeTypeId][dNew.eventTime] = dNew;
|
||||
DEBUG_LOG(m_logger) << "+Raw data: Time: " << dNew.eventTime <<
|
||||
", Participant: " << dNew.participantId <<
|
||||
", P-Type: T" << dNew.participantTypeId <<
|
||||
", Gear: " << dNew.gearId <<
|
||||
", ChargeType: C" << dNew.chargeTypeId <<
|
||||
", Fired: " << dNew.chargeFired <<
|
||||
", Remain: " << dNew.chargeRemain;
|
||||
|
||||
}
|
||||
if (m_crPartMap.value(dNew.participantId).value(dNew.gearId).contains(-1))
|
||||
m_crPartMap[dNew.participantId][dNew.gearId][-1].remove(dNew.eventTime);
|
||||
|
||||
p_before = d.participantId;
|
||||
pt_before = d.participantTypeId;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (auto partIt = m_crPartMap.cbegin() ; partIt != m_crPartMap.cend(); ++partIt) // Per Participant
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "Participant changed";
|
||||
const gear_map_t &gmap = partIt.value();
|
||||
|
||||
for (auto gearIt = gmap.cbegin(); gearIt != gmap.cend(); ++gearIt)
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "Gear changed";
|
||||
const charge_type_map_t &ctmap = gearIt.value();
|
||||
|
||||
for (auto ctIt = ctmap.cbegin() ; ctIt != ctmap.cend(); ++ctIt)
|
||||
{
|
||||
checkElapsedTimer(timeoutTimer);
|
||||
bool bGearIsBlankCharge = false;
|
||||
ChargeResupplyResult res;
|
||||
memset(&res, 0, sizeof(ChargeResupplyResult));
|
||||
|
||||
const time_map_t &tmap = ctIt.value();
|
||||
int start = -1;
|
||||
int shots = 0;
|
||||
int taken = 0;
|
||||
int given = 0;
|
||||
int end = -1;
|
||||
|
||||
const Database::RepChargeResupplyData &x = tmap.begin().value();
|
||||
if (x.chargeFired > 0)
|
||||
{
|
||||
start = x.chargeFired + x.chargeRemain;
|
||||
DEBUG_LOG(m_logger) << "Charge changed - 1st: Charge fired, therefore, START = " << start;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (x.chargeRemain == 0)
|
||||
{
|
||||
start = 0;
|
||||
DEBUG_LOG(m_logger) << "Charge changed - 1st: WZ, therefore, START = 0";
|
||||
}
|
||||
else
|
||||
{
|
||||
start = getStart(x.participantId, x.gearId, x.chargeTypeId, request.startTime(), 0);
|
||||
DEBUG_LOG(m_logger) << "### ChargeType changed - 1st: MunV, therefore, START = " << start;
|
||||
}
|
||||
}
|
||||
|
||||
if (res.participantId == 0)
|
||||
{
|
||||
res.participantId = x.participantId;
|
||||
res.participantTypeId = x.participantTypeId;
|
||||
res.partyId = x.partyId;
|
||||
}
|
||||
|
||||
DEBUG_LOG(m_logger) << "Res data: Participant: " << res.participantId <<
|
||||
", P-Type: T" << res.participantTypeId <<
|
||||
", ChargeType: C" << res.chargeTypeId <<
|
||||
", START: " << res.chargeStart <<
|
||||
", Fired: " << res.chargeFired <<
|
||||
", Taken: " << res.chargeTaken <<
|
||||
", Given: " << res.chargeGiven <<
|
||||
", End: " << res.chargeEnd;
|
||||
|
||||
|
||||
int current = start;
|
||||
for (const Database::RepChargeResupplyData &d : qAsConst(tmap)) // Per Timestamp
|
||||
{
|
||||
if (d.chargeTypeId < 0)
|
||||
{
|
||||
// Gear-zuordnung
|
||||
// do nothing
|
||||
// ChargeResupply will come...
|
||||
switch (d.chargeTypeId)
|
||||
{
|
||||
case -1:
|
||||
DEBUG_LOG(m_logger) << "Waffenzuordnung dryfire";
|
||||
break;
|
||||
case -2:
|
||||
DEBUG_LOG(m_logger) << "Charge blank ammunition for gear " << d.gearId;
|
||||
bGearIsBlankCharge = true;
|
||||
break;
|
||||
default:
|
||||
WARNING_LOG(m_logger) << "Unknown chargeTypeId (" << d.chargeTypeId << ") for gearType";
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (d.chargeFired > 0)
|
||||
{
|
||||
// Feuerereignis
|
||||
if (current - d.chargeFired != d.chargeRemain)
|
||||
WARNING_LOG(m_logger) << "Old Stock minus Fired Rounds is not equal to new Stock! Diff = " << (current - d.chargeFired - d.chargeRemain);
|
||||
shots += d.chargeFired;
|
||||
current = d.chargeRemain;
|
||||
res.chargeTypeId = d.chargeTypeId;
|
||||
DEBUG_LOG(m_logger) << "Feuerereignis - " << QString::number(d.eventTime) <<
|
||||
" - New Stock: Fired: " << shots <<
|
||||
", Taken: " << taken <<
|
||||
", Current: " << current;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (d.chargeFired == -1) // drop indicator
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "Gear dropped at Z" << d.eventTime <<
|
||||
" (is: " << d.chargeRemain <<
|
||||
" current: " << current <<
|
||||
" for time " << d.eventTime << ")" <<
|
||||
", Player: " << res.participantId <<
|
||||
", P-Type: T" << res.participantTypeId <<
|
||||
", Weapon: " << d.gearId <<
|
||||
", ChargeType: C" << res.chargeTypeId <<
|
||||
")";
|
||||
given += current;
|
||||
}
|
||||
else if (d.chargeRemain < current)
|
||||
{
|
||||
// ChargeResupply
|
||||
WARNING_LOG(m_logger) << "Negative Resupply! (is: " << d.chargeRemain
|
||||
<< " current: " << current
|
||||
<< " for time " << d.eventTime
|
||||
<< ")";
|
||||
}
|
||||
else
|
||||
taken += (d.chargeRemain - current);
|
||||
current = d.chargeRemain;
|
||||
res.chargeTypeId = d.chargeTypeId;
|
||||
DEBUG_LOG(m_logger) << "ChargeResupply - " << QString::number(d.eventTime) <<
|
||||
" - New Stock: Fired: " << shots <<
|
||||
", Taken: " << taken <<
|
||||
", Current: " << current;
|
||||
}
|
||||
}
|
||||
end = current;
|
||||
|
||||
if (res.chargeTypeId > 0)
|
||||
{
|
||||
res.chargeStart += start;
|
||||
res.chargeFired += shots;
|
||||
res.chargeTaken += taken;
|
||||
res.chargeGiven += given;
|
||||
res.chargeEnd += end;
|
||||
|
||||
DEBUG_LOG(m_logger) << "Res chgd: Participant: " << res.participantId <<
|
||||
", P-Type: T" << res.participantTypeId <<
|
||||
", ChargeType: C" << res.chargeTypeId <<
|
||||
", START: " << res.chargeStart <<
|
||||
", Fired: " << res.chargeFired <<
|
||||
", Taken: " << res.chargeTaken <<
|
||||
", Given: " << res.chargeGiven <<
|
||||
", End: " << res.chargeEnd;
|
||||
}
|
||||
// ist 0 wenn nur munvorrat angekommen, unnoetig
|
||||
if (res.chargeTypeId > 0)
|
||||
{
|
||||
if (bGearIsBlankCharge)
|
||||
DEBUG_LOG(m_logger) << "Gear with blank ammunition - skipping";
|
||||
else
|
||||
m_crResData[res.participantId][res.chargeTypeId] = res;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
QMap<int/*participantTypeId*/, charge_type_map2_t> finalMap;
|
||||
|
||||
for (const charge_type_map2_t &ctmap : qAsConst(m_crResData)) // Per Participant
|
||||
{
|
||||
for (const ChargeResupplyResult &res : qAsConst(ctmap)) // Per ChargeType
|
||||
{
|
||||
if (request.participantIds().size() > 0 && !contains(request.participantIds(), res.participantId))
|
||||
continue;
|
||||
|
||||
finalMap[res.participantTypeId][res.chargeTypeId].chargeTypeId = res.chargeTypeId;
|
||||
finalMap[res.participantTypeId][res.chargeTypeId].participantTypeId = res.participantTypeId;
|
||||
finalMap[res.participantTypeId][res.chargeTypeId].chargeStart += res.chargeStart;
|
||||
finalMap[res.participantTypeId][res.chargeTypeId].chargeFired += res.chargeFired;
|
||||
finalMap[res.participantTypeId][res.chargeTypeId].chargeTaken += res.chargeTaken;
|
||||
finalMap[res.participantTypeId][res.chargeTypeId].chargeGiven += res.chargeGiven;
|
||||
finalMap[res.participantTypeId][res.chargeTypeId].chargeEnd += res.chargeEnd;
|
||||
|
||||
DEBUG_LOG(m_logger) << "finalMap[T" << res.participantTypeId <<
|
||||
"][C" << res.chargeTypeId <<
|
||||
"] START: " << res.chargeStart <<
|
||||
", Fired: " << res.chargeFired <<
|
||||
", Taken: " << res.chargeTaken <<
|
||||
", Given: " << res.chargeGiven <<
|
||||
", End: " << res.chargeEnd;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
q.prepare(QLatin1String("INSERT INTO rep_charge_resupply_result (report_id, charge_type_id, participant_type_id, charge_start, charge_taken, charge_given, charge_end, charge_fired )"
|
||||
" VALUES ( :report_id, :charge_type_id, :participant_type_id, :charge_start, :charge_taken, :charge_given, :charge_end, :charge_fired )"));
|
||||
q.bindValue(QLatin1String(":report_id"), reportId);
|
||||
|
||||
DEBUG_LOG(m_logger) << "finalMap.size: " << finalMap.size();
|
||||
|
||||
for (const charge_type_map2_t &ctmap : qAsConst(finalMap))
|
||||
{
|
||||
for (const ChargeResupplyResult &res : qAsConst(ctmap))
|
||||
{
|
||||
checkElapsedTimer(timeoutTimer);
|
||||
DEBUG_LOG(m_logger) << "res.chargeTypeId: " << res.chargeTypeId;
|
||||
if (res.chargeTypeId > 0)
|
||||
{
|
||||
q.bindValue(QLatin1String(":charge_type_id"), res.chargeTypeId);
|
||||
q.bindValue(QLatin1String(":participant_type_id"), res.participantTypeId);
|
||||
q.bindValue(QLatin1String(":charge_start"), res.chargeStart);
|
||||
q.bindValue(QLatin1String(":charge_taken"), res.chargeTaken);
|
||||
q.bindValue(QLatin1String(":charge_given"), res.chargeGiven);
|
||||
q.bindValue(QLatin1String(":charge_fired"), res.chargeFired);
|
||||
q.bindValue(QLatin1String(":charge_end"), res.chargeEnd);
|
||||
DEBUG_LOG(m_logger) << " Inserting into rep_charge_resupply_result";
|
||||
if (!q.exec())
|
||||
{
|
||||
ERROR_LOG(m_logger) << "Error inserting into rep_charge_resupply_result" ;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
trans.commit();
|
||||
|
||||
INFO_LOG(m_logger) << " END generateChargeResupplyResult";
|
||||
return true;
|
||||
}
|
||||
|
||||
bool HandlerReportData::contains(const std::vector<int32_t> &vector, int32_t value)
|
||||
{
|
||||
for (int32_t i : vector)
|
||||
{
|
||||
if (i == value)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
int HandlerReportData::getStart(int partId, int gearId, int chargeTypeId, qint64 before, qint64 after)
|
||||
{
|
||||
NSqlQuery q(m_db->database());
|
||||
QString stmt = QLatin1String("SELECT charge_remain, participant_id from rep_charge_resupply_data WHERE (event_time < ") + QString::number(before)
|
||||
+ QLatin1String(") AND charge_type_id = ") + QString::number(chargeTypeId) + QLatin1String(" AND gear_id = ")
|
||||
+ QString::number(gearId);
|
||||
|
||||
if (after > 0)
|
||||
stmt += QLatin1String(" AND event_time >= ") + QString::number(after);
|
||||
|
||||
#ifdef GUEZ_MODE
|
||||
// gear does not change owner. should fix the gear(-1) = turm/wanne and correct start values.
|
||||
stmt += QLatin1String(" AND participant_id = ") + QString::number(partId);
|
||||
#endif
|
||||
|
||||
stmt += QLatin1String(" AND charge_remain >= 0 ORDER BY event_time DESC LIMIT 1");
|
||||
|
||||
DEBUG_LOG(m_logger) << " stmt: " << stmt;
|
||||
|
||||
if (!q.exec(stmt))
|
||||
{
|
||||
ERROR_LOG(m_logger) << "Couldn't fetch data from Table rep_charge_resupply_data";
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!q.next())
|
||||
{
|
||||
return 0; // kein Fehler, Waffenzuordnung ohne nachfolgenden Feuerereignis/MunVorrat
|
||||
}
|
||||
|
||||
int participant_id_select = q.value(1).toInt();
|
||||
// hatte er das Gear als letztes vor dem Auswertestart?
|
||||
if (participant_id_select == partId)
|
||||
return q.value(0).toInt(); // ja -> also hatte er auch den Munitionsvorrat
|
||||
return 0; // jemand anderes hatte das Gear -> kein ChargeResupply
|
||||
}
|
||||
|
||||
void HandlerReportData::getLastGearSetting(int participantId, const std::vector<int32_t> &chargeTypeIds, qint64 startTime)
|
||||
{
|
||||
DEBUG_LOG(m_logger) << " IN getLastGearSetting";
|
||||
NSqlQuery q(m_db->database());
|
||||
|
||||
QString stmt = QLatin1String("SELECT gear_id, gear_type_id, participant_type_id, event_time FROM rep_charge_resupply_data WHERE charge_type_id = -1 AND participant_id = ") +
|
||||
QString::number(participantId) + QLatin1String(" AND event_time < ") + QString::number(startTime)
|
||||
+ QLatin1String(" ORDER BY event_time DESC LIMIT 1");
|
||||
|
||||
DEBUG_LOG(m_logger) << "stmt: " << stmt;
|
||||
|
||||
if (!q.execAndFetch(stmt))
|
||||
return;
|
||||
|
||||
int gearId = q.value(0).toInt();
|
||||
int gearTypeId = q.value(1).toInt();
|
||||
int participantTypeId = q.value(2).toInt();
|
||||
qint64 eventTime = q.value(3).toLongLong();
|
||||
|
||||
stmt = QLatin1String("SELECT DISTINCT charge_type_id FROM rep_charge_resupply_data WHERE event_time < ") + QString::number(startTime)
|
||||
+ QLatin1String(" AND event_time >= ") + QString::number(eventTime)
|
||||
+ QLatin1String(" AND participant_id = ") + QString::number(participantId)
|
||||
+ QLatin1String(" AND gear_id = ") + QString::number(gearId);
|
||||
|
||||
DEBUG_LOG(m_logger) << "stmt: " << stmt;
|
||||
|
||||
if (!q.exec(stmt))
|
||||
return;
|
||||
|
||||
while (q.next())
|
||||
{
|
||||
int chargeTypeId = q.value(0).toInt();
|
||||
if (chargeTypeIds.size() > 0 && !contains(chargeTypeIds, chargeTypeId))
|
||||
continue;
|
||||
|
||||
DEBUG_LOG(m_logger) << "chargeTypeId: " << chargeTypeId;
|
||||
|
||||
Database::RepChargeResupplyData data;
|
||||
data.chargeFired = 0;
|
||||
data.chargeRemain = getStart(participantId, gearId, chargeTypeId, startTime, eventTime);
|
||||
data.chargeTypeId = chargeTypeId;
|
||||
data.gearId = gearId;
|
||||
data.gearTypeId = gearTypeId;
|
||||
data.eventTime = eventTime;
|
||||
data.participantId = participantId;
|
||||
data.participantTypeId = participantTypeId;
|
||||
|
||||
gear_map_t ctMap;
|
||||
ctMap[data.gearId][data.chargeTypeId][data.eventTime] = data;
|
||||
m_crGear[data.gearId][data.participantId].append(data);
|
||||
|
||||
m_crPartMap[participantId] = ctMap;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,574 @@
|
||||
/**
|
||||
* Handler for report data (all)
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
* Created by Hanna E. Rathje, SLSE, 2016-12-20
|
||||
*/
|
||||
|
||||
#include "handler_report_data.h"
|
||||
#include "rep_db.h"
|
||||
#include "settings.h"
|
||||
|
||||
#include <ngldb/dbtransaction.h>
|
||||
#include <ngldb/nsqlquery.h>
|
||||
|
||||
#include <ProjectDataManagement/pdm.hpp>
|
||||
|
||||
#include <QSet>
|
||||
#include <QJsonArray>
|
||||
#include <QJsonObject>
|
||||
#include <QJsonDocument>
|
||||
#include <DDS/Core/pacemaker.h>
|
||||
|
||||
using namespace ReportManagement;
|
||||
//-----------------------------------------------------------------------------
|
||||
HandlerReportData::HandlerReportData(const std::shared_ptr<DdsHandler> &ddsHandler,
|
||||
const std::shared_ptr<DatabaseInterface> &db)
|
||||
: Interface::Fts::CreateModifyReportRequestHandler(ddsHandler->fts())
|
||||
, Interface::Fts::RemoveReportRequestHandler(ddsHandler->fts())
|
||||
, Interface::Fts::ReportChangeStatusRequestHandler(ddsHandler->fts())
|
||||
, m_ddsHandler(ddsHandler)
|
||||
, m_db(db)
|
||||
, m_ppmDtc(nullptr)
|
||||
, m_aesDtc(nullptr)
|
||||
, m_logger(getLogger("HandlerReportData"))
|
||||
{
|
||||
} // end of ctor()
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
bool HandlerReportData::init()
|
||||
{
|
||||
INFO_LOG(m_logger) << "start init() DTC HandlerReportData ";
|
||||
|
||||
bool bRet = true;
|
||||
auto cbReport = [this, &bRet](Database::RepReport dbData)
|
||||
{
|
||||
ObjectReportInfo *ifs(new ObjectReportInfo(m_ddsHandler, m_db, this));
|
||||
Core::FunctionReplyObject ret = ifs->createObject(dbData);
|
||||
|
||||
if (ret.error())
|
||||
{
|
||||
delete ifs;
|
||||
ERROR_LOG(m_logger) << ret();
|
||||
bRet = false;
|
||||
return;
|
||||
}
|
||||
m_objReportMap.insert(ifs->getId(), ifs);
|
||||
};
|
||||
if (!m_db->select(cbReport) || !bRet)
|
||||
return false;
|
||||
|
||||
// init PPM DTC
|
||||
m_ppmDtc = ParticipantManagement::Interface::Dtc::create(m_ddsHandler->ddsConnector());
|
||||
if (m_ppmDtc == nullptr)
|
||||
{
|
||||
ERROR_LOG(m_logger) << "Could not create PPM DTC";
|
||||
return false;
|
||||
}
|
||||
m_ppmDtc->enableParticipant();
|
||||
m_ppmDtc->waitForHistoricalDataParticipant();
|
||||
|
||||
// init AES DTC
|
||||
m_aesDtc = AreaEffectSimulation::Interface::Dtc::create(m_ddsHandler->ddsConnector());
|
||||
if (m_aesDtc == nullptr)
|
||||
{
|
||||
ERROR_LOG(m_logger) << "Could not create AES DTC";
|
||||
return false;
|
||||
}
|
||||
m_aesDtc->enableMineArea();
|
||||
m_aesDtc->waitForHistoricalDataMineArea();
|
||||
m_aesDtc->enableBCContamination();
|
||||
m_aesDtc->waitForHistoricalDataBCContamination();
|
||||
|
||||
return true;
|
||||
} // end of init()
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
QString HandlerReportData::intVecToString(const std::vector<int> &intVec)
|
||||
{
|
||||
QStringList sl;
|
||||
sl.reserve(intVec.size());
|
||||
for (int i : intVec)
|
||||
sl += QString::number(i);
|
||||
return sl.join(QStringLiteral(", "));
|
||||
} // end of intVecToString()
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
void HandlerReportData::onCreateModifyReportRequest(const rti::core::SampleIdentity &cookie,
|
||||
const CreateModifyReportRequest &request)
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "onCreateModifyReportRequest" << request;
|
||||
|
||||
m_updateReportCookie = cookie;
|
||||
|
||||
m_reply.errorString(std::string());
|
||||
m_reply.replyState(Core::FtReplyState::InProgress);
|
||||
m_reply.currentTime(QDateTime::currentMSecsSinceEpoch());
|
||||
|
||||
m_ddsHandler->fts()->createModifyReportReply(m_updateReportCookie, m_reply);
|
||||
|
||||
qint32 reportId;
|
||||
bool ok = true;
|
||||
|
||||
if (request.id() == 0) // add
|
||||
reportId = 0;
|
||||
else // modify
|
||||
{
|
||||
reportId = request.id();
|
||||
ReportType repType = request.reportType(); // assuming this cannot be changed by this request
|
||||
ok = removeReportData(reportId, repType); // remove old data
|
||||
if (!ok)
|
||||
WARNING_LOG(m_logger) << "Cannot remove old data for report id = " << reportId;
|
||||
}
|
||||
|
||||
if (!insertReportData(request, reportId))
|
||||
{
|
||||
ERROR_LOG(m_logger) << "Error while creating report!";
|
||||
m_reply.errorString(tr_lts("dds","Error while creating report"));
|
||||
m_reply.replyState(Core::FtReplyState::Error);
|
||||
m_reply.currentTime(QDateTime::currentMSecsSinceEpoch());
|
||||
m_ddsHandler->fts()->createModifyReportReply(m_updateReportCookie, m_reply);
|
||||
return;
|
||||
}
|
||||
|
||||
m_reply.id(reportId);
|
||||
|
||||
// Generate data per reportType
|
||||
switch (request.reportType().underlying())
|
||||
{
|
||||
case ReportManagement::ReportType::UnitPower:
|
||||
{
|
||||
ok = generateUnitPowerResult(request, reportId);
|
||||
break;
|
||||
}
|
||||
case ReportManagement::ReportType::ParticipantDistance:
|
||||
{
|
||||
ok = generateParticipantDistanceResult(request, reportId, m_ppmDtc);
|
||||
break;
|
||||
}
|
||||
case ReportManagement::ReportType::MineArea:
|
||||
{
|
||||
ok = generateMineAreaResult(request, reportId, m_aesDtc);
|
||||
break;
|
||||
}
|
||||
case ReportManagement::ReportType::Nbc:
|
||||
{
|
||||
ok = generateNbcResult(request, reportId, m_aesDtc);
|
||||
break;
|
||||
}
|
||||
case ReportManagement::ReportType::Firings:
|
||||
case ReportManagement::ReportType::ExplosiveDevice:
|
||||
{
|
||||
ok = generateFiringsResult(request, reportId);
|
||||
break;
|
||||
}
|
||||
case ReportManagement::ReportType::AirSupport:
|
||||
{
|
||||
ok = generateAirSupportResult(request, reportId);
|
||||
break;
|
||||
}
|
||||
case ReportManagement::ReportType::ChargeResupply:
|
||||
{
|
||||
ok = generateChargeResupplyResult(request, reportId);
|
||||
break;
|
||||
}
|
||||
case ReportManagement::ReportType::ChargeAdministration:
|
||||
{
|
||||
ok = generateChargeAdminResult(request, reportId);
|
||||
break;
|
||||
}
|
||||
case ReportManagement::ReportType::VehicleRepair:
|
||||
case ReportManagement::ReportType::Decontamination:
|
||||
{
|
||||
ok = generateMaintenanceResult(request, reportId, m_ppmDtc);
|
||||
break;
|
||||
}
|
||||
case ReportManagement::ReportType::Treatment:
|
||||
case ReportManagement::ReportType::TreatmentPriority:
|
||||
case ReportManagement::ReportType::TreatmentChain:
|
||||
{
|
||||
ok = generateTreatmentResult(request, reportId, m_ppmDtc);
|
||||
break;
|
||||
}
|
||||
case ReportManagement::ReportType::TreatmentTimeline:
|
||||
{
|
||||
ok = generateTreatmentTimelineResult(request, reportId, m_ppmDtc);
|
||||
break;
|
||||
}
|
||||
case ReportManagement::ReportType::BuildingDamage:
|
||||
{
|
||||
ok = generateBuildingDamageResult(request, reportId);
|
||||
break;
|
||||
}
|
||||
case ReportManagement::ReportType::SanitationMaterial:
|
||||
{
|
||||
ok = generateSanitationMaterialResult(request, reportId);
|
||||
break;
|
||||
}
|
||||
|
||||
case ReportManagement::ReportType_def::MedevacNineLiner:
|
||||
{
|
||||
ok = generateMedevacNineLinerResult(request, reportId);
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
{
|
||||
WARNING_LOG(m_logger) << "Report Type unknown, not generating.";
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!ok)
|
||||
{
|
||||
ObjectReportInfo *objRep = m_objReportMap.value(reportId);
|
||||
objRep->removeObject();
|
||||
m_objReportMap.remove(reportId);
|
||||
|
||||
ERROR_LOG(m_logger) << "Error generating report with type " << request.reportType();
|
||||
m_reply.errorString(tr_lts("dds", "Error generating report"));
|
||||
m_reply.replyState(Core::FtReplyState::Error);
|
||||
m_reply.currentTime(QDateTime::currentMSecsSinceEpoch());
|
||||
}
|
||||
else
|
||||
{
|
||||
m_reply.errorString(std::string());
|
||||
m_reply.replyState(Core::FtReplyState::Completed);
|
||||
m_reply.currentTime(QDateTime::currentMSecsSinceEpoch());
|
||||
}
|
||||
|
||||
m_ddsHandler->fts()->createModifyReportReply(m_updateReportCookie, m_reply);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
void HandlerReportData::onRemoveReportRequest(const rti::core::SampleIdentity &cookie,
|
||||
const Core::RemoveElementRequest &request)
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "onRemoveReportRequest " << request;
|
||||
|
||||
int reportId = request.id();
|
||||
|
||||
Core::FunctionReplyObject ret;
|
||||
ObjectReportInfo *ifs = m_objReportMap.value(reportId);
|
||||
if (ifs == nullptr)
|
||||
{
|
||||
ret = Core::FunctionReplyObject(request.id(), tr_lts("dds", "Report with id %1 not found")).arg(reportId);
|
||||
m_ddsHandler->fts()->removeReportReply(cookie, ret);
|
||||
return;
|
||||
}
|
||||
|
||||
ReportManagement::ReportType repType = ifs->getReportType();
|
||||
|
||||
ret = ifs->removeObject();
|
||||
|
||||
if (ret.error())
|
||||
ERROR_LOG(m_logger) << ret();
|
||||
else
|
||||
{
|
||||
// delete ObjectReportInfo
|
||||
delete ifs;
|
||||
m_objReportMap.remove(reportId);
|
||||
}
|
||||
|
||||
m_ddsHandler->fts()->removeReportReply(cookie, ret);
|
||||
|
||||
// remove generated data as well
|
||||
removeReportData(reportId, repType);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
bool HandlerReportData::removeReportData(int reportId, ReportType repType)
|
||||
{
|
||||
INFO_LOG(m_logger) << "IN removeReportData";
|
||||
|
||||
bool ok = true;
|
||||
|
||||
switch (repType.underlying())
|
||||
{
|
||||
case ReportManagement::ReportType::UnitPower:
|
||||
{
|
||||
ok = removeReportDataResult(reportId, QStringLiteral("rep_unit_power_result"));
|
||||
break;
|
||||
}
|
||||
case ReportManagement::ReportType::ParticipantDistance:
|
||||
{
|
||||
ok = removeReportDataResult(reportId, QStringLiteral("rep_participant_distance_result"));
|
||||
break;
|
||||
}
|
||||
case ReportManagement::ReportType::MineArea:
|
||||
{
|
||||
ok = removeReportDataResult(reportId, QStringLiteral("rep_mine_area_result"));
|
||||
break;
|
||||
}
|
||||
case ReportManagement::ReportType::Nbc:
|
||||
{
|
||||
ok = removeReportDataResult(reportId, QStringLiteral("rep_nbc_result"));
|
||||
break;
|
||||
}
|
||||
case ReportManagement::ReportType::Firings:
|
||||
case ReportManagement::ReportType::ExplosiveDevice:
|
||||
{
|
||||
ok = removeReportDataResult(reportId, QStringLiteral("rep_firings_result"));
|
||||
break;
|
||||
}
|
||||
case ReportManagement::ReportType::AirSupport:
|
||||
{
|
||||
ok = removeReportDataResult(reportId, QStringLiteral("rep_air_support_result"));
|
||||
break;
|
||||
}
|
||||
case ReportManagement::ReportType::ChargeResupply:
|
||||
{
|
||||
ok = removeReportDataResult(reportId, QStringLiteral("rep_charge_resupply_result"));
|
||||
break;
|
||||
}
|
||||
case ReportManagement::ReportType::ChargeAdministration:
|
||||
{
|
||||
ok = removeReportDataResult(reportId, QStringLiteral("rep_charge_administration"));
|
||||
break;
|
||||
}
|
||||
case ReportManagement::ReportType::VehicleRepair:
|
||||
case ReportManagement::ReportType::Decontamination:
|
||||
{
|
||||
ok = removeReportDataResult(reportId, QStringLiteral("rep_maintenance_result"));
|
||||
break;
|
||||
}
|
||||
case ReportManagement::ReportType::BuildingDamage:
|
||||
{
|
||||
ok = removeReportDataResult(reportId, QStringLiteral("rep_building_damage_result"));
|
||||
break;
|
||||
}
|
||||
case ReportManagement::ReportType::Treatment:
|
||||
case ReportManagement::ReportType::TreatmentPriority:
|
||||
case ReportManagement::ReportType::TreatmentChain:
|
||||
{
|
||||
ok = removeReportDataResult(reportId, QStringLiteral("rep_treatment_result"));
|
||||
break;
|
||||
}
|
||||
case ReportManagement::ReportType::TreatmentTimeline:
|
||||
{
|
||||
ok = removeReportDataResult(reportId, QStringLiteral("rep_treatment_timeline_result"));
|
||||
break;
|
||||
}
|
||||
case ReportManagement::ReportType::MedevacNineLiner:
|
||||
{
|
||||
ok = removeReportDataResult(reportId, QStringLiteral("rep_san_nine_liner"));
|
||||
break;
|
||||
}
|
||||
case ReportManagement::ReportType::SanitationMaterial:
|
||||
{
|
||||
ok = removeReportDataResult(reportId, QStringLiteral("rep_sanitation_material_result"));
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
WARNING_LOG(m_logger) << "Report Type unknown, cannot remove generated data";
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!ok)
|
||||
WARNING_LOG(m_logger) << "Could not remove old generated data for report id = " << reportId;
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------------------------------------------
|
||||
void HandlerReportData::onReportChangeStatusRequest(const rti::core::SampleIdentity &cookie,
|
||||
const ReportChangeStatusRequest &request)
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "onReportChangeStatusRequest " << request;
|
||||
ObjectReportInfo *ifs = m_objReportMap.value(request.id());
|
||||
if (ifs == nullptr)
|
||||
{
|
||||
Core::FunctionReplyObject ret = Core::FunctionReplyObject(request.id(), tr_lts("dds", "Report with id %1 not found")).arg(request.id());
|
||||
m_ddsHandler->fts()->reportChangeStatusReply(cookie, ret);
|
||||
return;
|
||||
}
|
||||
Core::FunctionReplyObject ret = ifs->changeStatus(request);
|
||||
if (ret.error())
|
||||
ERROR_LOG(m_logger) << ret();
|
||||
|
||||
m_ddsHandler->fts()->reportChangeStatusReply(cookie, ret);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
bool HandlerReportData::insertReportData(const CreateModifyReportRequest &request, qint32 &reportId)
|
||||
{
|
||||
Database::RepReport data;
|
||||
|
||||
data.name = QString::fromStdString(request.name());
|
||||
data.description = QString::fromStdString(request.description());
|
||||
data.partyId = request.partyId();
|
||||
data.startTime = request.startTime();
|
||||
data.endTime = request.endTime();
|
||||
data.reportTypeId = request.reportType();
|
||||
data.visualisationType = request.visualisationType();
|
||||
data.intervalTime = request.intervalTime();
|
||||
data.lastModified = request.lastModified();
|
||||
data.operatorId = request.operatorId();
|
||||
data.fileStatusId = request.fileStatus();
|
||||
// area
|
||||
data.width = request.width();
|
||||
data.height = request.height();
|
||||
data.position = QPointF(request.cornerBottomLeft().lon(), request.cornerBottomLeft().lat());
|
||||
|
||||
const auto participants = m_ppmDtc->participants();
|
||||
QJsonArray participantIdArray;
|
||||
QJsonArray participantNamesArray;
|
||||
for (int id : request.participantIds())
|
||||
{
|
||||
participantIdArray.append(QJsonValue(id));
|
||||
QJsonValue name = QJsonValue(m_ppmDtc->hierarchyFromParticipant(id, participants));
|
||||
participantNamesArray.append(name);
|
||||
}
|
||||
|
||||
QJsonArray superiorIdsArray;
|
||||
for (Superior sup : request.superiorIds())
|
||||
{
|
||||
QJsonObject jsonData;
|
||||
jsonData[QStringLiteral("participantId")] = sup.participantId();
|
||||
jsonData[QStringLiteral("superiorId")] = sup.superiorId();
|
||||
superiorIdsArray.append(jsonData);
|
||||
}
|
||||
|
||||
QJsonArray unitIdArray;
|
||||
QJsonArray unitNamesArray;
|
||||
for (int id : request.unitIds())
|
||||
{
|
||||
unitIdArray.append(QJsonValue(id));
|
||||
QJsonValue name = QJsonValue(m_ppmDtc->hierarchyFromParticipant(id, participants));
|
||||
unitNamesArray.append(name);
|
||||
}
|
||||
|
||||
QJsonArray partTypeArray;
|
||||
for (int id : request.participantTypes())
|
||||
partTypeArray.append(QJsonValue(id));
|
||||
|
||||
QJsonArray chargeTypeIdsArray;
|
||||
for (int id : request.chargeTypeIds())
|
||||
chargeTypeIdsArray.append(QJsonValue(id));
|
||||
|
||||
QJsonArray mineAreaIdsArray;
|
||||
QJsonArray mineAreaNamesArray;
|
||||
for (int id : request.mineAreaIds())
|
||||
{
|
||||
mineAreaIdsArray.append(QJsonValue(id));
|
||||
QJsonValue name = QJsonValue(QString::fromStdString(m_aesDtc->mineArea(id).name()));
|
||||
mineAreaNamesArray.append(name);
|
||||
}
|
||||
|
||||
QJsonArray nbcIdsArray;
|
||||
QJsonArray nbcNamesArray;
|
||||
for (int id : request.nbcIds())
|
||||
{
|
||||
nbcIdsArray.append(QJsonValue(id));
|
||||
QJsonValue name = QJsonValue(QString::fromStdString(m_aesDtc->bCContamination(id).name()));
|
||||
nbcNamesArray.append(name);
|
||||
}
|
||||
|
||||
QJsonArray effectSourceArray;
|
||||
for (const ProjectDataManagement::EffectSource &es : request.effectSources())
|
||||
effectSourceArray.append(QJsonValue(es.underlying()));
|
||||
|
||||
QJsonObject obj;
|
||||
obj[QStringLiteral("participantIds")] = participantIdArray;
|
||||
obj[QStringLiteral("participantNames")] = participantNamesArray;
|
||||
obj[QStringLiteral("unitIds")] = unitIdArray;
|
||||
obj[QStringLiteral("superiorIds")] = superiorIdsArray;
|
||||
obj[QStringLiteral("unitNames")] = unitNamesArray;
|
||||
obj[QStringLiteral("participantTypes")] = partTypeArray;
|
||||
obj[QStringLiteral("groupByParty")] = request.groupByParty();
|
||||
obj[QStringLiteral("chargeTypeIds")] = chargeTypeIdsArray;
|
||||
obj[QStringLiteral("mineAreaIds")] = mineAreaIdsArray;
|
||||
obj[QStringLiteral("mineAreaNames")] = mineAreaNamesArray;
|
||||
obj[QStringLiteral("nbcIds")] = nbcIdsArray;
|
||||
obj[QStringLiteral("nbcNames")] = nbcNamesArray;
|
||||
obj[QStringLiteral("effectSources")] = effectSourceArray;
|
||||
|
||||
data.parameter = QString::fromUtf8(QJsonDocument(obj).toJson());
|
||||
|
||||
if (reportId == 0)
|
||||
{
|
||||
ObjectReportInfo *ifs(new ObjectReportInfo(m_ddsHandler, m_db, this));
|
||||
Core::FunctionReplyObject ret = ifs->createObject(data);
|
||||
if (ret.error())
|
||||
{
|
||||
delete ifs;
|
||||
ERROR_LOG(m_logger) << ret();
|
||||
return false;
|
||||
}
|
||||
m_objReportMap.insert(ifs->getId(), ifs);
|
||||
data.id = ifs->getId();
|
||||
reportId = ifs->getId();
|
||||
}
|
||||
else
|
||||
{
|
||||
data.id = reportId;
|
||||
ObjectReportInfo *ifs = m_objReportMap.value(reportId);
|
||||
if (!ifs)
|
||||
{
|
||||
ERROR_LOG(m_logger) << "Report not found - report id = " << reportId;
|
||||
return false;
|
||||
}
|
||||
Core::FunctionReplyObject ret = ifs->updateObject(data);
|
||||
if (ret.error())
|
||||
{
|
||||
delete ifs;
|
||||
ERROR_LOG(m_logger) << ret();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------------
|
||||
bool HandlerReportData::removeReportDataResult(int reportId, const QString &tableName)
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "Start removeReportDataResult";
|
||||
|
||||
DBTransaction trans(m_db->database());
|
||||
NSqlQuery q(m_db->database());
|
||||
|
||||
QString stmt = QStringLiteral("DELETE FROM ") + tableName + QStringLiteral(" WHERE report_id = :reportId");
|
||||
|
||||
q.prepare(stmt);
|
||||
q.bindValue(QStringLiteral(":reportId"), reportId);
|
||||
|
||||
DEBUG_LOG(m_logger) << "Statement: " << stmt;
|
||||
|
||||
if (!q.exec())
|
||||
{
|
||||
ERROR_LOG(m_logger) << "Error removing report data for report id = " << reportId;
|
||||
return false;
|
||||
}
|
||||
|
||||
trans.commit();
|
||||
|
||||
DEBUG_LOG(m_logger) << " END removeReportDataResult";
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------------------
|
||||
void HandlerReportData::checkElapsedTimer(QElapsedTimer &t)
|
||||
{
|
||||
TRACE_LOG(m_logger) << "checkElapsedTimer ...";
|
||||
if (t.elapsed() > 5 * 1000)
|
||||
{
|
||||
t.start();
|
||||
updateReportReply();
|
||||
}
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------------
|
||||
void HandlerReportData::updateReportReply()
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "updateReportReply: " << m_reply;
|
||||
m_reply.currentTime(QDateTime::currentMSecsSinceEpoch());
|
||||
m_ddsHandler->fts()->createModifyReportReply(m_updateReportCookie, m_reply);
|
||||
m_ddsHandler->pacemaker()->publishState();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,323 @@
|
||||
/**
|
||||
* Handler for report data (all)
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
* Created by Hanna E. Rathje, SLSE, 2016-12-20
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "dds_handler.h"
|
||||
#include "logger.h"
|
||||
#include "object_report_info.h"
|
||||
#include "rep_db.h"
|
||||
|
||||
#include <AreaEffectSimulation/aes_dtc.h>
|
||||
#include <ParticipantManagement/ppm_dtc.h>
|
||||
|
||||
#include <QElapsedTimer>
|
||||
#include <QMap>
|
||||
#include <QObject>
|
||||
|
||||
// ----------------------------------------------------------------------------------------------------------------------
|
||||
namespace ReportManagement
|
||||
{
|
||||
// Report ChargeResupply
|
||||
struct ChargeResupplyResult : Database::RepChargeResupplyResult
|
||||
{
|
||||
int participantId = 0;
|
||||
int partyId = 0;
|
||||
};
|
||||
|
||||
using time_map_t = QMap<time_t, Database::RepChargeResupplyData>;
|
||||
// QMap<chargeTypeId, time_map_t>
|
||||
using charge_type_map_t = QMap<int, time_map_t>;
|
||||
// QMap<GearId, charge_type_map_t>
|
||||
using gear_map_t = QMap<int, charge_type_map_t>;
|
||||
// QMap<ParticipantId, gear_map_t>
|
||||
using participant_map_t = QMap<int, gear_map_t>;
|
||||
|
||||
// QMap<participantId, QVector<Database::RepChargeResupplyData>
|
||||
using participant_map2_t = QMap<int, QVector<Database::RepChargeResupplyData>>;
|
||||
// QMap<chargeTypeId, Database::RepChargeResupplyResult
|
||||
using charge_type_map2_t = QMap<int, ChargeResupplyResult>;
|
||||
|
||||
// Report UnitPower:
|
||||
struct ParticipantKeyData
|
||||
{
|
||||
int participantId = 0;
|
||||
int key = 0;
|
||||
bool ready = false;
|
||||
int vulnerabilityState = 0;
|
||||
};
|
||||
|
||||
struct UnitPowerData : public ParticipantKeyData
|
||||
{
|
||||
qint64 eventTime = 0;
|
||||
};
|
||||
|
||||
// Report ParticipantDistance:
|
||||
struct DataParticipantPosition
|
||||
{
|
||||
int participantId = 0;
|
||||
int participantTypeId = 0;
|
||||
qint64 timestamp = 0;
|
||||
};
|
||||
|
||||
// Report Firings:
|
||||
struct FiringData
|
||||
{
|
||||
qint64 startTime = 0;
|
||||
qint64 endTime = 0;
|
||||
int firings = 0;
|
||||
int hits = 0;
|
||||
int hitsFriendlyFire = 0;
|
||||
};
|
||||
|
||||
// Report AirSupport:
|
||||
struct AirSupportImpactData
|
||||
{
|
||||
int aesId = 0;
|
||||
QString aesName;
|
||||
int chargeTypeId = 0;
|
||||
int impacts = 0;
|
||||
};
|
||||
|
||||
// Report Charge Administration:
|
||||
struct ChargeTypeData
|
||||
{
|
||||
int chargeTypeId = 0;
|
||||
ProjectDataManagement::EffectSource effectSourceId = ProjectDataManagement::EffectSource::get_default();
|
||||
int chargeQuantity = 0;
|
||||
int usedCharge = 0;
|
||||
int chargeAddition = 0;
|
||||
int chargeQuantityStart = 0;
|
||||
int usedChargeStart = 0;
|
||||
int chargePlanned = 0;
|
||||
// int chargeAvailable = 0;
|
||||
};
|
||||
|
||||
// Report Vehicle Repair & Decontamination :
|
||||
struct MaintenanceData
|
||||
{
|
||||
int participantId = 0;
|
||||
int participantTypeId = 0;
|
||||
qint64 time_event = 0;
|
||||
qint64 time_position_changed = 0;
|
||||
qint64 time_vulnerability = 0;
|
||||
// qint64 time_sanitation = 0;
|
||||
// bool success_sanitation = false;
|
||||
// int vitality = 0;
|
||||
};
|
||||
|
||||
// Report Building Damage:
|
||||
struct BuildingDamageData
|
||||
{
|
||||
int buildingId = 0;
|
||||
qint64 timePoint = 0;
|
||||
double buildingDamagePercent = 0;
|
||||
QByteArray roomStates;
|
||||
int damages[5] = {0, 0, 0, 0, 0};
|
||||
};
|
||||
|
||||
// Report SanitationMaterial:
|
||||
struct SanitationMaterialData
|
||||
{
|
||||
int uniqueId = 0;
|
||||
int materialId = 0;
|
||||
int amountStart = 0;
|
||||
int resupplied = 0;
|
||||
int used = 0;
|
||||
int amount = 0;
|
||||
int qualification = 0;
|
||||
int duration = 0;
|
||||
};
|
||||
|
||||
// Report Treatment / TreatmentPriority / old TreatmentChain
|
||||
struct TreatmentData
|
||||
{
|
||||
int participantId = 0;
|
||||
int participantTypeId = 0;
|
||||
qint64 time_enter_area = 0;
|
||||
qint64 time_position_changed = 0;
|
||||
qint64 time_vulnerability = 0;
|
||||
qint64 time_vitality = 0;
|
||||
qint64 time_treatment = 0;
|
||||
qint64 time_nine_liner = 0;
|
||||
int sanitation_result = 0;
|
||||
int sanitation_evaluation = 0;
|
||||
qint64 sanitation_procedures_taken;
|
||||
int qualification = 0;
|
||||
int priority = 0;
|
||||
int vulnerability = 0;
|
||||
int vulnerabilityState = 0;
|
||||
int vitality = 0;
|
||||
double pos_x = 0.00;
|
||||
double pos_y = 0.00;
|
||||
double pos_x_m = 0.00;
|
||||
double pos_y_m = 0.00;
|
||||
int area_id;
|
||||
QString area_name;
|
||||
bool kIAAfterWIA = false;
|
||||
};
|
||||
|
||||
// Report TreatmentTimeline
|
||||
struct TreatmentTimelineData
|
||||
{
|
||||
int participantId = 0;
|
||||
int participantTypeId = 0;
|
||||
qint64 eventTime = 0;
|
||||
int eventTypeId = 0;
|
||||
int vulnerability = 0;
|
||||
int vulnerabilityState = 0;
|
||||
int vitality = 0;
|
||||
QString properties;
|
||||
};
|
||||
|
||||
// ----------------------------------------------------------------------------------------------------------------------
|
||||
class HandlerReportData final
|
||||
: public QObject
|
||||
, protected Interface::Fts::CreateModifyReportRequestHandler
|
||||
, protected Interface::Fts::RemoveReportRequestHandler
|
||||
, protected Interface::Fts::ReportChangeStatusRequestHandler
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit HandlerReportData(const std::shared_ptr<DdsHandler> &ddsHandler, const std::shared_ptr<DatabaseInterface> &db);
|
||||
|
||||
/**
|
||||
* Initialize the handler to manage information from infrastructure management
|
||||
*/
|
||||
bool init();
|
||||
|
||||
private: // methods
|
||||
static QString intVecToString(const std::vector<int> &intVec);
|
||||
void onCreateModifyReportRequest(const rti::core::SampleIdentity &cookie, const CreateModifyReportRequest &request) override final;
|
||||
void onRemoveReportRequest(const rti::core::SampleIdentity &cookie, const Core::RemoveElementRequest &request) override final;
|
||||
void onReportChangeStatusRequest(const rti::core::SampleIdentity &cookie, const ReportChangeStatusRequest &request) override final;
|
||||
bool insertReportData(const CreateModifyReportRequest &request, qint32 &reportId);
|
||||
|
||||
// UnitPower
|
||||
bool generateUnitPowerResult(const CreateModifyReportRequest &request, qint32 reportId);
|
||||
QMap<qint32, ParticipantKeyData> generateUnitPowerResultPerInterval(const QMap<qint32, ParticipantKeyData> &resultMapPreviousInterval,
|
||||
const QVector<UnitPowerData> &dataVec,
|
||||
int &startIndex,
|
||||
qint64 intervalEnd);
|
||||
|
||||
bool insertResultMap(qint32 reportId, qint64 intervalStart, qint64 intervalEnd, const QMap<int, QMap<int, int>> &sumMap);
|
||||
|
||||
bool getParticipantInitial(const QVector<int> &participantIds,
|
||||
qint64 startTime,
|
||||
qint64 endTime,
|
||||
const QString &keyStr,
|
||||
QMap<qint32, ParticipantKeyData> &initialParticipantStates);
|
||||
|
||||
// remove generated data for modify & remove report
|
||||
bool removeReportDataResult(int reportId, const QString &tableName);
|
||||
bool removeReportData(int reportId, ReportType repType);
|
||||
|
||||
// ParticipantDistance
|
||||
bool generateParticipantDistanceResult(const CreateModifyReportRequest &request, int reportId, const std::shared_ptr<ParticipantManagement::Interface::Dtc> &ppmDtc);
|
||||
|
||||
// MineArea
|
||||
bool generateMineAreaResult(const CreateModifyReportRequest &request, int reportId, const std::shared_ptr<AreaEffectSimulation::Interface::Dtc> &aesDtc);
|
||||
|
||||
// NBC
|
||||
bool generateNbcResult(const CreateModifyReportRequest &request, int reportId, const std::shared_ptr<AreaEffectSimulation::Interface::Dtc> &aesDtc);
|
||||
|
||||
// Report Firings
|
||||
bool generateFiringsResult(const CreateModifyReportRequest &request, int reportId);
|
||||
|
||||
// Report AirSupport
|
||||
bool generateAirSupportResult(const CreateModifyReportRequest &request, int reportId);
|
||||
|
||||
// Report ChargeResupply
|
||||
bool generateChargeResupplyResult(const CreateModifyReportRequest &request, int reportId);
|
||||
static bool contains(const std::vector<int32_t> &vector, int32_t value);
|
||||
int getStart(int partId, int gearId, int chargeTypeId, qint64 before, qint64 after);
|
||||
void getLastGearSetting(int participantId, const std::vector<int32_t> &chargeTypeIds, qint64 startTime);
|
||||
|
||||
// Report ChargeAdministration
|
||||
bool generateChargeAdminResult(const CreateModifyReportRequest &request, int reportId);
|
||||
bool calculateStock(int chargeTypeId, const ProjectDataManagement::EffectSource &es, qint64 startTime, qint64 endTime, int partyId, int reportId);
|
||||
|
||||
// Report VehicleRepair & Decontamination
|
||||
bool generateMaintenanceResult(const CreateModifyReportRequest &request, int reportId, const std::shared_ptr<ParticipantManagement::Interface::Dtc> &ppmDtc);
|
||||
|
||||
// Report BuildingDamage
|
||||
bool generateBuildingDamageResult(const CreateModifyReportRequest &request, int reportId);
|
||||
void readRoomStates(BuildingDamageData &bdd);
|
||||
|
||||
// Report Sanitation Material
|
||||
bool generateSanitationMaterialResult(const CreateModifyReportRequest &request, int reportId);
|
||||
bool calculateSanitationMaterialStock(int uniqueId, int materialId, qint64 startTime, qint64 endTime, int partyId, int reportId, int qualif);
|
||||
|
||||
// Report Sanitation
|
||||
QPair<int, qint64> getNextFunctionalAreaEntry(int eqNo, qint64 vbgTime);
|
||||
qint64 get9LinerTime(int equipmentNumber, qint64 timeVulnerability);
|
||||
// qint64 getTimeTransport(int equipmentNumber, qint64 timeVulnerability);
|
||||
qint64 getPosChangedTime(int equipmentNumber, qint64 timeVulnerability);
|
||||
bool getPriorityCorrect(int participantId, qint64 timeTreatment, int priority);
|
||||
|
||||
// Report MedevacNineLiner
|
||||
bool generateMedevacNineLinerResult(const CreateModifyReportRequest &request, int reportId);
|
||||
|
||||
// Report Treatment / TreatmentPriority / TreatmentChain
|
||||
bool generateTreatmentResult(const CreateModifyReportRequest &request, int reportId, const std::shared_ptr<ParticipantManagement::Interface::Dtc> &ppmDtc);
|
||||
qint64 sinceWhenVitality(int participantId, int vitality, qint64 currTime);
|
||||
qint64 sinceWhenVulnerability(int participantId, int vulnerability, qint64 currTime);
|
||||
bool checkVulnerabilityStateWIA(int participantId, qint64 currTime);
|
||||
|
||||
// Report TreatmentTimeline
|
||||
bool generateTreatmentTimelineResult(const CreateModifyReportRequest &request, int reportId, const std::shared_ptr<ParticipantManagement::Interface::Dtc> &ppmDtc);
|
||||
|
||||
void checkElapsedTimer(QElapsedTimer &t);
|
||||
void updateReportReply();
|
||||
|
||||
private: // attributes
|
||||
std::shared_ptr<DdsHandler> m_ddsHandler;
|
||||
std::shared_ptr<DatabaseInterface> m_db;
|
||||
|
||||
// needed to save participant names and area effects names in report
|
||||
std::shared_ptr<ParticipantManagement::Interface::Dtc> m_ppmDtc;
|
||||
std::shared_ptr<AreaEffectSimulation::Interface::Dtc> m_aesDtc;
|
||||
|
||||
QMap<int, ObjectReportInfo *> m_objReportMap;
|
||||
|
||||
// Report ParticipantDistance:
|
||||
|
||||
// <participantId,startPosition>
|
||||
QMap<int, DataParticipantPosition> m_startInfo;
|
||||
// <participantId, distance>
|
||||
QMap<int, double> m_distanceMap;
|
||||
// <participantTypeId, <participantId, distance>>
|
||||
QMap<int, QMap<int, double>> m_distanceMapType;
|
||||
|
||||
// Report Firings:
|
||||
|
||||
// QMap<participantId, gear_map_t > see typedefs
|
||||
participant_map_t m_crPartMap;
|
||||
// QMap<gearId, participant_map2_t>
|
||||
QMap<int, participant_map2_t> m_crGear;
|
||||
// QMap<int, charge_type_map2_t>
|
||||
QMap<int, charge_type_map2_t> m_crResData;
|
||||
|
||||
// Report Vehicle Repair & Decontamination ( = Maintenance)
|
||||
QVector<MaintenanceData> m_maintenanceData;
|
||||
|
||||
// Reports Treatment
|
||||
QVector<TreatmentData> m_treatmentData;
|
||||
|
||||
// Report TreatmentTimeline
|
||||
QVector<TreatmentTimelineData> m_treatmentTimelineData;
|
||||
|
||||
// Report Building Damage
|
||||
QVector<BuildingDamageData> m_buildingDamageData;
|
||||
|
||||
rti::core::SampleIdentity m_updateReportCookie;
|
||||
UpdateReportReply m_reply;
|
||||
|
||||
LOGGER_T m_logger;
|
||||
};
|
||||
} // namespace ReportManagement
|
||||
@@ -0,0 +1,144 @@
|
||||
/**
|
||||
* Handler for report Firings
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
* Created by Hanna E. Rathje, SLSE, 2016-12-20
|
||||
*/
|
||||
|
||||
#include "handler_report_data.h"
|
||||
|
||||
#include <ngldb/nsqlquery.h>
|
||||
#include <ngldb/dbtransaction.h>
|
||||
|
||||
using namespace ReportManagement;
|
||||
|
||||
bool HandlerReportData::generateFiringsResult(const CreateModifyReportRequest &request, int reportId)
|
||||
{
|
||||
INFO_LOG(m_logger) << "Start generateFiringsResult - reportId: " << reportId;
|
||||
|
||||
if (request.chargeTypeIds().size() <= 0 || request.participantIds().size() <= 0 || request.participantTypes().size() <= 0)
|
||||
{
|
||||
ERROR_LOG(m_logger) << "No elements selected to generate the report";
|
||||
DEBUG_LOG(m_logger) << "request.chargeTypeIds().size()" << request.chargeTypeIds().size();
|
||||
DEBUG_LOG(m_logger) << "request.participantIds().size()" << request.participantIds().size();
|
||||
DEBUG_LOG(m_logger) << "request.participantTypes().size()" << request.participantTypes().size();
|
||||
return false;
|
||||
}
|
||||
|
||||
DBTransaction trans(m_db->database());
|
||||
NSqlQuery qSelect(m_db->database());
|
||||
NSqlQuery qInsert(m_db->database());
|
||||
QString stmtInsert, stmtSelect;
|
||||
|
||||
stmtSelect = QStringLiteral("SELECT vulnerability_state, hit, hit_friendly_fire "
|
||||
" FROM rep_firings_data "
|
||||
" WHERE party_id = :partyId AND "
|
||||
"(event_time BETWEEN :startTime AND :endTime) AND "
|
||||
" charge_type_id = :chargeId AND ");
|
||||
|
||||
if (request.participantTypes().size() > 0)
|
||||
{
|
||||
const QString pTypeIdsStr = intVecToString(request.participantTypes());
|
||||
stmtSelect += QStringLiteral(" participant_type_id IN (%1) ").arg(pTypeIdsStr);
|
||||
}
|
||||
|
||||
stmtSelect += QStringLiteral(" ORDER BY vulnerability_state");
|
||||
|
||||
if (!qSelect.prepare(stmtSelect))
|
||||
{
|
||||
ERROR_LOG(m_logger) << "Error preparing select statement: " << stmtSelect;
|
||||
return false;
|
||||
}
|
||||
|
||||
stmtInsert = QStringLiteral("INSERT INTO rep_firings_result (report_id, start_time, end_time, charge_type_id, vulnerability_state, firings, hits, hits_friendly_fire) "
|
||||
"VALUES (:reportId, :start, :end, :chargeId, :vbg, :firings, :hit, :hit_ff)");
|
||||
|
||||
if (!qInsert.prepare(stmtInsert))
|
||||
{
|
||||
ERROR_LOG(m_logger) << "Error preparing stmt: " << stmtInsert;
|
||||
return false;
|
||||
}
|
||||
|
||||
qInsert.bindValue(QStringLiteral(":reportId"), reportId);
|
||||
|
||||
QElapsedTimer timeoutTimer;
|
||||
timeoutTimer.start();
|
||||
for (const int &chargeId : qAsConst(request.chargeTypeIds()))
|
||||
{
|
||||
if (chargeId == 0) continue; // skip 0
|
||||
|
||||
qInsert.bindValue(QStringLiteral(":chargeId"), chargeId);
|
||||
|
||||
DEBUG_LOG(m_logger) << "Charge id = " << chargeId;
|
||||
|
||||
qint64 t1;
|
||||
t1 = request.startTime();
|
||||
while (t1 <= request.endTime())
|
||||
{
|
||||
checkElapsedTimer(timeoutTimer);
|
||||
qint64 t2 = qMin(qMax(t1, t1 + request.intervalTime() - 1), request.endTime());
|
||||
if (request.intervalTime() == 0) // || request.visualisationType() == VisualisationType::Table)
|
||||
t2 = request.endTime();
|
||||
|
||||
qInsert.bindValue(QStringLiteral(":start"), t1);
|
||||
qInsert.bindValue(QStringLiteral(":end"), t2);
|
||||
|
||||
DEBUG_LOG(m_logger) << " Inserting: reportId, start, end, interval = " << reportId << " , " << t1 << " , " << t2 << " , "
|
||||
<< request.intervalTime();
|
||||
|
||||
qSelect.bindValue(QStringLiteral(":partyId"), request.partyId());
|
||||
qSelect.bindValue(QStringLiteral(":chargeId"), chargeId);
|
||||
qSelect.bindValue(QStringLiteral(":startTime"), t1);
|
||||
qSelect.bindValue(QStringLiteral(":endTime"), t2);
|
||||
|
||||
QMap<int, QVector<int>> vbgMap;
|
||||
|
||||
if (!qSelect.exec())
|
||||
{
|
||||
ERROR_LOG(m_logger) << "Error executing stmt: " << stmtSelect;
|
||||
return false;
|
||||
}
|
||||
|
||||
while (qSelect.next())
|
||||
{
|
||||
int vbg = qSelect.value(0).toInt();
|
||||
if (!vbgMap.contains(vbg))
|
||||
vbgMap.insert(vbg, {0, 0, 0});
|
||||
if (vbg == ProjectDataManagement::VulnerabilityState_def::CombatReady ||
|
||||
vbg == ProjectDataManagement::VulnerabilityState_def::NearMiss ||
|
||||
vbg == ProjectDataManagement::VulnerabilityState_def::HitWithNoEffect)
|
||||
vbgMap[vbg][0] ++; // firings
|
||||
|
||||
vbgMap[vbg][1] += qSelect.value(1).toInt(); // hits
|
||||
vbgMap[vbg][2] += qSelect.value(2).toInt(); // hits ff
|
||||
|
||||
}
|
||||
|
||||
for (auto it = vbgMap.begin(); it != vbgMap.end(); ++it)
|
||||
{
|
||||
qInsert.bindValue(QStringLiteral(":vbg"), it.key());
|
||||
qInsert.bindValue(QStringLiteral(":firings"), it.value()[0]);
|
||||
qInsert.bindValue(QStringLiteral(":hit"), it.value()[1]);
|
||||
qInsert.bindValue(QStringLiteral(":hit_ff"), it.value()[2]);
|
||||
DEBUG_LOG(m_logger) << " Inserting report id, charge type id = " << reportId << " , " << chargeId;
|
||||
DEBUG_LOG(m_logger) << " Inserting vbg, firings, hits, hits ff = " << it.key() << ", " << it.value()[0] << " , " << it.value()[1] << " , " << it.value()[2];
|
||||
if (!qInsert.exec())
|
||||
{
|
||||
ERROR_LOG(m_logger) << "Error inserting report id, charge type id, VBG = " << reportId << " , " << chargeId << " , " << it.key();
|
||||
trans.rollback();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
t1 += request.intervalTime();
|
||||
if (request.intervalTime() == 0) // || request.visualisationType() == VisualisationType::Table)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
trans.commit();
|
||||
|
||||
INFO_LOG(m_logger) << " END generateFiringsResult";
|
||||
return true;
|
||||
}
|
||||
@@ -0,0 +1,550 @@
|
||||
/**
|
||||
* Handler for report get data
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
* Created by Hanna E. Rathje, SLSE, 2016-12-20
|
||||
*/
|
||||
|
||||
#include "handler_report_get_data.h"
|
||||
#include "rep_db.h"
|
||||
|
||||
#include "settings.h"
|
||||
|
||||
#include <LtsUtilsCore/dds_vector.h>
|
||||
#include <ProjectDataManagement/pdm.hpp>
|
||||
|
||||
#include <QJsonArray>
|
||||
#include <QJsonDocument>
|
||||
#include <QJsonObject>
|
||||
#include <QSet>
|
||||
#include <ngldb/nsqlquery.h>
|
||||
|
||||
using namespace ReportManagement;
|
||||
//-----------------------------------------------------------------------------
|
||||
HandlerReportGetData::HandlerReportGetData(const std::shared_ptr<DdsHandler> &ddsHandler, const std::shared_ptr<DatabaseInterface> &db)
|
||||
: Interface::Fts::GetReportDataRequestHandler(ddsHandler->fts())
|
||||
, m_ddsHandler(ddsHandler)
|
||||
, m_db(db)
|
||||
, m_logger(getLogger("HandlerReportGetData"))
|
||||
{
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
HandlerReportGetData::~HandlerReportGetData() {}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
bool HandlerReportGetData::init() { return true; }
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
void HandlerReportGetData::onGetReportDataRequest(const rti::core::SampleIdentity &cookie, const GetReportDataRequest &request)
|
||||
{
|
||||
GetReportDataReply ret = getReportDataRequest(request);
|
||||
if (ret.errorString().size() != 0)
|
||||
{
|
||||
Core::FunctionReplyObject fro(ret.id(), ret.errorString(), ret.errorParams());
|
||||
WARNING_LOG(m_logger) << "error: " << fro();
|
||||
}
|
||||
m_ddsHandler->fts()->getReportDataReply(cookie, ret);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
GetReportDataReply HandlerReportGetData::getReportDataRequest(const GetReportDataRequest &request)
|
||||
{
|
||||
INFO_LOG(m_logger) << "IN onGetReportDataRequest";
|
||||
|
||||
// Get data per reportType
|
||||
QByteArray reportData;
|
||||
switch (request.reportType().underlying())
|
||||
{
|
||||
case ReportManagement::ReportType::UnitPower:
|
||||
reportData = getUnitPowerResult(request.reportId());
|
||||
break;
|
||||
case ReportManagement::ReportType::ParticipantDistance:
|
||||
reportData = getParticipantDistanceResult(request.reportId());
|
||||
break;
|
||||
case ReportManagement::ReportType::MineArea:
|
||||
reportData = getMineAreaResult(request.reportId());
|
||||
break;
|
||||
case ReportManagement::ReportType::Nbc:
|
||||
reportData = getNbcResult(request.reportId());
|
||||
break;
|
||||
case ReportManagement::ReportType::Firings:
|
||||
case ReportManagement::ReportType::ExplosiveDevice:
|
||||
reportData = getFiringsResult(request.reportId());
|
||||
break;
|
||||
case ReportManagement::ReportType::AirSupport:
|
||||
reportData = getAirSupportResult(request.reportId());
|
||||
break;
|
||||
|
||||
case ReportManagement::ReportType::ChargeResupply:
|
||||
reportData = getChargeResupplyResult(request.reportId());
|
||||
break;
|
||||
case ReportManagement::ReportType::ChargeAdministration:
|
||||
reportData = getChargeAdminResult(request.reportId());
|
||||
break;
|
||||
case ReportManagement::ReportType::VehicleRepair:
|
||||
case ReportManagement::ReportType::Decontamination:
|
||||
reportData = getMaintenanceResult(request.reportId());
|
||||
break;
|
||||
case ReportManagement::ReportType::BuildingDamage:
|
||||
reportData = getBuildingDamageResult(request.reportId());
|
||||
break;
|
||||
case ReportManagement::ReportType::SanitationMaterial:
|
||||
reportData = getSanitationMaterialResult(request.reportId());
|
||||
break;
|
||||
case ReportManagement::ReportType::MedevacNineLiner:
|
||||
reportData = getSanNineLinerResult(request.reportId());
|
||||
break;
|
||||
case ReportManagement::ReportType::Treatment:
|
||||
case ReportManagement::ReportType::TreatmentPriority:
|
||||
case ReportManagement::ReportType::TreatmentChain:
|
||||
reportData = getTreatmentResult(request.reportId());
|
||||
break;
|
||||
case ReportManagement::ReportType::TreatmentTimeline:
|
||||
reportData = getTreatmentTimelineResult(request.reportId());
|
||||
break;
|
||||
default:
|
||||
WARNING_LOG(m_logger) << "Report Type unknown, no generating.";
|
||||
break;
|
||||
}
|
||||
|
||||
GetReportDataReply ret;
|
||||
ret.id(request.reportId());
|
||||
|
||||
if (reportData.isEmpty())
|
||||
{
|
||||
Core::FunctionReplyObject fro = Core::FunctionReplyObject(tr_lts("dds", "No data for this report (report type: %1)")).arg(request.reportType().underlying());
|
||||
ret.errorString(fro.str());
|
||||
ret.errorParams(fro.args());
|
||||
}
|
||||
else
|
||||
ret.reportData(LtsUtils::convert<std::vector<uint8_t>>(reportData));
|
||||
return ret;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
QByteArray HandlerReportGetData::getUnitPowerResult(int reportId) const
|
||||
{
|
||||
QJsonArray array;
|
||||
auto cbData = [&array](const Database::RepUnitPowerResult &data)
|
||||
{
|
||||
QJsonObject object;
|
||||
|
||||
object.insert(QLatin1String("id"), data.id);
|
||||
object.insert(QLatin1String("group_id"), data.groupId);
|
||||
object.insert(QLatin1String("start_time"), data.startTime);
|
||||
object.insert(QLatin1String("end_time"), data.endTime);
|
||||
object.insert(QLatin1String("ready"), data.ready);
|
||||
object.insert(QLatin1String("not_ready"), data.notReady);
|
||||
object.insert(QLatin1String("vulnerability_state1"), data.vulnerabilityState1);
|
||||
object.insert(QLatin1String("vulnerability_state2"), data.vulnerabilityState2);
|
||||
object.insert(QLatin1String("vulnerability_state3"), data.vulnerabilityState3);
|
||||
object.insert(QLatin1String("vulnerability_state4"), data.vulnerabilityState4);
|
||||
object.insert(QLatin1String("vulnerability_state5"), data.vulnerabilityState5);
|
||||
object.insert(QLatin1String("vulnerability_state6"), data.vulnerabilityState6);
|
||||
object.insert(QLatin1String("vulnerability_state7"), data.vulnerabilityState7);
|
||||
object.insert(QLatin1String("vulnerability_state8"), data.vulnerabilityState8);
|
||||
object.insert(QLatin1String("vulnerability_state9"), data.vulnerabilityState9);
|
||||
object.insert(QLatin1String("vulnerability_state10"), data.vulnerabilityState10);
|
||||
object.insert(QLatin1String("vulnerability_state11"), data.vulnerabilityState11);
|
||||
|
||||
array.append(object);
|
||||
};
|
||||
if (!m_db->selectByReportId(cbData, reportId))
|
||||
return QByteArray();
|
||||
|
||||
QJsonDocument doc(array);
|
||||
return doc.toBinaryData();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
QByteArray HandlerReportGetData::getParticipantDistanceResult(int reportId) const
|
||||
{
|
||||
QJsonArray array;
|
||||
auto cbData = [&array](const Database::RepParticipantDistanceResult &data)
|
||||
{
|
||||
QJsonObject object;
|
||||
|
||||
object.insert(QLatin1String("id"), data.id);
|
||||
object.insert(QLatin1String("party_id"), data.partyId);
|
||||
object.insert(QLatin1String("participant_type_id"), data.participantTypeId);
|
||||
object.insert(QLatin1String("participant_id"), data.participantId);
|
||||
object.insert(QLatin1String("participant_name"), data.participantName);
|
||||
object.insert(QLatin1String("participant_equipment_number"), data.participantEquipmentNumber);
|
||||
object.insert(QLatin1String("distance"), data.distance);
|
||||
|
||||
array.append(object);
|
||||
};
|
||||
if (!m_db->selectByReportId(cbData, reportId))
|
||||
return QByteArray();
|
||||
|
||||
QJsonDocument doc(array);
|
||||
return doc.toBinaryData();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
QByteArray HandlerReportGetData::getMineAreaResult(int reportId) const
|
||||
{
|
||||
QJsonArray array;
|
||||
auto cbData = [&array](const Database::RepMineAreaResult &data)
|
||||
{
|
||||
QJsonObject object;
|
||||
|
||||
object.insert(QLatin1String("id"), data.id);
|
||||
object.insert(QLatin1String("mine_area_id"), data.mineAreaId);
|
||||
object.insert(QLatin1String("mine_area_name"), data.mineAreaName);
|
||||
object.insert(QLatin1String("participant_type_id"), data.participantTypeId);
|
||||
object.insert(QLatin1String("hit"), data.hit);
|
||||
object.insert(QLatin1String("hit_friendly_fire"), data.hitFriendlyFire);
|
||||
|
||||
array.append(object);
|
||||
};
|
||||
if (!m_db->selectByReportId(cbData, reportId))
|
||||
return QByteArray();
|
||||
|
||||
QJsonDocument doc(array);
|
||||
return doc.toBinaryData();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
QByteArray HandlerReportGetData::getNbcResult(int reportId) const
|
||||
{
|
||||
QJsonArray array;
|
||||
auto cbData = [&array](const Database::RepNbcResult &data)
|
||||
{
|
||||
QJsonObject object;
|
||||
|
||||
object.insert(QLatin1String("id"), data.id);
|
||||
object.insert(QLatin1String("nbc_id"), data.nbcId);
|
||||
object.insert(QLatin1String("nbc_name"), data.nbcName);
|
||||
object.insert(QLatin1String("aes_type"), data.aesType);
|
||||
object.insert(QLatin1String("charge_type_id"), data.chargeTypeId);
|
||||
object.insert(QLatin1String("party_id"), data.partyId);
|
||||
object.insert(QLatin1String("participant_type_id"), data.participantTypeId);
|
||||
object.insert(QLatin1String("hit"), data.hit);
|
||||
object.insert(QLatin1String("protection"), data.protection);
|
||||
|
||||
array.append(object);
|
||||
};
|
||||
if (!m_db->selectByReportId(cbData, reportId))
|
||||
return QByteArray();
|
||||
|
||||
QJsonDocument doc(array);
|
||||
|
||||
return doc.toBinaryData();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
QByteArray HandlerReportGetData::getFiringsResult(int reportId) const
|
||||
{
|
||||
QJsonArray array;
|
||||
auto cbData = [&array](const Database::RepFiringsResult &data)
|
||||
{
|
||||
QJsonObject object;
|
||||
|
||||
object.insert(QLatin1String("id"), data.id);
|
||||
object.insert(QLatin1String("start_time"), data.startTime);
|
||||
object.insert(QLatin1String("end_time"), data.endTime);
|
||||
object.insert(QLatin1String("charge_type_id"), data.chargeTypeId);
|
||||
object.insert(QLatin1String("vulnerability_state"), data.vulnerabilityState);
|
||||
object.insert(QLatin1String("firings"), data.firings);
|
||||
object.insert(QLatin1String("hits"), data.hits);
|
||||
object.insert(QLatin1String("hits_friendly_fire"), data.hitsFriendlyFire);
|
||||
|
||||
array.append(object);
|
||||
};
|
||||
if (!m_db->selectByReportId(cbData, reportId, QStringLiteral(" ORDER BY charge_type_id, start_time")))
|
||||
return QByteArray();
|
||||
|
||||
QJsonDocument doc(array);
|
||||
return doc.toBinaryData();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
QByteArray HandlerReportGetData::getAirSupportResult(int reportId) const
|
||||
{
|
||||
QJsonArray array;
|
||||
auto cbData = [&array](const Database::RepAirSupportResult &data)
|
||||
{
|
||||
QJsonObject object;
|
||||
|
||||
object.insert(QLatin1String("id"), data.id);
|
||||
object.insert(QLatin1String("start_time"), data.startTime);
|
||||
object.insert(QLatin1String("end_time"), data.endTime);
|
||||
// object.insert(QLatin1String("aes_id"), data.aesId);
|
||||
// object.insert(QLatin1String("aes_name"), data.aesName);
|
||||
object.insert(QLatin1String("charge_type_id"), data.chargeTypeId);
|
||||
object.insert(QLatin1String("vulnerability_state"), data.vulnerabilityState);
|
||||
object.insert(QLatin1String("impacts"), data.impacts);
|
||||
object.insert(QLatin1String("hits_buildings"), data.hitsBuildings);
|
||||
object.insert(QLatin1String("hits"), data.hits);
|
||||
object.insert(QLatin1String("hits_friendly_fire"), data.hitsFriendlyFire);
|
||||
|
||||
array.append(object);
|
||||
};
|
||||
if (!m_db->selectByReportId(cbData, reportId))
|
||||
return QByteArray();
|
||||
|
||||
QJsonDocument doc(array);
|
||||
return doc.toBinaryData();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
QByteArray HandlerReportGetData::getChargeResupplyResult(int reportId) const
|
||||
{
|
||||
QJsonArray array;
|
||||
auto cbData = [&array](const Database::RepChargeResupplyResult &data)
|
||||
{
|
||||
QJsonObject object;
|
||||
|
||||
object.insert(QLatin1String("id"), data.id);
|
||||
object.insert(QLatin1String("participant_type_id"), data.participantTypeId);
|
||||
object.insert(QLatin1String("charge_type_id"), data.chargeTypeId);
|
||||
object.insert(QLatin1String("charge_start"), data.chargeStart);
|
||||
object.insert(QLatin1String("charge_taken"), data.chargeTaken);
|
||||
object.insert(QLatin1String("charge_given"), data.chargeGiven);
|
||||
object.insert(QLatin1String("charge_end"), data.chargeEnd);
|
||||
object.insert(QLatin1String("charge_fired"), data.chargeFired);
|
||||
|
||||
array.append(object);
|
||||
};
|
||||
if (!m_db->selectByReportId(cbData, reportId))
|
||||
return QByteArray();
|
||||
|
||||
QJsonDocument doc(array);
|
||||
return doc.toBinaryData();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
QByteArray HandlerReportGetData::getChargeAdminResult(int reportId) const
|
||||
{
|
||||
QJsonArray array;
|
||||
auto cbData = [&array](const Database::RepChargeAdministration &data)
|
||||
{
|
||||
QJsonObject object;
|
||||
|
||||
object.insert(QLatin1String("id"), data.id);
|
||||
object.insert(QLatin1String("charge_type_id"), data.chargeTypeId);
|
||||
object.insert(QLatin1String("effect_source_id"), data.effectSourceId.underlying());
|
||||
object.insert(QLatin1String("charge_start"), data.chargeStart);
|
||||
object.insert(QLatin1String("charge_resupplied"), data.chargeResupplied);
|
||||
object.insert(QLatin1String("charge_end"), data.chargeEnd);
|
||||
object.insert(QLatin1String("charge_fired"), data.chargeFired);
|
||||
object.insert(QLatin1String("charge_planned"), data.chargePlanned);
|
||||
object.insert(QLatin1String("charge_available"), data.chargeAvailable);
|
||||
|
||||
array.append(object);
|
||||
};
|
||||
if (!m_db->selectByReportId(cbData, reportId, QStringLiteral(" ORDER BY effect_source_id, charge_type_id")))
|
||||
return QByteArray();
|
||||
|
||||
QJsonDocument doc(array);
|
||||
return doc.toBinaryData();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
QByteArray HandlerReportGetData::getMaintenanceResult(int reportId) const
|
||||
{
|
||||
QJsonArray array;
|
||||
auto cbData = [&array](const Database::RepMaintenanceResult &data)
|
||||
{
|
||||
QJsonObject object;
|
||||
|
||||
object.insert(QLatin1String("id"), data.id);
|
||||
// object.insert(QLatin1String("party_id"), data.partyId);
|
||||
object.insert(QLatin1String("participant_type_id"), data.participantTypeId);
|
||||
object.insert(QLatin1String("participant_id"), data.participantId);
|
||||
object.insert(QLatin1String("participant_name"), data.participantName);
|
||||
object.insert(QLatin1String("participant_equipment_number"), data.participantEquipmentNumber);
|
||||
object.insert(QLatin1String("time_event"), data.timeEvent);
|
||||
object.insert(QLatin1String("time_position_changed"), data.timePositionChanged);
|
||||
object.insert(QLatin1String("time_vulnerability"), data.timeVulnerability);
|
||||
|
||||
array.append(object);
|
||||
};
|
||||
if (!m_db->selectByReportId(cbData, reportId))
|
||||
return QByteArray();
|
||||
|
||||
QJsonDocument doc(array);
|
||||
return doc.toBinaryData();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
QByteArray HandlerReportGetData::getTreatmentResult(int reportId) const
|
||||
{
|
||||
QJsonArray array;
|
||||
auto cbData = [&array](const Database::RepTreatmentResult &data)
|
||||
{
|
||||
QJsonObject object;
|
||||
|
||||
object.insert(QLatin1String("id"), data.id);
|
||||
// object.insert(QLatin1String("party_id"), data.partyId);
|
||||
object.insert(QLatin1String("participant_type_id"), data.participantTypeId);
|
||||
object.insert(QLatin1String("participant_id"), data.participantId);
|
||||
object.insert(QLatin1String("participant_name"), data.participantName);
|
||||
object.insert(QLatin1String("participant_equipment_number"), data.participantEquipmentNumber);
|
||||
object.insert(QLatin1String("vitality"), data.vitality);
|
||||
object.insert(QLatin1String("vulnerability"), data.vulnerability);
|
||||
object.insert(QLatin1String("vulnerability_state"), data.vulnerabilityState);
|
||||
object.insert(QLatin1String("priority"), data.priority);
|
||||
object.insert(QLatin1String("priority_correct"), data.priorityCorrect);
|
||||
object.insert(QLatin1String("time_vulnerability"), data.timeVulnerability);
|
||||
object.insert(QLatin1String("time_vitality"), data.timeVitality);
|
||||
object.insert(QLatin1String("time_nine_liner"), data.timeNineLiner);
|
||||
object.insert(QLatin1String("time_position_changed"), data.timePositionChanged);
|
||||
object.insert(QLatin1String("time_enter_area"), data.timeEnterArea);
|
||||
object.insert(QLatin1String("time_treatment"), data.timeTreatment);
|
||||
object.insert(QLatin1String("sanitation_result"), data.sanitationResult);
|
||||
object.insert(QLatin1String("sanitation_evaluation"), data.sanitationEvaluation);
|
||||
object.insert(QLatin1String("sanitation_procedures_taken"), data.sanitationProceduresTaken);
|
||||
object.insert(QLatin1String("qualification"), data.qualification);
|
||||
object.insert(QLatin1String("area_id"), data.areaId);
|
||||
object.insert(QLatin1String("area_name"), data.areaName);
|
||||
object.insert(QLatin1String("kia_after_wia"), data.kiaAfterWia);
|
||||
|
||||
array.append(object);
|
||||
};
|
||||
if (!m_db->selectByReportId(cbData, reportId))
|
||||
return QByteArray();
|
||||
|
||||
QJsonDocument doc(array);
|
||||
return doc.toBinaryData();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
QByteArray HandlerReportGetData::getBuildingDamageResult(int reportId) const
|
||||
{
|
||||
QJsonArray array;
|
||||
auto cbData = [&array](const Database::RepBuildingDamageResult &data)
|
||||
{
|
||||
QJsonObject object;
|
||||
|
||||
object.insert(QLatin1String("id"), data.id);
|
||||
object.insert(QLatin1String("building_id"), data.buildingId);
|
||||
object.insert(QLatin1String("time_point"), data.timePoint);
|
||||
object.insert(QLatin1String("damage_20"), data.damage20);
|
||||
object.insert(QLatin1String("damage_40"), data.damage40);
|
||||
object.insert(QLatin1String("damage_60"), data.damage60);
|
||||
object.insert(QLatin1String("damage_80"), data.damage80);
|
||||
object.insert(QLatin1String("damage_100"), data.damage100);
|
||||
|
||||
array.append(object);
|
||||
};
|
||||
if (!m_db->selectByReportId(cbData, reportId))
|
||||
return QByteArray();
|
||||
|
||||
QJsonDocument doc(array);
|
||||
return doc.toBinaryData();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
QByteArray HandlerReportGetData::getSanitationMaterialResult(int reportId) const
|
||||
{
|
||||
QJsonArray array;
|
||||
NSqlQuery qSelect(m_db->database());
|
||||
|
||||
QString stmt = QLatin1String("SELECT id, material_id, sanitation_unique_id, qualification, amount_start, amount_resupplied, amount_end, amount_used, duration FROM "
|
||||
"rep_sanitation_material_result WHERE report_id = :reportId ORDER BY sanitation_unique_id, qualification, material_id");
|
||||
DEBUG_LOG(m_logger) << " stmt: " << stmt;
|
||||
|
||||
qSelect.prepare(stmt);
|
||||
qSelect.bindValue(QLatin1String(":reportId"), reportId);
|
||||
|
||||
if (!qSelect.exec())
|
||||
{
|
||||
ERROR_LOG(m_logger) << "Couldn't select sanitation material result ";
|
||||
return QByteArray();
|
||||
}
|
||||
|
||||
while (qSelect.next())
|
||||
{
|
||||
QJsonObject object;
|
||||
|
||||
object.insert(QLatin1String("id"), qSelect.value(0).toLongLong());
|
||||
object.insert(QLatin1String("material_id"), qSelect.value(1).toInt());
|
||||
object.insert(QLatin1String("sanitation_unique_id"), qSelect.value(2).toLongLong());
|
||||
object.insert(QLatin1String("qualification"), qSelect.value(3).toLongLong());
|
||||
object.insert(QLatin1String("amount_start"), qSelect.value(4).toLongLong());
|
||||
object.insert(QLatin1String("amount_resupplied"), qSelect.value(5).toLongLong());
|
||||
object.insert(QLatin1String("amount_end"), qSelect.value(6).toLongLong());
|
||||
object.insert(QLatin1String("amount_used"), qSelect.value(7).toLongLong());
|
||||
object.insert(QLatin1String("duration"), qSelect.value(8).toLongLong());
|
||||
|
||||
array.append(object);
|
||||
}
|
||||
|
||||
/*
|
||||
auto cbData = [&array] (const Database::RepSanitationMaterialResult &data)
|
||||
{
|
||||
QJsonObject object;
|
||||
|
||||
object.insert(QLatin1String("id"), data.id);
|
||||
object.insert(QLatin1String("material_id"), data.materialId);
|
||||
object.insert(QLatin1String("sanitation_unique_id"), data.sanitationUniqueId);
|
||||
object.insert(QLatin1String("qualification"), data.qualification);
|
||||
object.insert(QLatin1String("amount_start"), data.amountStart);
|
||||
object.insert(QLatin1String("amount_resupplied"), data.amountResupplied);
|
||||
object.insert(QLatin1String("amount_end"), data.amountEnd);
|
||||
object.insert(QLatin1String("amount_used"), data.amountUsed);
|
||||
object.insert(QLatin1String("duration"), data.duration);
|
||||
|
||||
array.append(object);
|
||||
};
|
||||
if (!m_db->selectByReportId(cbData, reportId))
|
||||
return QByteArray();
|
||||
*/
|
||||
|
||||
QJsonDocument doc(array);
|
||||
return doc.toBinaryData();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
QByteArray HandlerReportGetData::getSanNineLinerResult(int reportId) const
|
||||
{
|
||||
QJsonArray array;
|
||||
auto cbData = [&array](const Database::RepSanNineLiner &data)
|
||||
{
|
||||
QJsonObject object;
|
||||
|
||||
object.insert(QLatin1String("id"), data.id);
|
||||
object.insert(QLatin1String("nine_liner_id"), data.nineLinerId);
|
||||
|
||||
array.append(object);
|
||||
};
|
||||
if (!m_db->selectByReportId(cbData, reportId))
|
||||
return QByteArray();
|
||||
|
||||
QJsonDocument doc(array);
|
||||
return doc.toBinaryData();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
QByteArray HandlerReportGetData::getTreatmentTimelineResult(int reportId) const
|
||||
{
|
||||
QJsonArray array;
|
||||
auto cbData = [&array](const Database::RepTreatmentTimelineResult &data)
|
||||
{
|
||||
QJsonObject object;
|
||||
|
||||
object.insert(QLatin1String("id"), data.id);
|
||||
// object.insert(QLatin1String("party_id"), data.partyId);
|
||||
object.insert(QLatin1String("participant_type_id"), data.participantTypeId);
|
||||
object.insert(QLatin1String("participant_id"), data.participantId);
|
||||
object.insert(QLatin1String("participant_name"), data.participantName);
|
||||
object.insert(QLatin1String("participant_equipment_number"), data.participantEquipmentNumber);
|
||||
object.insert(QLatin1String("vulnerability"), data.vulnerability);
|
||||
object.insert(QLatin1String("vulnerability_state"), data.vulnerabilityState);
|
||||
object.insert(QLatin1String("vitality"), data.vitality);
|
||||
object.insert(QLatin1String("event_type_id"), data.eventTypeId.underlying());
|
||||
object.insert(QLatin1String("event_time"), data.eventTime);
|
||||
object.insert(QLatin1String("properties"), data.properties);
|
||||
|
||||
array.append(object);
|
||||
};
|
||||
if (!m_db->selectByReportId(cbData, reportId))
|
||||
return QByteArray();
|
||||
|
||||
QJsonDocument doc(array);
|
||||
return doc.toBinaryData();
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
/**
|
||||
* Handler for report get data
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
* Created by Hanna E. Rathje, SLSE, 2016-12-20
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "dds_handler.h"
|
||||
#include "logger.h"
|
||||
#include "rep_db.h"
|
||||
|
||||
#include <ParticipantManagement/ppm_dtc.h>
|
||||
|
||||
#include <QtCore/QObject>
|
||||
#include <functional>
|
||||
|
||||
namespace ReportManagement
|
||||
{
|
||||
|
||||
class HandlerReportGetData final : public QObject,
|
||||
protected Interface::Fts::GetReportDataRequestHandler
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit HandlerReportGetData(const std::shared_ptr<DdsHandler> &ddsHandler, const std::shared_ptr<DatabaseInterface> &db);
|
||||
|
||||
~HandlerReportGetData();
|
||||
|
||||
bool init();
|
||||
|
||||
private: // methods
|
||||
void onGetReportDataRequest(const rti::core::SampleIdentity &cookie,
|
||||
const GetReportDataRequest &request) override final;
|
||||
GetReportDataReply getReportDataRequest(const GetReportDataRequest &request);
|
||||
|
||||
QByteArray getUnitPowerResult(int reportId) const;
|
||||
QByteArray getParticipantDistanceResult(int reportId) const;
|
||||
QByteArray getMineAreaResult(int reportId) const;
|
||||
QByteArray getNbcResult(int reportId) const;
|
||||
QByteArray getFiringsResult(int reportId) const;
|
||||
QByteArray getAirSupportResult(int reportId) const;
|
||||
QByteArray getChargeResupplyResult(int reportId) const;
|
||||
QByteArray getChargeAdminResult(int reportId) const;
|
||||
QByteArray getMaintenanceResult(int reportId) const;
|
||||
QByteArray getBuildingDamageResult(int reportId) const;
|
||||
QByteArray getSanitationMaterialResult(int reportId) const;
|
||||
QByteArray getSanNineLinerResult(int reportId) const;
|
||||
QByteArray getTreatmentResult(int reportId) const;
|
||||
QByteArray getTreatmentTimelineResult(int reportId) const;
|
||||
|
||||
private: // attributes
|
||||
std::shared_ptr<DdsHandler> m_ddsHandler; ///< Pointer to DDS handler
|
||||
std::shared_ptr<DatabaseInterface> m_db;
|
||||
|
||||
NGL::INGLLogger &m_logger; ///< Interface to the Logging-Facility
|
||||
|
||||
};
|
||||
} // namespace ReportManagement
|
||||
|
||||
@@ -0,0 +1,114 @@
|
||||
/**
|
||||
* Handler for report maintenance
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
* Created by Hanna E. Rathje, SLSE, 2016-12-20
|
||||
*/
|
||||
|
||||
#include "handler_report_data.h"
|
||||
|
||||
#include <ngldb/nsqlquery.h>
|
||||
#include <ngldb/dbtransaction.h>
|
||||
|
||||
#include <QVariant>
|
||||
|
||||
using namespace ReportManagement;
|
||||
|
||||
bool HandlerReportData::generateMaintenanceResult(const CreateModifyReportRequest &request,
|
||||
int reportId,
|
||||
const std::shared_ptr<ParticipantManagement::Interface::Dtc> &ppmDtc)
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "Start generateMaintenanceResult";
|
||||
|
||||
DBTransaction trans(m_db->database());
|
||||
NSqlQuery qSelect(m_db->database());
|
||||
NSqlQuery qInsert(m_db->database());
|
||||
|
||||
QString stmtSelect = QStringLiteral("SELECT participant_type_id, participant_id, time_event, time_position_changed, time_vulnerability "
|
||||
"FROM rep_maintenance_data "
|
||||
"WHERE party_id = :partyId AND (time_event between :startTime and :endTime) ");
|
||||
if (request.participantTypes().size() > 0)
|
||||
{
|
||||
const QString pTypeIdsStr = intVecToString(request.participantTypes());
|
||||
stmtSelect += QStringLiteral(" AND participant_type_id IN (%1) ").arg(pTypeIdsStr);
|
||||
}
|
||||
if (request.participantIds().size() > 0)
|
||||
{
|
||||
const QString pIdsStr = intVecToString(request.participantIds());
|
||||
stmtSelect += QStringLiteral(" AND participant_id IN (%1) ").arg(pIdsStr);
|
||||
}
|
||||
stmtSelect += QStringLiteral(" ORDER by participant_type_id, participant_id, time_event");
|
||||
|
||||
DEBUG_LOG(m_logger) << "Statement: " << stmtSelect;
|
||||
DEBUG_LOG(m_logger) << "Party Id = " << request.partyId();
|
||||
DEBUG_LOG(m_logger) << "Start Time = " << request.startTime();
|
||||
DEBUG_LOG(m_logger) << "End Time = " << request.endTime();
|
||||
|
||||
qSelect.prepare(stmtSelect);
|
||||
qSelect.bindValue(QStringLiteral(":startTime"), request.startTime());
|
||||
qSelect.bindValue(QStringLiteral(":endTime"), request.endTime());
|
||||
qSelect.bindValue(QStringLiteral(":partyId"), request.partyId());
|
||||
|
||||
if (!qSelect.exec())
|
||||
{
|
||||
ERROR_LOG(m_logger) << "Error selecting report data for report id = " << reportId;
|
||||
return false;
|
||||
}
|
||||
|
||||
m_maintenanceData.clear();
|
||||
|
||||
while (qSelect.next())
|
||||
{
|
||||
MaintenanceData vrData;
|
||||
vrData.participantTypeId = qSelect.value(0).toInt();
|
||||
vrData.participantId = qSelect.value(1).toInt();
|
||||
vrData.time_event = qSelect.value(2).toLongLong();
|
||||
vrData.time_position_changed = qSelect.value(3).toLongLong();
|
||||
vrData.time_vulnerability = qSelect.value(4).toLongLong();
|
||||
|
||||
m_maintenanceData.append(vrData);
|
||||
}
|
||||
|
||||
QString stmtInsert = QStringLiteral("INSERT INTO rep_maintenance_result (report_id, participant_type_id, participant_id, participant_name, participant_equipment_number, time_event, time_position_changed, time_vulnerability)"
|
||||
" values (:reportId, :pTypeId, :participantId, :participantName, :participantEqNo, :time_event, :time_position, :time_vulnerability)");
|
||||
|
||||
if (!qInsert.prepare(stmtInsert))
|
||||
{
|
||||
ERROR_LOG(m_logger) << "Error preparing statement: " << stmtInsert;
|
||||
return false;
|
||||
}
|
||||
|
||||
qInsert.bindValue(QStringLiteral(":reportId"), reportId);
|
||||
|
||||
for (const auto &vrData : qAsConst(m_maintenanceData))
|
||||
{
|
||||
const auto participant = ppmDtc->participant(vrData.participantId);
|
||||
|
||||
qInsert.bindValue(QStringLiteral(":pTypeId"), vrData.participantTypeId);
|
||||
qInsert.bindValue(QStringLiteral(":participantId"), vrData.participantId);
|
||||
qInsert.bindValue(QStringLiteral(":participantName"), ppmDtc->hierarchyFromParticipant(vrData.participantId));
|
||||
qInsert.bindValue(QStringLiteral(":participantEqNo"), participant.equipmentNumber().is_set() ?
|
||||
participant.equipmentNumber().get() : 0);
|
||||
|
||||
qInsert.bindValue(QStringLiteral(":time_event"), vrData.time_event);
|
||||
qInsert.bindValue(QStringLiteral(":time_position"), vrData.time_position_changed);
|
||||
qInsert.bindValue(QStringLiteral(":time_vulnerability"), vrData.time_vulnerability);
|
||||
|
||||
DEBUG_LOG(m_logger) << "Statement: " << stmtInsert;
|
||||
|
||||
if (!qInsert.exec())
|
||||
{
|
||||
ERROR_LOG(m_logger) << "Error inserting report data for report id = " << reportId;
|
||||
trans.rollback();
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
trans.commit();
|
||||
|
||||
DEBUG_LOG(m_logger) << " END generateMaintenanceResult";
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,96 @@
|
||||
/**
|
||||
* Handler for report mine area
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
* Created by Hanna E. Rathje, SLSE, 2016-12-20
|
||||
*/
|
||||
|
||||
#include "handler_report_data.h"
|
||||
|
||||
#include <ngldb/nsqlquery.h>
|
||||
#include <ngldb/dbtransaction.h>
|
||||
|
||||
#include <QPair>
|
||||
#include <QVariant>
|
||||
|
||||
using namespace ReportManagement;
|
||||
|
||||
bool HandlerReportData::generateMineAreaResult(const CreateModifyReportRequest &request,
|
||||
int reportId,
|
||||
const std::shared_ptr<AreaEffectSimulation::Interface::Dtc> &aesDtc)
|
||||
{
|
||||
INFO_LOG(m_logger) << "Start generateMineAreaResult";
|
||||
|
||||
DBTransaction trans(m_db->database());
|
||||
|
||||
NSqlQuery qSelect(m_db->database());
|
||||
NSqlQuery qInsert(m_db->database());
|
||||
|
||||
const QString mineAreaIdsStr = intVecToString(request.mineAreaIds());
|
||||
|
||||
QString stmtSelect = QStringLiteral("SELECT mine_area_id, participant_type_id, SUM(hit) as hit, SUM(hit_friendly_fire) as hit_friendly_fire "
|
||||
" FROM rep_mine_area_data "
|
||||
" WHERE party_id = :partyId AND (event_time between :startTime and :endTime ) ");
|
||||
if (request.mineAreaIds().size() > 0)
|
||||
stmtSelect += QStringLiteral(" AND mine_area_id IN (%1)").arg(mineAreaIdsStr);
|
||||
stmtSelect += QStringLiteral(" GROUP BY mine_area_id, participant_type_id ");
|
||||
stmtSelect += QStringLiteral(" ORDER by mine_area_id, participant_type_id ");
|
||||
|
||||
DEBUG_LOG(m_logger) << "Statement: " << stmtSelect;
|
||||
|
||||
if (!qSelect.prepare(stmtSelect))
|
||||
{
|
||||
ERROR_LOG(m_logger) << "Error preparing select stmt: " << stmtSelect;
|
||||
return false;
|
||||
}
|
||||
|
||||
qSelect.bindValue(QStringLiteral(":startTime"), request.startTime());
|
||||
qSelect.bindValue(QStringLiteral(":endTime"), request.endTime());
|
||||
qSelect.bindValue(QStringLiteral(":partyId"), request.partyId());
|
||||
|
||||
if (!qSelect.exec())
|
||||
{
|
||||
ERROR_LOG(m_logger) << "Error selecting report data for report id = " << reportId;
|
||||
return false;
|
||||
}
|
||||
|
||||
QString stmtInsert = QStringLiteral("INSERT INTO rep_mine_area_result (report_id, mine_area_id, mine_area_name, participant_type_id, hit, hit_friendly_fire)"
|
||||
" values (:reportId, :mineAreaId, :mineAreaName, :pTypeId, :hit, :hit_ff )");
|
||||
|
||||
if (!qInsert.prepare(stmtInsert))
|
||||
{
|
||||
ERROR_LOG(m_logger) << "Error preparing insert stmt: " << stmtInsert;
|
||||
return false;
|
||||
}
|
||||
|
||||
qInsert.bindValue(QStringLiteral(":reportId"), reportId);
|
||||
|
||||
while (qSelect.next())
|
||||
{
|
||||
int mineAreaId = qSelect.value(0).toInt();
|
||||
int participantTypeId = qSelect.value(1).toInt();
|
||||
int hit = qSelect.value(2).toInt();
|
||||
int hitFriendlyFire = qSelect.value(3).toInt();
|
||||
|
||||
INFO_LOG(m_logger) << "MineAreaId: " << mineAreaId;
|
||||
INFO_LOG(m_logger) << "participantTypeId: " << participantTypeId;
|
||||
INFO_LOG(m_logger) << "hit: " << hit;
|
||||
INFO_LOG(m_logger) << "hit_ff: " << hitFriendlyFire;
|
||||
|
||||
qInsert.bindValue(QStringLiteral(":mineAreaId") , mineAreaId);
|
||||
QString mineAreaName = QString::fromStdString(aesDtc->mineArea(mineAreaId).name());
|
||||
qInsert.bindValue(QStringLiteral(":mineAreaName") , mineAreaName);
|
||||
qInsert.bindValue(QStringLiteral(":pTypeId") , participantTypeId);
|
||||
qInsert.bindValue(QStringLiteral(":hit") , hit);
|
||||
qInsert.bindValue(QStringLiteral(":hit_ff") , hitFriendlyFire);
|
||||
|
||||
if (!qInsert.exec())
|
||||
ERROR_LOG(m_logger) << "Error while inserting into rep_mine_area_result: MineAreaId: " << mineAreaId << ", participantTYpeId: " << participantTypeId;
|
||||
}
|
||||
|
||||
trans.commit();
|
||||
|
||||
INFO_LOG(m_logger) << " END generateMineAreaResult";
|
||||
return true;
|
||||
}
|
||||
@@ -0,0 +1,109 @@
|
||||
/**
|
||||
* Handler for report nbc
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
* Created by Hanna E. Rathje, SLSE, 2016-12-20
|
||||
*/
|
||||
|
||||
#include "handler_report_data.h"
|
||||
|
||||
#include <ngldb/nsqlquery.h>
|
||||
#include <ngldb/dbtransaction.h>
|
||||
|
||||
#include <QVariant>
|
||||
|
||||
using namespace ReportManagement;
|
||||
|
||||
bool HandlerReportData::generateNbcResult(const CreateModifyReportRequest &request,
|
||||
int reportId,
|
||||
const std::shared_ptr<AreaEffectSimulation::Interface::Dtc> &aesDtc)
|
||||
{
|
||||
INFO_LOG(m_logger) << "Start generateNbcResult - reportId: " << reportId;
|
||||
|
||||
if (request.nbcIds().size() <= 0)
|
||||
{
|
||||
ERROR_LOG(m_logger) << "No elements selected to generate the report";
|
||||
DEBUG_LOG(m_logger) << "request.nbcIds().size()" << request.nbcIds().size();
|
||||
return false;
|
||||
}
|
||||
|
||||
const QString nbcIdsStr = intVecToString(request.nbcIds());
|
||||
|
||||
DBTransaction trans(m_db->database());
|
||||
NSqlQuery qSelect(m_db->database());
|
||||
NSqlQuery qInsert(m_db->database());
|
||||
|
||||
QString stmtSelect = QStringLiteral("SELECT nbc_id, aes_type, charge_type_id, party_id, participant_type_id, SUM(hit) AS hit, SUM(protection) AS protection "
|
||||
" FROM rep_nbc_data WHERE ") +
|
||||
QStringLiteral(" nbc_id IN (%1)").arg(nbcIdsStr) +
|
||||
QStringLiteral(" AND (event_time BETWEEN :startTime AND :endTime) "
|
||||
" GROUP BY nbc_id, aes_type, charge_type_id, party_id, participant_type_id "
|
||||
" ORDER BY nbc_id, party_id, participant_type_id ");
|
||||
|
||||
DEBUG_LOG(m_logger) << "Statement select: " << stmtSelect;
|
||||
|
||||
if (!qSelect.prepare(stmtSelect))
|
||||
{
|
||||
ERROR_LOG(m_logger) << "Error preparing select statement: " << stmtSelect;
|
||||
return false;
|
||||
}
|
||||
qSelect.bindValue(QStringLiteral(":startTime"), request.startTime());
|
||||
qSelect.bindValue(QStringLiteral(":endTime"), request.endTime());
|
||||
|
||||
if (!qSelect.exec())
|
||||
{
|
||||
ERROR_LOG(m_logger) << "Error selecting report data for report id = " << reportId;
|
||||
return false;
|
||||
}
|
||||
|
||||
while (qSelect.next())
|
||||
{
|
||||
int nbcId = qSelect.value(0).toInt();
|
||||
int aesType = qSelect.value(1).toInt();
|
||||
int chargeTypeId = qSelect.value(2).toInt();
|
||||
int partyId = qSelect.value(3).toInt();
|
||||
int participantTypeId = qSelect.value(4).toInt();
|
||||
int hit = qSelect.value(5).toInt();
|
||||
int protection = qSelect.value(6).toInt();
|
||||
|
||||
DEBUG_LOG(m_logger) << "NbcId: " << nbcId;
|
||||
DEBUG_LOG(m_logger) << "AesType: " << aesType;
|
||||
DEBUG_LOG(m_logger) << "ChargeTypeId: " << chargeTypeId;
|
||||
DEBUG_LOG(m_logger) << "PartyId: " << partyId;
|
||||
DEBUG_LOG(m_logger) << "participantTypeId: " << participantTypeId;
|
||||
DEBUG_LOG(m_logger) << "Hit: " << hit;
|
||||
DEBUG_LOG(m_logger) << "Protected: " << protection;
|
||||
|
||||
QString stmtInsert = QStringLiteral("INSERT INTO rep_nbc_result (report_id, nbc_id, nbc_name, aes_type, charge_type_id, party_id, participant_type_id, hit, protection)"
|
||||
" VALUES (:reportId, :nbcId, :nbcName, :aesType, :chargeId, :partyId, :pTypeId, :hit, :protection )");
|
||||
|
||||
if (!qInsert.prepare(stmtInsert))
|
||||
{
|
||||
ERROR_LOG(m_logger) << "Error preparing insert statement: " << stmtInsert;
|
||||
return false;
|
||||
}
|
||||
|
||||
qInsert.bindValue(QStringLiteral(":reportId"), reportId);
|
||||
qInsert.bindValue(QStringLiteral(":nbcId"), nbcId);
|
||||
QString nbcName = QString::fromStdString(aesDtc->bCContamination(nbcId).name());
|
||||
qInsert.bindValue(QStringLiteral(":nbcName"), nbcName);
|
||||
qInsert.bindValue(QStringLiteral(":aesType"), aesType);
|
||||
qInsert.bindValue(QStringLiteral(":chargeId"), chargeTypeId);
|
||||
qInsert.bindValue(QStringLiteral(":partyId"), partyId);
|
||||
qInsert.bindValue(QStringLiteral(":pTypeId"), participantTypeId);
|
||||
qInsert.bindValue(QStringLiteral(":hit"), hit);
|
||||
qInsert.bindValue(QStringLiteral(":protection"), protection);
|
||||
|
||||
if (!qInsert.exec())
|
||||
{
|
||||
ERROR_LOG(m_logger) << "Error while inserting into rep_nbc_result: nbcId = " << nbcId
|
||||
<< ", partyId = " << partyId << ", participantTypeId: " << participantTypeId;
|
||||
}
|
||||
}
|
||||
|
||||
trans.commit();
|
||||
|
||||
INFO_LOG(m_logger) << " END generateNbcResult";
|
||||
return true;
|
||||
}
|
||||
+180
@@ -0,0 +1,180 @@
|
||||
/**
|
||||
* Handler for report participant distance
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
* Created by Hanna E. Rathje, SLSE, 2016-12-20
|
||||
*/
|
||||
|
||||
#include "handler_report_data.h"
|
||||
|
||||
#include <ngldb/nsqlquery.h>
|
||||
#include <ngldb/dbtransaction.h>
|
||||
|
||||
#include <LtsCoordTrans/lts_coord_trans.h>
|
||||
#include <QtCore/qmath.h>
|
||||
#include <QVariant>
|
||||
|
||||
using namespace ReportManagement;
|
||||
|
||||
bool HandlerReportData::generateParticipantDistanceResult(const CreateModifyReportRequest &request,
|
||||
int reportId,
|
||||
const std::shared_ptr<ParticipantManagement::Interface::Dtc> &ppmDtc)
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "Start generateParticipantDistanceResult";
|
||||
|
||||
DBTransaction trans(m_db->database());
|
||||
NSqlQuery qSelect(m_db->database());
|
||||
NSqlQuery qInsert(m_db->database());
|
||||
|
||||
QString stmtSelect = QStringLiteral("SELECT participant_type_id, participant_id, sample_time, pos_lon, pos_lat "
|
||||
"FROM rec_participant_position "
|
||||
"WHERE party_id = :partyId AND (sample_time between :startTime and :endTime) "
|
||||
"AND (pos_lon > 0 OR pos_lat > 0)"); // ignore (0,0)
|
||||
|
||||
if (request.participantTypes().size() > 0)
|
||||
{
|
||||
const QString pTypeIdsStr = intVecToString(request.participantTypes());
|
||||
stmtSelect += QStringLiteral(" AND participant_type_id IN (%1) ").arg(pTypeIdsStr);
|
||||
}
|
||||
|
||||
if (request.participantIds().size() > 0)
|
||||
{
|
||||
const QString participants = intVecToString(request.participantIds());
|
||||
stmtSelect += QStringLiteral(" AND participant_id IN (%1)").arg(participants);
|
||||
}
|
||||
|
||||
stmtSelect += QStringLiteral(" ORDER by participant_type_id, participant_id, sample_time, rec_id");
|
||||
|
||||
qSelect.prepare(stmtSelect);
|
||||
|
||||
qSelect.bindValue(QStringLiteral(":startTime"), request.startTime());
|
||||
qSelect.bindValue(QStringLiteral(":endTime"), request.endTime());
|
||||
qSelect.bindValue(QStringLiteral(":partyId"), request.partyId());
|
||||
|
||||
DEBUG_LOG(m_logger) << "Select statement: " << stmtSelect;
|
||||
DEBUG_LOG(m_logger) << "Party id = " << request.partyId();
|
||||
DEBUG_LOG(m_logger) << "StartTime = " << request.startTime();
|
||||
DEBUG_LOG(m_logger) << "EndTime = " << request.endTime();
|
||||
|
||||
if (!qSelect.exec())
|
||||
{
|
||||
ERROR_LOG(m_logger) << "Error selecting report data for report id = " << reportId;
|
||||
return false;
|
||||
}
|
||||
|
||||
int participantId = -1;
|
||||
int participantTypeId = -1;
|
||||
LtsCoordTrans::UtmCoordinate delta;
|
||||
|
||||
m_distanceMapType.clear();
|
||||
|
||||
int zone = -1;
|
||||
QElapsedTimer timeoutTimer;
|
||||
timeoutTimer.start();
|
||||
while (qSelect.next())
|
||||
{
|
||||
double deltaDistance = 0.00;
|
||||
checkElapsedTimer(timeoutTimer);
|
||||
if (participantTypeId != qSelect.value(0).toInt()) // new participantTypeId
|
||||
m_distanceMap.clear();
|
||||
|
||||
if (participantId != qSelect.value(1).toInt())
|
||||
{
|
||||
// new participantId, initial position
|
||||
participantTypeId = qSelect.value(0).toInt();
|
||||
participantId = qSelect.value(1).toInt();
|
||||
delta = LtsCoordTrans::UtmCoordinate::fromGeographic(qSelect.value(3).toDouble(), qSelect.value(4).toDouble(), zone);
|
||||
zone = delta.zone;
|
||||
deltaDistance = 0.00;
|
||||
|
||||
DataParticipantPosition startInfo;
|
||||
startInfo.participantId = participantId;
|
||||
startInfo.participantTypeId = qSelect.value(0).toInt();
|
||||
startInfo.timestamp = qSelect.value(2).toLongLong();
|
||||
|
||||
m_startInfo[participantId] = startInfo;
|
||||
|
||||
DEBUG_LOG(m_logger) << "New ParticipantId: " << participantId <<
|
||||
", Delta-x: " << delta.x <<
|
||||
", Delta.y: " << delta.y <<
|
||||
", Timestamp: " << qSelect.value(2).toLongLong() <<
|
||||
", Delta-Distance: " << deltaDistance <<
|
||||
", Delta-Zone: " << zone;
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
LtsCoordTrans::UtmCoordinate nextPos = LtsCoordTrans::UtmCoordinate::fromGeographic(qSelect.value(3).toDouble(), qSelect.value(4).toDouble(), zone);
|
||||
|
||||
TRACE_LOG(m_logger) << "nextPos.x: " << nextPos.x << ", nextPos.y: " << nextPos.y;
|
||||
|
||||
delta.x = nextPos.x - delta.x;
|
||||
delta.y = nextPos.y - delta.y;
|
||||
deltaDistance = qSqrt((delta.x * delta.x) + (delta.y * delta.y));
|
||||
delta = nextPos;
|
||||
|
||||
DEBUG_LOG(m_logger) << "Same ParticipantId: " << participantId <<
|
||||
", Delta-x: " << delta.x <<
|
||||
", Delta-y: " << delta.y <<
|
||||
", Timestamp: " << qSelect.value(2).toLongLong() <<
|
||||
", Delta-Distance: " << deltaDistance <<
|
||||
", Delta-Zone: " << zone;
|
||||
|
||||
m_distanceMap[participantId] += deltaDistance;
|
||||
}
|
||||
m_distanceMapType.insert(participantTypeId, m_distanceMap);
|
||||
|
||||
}
|
||||
|
||||
QString stmtInsert = QStringLiteral("INSERT INTO rep_participant_distance_result (report_id, party_id, participant_type_id, participant_id, participant_name, participant_equipment_number, distance)"
|
||||
" values (:reportId, :partyId, :pTypeId, :participantId, :participantName, :participantEqNo, :distance)");
|
||||
|
||||
if (!qInsert.prepare(stmtInsert))
|
||||
{
|
||||
ERROR_LOG(m_logger) << "Error preparing statement: " << stmtInsert;
|
||||
return false;
|
||||
}
|
||||
|
||||
qInsert.bindValue(QStringLiteral(":reportId"), reportId);
|
||||
qInsert.bindValue(QStringLiteral(":partyId"), request.partyId());
|
||||
|
||||
for (auto it = m_distanceMapType.cbegin(); it != m_distanceMapType.cend(); ++it)
|
||||
{
|
||||
const int typeId = it.key();
|
||||
for (auto itt = it.value().cbegin(); itt != it.value().cend(); ++itt)
|
||||
{
|
||||
const int partId = itt.key();
|
||||
const DataParticipantPosition &pos = m_startInfo[partId];
|
||||
const auto participant = ppmDtc->participant(partId);
|
||||
|
||||
qInsert.bindValue(QStringLiteral(":pTypeId"), typeId);
|
||||
qInsert.bindValue(QStringLiteral(":participantId"), partId);
|
||||
qInsert.bindValue(QStringLiteral(":participantName"), ppmDtc->hierarchyFromParticipant(partId));
|
||||
qInsert.bindValue(QStringLiteral(":participantEqNo"), participant.equipmentNumber().is_set() ?
|
||||
participant.equipmentNumber().get() : 0);
|
||||
|
||||
// double dist = static_cast<double>(static_cast<int>(itt.value()*100+0.5))/100.0; // round to 2 decimals
|
||||
int dist = static_cast<int>(itt.value());
|
||||
qInsert.bindValue(QStringLiteral(":distance"), dist);
|
||||
|
||||
DEBUG_LOG(m_logger) << "### ParticipantTypeId: " << pos.participantTypeId <<
|
||||
", ParticipantId: " << pos.participantId <<
|
||||
", Distance (map): " << itt.value() <<
|
||||
", Distance (calculated): " << dist;
|
||||
|
||||
if (!qInsert.exec())
|
||||
{
|
||||
ERROR_LOG(m_logger) << "Error inserting report data for report id = " << reportId;
|
||||
trans.rollback();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
trans.commit();
|
||||
|
||||
DEBUG_LOG(m_logger) << " END generateParticipantDistanceResult";
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,570 @@
|
||||
/**
|
||||
* Handler for report treatment
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
* Created by Hanna E. Rathje, SLSE, 2016-12-20
|
||||
*/
|
||||
|
||||
#include "handler_report_data.h"
|
||||
|
||||
#include <ngldb/nsqlquery.h>
|
||||
#include <ngldb/dbtransaction.h>
|
||||
#include <LtsCoordTrans/lts_coord_trans.h>
|
||||
|
||||
#include <QVariant>
|
||||
|
||||
using namespace ReportManagement;
|
||||
|
||||
bool HandlerReportData::generateTreatmentResult(const CreateModifyReportRequest &request,
|
||||
int reportId,
|
||||
const std::shared_ptr<ParticipantManagement::Interface::Dtc> &ppmDtc)
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "Start generateTreatmentResult";
|
||||
|
||||
DBTransaction trans(m_db->database());
|
||||
NSqlQuery qSelect(m_db->database());
|
||||
NSqlQuery qInsert(m_db->database());
|
||||
//NSqlQuery qDelete(m_db->database());
|
||||
|
||||
QString stmtSelect = QStringLiteral("SELECT participant_type_id, participant_id, vitality, vulnerability, vulnerability_state, priority, time_vulnerability, time_vitality, time_nine_liner, time_position_changed,"
|
||||
" time_enter_area, time_treatment, sanitation_result, sanitation_evaluation, sanitation_procedures_taken, qualification, position_x, position_y, position_x_m, position_y_m, area_id, area_name "
|
||||
"FROM rep_treatment_data "
|
||||
// "WHERE party_id = :partyId AND (time_treatment between :startTime and :endTime) ");
|
||||
"WHERE party_id = :partyId AND (time_vulnerability between :startTime and :endTime) ");
|
||||
if (request.participantTypes().size() > 0)
|
||||
{
|
||||
const QString pTypeIdsStr = intVecToString(request.participantTypes());
|
||||
stmtSelect += QStringLiteral(" AND participant_type_id IN (%1) ").arg(pTypeIdsStr);
|
||||
}
|
||||
if (request.participantIds().size() > 0)
|
||||
{
|
||||
const QString pIdsStr = intVecToString(request.participantIds());
|
||||
stmtSelect += QStringLiteral(" AND participant_id IN (%1) ").arg(pIdsStr);
|
||||
}
|
||||
|
||||
if (request.width() > 0 && request.height() > 0)
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "#### Filtering data on geographic position";
|
||||
LtsCoordTrans::UtmCoordinate coord(LtsCoordTrans::UtmCoordinate::fromGeographic(request.cornerBottomLeft().lon(),
|
||||
request.cornerBottomLeft().lat()));
|
||||
|
||||
double x1 = coord.x + request.height();
|
||||
double y1 = coord.y + request.width();
|
||||
DEBUG_LOG(m_logger) << "#### (x,x1,y,y1) = (" << coord.x << "," << x1 << "," << coord.y << "," << y1 << ")";
|
||||
|
||||
stmtSelect += QLatin1String(" AND position_x_m >= ") + QString::number(coord.x);
|
||||
stmtSelect += QLatin1String(" AND position_x_m <= ") + QString::number(x1);
|
||||
stmtSelect += QLatin1String(" AND position_y_m >= ") + QString::number(coord.y);
|
||||
stmtSelect += QLatin1String(" AND position_y_m <= ") + QString::number(y1);
|
||||
}
|
||||
|
||||
// stmtSelect += QStringLiteral(" ORDER by participant_type_id, participant_id, time_treatment");
|
||||
stmtSelect += QStringLiteral(" ORDER by time_vulnerability");
|
||||
|
||||
DEBUG_LOG(m_logger) << "Statement: " << stmtSelect;
|
||||
DEBUG_LOG(m_logger) << "Party Id = " << request.partyId();
|
||||
DEBUG_LOG(m_logger) << "Start Time = " << request.startTime();
|
||||
DEBUG_LOG(m_logger) << "End Time = " << request.endTime();
|
||||
|
||||
qSelect.prepare(stmtSelect);
|
||||
qSelect.bindValue(QStringLiteral(":startTime"), request.startTime());
|
||||
qSelect.bindValue(QStringLiteral(":endTime"), request.endTime());
|
||||
qSelect.bindValue(QStringLiteral(":partyId"), request.partyId());
|
||||
|
||||
if (!qSelect.exec())
|
||||
{
|
||||
ERROR_LOG(m_logger) << "Error selecting report data for report id = " << reportId;
|
||||
return false;
|
||||
}
|
||||
|
||||
m_treatmentData.clear();
|
||||
|
||||
while (qSelect.next())
|
||||
{
|
||||
TreatmentData tData;
|
||||
tData.participantTypeId = qSelect.value(0).toInt();
|
||||
tData.participantId = qSelect.value(1).toInt();
|
||||
tData.vitality = qSelect.value(2).toInt();
|
||||
tData.vulnerability = qSelect.value(3).toInt();
|
||||
tData.vulnerabilityState = qSelect.value(4).toInt();
|
||||
tData.priority = qSelect.value(5).toInt();
|
||||
tData.time_vulnerability = qSelect.value(6).toLongLong();
|
||||
tData.time_vitality = qSelect.value(7).toLongLong();
|
||||
tData.time_nine_liner = qSelect.value(8).toLongLong();
|
||||
tData.time_position_changed = qSelect.value(9).toLongLong();
|
||||
tData.time_enter_area = qSelect.value(10).toLongLong();
|
||||
tData.time_treatment = qSelect.value(11).toLongLong();
|
||||
tData.sanitation_result = qSelect.value(12).toInt();
|
||||
tData.sanitation_evaluation = qSelect.value(13).toInt();
|
||||
tData.sanitation_procedures_taken = qSelect.value(14).toLongLong();
|
||||
tData.qualification = qSelect.value(15).toInt();
|
||||
tData.pos_x = qSelect.value(16).toDouble();
|
||||
tData.pos_y = qSelect.value(17).toDouble();
|
||||
tData.pos_x_m = qSelect.value(18).toDouble();
|
||||
tData.pos_y_m = qSelect.value(19).toDouble();
|
||||
|
||||
tData.area_id = qSelect.value(20).toInt();
|
||||
tData.area_name = qSelect.value(21).toInt();
|
||||
|
||||
m_treatmentData.append(tData);
|
||||
}
|
||||
|
||||
QString stmtInsert = QStringLiteral("INSERT INTO rep_treatment_result (report_id, participant_type_id, participant_id, participant_name, participant_equipment_number, vitality, vulnerability, vulnerability_state, priority, "
|
||||
" priority_correct, time_vulnerability, time_vitality, time_nine_liner, time_position_changed, time_enter_area, time_treatment, sanitation_result, sanitation_evaluation, sanitation_procedures_taken, qualification, "
|
||||
" position_x, position_y, position_x_m, position_y_m, area_id, area_name, kia_after_wia ) "
|
||||
" values (:reportId, :pTypeId, :participantId, :participantName, :participantEqNo, :vitality, :vulnerability, :vbg, :priority, "
|
||||
" :pCorrect, :time_vulnerability, :time_vitality, :time_nine_liner, :time_position, :time_enter_area, :time_treatment, :result, :eval, :taken, :qualification, :pos_x, :pos_y, :pos_x_m, :pos_y_m, :area_id, :area_name, :kia_after_wia)");
|
||||
|
||||
if (!qInsert.prepare(stmtInsert))
|
||||
{
|
||||
ERROR_LOG(m_logger) << "Error preparing statement: " << stmtInsert;
|
||||
return false;
|
||||
}
|
||||
|
||||
qInsert.bindValue(QStringLiteral(":reportId"), reportId);
|
||||
|
||||
QElapsedTimer timeoutTimer;
|
||||
timeoutTimer.start();
|
||||
for (const TreatmentData &tData : qAsConst(m_treatmentData))
|
||||
{
|
||||
checkElapsedTimer(timeoutTimer);
|
||||
const auto participant = ppmDtc->participant(tData.participantId);
|
||||
|
||||
qInsert.bindValue(QStringLiteral(":pTypeId"), tData.participantTypeId);
|
||||
qInsert.bindValue(QStringLiteral(":participantId"), tData.participantId);
|
||||
qInsert.bindValue(QStringLiteral(":participantName"), ppmDtc->hierarchyFromParticipant(tData.participantId));
|
||||
qInsert.bindValue(QStringLiteral(":participantEqNo"), participant.equipmentNumber().is_set() ?
|
||||
participant.equipmentNumber().get() : 0);
|
||||
qInsert.bindValue(QStringLiteral(":vitality"), tData.vitality);
|
||||
qInsert.bindValue(QStringLiteral(":vulnerability"), tData.vulnerability);
|
||||
qInsert.bindValue(QStringLiteral(":vbg"), tData.vulnerabilityState);
|
||||
qInsert.bindValue(QStringLiteral(":priority"), tData.priority);
|
||||
|
||||
// recalculate time_vulnerability
|
||||
qint64 timeVuln = sinceWhenVulnerability(tData.participantId, tData.vulnerability, tData.time_vulnerability);
|
||||
qInsert.bindValue(QStringLiteral(":time_vulnerability"), timeVuln);
|
||||
|
||||
bool kiaAfterWia = false;
|
||||
// Check if KIA is also KIA after WIA
|
||||
if (tData.vulnerabilityState == ProjectDataManagement::VulnerabilityState_def::CatastrophicKill)
|
||||
kiaAfterWia = checkVulnerabilityStateWIA(tData.participantId, tData.time_vulnerability);
|
||||
|
||||
qInsert.bindValue(QStringLiteral(":kia_after_wia"), kiaAfterWia);
|
||||
|
||||
// recalculate time_vitality
|
||||
if (tData.time_treatment > 0)
|
||||
{
|
||||
qint64 timeVit = sinceWhenVitality(tData.participantId, tData.vitality, tData.time_vitality);
|
||||
qInsert.bindValue(QStringLiteral(":time_vitality"), timeVit);
|
||||
}
|
||||
|
||||
//qInsert.bindValue(QStringLiteral(":time_nine_liner"), tData.time_nine_liner);
|
||||
//qInsert.bindValue(QStringLiteral(":time_position"), tData.time_position_changed);
|
||||
//qInsert.bindValue(QStringLiteral(":time_enter_area"), tData.time_enter_area);
|
||||
qInsert.bindValue(QStringLiteral(":time_treatment"), tData.time_treatment);
|
||||
qInsert.bindValue(QStringLiteral(":result"), tData.sanitation_result);
|
||||
qInsert.bindValue(QStringLiteral(":eval"), tData.sanitation_evaluation);
|
||||
qInsert.bindValue(QStringLiteral(":taken"), tData.sanitation_procedures_taken);
|
||||
qInsert.bindValue(QStringLiteral(":qualification"), tData.qualification);
|
||||
qInsert.bindValue(QStringLiteral(":pos_x"), tData.pos_x);
|
||||
qInsert.bindValue(QStringLiteral(":pos_y"), tData.pos_y);
|
||||
qInsert.bindValue(QStringLiteral(":pos_x_m"), tData.pos_x_m);
|
||||
qInsert.bindValue(QStringLiteral(":pos_y_m"), tData.pos_y_m);
|
||||
if (tData.pos_x != 0 && tData.pos_y != 0) // we have a valid position
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "### Valid position";
|
||||
if (tData.pos_x_m == 0 && tData.pos_y_m == 0) // old data, recalculate
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "### Recalculate position";
|
||||
LtsCoordTrans::UtmCoordinate coord(LtsCoordTrans::UtmCoordinate::fromGeographic(tData.pos_x,tData.pos_y));
|
||||
qInsert.bindValue(QStringLiteral(":pos_x_m"), coord.x);
|
||||
qInsert.bindValue(QStringLiteral(":pos_y_m"), coord.y);
|
||||
}
|
||||
}
|
||||
|
||||
DEBUG_LOG(m_logger) << "Initial Time enter area = " << tData.time_enter_area;
|
||||
DEBUG_LOG(m_logger) << "Initial Time 9 liner = " << tData.time_nine_liner;
|
||||
|
||||
//if (tData.time_treatment > 0 && participant.equipmentNumber().is_set())
|
||||
// get FunctionalArea for participants with vulnerabilityState > 0, too
|
||||
if (participant.equipmentNumber().is_set())
|
||||
{
|
||||
// re-calculate time enter in Functional Area
|
||||
QPair<int, qint64> fa = getNextFunctionalAreaEntry(participant.equipmentNumber().get(), tData.time_vulnerability);
|
||||
qint64 time_enter_fa = fa.second;
|
||||
int area_id = fa.first;
|
||||
QString area_name;
|
||||
if (area_id > 0)
|
||||
{
|
||||
area_name = QString::fromStdString(m_aesDtc->functionalArea(area_id).name());
|
||||
qInsert.bindValue(QStringLiteral(":area_id"), area_id);
|
||||
qInsert.bindValue(QStringLiteral(":area_name"), area_name);
|
||||
}
|
||||
if (time_enter_fa > 0)
|
||||
{
|
||||
INFO_LOG(m_logger) << "Re-calculated time enter area = " << time_enter_fa;
|
||||
qInsert.bindValue(QStringLiteral(":time_enter_area"), time_enter_fa);
|
||||
}
|
||||
|
||||
if (tData.time_treatment > 0 )
|
||||
{
|
||||
// recalculate time_nine_liner
|
||||
qint64 time_9liner = get9LinerTime(participant.equipmentNumber().get(), tData.time_vulnerability);
|
||||
if (time_9liner > 0 && time_9liner != tData.time_nine_liner)
|
||||
{
|
||||
INFO_LOG(m_logger) << "Re-calculated time 9 liner = " << time_9liner;
|
||||
qInsert.bindValue(QStringLiteral(":time_nine_liner"), time_9liner);
|
||||
}
|
||||
|
||||
// recalculate time_position_changed
|
||||
qint64 time_pos_changed = getPosChangedTime(participant.equipmentNumber().get(), tData.time_vulnerability);
|
||||
if (time_pos_changed > 0 && time_pos_changed != tData.time_position_changed)
|
||||
{
|
||||
INFO_LOG(m_logger) << "Re-calculated time position changed = " << time_pos_changed;
|
||||
qInsert.bindValue(QStringLiteral(":time_position"), time_pos_changed);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// recalculate priority correct
|
||||
if (tData.time_treatment > 0)
|
||||
{
|
||||
bool pCorrect = false;
|
||||
pCorrect = getPriorityCorrect(participant.id(), tData.time_treatment, tData.priority);
|
||||
qInsert.bindValue(QStringLiteral(":pCorrect"), pCorrect);
|
||||
}
|
||||
|
||||
DEBUG_LOG(m_logger) << "Statement: " << stmtInsert;
|
||||
|
||||
if (!qInsert.exec())
|
||||
{
|
||||
ERROR_LOG(m_logger) << "Error inserting report data for report id = " << reportId;
|
||||
trans.rollback();
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
/* not needed because we filtered the data at the beginning
|
||||
if (request.reportType() == ReportType::TreatmentPriority)
|
||||
{
|
||||
if (request.width() > 0 && request.height() > 0 && request.cornerBottomLeft().lon() != 0 && request.cornerBottomLeft().lat() != 0)
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "Filtering data on geographic position on area (x) " << request.cornerBottomLeft().lon() << ", (y)" << request.cornerBottomLeft().lat()
|
||||
<< " width: " << request.width() << ", height: " << request.height();
|
||||
|
||||
LtsCoordTrans::UtmCoordinate coord(LtsCoordTrans::UtmCoordinate::fromGeographic(request.cornerBottomLeft().lon(),
|
||||
request.cornerBottomLeft().lat()));
|
||||
|
||||
QString stmtDelete = QStringLiteral("DELETE FROM rep_treatment_result WHERE report_id = %1 AND (").arg(reportId);
|
||||
|
||||
stmtDelete += QLatin1String(" position_x_m < ") + QString::number(coord.x);
|
||||
stmtDelete += QLatin1String(" OR position_x_m > ") + QString::number(coord.x) + QLatin1String(" + ") + QString::number(request.height());
|
||||
stmtDelete += QLatin1String(" OR position_y_m < ") + QString::number(coord.y);
|
||||
stmtDelete += QLatin1String(" OR position_y_m > ") + QString::number(coord.y) + QLatin1String(" + ") + QString::number(request.width());
|
||||
stmtDelete += QLatin1String(")");
|
||||
|
||||
DEBUG_LOG(m_logger) << "Statement delete: " << stmtDelete;
|
||||
|
||||
qDelete.prepare(stmtDelete);
|
||||
if (!qDelete.exec())
|
||||
ERROR_LOG(m_logger) << "Error deleting data for report id = " << reportId;
|
||||
|
||||
}
|
||||
}
|
||||
*/
|
||||
trans.commit();
|
||||
|
||||
DEBUG_LOG(m_logger) << " END generateTreatmentResult";
|
||||
return true;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
QPair<int, qint64> HandlerReportData::getNextFunctionalAreaEntry(int eqNo, qint64 vbgTime)
|
||||
{
|
||||
qint64 time_enter = 0;
|
||||
int area_id = 0;
|
||||
|
||||
QPair<int, qint64> ret;
|
||||
ret.first = area_id;
|
||||
ret.second = time_enter;
|
||||
|
||||
NSqlQuery qSelect(m_db->database());
|
||||
QString stmtSelect = QStringLiteral("SELECT e.sample_time, e.aes_item_id "
|
||||
"FROM rec_functional_area_entry e, rec_functional_area f "
|
||||
"WHERE e.aes_item_id = f.id "
|
||||
"AND f.functional_area_type_id IN (3,4) " // Medical Treatment Facility
|
||||
"AND equipment_number = :eqNo AND (e.sample_time >= :vbgTime) "
|
||||
"ORDER by e.sample_time DESC LIMIT 1");
|
||||
|
||||
DEBUG_LOG(m_logger) << "#### getNextFunctionalAreaEntry() - Get time of first functional area entry after VBG changed";
|
||||
|
||||
DEBUG_LOG(m_logger) << "Equipment number = " << eqNo;
|
||||
DEBUG_LOG(m_logger) << "Time = " << vbgTime;
|
||||
DEBUG_LOG(m_logger) << "Statement: " << stmtSelect;
|
||||
|
||||
qSelect.prepare(stmtSelect);
|
||||
qSelect.bindValue(QStringLiteral(":vbgTime"), vbgTime);
|
||||
qSelect.bindValue(QStringLiteral(":eqNo") , eqNo);
|
||||
|
||||
if (!qSelect.execAndFetch())
|
||||
{
|
||||
WARNING_LOG(m_logger) << "Error selecting data for equipment number = " << eqNo;
|
||||
return ret;
|
||||
}
|
||||
|
||||
time_enter = qSelect.value(0).toLongLong();
|
||||
area_id = qSelect.value(1).toLongLong();
|
||||
|
||||
ret.first = area_id;
|
||||
ret.second = time_enter;
|
||||
|
||||
DEBUG_LOG(m_logger) << "Functional area id = " << area_id;
|
||||
DEBUG_LOG(m_logger) << "Entry time = " << time_enter;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
qint64 HandlerReportData::get9LinerTime(int equipmentNumber, qint64 timeVulnerability)
|
||||
{
|
||||
qint64 time_9liner = 0;
|
||||
NSqlQuery qSelect(m_db->database());
|
||||
|
||||
DEBUG_LOG(m_logger) << "#### get9LinerTime() - Get time of first 9Liner after VBG changed";
|
||||
|
||||
// TODO: replace HardCoded (sub_device_id = 14 and equipment_function_id = 5 AND device_specific_event_code = 1)";
|
||||
|
||||
QString stmtSelect = QStringLiteral(" SELECT sample_time "
|
||||
" FROM rec_equipment_system_event WHERE equipment_number = :eqNo "
|
||||
" AND sample_time >= :vbgTime "
|
||||
" AND sub_device_id = 14 and equipment_function_id = 5 AND device_specific_event_code = 1 "
|
||||
" ORDER BY sample_time LIMIT 1");
|
||||
|
||||
DEBUG_LOG(m_logger) << "Statement: " << stmtSelect;
|
||||
DEBUG_LOG(m_logger) << "Equipment number = " << equipmentNumber;
|
||||
DEBUG_LOG(m_logger) << "Time vulnerability = " << timeVulnerability;
|
||||
|
||||
qSelect.prepare(stmtSelect);
|
||||
qSelect.bindValue(QStringLiteral(":vbgTime"), timeVulnerability);
|
||||
qSelect.bindValue(QStringLiteral(":eqNo") , equipmentNumber);
|
||||
|
||||
if (!qSelect.execAndFetch())
|
||||
{
|
||||
WARNING_LOG(m_logger) << "Error selecting data for equipment number = " << equipmentNumber;
|
||||
return time_9liner;
|
||||
}
|
||||
|
||||
time_9liner = qSelect.value(0).toLongLong();
|
||||
|
||||
DEBUG_LOG(m_logger) << "Time 9Liner = " << time_9liner;
|
||||
|
||||
return time_9liner;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
bool HandlerReportData::getPriorityCorrect(int participantId, qint64 timeTreatment, int priority)
|
||||
{
|
||||
bool pCorrect = true;
|
||||
|
||||
// top priority, we dont need to check any further
|
||||
if (priority == 1)
|
||||
return pCorrect;
|
||||
|
||||
DEBUG_LOG(m_logger) << "### getPriorityCorrect for participant " << participantId;
|
||||
DEBUG_LOG(m_logger) << "### Priority = " << priority;
|
||||
DEBUG_LOG(m_logger) << "### Time treatment = " << timeTreatment;
|
||||
|
||||
NSqlQuery qSelect(m_db->database());
|
||||
|
||||
// looking for another participant id who had lower priority (i.E. bigger priority for treatment)
|
||||
// and he was already vulnerable at the timeTreatment, but he was treated later
|
||||
QString stmtSelect = QStringLiteral(" SELECT participant_id, priority, time_vulnerability, time_treatment FROM rep_treatment_data WHERE "
|
||||
" participant_id != :pId AND priority < :priority AND "
|
||||
" time_treatment > :treatTime AND time_vulnerability <= :vbgTime");
|
||||
|
||||
DEBUG_LOG(m_logger) << "Statement: " << stmtSelect;
|
||||
|
||||
qSelect.prepare(stmtSelect);
|
||||
qSelect.bindValue(QStringLiteral(":pId"), participantId);
|
||||
qSelect.bindValue(QStringLiteral(":priority"), priority);
|
||||
qSelect.bindValue(QStringLiteral(":vbgTime"), timeTreatment);
|
||||
qSelect.bindValue(QStringLiteral(":treatTime"), timeTreatment);
|
||||
|
||||
if (qSelect.exec())
|
||||
{
|
||||
while (qSelect.next())
|
||||
{
|
||||
INFO_LOG(m_logger) << "Bigger priority for participant id = " << qSelect.value(0).toInt() << ", priority = " << qSelect.value(1).toInt();
|
||||
INFO_LOG(m_logger) << "Vulnerability time = " << qSelect.value(2).toLongLong() << ", treated at = " << qSelect.value(3).toLongLong();
|
||||
pCorrect = false;
|
||||
break; // if we want to see all bigger priorities, do not break. if we want run time optimal, break.
|
||||
}
|
||||
}
|
||||
|
||||
return pCorrect;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
qint64 HandlerReportData::getPosChangedTime(int equipmentNumber, qint64 timeVulnerability)
|
||||
{
|
||||
qint64 time_pos_changed = timeVulnerability;
|
||||
NSqlQuery qSelect(m_db->database());
|
||||
|
||||
DEBUG_LOG(m_logger) << "####getPosChangedTime() - Get time of transport initiated after VBG changed";
|
||||
|
||||
// TODO: replace HardCoded (sub_device_id = 14 and equipment_function_id = 5 AND device_specific_event_code = 2)";
|
||||
|
||||
QString stmtSelect = QStringLiteral(" SELECT sample_time "
|
||||
" FROM rec_equipment_system_event WHERE equipment_number = :eqNo "
|
||||
" AND sample_time >= :vbgTime "
|
||||
" AND sub_device_id = 14 and equipment_function_id = 5 AND device_specific_event_code = 2 "
|
||||
" ORDER BY sample_time LIMIT 1");
|
||||
|
||||
DEBUG_LOG(m_logger) << "Statement: " << stmtSelect;
|
||||
DEBUG_LOG(m_logger) << "Equipment number = " << equipmentNumber;
|
||||
DEBUG_LOG(m_logger) << "Time vulnerability = " << timeVulnerability;
|
||||
|
||||
qSelect.prepare(stmtSelect);
|
||||
qSelect.bindValue(QStringLiteral(":vbgTime"), timeVulnerability);
|
||||
qSelect.bindValue(QStringLiteral(":eqNo") , equipmentNumber);
|
||||
|
||||
if (!qSelect.execAndFetch())
|
||||
{
|
||||
WARNING_LOG(m_logger) << "Error selecting data for equipment number = " << equipmentNumber;
|
||||
return time_pos_changed;
|
||||
}
|
||||
|
||||
time_pos_changed = qSelect.value(0).toLongLong();
|
||||
DEBUG_LOG(m_logger) << "Time Position changed = " << time_pos_changed;
|
||||
|
||||
return time_pos_changed;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
qint64 HandlerReportData::sinceWhenVitality(int participantId, int vitality, qint64 currTime)
|
||||
{
|
||||
qint64 time = currTime;
|
||||
NSqlQuery qSelect(m_db->database());
|
||||
QString stmtSelect = QStringLiteral("SELECT event_time, vitality "
|
||||
"FROM rep_treatment_timeline_data "
|
||||
"WHERE participant_id = :participantId AND (event_time <= :currTime) "
|
||||
"ORDER BY event_time DESC");
|
||||
|
||||
DEBUG_LOG(m_logger) << "!!! sinceWhenVitality";
|
||||
DEBUG_LOG(m_logger) << "Statement: " << stmtSelect;
|
||||
DEBUG_LOG(m_logger) << "Participant Id = " << participantId;
|
||||
DEBUG_LOG(m_logger) << "Time = " << currTime;
|
||||
DEBUG_LOG(m_logger) << "Vitality = " << vitality;
|
||||
|
||||
qSelect.prepare(stmtSelect);
|
||||
qSelect.bindValue(QStringLiteral(":currTime"), currTime);
|
||||
qSelect.bindValue(QStringLiteral(":participantId"), participantId);
|
||||
|
||||
if (!qSelect.exec())
|
||||
{
|
||||
ERROR_LOG(m_logger) << "Error selecting data for participant id = " << participantId;
|
||||
return time;
|
||||
}
|
||||
|
||||
while (qSelect.next())
|
||||
{
|
||||
int vit = qSelect.value(1).toInt();
|
||||
if (vit == vitality)
|
||||
{
|
||||
time = qSelect.value(0).toLongLong();
|
||||
continue;
|
||||
}
|
||||
else
|
||||
break;
|
||||
}
|
||||
|
||||
DEBUG_LOG(m_logger) << "### Recalculated time vitality = " << time;
|
||||
|
||||
return time;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
qint64 HandlerReportData::sinceWhenVulnerability(int participantId, int vulnerability, qint64 currTime)
|
||||
{
|
||||
qint64 time = currTime;
|
||||
NSqlQuery qSelect(m_db->database());
|
||||
QString stmtSelect = QStringLiteral("SELECT event_time, vulnerability "
|
||||
"FROM rep_treatment_timeline_data "
|
||||
"WHERE participant_id = :participantId AND (event_time <= :currTime) "
|
||||
"ORDER BY event_time DESC");
|
||||
|
||||
DEBUG_LOG(m_logger) << "!!! sinceWhenVulnerability";
|
||||
DEBUG_LOG(m_logger) << "Statement: " << stmtSelect;
|
||||
DEBUG_LOG(m_logger) << "Participant Id = " << participantId;
|
||||
DEBUG_LOG(m_logger) << "Time = " << currTime;
|
||||
DEBUG_LOG(m_logger) << "Vulnerability = " << vulnerability;
|
||||
|
||||
qSelect.prepare(stmtSelect);
|
||||
qSelect.bindValue(QStringLiteral(":currTime"), currTime);
|
||||
qSelect.bindValue(QStringLiteral(":participantId"), participantId);
|
||||
|
||||
if (!qSelect.exec())
|
||||
{
|
||||
ERROR_LOG(m_logger) << "Error selecting data for participant id = " << participantId;
|
||||
return time;
|
||||
}
|
||||
|
||||
while (qSelect.next())
|
||||
{
|
||||
int vuln = qSelect.value(1).toInt();
|
||||
DEBUG_LOG(m_logger) << "Checking - time = " << qSelect.value(0).toLongLong() << ", vuln = " << vuln;
|
||||
if (vuln == vulnerability)
|
||||
{
|
||||
time = qSelect.value(0).toLongLong();
|
||||
continue;
|
||||
}
|
||||
else
|
||||
break;
|
||||
}
|
||||
|
||||
DEBUG_LOG(m_logger) << "### Recalculated time vulnerability = " << time;
|
||||
|
||||
return time;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
bool HandlerReportData::checkVulnerabilityStateWIA(int participantId, qint64 currTime)
|
||||
{
|
||||
qint64 time = currTime;
|
||||
NSqlQuery qSelect(m_db->database());
|
||||
QString stmtSelect = QStringLiteral("SELECT vulnerability_state "
|
||||
"FROM rep_treatment_timeline_data "
|
||||
"WHERE participant_id = :participantId AND event_time <= :currTime "
|
||||
"AND event_type_id = :eventTypeId AND vulnerability_state = :vulnerabilityState "
|
||||
"ORDER BY event_time DESC");
|
||||
|
||||
DEBUG_LOG(m_logger) << "!!! checkVulnerabilityStateWIA";
|
||||
DEBUG_LOG(m_logger) << "Statement: " << stmtSelect;
|
||||
DEBUG_LOG(m_logger) << "Participant Id = " << participantId;
|
||||
DEBUG_LOG(m_logger) << "Time = " << currTime;
|
||||
|
||||
qSelect.prepare(stmtSelect);
|
||||
qSelect.bindValue(QStringLiteral(":currTime"), currTime);
|
||||
qSelect.bindValue(QStringLiteral(":eventTypeId"), ReportManagement::EventType_def::VBGSet);
|
||||
qSelect.bindValue(QStringLiteral(":vulnerabilityState"), ProjectDataManagement::VulnerabilityState_def::CatastrophicKill);
|
||||
qSelect.bindValue(QStringLiteral(":participantId"), participantId);
|
||||
|
||||
if (!qSelect.exec())
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "Error MedicalTimeout for participant " << participantId;
|
||||
return false;
|
||||
}
|
||||
|
||||
bool medicalTimeout = false;
|
||||
if (qSelect.next())
|
||||
medicalTimeout = true;
|
||||
|
||||
DEBUG_LOG(m_logger) << "### medicalTimeout = " << medicalTimeout << ", time: " << time;
|
||||
|
||||
return medicalTimeout;
|
||||
}
|
||||
|
||||
+136
@@ -0,0 +1,136 @@
|
||||
/**
|
||||
* Handler for report treatment
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
* Created by Hanna E. Rathje, SLSE, 2016-12-20
|
||||
*/
|
||||
|
||||
#include "handler_report_data.h"
|
||||
|
||||
#include <ngldb/nsqlquery.h>
|
||||
#include <ngldb/dbtransaction.h>
|
||||
#include <LtsCoordTrans/lts_coord_trans.h>
|
||||
|
||||
#include <QVariant>
|
||||
#include <QJsonDocument>
|
||||
|
||||
using namespace ReportManagement;
|
||||
|
||||
bool HandlerReportData::generateTreatmentTimelineResult(const CreateModifyReportRequest &request,
|
||||
int reportId,
|
||||
const std::shared_ptr<ParticipantManagement::Interface::Dtc> &ppmDtc)
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "Start generateTreatmentTimelineResult";
|
||||
|
||||
DBTransaction trans(m_db->database());
|
||||
NSqlQuery qSelect(m_db->database());
|
||||
NSqlQuery qInsert(m_db->database());
|
||||
|
||||
QString stmtSelect = QStringLiteral("SELECT participant_type_id, participant_id, vitality, vulnerability, vulnerability_state, event_time, event_type_id, properties "
|
||||
"FROM rep_treatment_timeline_data "
|
||||
"WHERE party_id = :partyId AND (event_time between :startTime and :endTime) ");
|
||||
if (request.participantTypes().size() > 0)
|
||||
{
|
||||
const QString pTypeIdsStr = intVecToString(request.participantTypes());
|
||||
stmtSelect += QStringLiteral(" AND participant_type_id IN (%1) ").arg(pTypeIdsStr);
|
||||
}
|
||||
if (request.participantIds().size() > 0)
|
||||
{
|
||||
const QString pIdsStr = intVecToString(request.participantIds());
|
||||
stmtSelect += QStringLiteral(" AND participant_id IN (%1) ").arg(pIdsStr);
|
||||
}
|
||||
|
||||
stmtSelect += QStringLiteral(" ORDER by participant_type_id, participant_id, event_time, event_type_id");
|
||||
|
||||
DEBUG_LOG(m_logger) << "Statement: " << stmtSelect;
|
||||
DEBUG_LOG(m_logger) << "Party Id = " << request.partyId();
|
||||
DEBUG_LOG(m_logger) << "Start Time = " << request.startTime();
|
||||
DEBUG_LOG(m_logger) << "End Time = " << request.endTime();
|
||||
|
||||
qSelect.prepare(stmtSelect);
|
||||
qSelect.bindValue(QStringLiteral(":startTime"), request.startTime());
|
||||
qSelect.bindValue(QStringLiteral(":endTime"), request.endTime());
|
||||
qSelect.bindValue(QStringLiteral(":partyId"), request.partyId());
|
||||
|
||||
if (!qSelect.exec())
|
||||
{
|
||||
ERROR_LOG(m_logger) << "Error selecting report data for report id = " << reportId;
|
||||
return false;
|
||||
}
|
||||
|
||||
m_treatmentTimelineData.clear();
|
||||
|
||||
QElapsedTimer timeoutTimer;
|
||||
timeoutTimer.start();
|
||||
TreatmentTimelineData oldData;
|
||||
|
||||
while (qSelect.next())
|
||||
{
|
||||
checkElapsedTimer(timeoutTimer);
|
||||
|
||||
TreatmentTimelineData tData;
|
||||
tData.participantTypeId = qSelect.value(0).toInt();
|
||||
tData.participantId = qSelect.value(1).toInt();
|
||||
tData.vitality = qSelect.value(2).toInt();
|
||||
tData.vulnerability = qSelect.value(3).toInt();
|
||||
tData.vulnerabilityState = qSelect.value(4).toInt();
|
||||
tData.eventTime = qSelect.value(5).toLongLong();
|
||||
tData.eventTypeId = qSelect.value(6).toInt();
|
||||
tData.properties = qSelect.value(7).toString();
|
||||
|
||||
// 2 events TransportInitiated one after another, we save only first one
|
||||
if (oldData.eventTypeId == ReportManagement::EventType::TransportInitiated &&
|
||||
tData.eventTypeId == ReportManagement::EventType::TransportInitiated)
|
||||
continue;
|
||||
|
||||
m_treatmentTimelineData.append(tData);
|
||||
|
||||
oldData = tData;
|
||||
}
|
||||
|
||||
QString stmtInsert = QStringLiteral("INSERT INTO rep_treatment_timeline_result (report_id, participant_type_id, participant_id, participant_name, participant_equipment_number, vitality, vulnerability, vulnerability_state, "
|
||||
" event_type_id, event_time, properties ) "
|
||||
" values (:reportId, :pTypeId, :participantId, :participantName, :participantEqNo, :vitality, :vulnerability, :vbg, "
|
||||
" :eventType, :eventTime, :properties)");
|
||||
|
||||
if (!qInsert.prepare(stmtInsert))
|
||||
{
|
||||
ERROR_LOG(m_logger) << "Error preparing statement: " << stmtInsert;
|
||||
return false;
|
||||
}
|
||||
|
||||
qInsert.bindValue(QStringLiteral(":reportId"), reportId);
|
||||
|
||||
for (const TreatmentTimelineData &tData : qAsConst(m_treatmentTimelineData))
|
||||
{
|
||||
const auto participant = ppmDtc->participant(tData.participantId);
|
||||
|
||||
qInsert.bindValue(QStringLiteral(":pTypeId"), tData.participantTypeId);
|
||||
qInsert.bindValue(QStringLiteral(":participantId"), tData.participantId);
|
||||
qInsert.bindValue(QStringLiteral(":participantName"), ppmDtc->hierarchyFromParticipant(tData.participantId));
|
||||
qInsert.bindValue(QStringLiteral(":participantEqNo"), participant.equipmentNumber().is_set() ?
|
||||
participant.equipmentNumber().get() : 0);
|
||||
qInsert.bindValue(QStringLiteral(":vitality"), tData.vitality);
|
||||
qInsert.bindValue(QStringLiteral(":vulnerability"), tData.vulnerability);
|
||||
qInsert.bindValue(QStringLiteral(":vbg"), tData.vulnerabilityState);
|
||||
qInsert.bindValue(QStringLiteral(":eventTime"), tData.eventTime);
|
||||
qInsert.bindValue(QStringLiteral(":eventType"), tData.eventTypeId);
|
||||
qInsert.bindValue(QStringLiteral(":properties"), tData.properties.size() > 0 ? tData.properties : QString());
|
||||
|
||||
DEBUG_LOG(m_logger) << "Statement: " << stmtInsert;
|
||||
|
||||
if (!qInsert.exec())
|
||||
{
|
||||
ERROR_LOG(m_logger) << "Error inserting report data for report id = " << reportId;
|
||||
trans.rollback();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
trans.commit();
|
||||
|
||||
DEBUG_LOG(m_logger) << " END generateTreatmentTimelineResult";
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,268 @@
|
||||
/**
|
||||
* Handler for report unit power
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author:
|
||||
* Created by hjl, SLSE, 2016-09-21
|
||||
*/
|
||||
|
||||
#include "handler_report_data.h"
|
||||
#include "rep_db.h"
|
||||
|
||||
#include <ProjectDataManagement/pdm.hpp>
|
||||
#include <LtsUtilsCore/dds_vector.h>
|
||||
|
||||
#include <QSet>
|
||||
#include <QVector>
|
||||
#include <QVariant>
|
||||
|
||||
#include <ngldb/nsqlquery.h>
|
||||
#include <ngldb/dbtransaction.h>
|
||||
|
||||
using namespace ReportManagement;
|
||||
// -----------------------------------------------------------------------------------------------------------------------------------------
|
||||
bool HandlerReportData::insertResultMap(qint32 reportId, qint64 intervalStart, qint64 intervalEnd, const QMap<int, QMap<int, int> > &sumMap)
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "sumMap.size: " << sumMap.size();
|
||||
DEBUG_LOG(m_logger) << "Interval: (" << intervalStart << ", " << intervalEnd << ")";
|
||||
|
||||
for (auto it = sumMap.begin(); it != sumMap.end(); ++it)
|
||||
{
|
||||
Database::RepUnitPowerResult resData;
|
||||
resData.reportId = reportId;
|
||||
resData.groupId = it.key();
|
||||
resData.startTime = intervalStart;
|
||||
resData.endTime = intervalEnd;
|
||||
|
||||
QMap<int, int> map = it.value();
|
||||
resData.ready = map[0];
|
||||
resData.notReady = 0;
|
||||
resData.vulnerabilityState1 = map[1]; resData.notReady += map[1];
|
||||
resData.vulnerabilityState2 = map[2]; resData.notReady += map[2];
|
||||
resData.vulnerabilityState3 = map[3]; resData.notReady += map[3];
|
||||
resData.vulnerabilityState4 = map[4]; resData.notReady += map[4];
|
||||
resData.vulnerabilityState5 = map[5]; resData.notReady += map[5];
|
||||
resData.vulnerabilityState6 = map[6]; resData.notReady += map[6];
|
||||
resData.vulnerabilityState7 = map[7]; resData.notReady += map[7];
|
||||
resData.vulnerabilityState8 = map[8]; resData.notReady += map[8];
|
||||
resData.vulnerabilityState9 = map[9]; resData.notReady += map[9];
|
||||
// 10, 11 are combat ready, IO 2021-08-09
|
||||
resData.vulnerabilityState10 = map[10]; resData.ready += map[10];
|
||||
resData.vulnerabilityState11 = map[11]; resData.ready += map[11];
|
||||
|
||||
DEBUG_LOG(m_logger) << "ready: " << resData.ready << ", not ready: " << resData.notReady;
|
||||
int total = resData.ready + resData.notReady;
|
||||
|
||||
DEBUG_LOG(m_logger) << "+++++++++++++++ total: " << total;
|
||||
|
||||
if (!m_db->insert(resData))
|
||||
{
|
||||
ERROR_LOG(m_logger) << "Error while inserting result data for reportId " << reportId;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------------------------------------------------------------------
|
||||
bool HandlerReportData::getParticipantInitial(const QVector<int> &participantIds,
|
||||
qint64 startTime,
|
||||
qint64 endTime,
|
||||
const QString &keyStr,
|
||||
QMap<qint32, ParticipantKeyData> &initialParticipantStates)
|
||||
{
|
||||
NSqlQuery qBeforeStart(m_db->database());
|
||||
NSqlQuery qAfterStart(m_db->database());
|
||||
|
||||
// Suche letztes Ereignis vor startTime für Participant X
|
||||
QString stmt = QStringLiteral("SELECT ready, %1 FROM "
|
||||
"rep_unit_power_data WHERE id = "
|
||||
"(SELECT id FROM rep_unit_power_data "
|
||||
"WHERE event_time < :startTime AND participant_id = :participant_id "
|
||||
"ORDER by event_time DESC LIMIT 1)").arg(keyStr);
|
||||
if (!qBeforeStart.prepare(stmt))
|
||||
return false;
|
||||
|
||||
DEBUG_LOG(m_logger) << "stmt: " << stmt;
|
||||
// Suche erstes Ereignis nach startTime für Participant X
|
||||
stmt = QStringLiteral("SELECT ready, %1 FROM "
|
||||
"rep_unit_power_data WHERE id = "
|
||||
"(SELECT id FROM rep_unit_power_data "
|
||||
"WHERE event_time >= :startTime AND event_time <= :endTime AND participant_id = :participant_id "
|
||||
"ORDER by event_time ASC LIMIT 1)").arg(keyStr);
|
||||
if (!qAfterStart.prepare(stmt))
|
||||
return false;
|
||||
|
||||
DEBUG_LOG(m_logger) << "stmt: " << stmt;
|
||||
|
||||
qBeforeStart.bindValue(QStringLiteral(":startTime"), startTime);
|
||||
qAfterStart.bindValue(QStringLiteral(":startTime"), startTime);
|
||||
qAfterStart.bindValue(QStringLiteral(":endTime"), endTime);
|
||||
for (int participantId : qAsConst(participantIds))
|
||||
{
|
||||
qBeforeStart.bindValue(QStringLiteral(":participant_id"), participantId);
|
||||
if (!qBeforeStart.exec())
|
||||
return false;
|
||||
if (qBeforeStart.next())
|
||||
{
|
||||
ParticipantKeyData data;
|
||||
data.ready = qBeforeStart.value(0).toBool();
|
||||
data.key = qBeforeStart.value(1).toInt();
|
||||
data.participantId = participantId;
|
||||
|
||||
DEBUG_LOG(m_logger) << "### BEFORE: key: " << data.key << ", ready: " << data.ready << ", participantId: " << data.participantId;
|
||||
initialParticipantStates[participantId] = data;
|
||||
continue;
|
||||
}
|
||||
|
||||
qAfterStart.bindValue(QStringLiteral(":participant_id"), participantId);
|
||||
if (!qAfterStart.exec())
|
||||
return false;
|
||||
if (qAfterStart.next())
|
||||
{
|
||||
ParticipantKeyData data;
|
||||
data.ready = qAfterStart.value(0).toBool();
|
||||
data.key = qAfterStart.value(1).toInt();
|
||||
data.participantId = participantId;
|
||||
DEBUG_LOG(m_logger) << "### AFTER: key: " << data.key << ", ready: " << data.ready << ", participantId: " << data.participantId;
|
||||
|
||||
initialParticipantStates[participantId] = data;
|
||||
continue;
|
||||
}
|
||||
// No data -> ignore this participant ...
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------------------------------------------------------------------
|
||||
bool HandlerReportData::generateUnitPowerResult(const CreateModifyReportRequest &request, qint32 reportId)
|
||||
{
|
||||
// TODO: request.selectedParticipantIds() == im MMI selektierte Participants (auch units),
|
||||
// nicht relvant für Report-Erzeugung, nur MMI + Legende in Berichtsausgabe
|
||||
// request.participantIds() == auszuwertende Participants (wird im MMI ausgefüllt)
|
||||
|
||||
|
||||
QString keyStr = request.groupByParty() ? QStringLiteral("party_id") : QStringLiteral("participant_type_id");
|
||||
// 1. ParticipantVec - only participantIds
|
||||
// QSet<int> participantIds;
|
||||
// for (auto it = request.participantIds().begin(); it != request.participantIds().end(); ++it)
|
||||
// participantIds += *it;
|
||||
|
||||
// participantId -> ParticipantKeyData
|
||||
QMap<int, ParticipantKeyData> resultMapPrevious;
|
||||
|
||||
if (!getParticipantInitial(LtsUtils::convert<QVector<int>>(request.participantIds()),
|
||||
request.startTime(),
|
||||
request.endTime(),
|
||||
keyStr,
|
||||
resultMapPrevious))
|
||||
return false;
|
||||
|
||||
DEBUG_LOG(m_logger) << "resultMapPrevious size: " << resultMapPrevious.size();
|
||||
|
||||
// Get analyzed data from db for a certain time frame
|
||||
// TODO: index on event_time, participant_id und ggf.party_id/participant_type_id
|
||||
QString stmt = QStringLiteral("SELECT participant_id, ready, vulnerability_state, event_time "
|
||||
" FROM rep_unit_power_data WHERE event_time > :intervalStart"
|
||||
" AND event_time <= :intervalEnd ");
|
||||
if (request.participantIds().size() > 0)
|
||||
{
|
||||
const QString participantIdStr = intVecToString(request.participantIds());
|
||||
stmt += QStringLiteral(" AND participant_id IN (%1)").arg(participantIdStr);
|
||||
}
|
||||
stmt += QStringLiteral(" ORDER by event_time");
|
||||
DEBUG_LOG(m_logger) << "stmt: " << stmt;
|
||||
|
||||
DBTransaction trans(m_db->database());
|
||||
NSqlQuery q(m_db->database());
|
||||
if (!q.prepare(stmt))
|
||||
return false; // ...
|
||||
|
||||
q.bindValue(QStringLiteral(":intervalStart"), request.startTime());
|
||||
q.bindValue(QStringLiteral(":intervalEnd"), request.endTime());
|
||||
|
||||
if (!q.exec())
|
||||
{
|
||||
ERROR_LOG(m_logger) << "Error while executing stmt: " << stmt;
|
||||
return false;
|
||||
}
|
||||
|
||||
QVector<UnitPowerData> dataVec;
|
||||
while (q.next())
|
||||
{
|
||||
UnitPowerData data;
|
||||
data.participantId = q.value(0).toInt();
|
||||
data.ready = q.value(1).toBool();
|
||||
data.vulnerabilityState = q.value(2).toInt();
|
||||
data.eventTime = q.value(3).toLongLong();
|
||||
dataVec.append(data);
|
||||
}
|
||||
|
||||
DEBUG_LOG(m_logger) << "dataVec size: " << dataVec.size();
|
||||
|
||||
qint64 t1 = request.startTime();
|
||||
int startIndex = 0;
|
||||
QElapsedTimer timeoutTimer;
|
||||
timeoutTimer.start();
|
||||
while (t1 <= request.endTime())
|
||||
{
|
||||
checkElapsedTimer(timeoutTimer);
|
||||
qint64 t2 = qMin(qMax(t1, t1 + request.intervalTime() - 1), request.endTime());
|
||||
if (request.intervalTime() == 0) t2 = request.endTime();
|
||||
|
||||
INFO_LOG(m_logger) << "Generating report data for interval t1: " << t1 << ", t2: " << t2;
|
||||
|
||||
resultMapPrevious = generateUnitPowerResultPerInterval(resultMapPrevious, dataVec, startIndex, t2);
|
||||
DEBUG_LOG(m_logger) << "resultMapPrevious.size() = " << resultMapPrevious.size();
|
||||
|
||||
// <key, <vulnerabilityState, sum>>
|
||||
QMap<int, QMap<int, int>> sumMap;
|
||||
for (auto it = resultMapPrevious.begin(); it != resultMapPrevious.end(); ++it)
|
||||
{
|
||||
ParticipantKeyData data = it.value();
|
||||
sumMap[data.key][data.vulnerabilityState]++;
|
||||
}
|
||||
|
||||
// here we write in DB
|
||||
trans.begin();
|
||||
if (!insertResultMap(reportId, t1, t2, sumMap))
|
||||
return false;
|
||||
trans.commit();
|
||||
|
||||
t1 += request.intervalTime();
|
||||
if (request.intervalTime() == 0) break;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------------------------------------------------------------------
|
||||
QMap<qint32, ParticipantKeyData> HandlerReportData::generateUnitPowerResultPerInterval(const QMap<qint32, ParticipantKeyData> &resultMapPreviousInterval,
|
||||
const QVector<UnitPowerData> &dataVec, int &startIndex, qint64 intervalEnd)
|
||||
{
|
||||
QMap<qint32, ParticipantKeyData> readyPerParticipantId(resultMapPreviousInterval);
|
||||
|
||||
DEBUG_LOG(m_logger) << "Begin startIndex: " << startIndex;
|
||||
for (; startIndex < dataVec.size(); ++startIndex)
|
||||
{
|
||||
qint64 eventTime = dataVec[startIndex].eventTime;
|
||||
|
||||
if (eventTime > intervalEnd)
|
||||
break;
|
||||
|
||||
qint32 participantId = dataVec[startIndex].participantId;
|
||||
ParticipantKeyData data = readyPerParticipantId[participantId];
|
||||
int key = data.key;
|
||||
data = dataVec[startIndex];
|
||||
data.key = key;
|
||||
|
||||
DEBUG_LOG(m_logger) << "Participant: " << participantId << ", key: " << data.key << ", ready: " << data.ready;
|
||||
readyPerParticipantId[participantId] = data;
|
||||
}
|
||||
|
||||
DEBUG_LOG(m_logger) << "End startIndex: " << startIndex;
|
||||
DEBUG_LOG(m_logger) << "readyPerParticipantId size: " << readyPerParticipantId.size();
|
||||
|
||||
return readyPerParticipantId;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,231 @@
|
||||
/**
|
||||
* Handler for report Sanitation Material
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
* Created by Hanna E. Rathje, SLSE, 2016-12-20
|
||||
*/
|
||||
|
||||
#include "handler_report_data.h"
|
||||
|
||||
#include <ngldb/nsqlquery.h>
|
||||
#include <ngldb/dbtransaction.h>
|
||||
|
||||
#include <QVariant>
|
||||
|
||||
using namespace ReportManagement;
|
||||
|
||||
// ------------------------------------------------------------------------------------------------------------------
|
||||
bool HandlerReportData::generateSanitationMaterialResult(const CreateModifyReportRequest &request, int reportId)
|
||||
{
|
||||
INFO_LOG(m_logger) << "Start generateSanitationMaterialResult ";
|
||||
|
||||
DBTransaction trans(m_db->database());
|
||||
NSqlQuery qInsert(m_db->database());
|
||||
NSqlQuery qSelect(m_db->database());
|
||||
NSqlQuery qDelete(m_db->database());
|
||||
|
||||
// find all sanitation unique ids
|
||||
QSet<qint64> sanitationIds;
|
||||
QString stmt = QLatin1String("SELECT DISTINCT sanitation_unique_id FROM rep_sanitation_material_data "
|
||||
" WHERE (event_time BETWEEN ") + QString::number(request.startTime()) + QLatin1String(" AND ") + QString::number(request.endTime()) + QLatin1String(") ");
|
||||
|
||||
stmt += QLatin1String(" AND material_id != 0 ");
|
||||
|
||||
if (request.chargeTypeIds().size() > 0)
|
||||
{
|
||||
const QString chargeTypeIds = intVecToString(request.chargeTypeIds());
|
||||
stmt += QLatin1String(" AND (material_id IN (") + chargeTypeIds + QLatin1String("))");
|
||||
}
|
||||
|
||||
if (request.participantIds().size() > 0)
|
||||
{
|
||||
const QString participants = intVecToString(request.participantIds());
|
||||
stmt += QStringLiteral(" AND participant_id IN (%1)").arg(participants);
|
||||
}
|
||||
|
||||
//TODO: read from TAB or PPM enum. Skip qualification 0 = NotAsigned
|
||||
const QSet<int> qualifications = {1,2,3};
|
||||
stmt += QLatin1String(" AND qualification IN (1,2,3) ");
|
||||
|
||||
DEBUG_LOG(m_logger) << " stmt: " << stmt;
|
||||
|
||||
if (!qSelect.exec(stmt))
|
||||
{
|
||||
ERROR_LOG(m_logger) << "Couldn't select sanitation unique ids ";
|
||||
return false;
|
||||
}
|
||||
while (qSelect.next())
|
||||
sanitationIds += qSelect.value(0).toInt();
|
||||
|
||||
if (sanitationIds.isEmpty())
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "No available sanitation unique ids for this report";
|
||||
return true;
|
||||
}
|
||||
|
||||
qInsert.prepare(QLatin1String("INSERT INTO rep_sanitation_material_result (report_id, sanitation_unique_id, qualification, material_id ) VALUES (:reportId, :uqId, :qualif, :materialId )"));
|
||||
qInsert.bindValue(QLatin1String(":reportId"), reportId);
|
||||
|
||||
for (qint64 sanitationId : qAsConst(sanitationIds))
|
||||
{
|
||||
qInsert.bindValue(QLatin1String(":uqId"), sanitationId);
|
||||
|
||||
for (int qualif : qualifications)
|
||||
{
|
||||
qInsert.bindValue(QLatin1String(":qualif"), qualif);
|
||||
for (auto it = request.chargeTypeIds().begin(); it != request.chargeTypeIds().end(); ++it)
|
||||
{
|
||||
int materialId = *it;
|
||||
if (materialId == 0) continue; // skip 0
|
||||
|
||||
qInsert.bindValue(QLatin1String(":materialId"), materialId);
|
||||
|
||||
if (!qInsert.exec())
|
||||
{
|
||||
ERROR_LOG(m_logger) << "Error inserting report id, sanitationUniqueId, qualif, materialId = " << reportId << " , " << sanitationId << " , " << qualif << " , "<< materialId;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!calculateSanitationMaterialStock(sanitationId, materialId, request.startTime(), request.endTime(), request.partyId(), reportId, qualif))
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// delete empty records
|
||||
qDelete.prepare(QLatin1String("DELETE FROM rep_sanitation_material_result WHERE report_id = :reportId AND amount_start = 0 AND amount_resupplied = 0 AND amount_end = 0 AND amount_used = 0"));
|
||||
qDelete.bindValue(QLatin1String(":reportId"), reportId);
|
||||
if (!qDelete.exec())
|
||||
WARNING_LOG(m_logger) << "Couldn't delete empty records ";
|
||||
|
||||
trans.commit();
|
||||
|
||||
INFO_LOG(m_logger) << " END generateSanitationMaterialResult";
|
||||
return true;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------------------------
|
||||
bool HandlerReportData::calculateSanitationMaterialStock(int uniqueId, int materialId, qint64 startTime, qint64 endTime, int partyId, int reportId, int qualif)
|
||||
{
|
||||
SanitationMaterialData sanMatData;
|
||||
sanMatData.uniqueId = uniqueId;
|
||||
sanMatData.materialId = materialId;
|
||||
sanMatData.qualification = qualif;
|
||||
|
||||
NSqlQuery qSelect(m_db->database());
|
||||
NSqlQuery qInit(m_db->database());
|
||||
NSqlQuery qUpdate(m_db->database());
|
||||
QString stmt = QLatin1String("SELECT material_amount, event_time, material_id, sanitation_unique_id, qualification "
|
||||
" FROM rep_sanitation_material_data "
|
||||
" WHERE event_time > 0 AND event_time < ") + QString::number(startTime) +
|
||||
QLatin1String(" AND party_id = ") + QString::number(partyId) +
|
||||
QLatin1String(" AND material_id = ") + QString::number(materialId) +
|
||||
QLatin1String(" AND sanitation_unique_id = ") + QString::number(uniqueId) +
|
||||
QLatin1String(" AND qualification = ") + QString::number(qualif) +
|
||||
QLatin1String(" ORDER BY event_time DESC LIMIT 1");
|
||||
|
||||
DEBUG_LOG(m_logger) << "Start Statement: " << stmt;
|
||||
|
||||
if (!qInit.exec(stmt))
|
||||
{
|
||||
ERROR_LOG(m_logger) << "Error while selecting start-data for materialId, uniqueId " << materialId << ", " << uniqueId
|
||||
<< ", qualification " << qualif << ", stmt='" << stmt << "'";
|
||||
return false;
|
||||
}
|
||||
if (!qInit.next()) // not found a valid record
|
||||
{
|
||||
INFO_LOG(m_logger) << "No start entry for materialId = " << materialId << ", sanitation id = " << uniqueId << ", qualification = " << qualif <<" -> assuming 0";
|
||||
//return true;
|
||||
sanMatData.amount = 0;
|
||||
sanMatData.amountStart = 0;
|
||||
sanMatData.used = 0;
|
||||
sanMatData.resupplied = 0;
|
||||
sanMatData.duration = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
qInit.first();
|
||||
sanMatData.amount = qInit.value(0).toInt();
|
||||
sanMatData.amountStart = sanMatData.amount;
|
||||
sanMatData.used = 0;
|
||||
sanMatData.resupplied = 0;
|
||||
sanMatData.duration = 0;
|
||||
}
|
||||
|
||||
DEBUG_LOG(m_logger) << "START materialId = " << QString::number(materialId) << " , "
|
||||
<< "sanitation id " << uniqueId << ", qualification " << qualif
|
||||
<< " amountStart = " << sanMatData.amountStart;
|
||||
|
||||
stmt = QLatin1String("SELECT material_amount, event_time FROM rep_sanitation_material_data "
|
||||
" WHERE event_time >= ") + QString::number(startTime) +
|
||||
QLatin1String(" AND event_time <= ") + QString::number(endTime) +
|
||||
QLatin1String(" AND party_id = ") + QString::number(partyId) +
|
||||
QLatin1String(" AND material_id = ") + QString::number(materialId) +
|
||||
QLatin1String(" AND sanitation_unique_id = ") + QString::number(uniqueId) +
|
||||
QLatin1String(" AND qualification = ") + QString::number(qualif) +
|
||||
QLatin1String(" ORDER BY event_time ");
|
||||
|
||||
if (!qSelect.exec(stmt))
|
||||
{
|
||||
ERROR_LOG(m_logger) << "Error while selecting data for materialId " << materialId <<
|
||||
", sanitation id " << uniqueId << ", qualification " << qualif;
|
||||
return false;
|
||||
}
|
||||
|
||||
DEBUG_LOG(m_logger) << "Select statement: " << stmt;
|
||||
int amount = 0;
|
||||
int amountOld = sanMatData.amountStart;
|
||||
|
||||
int duration = 0;
|
||||
|
||||
long long lastTime = 0;
|
||||
if (amountOld == 0)
|
||||
lastTime = startTime;
|
||||
|
||||
while (qSelect.next())
|
||||
{
|
||||
amount = qSelect.value(0).toInt();
|
||||
long long crtTime = qSelect.value(1).toLongLong();
|
||||
|
||||
if (amount == 0 || amountOld == 0)
|
||||
{
|
||||
duration += crtTime - lastTime;
|
||||
DEBUG_LOG(m_logger) << "## Adding (" << crtTime << " - " << lastTime << ") = " << crtTime - lastTime;
|
||||
DEBUG_LOG(m_logger) << "## New duration = " << duration;
|
||||
}
|
||||
int diff = amount - amountOld;
|
||||
if (diff > 0)
|
||||
sanMatData.resupplied += diff;
|
||||
else if (diff < 0)
|
||||
sanMatData.used += qAbs(diff);
|
||||
amountOld = amount;
|
||||
lastTime = crtTime;
|
||||
}
|
||||
sanMatData.amount = amount;
|
||||
sanMatData.duration = duration;
|
||||
|
||||
DEBUG_LOG(m_logger) << "UPDATING stock for materialId: " << materialId <<
|
||||
", sanitation id " << uniqueId << ", qualification " << qualif;
|
||||
|
||||
stmt = QLatin1String("UPDATE rep_sanitation_material_result SET "
|
||||
" amount_start = ") + QString::number(sanMatData.amountStart) + QLatin1String(", ") +
|
||||
QLatin1String(" amount_resupplied = ") + QString::number(sanMatData.resupplied) + QLatin1String(", ") +
|
||||
QLatin1String(" amount_end = ") + QString::number(sanMatData.amount) + QLatin1String(", ") +
|
||||
QLatin1String(" amount_used = ") + QString::number(sanMatData.used) + QLatin1String(", ") +
|
||||
QLatin1String(" duration = ") + QString::number(sanMatData.duration) +
|
||||
QLatin1String(" WHERE report_id = ") + QString::number(reportId) +
|
||||
QLatin1String(" AND material_id = ") + QString::number(sanMatData.materialId) +
|
||||
QLatin1String(" AND sanitation_unique_id = ") + QString::number(sanMatData.uniqueId) +
|
||||
QLatin1String(" AND qualification = ") + QString::number(sanMatData.qualification);
|
||||
|
||||
DEBUG_LOG(m_logger) << "Update statement: " << stmt;
|
||||
|
||||
if (!qUpdate.exec(stmt))
|
||||
{
|
||||
ERROR_LOG(m_logger) << "Error while updating stock for materialId, uniqueId, qualification " << materialId << ", " << uniqueId << ", " << qualif;
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
+42
@@ -0,0 +1,42 @@
|
||||
/**
|
||||
* @RDE_HEADER@
|
||||
* main for ReportManagement Generator
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
*/
|
||||
|
||||
#include <nglapplication/nglcoreapplication.h>
|
||||
#include <LtsCommandLineParser/LtsCommandLineParser.h>
|
||||
|
||||
#include "main_handler.h"
|
||||
#include "logger.h"
|
||||
#include "settings.h"
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
NGLCoreApplication app(argc, argv);
|
||||
|
||||
LtsCommandLineParser::LtsCommandLineParser options;
|
||||
if (!options.init())
|
||||
return -1;
|
||||
app.createLogger("REP", options.exerciseId());
|
||||
|
||||
ReportManagement::Settings::setIniFile(options.iniFile());
|
||||
|
||||
int iRet = -3;
|
||||
{
|
||||
std::unique_ptr<ReportManagement::MainHandler> mainHandler(new ReportManagement::MainHandler);
|
||||
|
||||
if (!mainHandler->init(options.domainId(), options.exerciseId()))
|
||||
return iRet;
|
||||
|
||||
STARTUP_LOG(app.baseLogger());
|
||||
|
||||
iRet = app.exec();
|
||||
|
||||
SHUTDOWN_LOG(app.baseLogger());
|
||||
}
|
||||
|
||||
return iRet;
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
/**
|
||||
* MainHandler for ReportManagement Generator
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
*/
|
||||
#include "main_handler.h"
|
||||
|
||||
#include "settings.h"
|
||||
#include "logger.h"
|
||||
#include <DDS/DDSConnector/dds_connector.h>
|
||||
#include <DDS/Core/pacemaker.h>
|
||||
#include <ngldb/db_service_handler.h>
|
||||
|
||||
#include <PresentationManagement/initialization.h>
|
||||
|
||||
|
||||
namespace ReportManagement
|
||||
{
|
||||
|
||||
MainHandler::MainHandler(QObject *parent)
|
||||
: QObject(parent)
|
||||
, m_ddsHandler(nullptr)
|
||||
, m_dbHandler(nullptr)
|
||||
, m_preService(nullptr)
|
||||
, m_logger(getLogger("MainHandlerGenerator"))
|
||||
{}
|
||||
|
||||
MainHandler::~MainHandler()
|
||||
{
|
||||
m_reportGetData = nullptr;
|
||||
m_reportData = nullptr;
|
||||
m_ddsHandler = nullptr;
|
||||
m_dbHandler = nullptr;
|
||||
delete m_preService;
|
||||
}
|
||||
|
||||
bool MainHandler::init(int domainId, int exerciseId)
|
||||
{
|
||||
// initialize database
|
||||
m_dbHandler = std::make_shared<DbHandler>();
|
||||
if (!m_dbHandler->init(exerciseId, Settings::settings()))
|
||||
return false;
|
||||
|
||||
// initialize DDS
|
||||
m_ddsHandler = std::make_shared<DdsHandler>(domainId, exerciseId);
|
||||
if (!m_ddsHandler->init(true))
|
||||
return false;
|
||||
|
||||
m_reportData = std::make_shared<HandlerReportData>(m_ddsHandler, m_dbHandler->db());
|
||||
|
||||
if (!m_reportData->init())
|
||||
return false;
|
||||
|
||||
m_preService = new PresentationManagement::Initialization;
|
||||
if (!m_preService->initialize(m_ddsHandler->ddsConnector(), m_dbHandler->db()->database()))
|
||||
return false;
|
||||
if (!m_preService->loadFromDatabase())
|
||||
return false;
|
||||
|
||||
m_reportGetData = std::make_shared<HandlerReportGetData>(m_ddsHandler, m_dbHandler->db());
|
||||
|
||||
|
||||
m_ddsHandler->pacemaker()->setNewState(Core::RunningState::Running);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
} // ReportManagement
|
||||
+50
@@ -0,0 +1,50 @@
|
||||
/**
|
||||
* MainHandler for ReportManagement Generator
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <QObject>
|
||||
|
||||
#include "dds_handler.h"
|
||||
#include "handler_report_data.h"
|
||||
#include "handler_report_get_data.h"
|
||||
#include "logger.h"
|
||||
#include "rep_db.h"
|
||||
|
||||
namespace NGLDB
|
||||
{
|
||||
template <typename DB> class DbServiceHandler;
|
||||
}
|
||||
|
||||
namespace PresentationManagement
|
||||
{
|
||||
class Initialization;
|
||||
}
|
||||
|
||||
namespace ReportManagement
|
||||
{
|
||||
using DbHandler = NGLDB::DbServiceHandler<DatabaseInterface>;
|
||||
class MainHandler : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit MainHandler(QObject *parent = nullptr);
|
||||
~MainHandler();
|
||||
|
||||
bool init(int domainId, int exerciseId);
|
||||
|
||||
private:
|
||||
|
||||
std::shared_ptr<DdsHandler> m_ddsHandler;
|
||||
std::shared_ptr<DbHandler> m_dbHandler;
|
||||
std::shared_ptr<HandlerReportData> m_reportData;
|
||||
std::shared_ptr<HandlerReportGetData> m_reportGetData;
|
||||
//external
|
||||
PresentationManagement::Initialization *m_preService;
|
||||
|
||||
LOGGER_T m_logger;
|
||||
};
|
||||
} // namespace ReportManagement
|
||||
@@ -0,0 +1,213 @@
|
||||
/**
|
||||
* ReportInfo Object
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
* Created by Hanna E. Rathje, SLSE, 2017-01-18
|
||||
*/
|
||||
|
||||
#include "object_report_info.h"
|
||||
#include "dds_handler.h"
|
||||
#include "logger.h"
|
||||
|
||||
#include <QJsonObject>
|
||||
#include <QJsonDocument>
|
||||
#include <QJsonArray>
|
||||
#include <QSet>
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
namespace ReportManagement
|
||||
{
|
||||
ObjectReportInfo::ObjectReportInfo(const std::shared_ptr<DdsHandler> &ddsHandler,
|
||||
const std::shared_ptr<DatabaseInterface> &db,
|
||||
QObject *parent)
|
||||
: QObject(parent)
|
||||
, m_ddsHandler(ddsHandler)
|
||||
, m_db(db)
|
||||
, m_logger(getLogger("ObjectReportInfo"))
|
||||
{
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
ObjectReportInfo::~ObjectReportInfo()
|
||||
{
|
||||
m_ddsHandler->dts()->removeReportInfoByKey(m_data.id);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
bool ObjectReportInfo::isValid() const
|
||||
{
|
||||
return m_data.id > 0;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
Core::FunctionReplyObject ObjectReportInfo::createObject(Database::RepReport &dbData)
|
||||
{
|
||||
m_data = dbData;
|
||||
|
||||
if (m_data.id <= 0)
|
||||
{
|
||||
if (!m_db->insert(dbData))
|
||||
return Core::FunctionReplyObject(0, tr_lts("dds", "Error inserting RepReport-data into database"));
|
||||
|
||||
m_data.id = dbData.id;
|
||||
DEBUG_LOG(m_logger) << "New reportId: " << m_data.id;
|
||||
}
|
||||
|
||||
// Publish Data via DTS
|
||||
onPublishData();
|
||||
|
||||
return Core::FunctionReplyObject(m_data.id);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
Core::FunctionReplyObject ObjectReportInfo::updateObject(const Database::RepReport &dbData)
|
||||
{
|
||||
if (!isValid())
|
||||
return Core::FunctionReplyObject(dbData.id, tr_lts("dds", "Object not valid/blocked"));
|
||||
|
||||
if (!m_db->update(dbData))
|
||||
return Core::FunctionReplyObject(dbData.id, tr_lts("dds", "Error updating RepReport-data into database"));
|
||||
|
||||
m_data = dbData;
|
||||
DEBUG_LOG(m_logger) << "Data changed for reportId: " << m_data.id;
|
||||
|
||||
// Publish Data via DTS
|
||||
onPublishData();
|
||||
|
||||
return Core::FunctionReplyObject(m_data.id);
|
||||
}
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
Core::FunctionReplyObject ObjectReportInfo::removeObject()
|
||||
{
|
||||
|
||||
if (!m_db->removeRepReport(m_data.id))
|
||||
return Core::FunctionReplyObject(m_data.id, tr_lts("dds", "ReportInfo with id %1 can not be removed from DB")).arg(m_data.id);
|
||||
|
||||
if (!m_ddsHandler->dts()->removeReportInfoByKey(m_data.id))
|
||||
return Core::FunctionReplyObject(m_data.id, tr_lts("dds", "ReportInfo with id %1 can not be removed from DDS")).arg(m_data.id);
|
||||
|
||||
return Core::FunctionReplyObject(m_data.id);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------------------------------------
|
||||
Core::FunctionReplyObject ObjectReportInfo::changeStatus(const ReportChangeStatusRequest &request)
|
||||
{
|
||||
if (!isValid())
|
||||
return Core::FunctionReplyObject(m_data.id, tr_lts("dds", "Trying to update an already removed Report object with id = %1")).arg(m_data.id);
|
||||
|
||||
m_data.fileStatusId = request.fileStatus();
|
||||
m_data.operatorId = request.operatorId();
|
||||
m_data.lastModified = request.lastModified();
|
||||
|
||||
// Publish Data via DTS
|
||||
onPublishData();
|
||||
|
||||
return Core::FunctionReplyObject(m_data.id);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
void ObjectReportInfo::onPublishData()
|
||||
{
|
||||
INFO_LOG(m_logger) << "Publish ReportInfo-data to dds (" << m_data.id << ") ...";
|
||||
ReportInfo data = toDdsData(m_data);
|
||||
|
||||
if (!m_ddsHandler->dts()->publish(data))
|
||||
ERROR_LOG(m_logger) << "Error publishing ReportInfo-data to dds";
|
||||
}
|
||||
|
||||
// TODO: add in LtsUtils ?
|
||||
// -------------------------------------------------------------------------------------------------------
|
||||
static inline std::vector<int32_t> fromJsonArray(const QJsonArray &arrayContent)
|
||||
{
|
||||
std::vector<int32_t> ret;
|
||||
ret.reserve(arrayContent.size());
|
||||
for (const auto &ele : arrayContent)
|
||||
ret.push_back(ele.toInt());
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------------------------------------
|
||||
static inline std::vector<std::string> fromJsonArrayToString(const QJsonArray &arrayContent)
|
||||
{
|
||||
std::vector<std::string> ret;
|
||||
ret.reserve(arrayContent.size());
|
||||
for (const auto &ele : arrayContent)
|
||||
ret.emplace_back(ele.toString().toStdString());
|
||||
|
||||
return ret;
|
||||
}
|
||||
// -------------------------------------------------------------------------------------------------------
|
||||
static inline std::vector<Superior> fromJsonArrayToSuperior(const QJsonArray &arrayContent)
|
||||
{
|
||||
std::vector<Superior> ret;
|
||||
ret.reserve(arrayContent.size());
|
||||
for (const auto &obj : arrayContent)
|
||||
{
|
||||
Superior sup;
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(5, 10, 0)
|
||||
sup.participantId(obj[QStringLiteral("participantId")].toInt());
|
||||
sup.superiorId(obj[QStringLiteral("superiorId")].toInt());
|
||||
#else
|
||||
sup.participantId(obj.toObject().value(QStringLiteral("participantId")).toInt());
|
||||
sup.superiorId(obj.toObject().value(QStringLiteral("superiorId")).toInt());
|
||||
|
||||
#endif
|
||||
ret.push_back(sup);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
// -------------------------------------------------------------------------------------------------------
|
||||
// convert methods
|
||||
// -------------------------------------------------------------------------------------------------------
|
||||
// Database::RepReport => ReportManagement::ReportInfo
|
||||
ReportInfo ObjectReportInfo::toDdsData(const Database::RepReport &dbData)
|
||||
{
|
||||
ReportInfo ddsData;
|
||||
|
||||
ddsData.id(dbData.id);
|
||||
ddsData.name(dbData.name.toStdString());
|
||||
ddsData.description(dbData.description.toStdString());
|
||||
ddsData.reportType(dbData.reportTypeId);
|
||||
ddsData.partyId(dbData.partyId);
|
||||
ddsData.startTime(dbData.startTime);
|
||||
ddsData.endTime(dbData.endTime);
|
||||
ddsData.visualisationType(dbData.visualisationType);
|
||||
ddsData.intervalTime(dbData.intervalTime);
|
||||
ddsData.lastModified(dbData.lastModified);
|
||||
ddsData.operatorId(dbData.operatorId);
|
||||
ddsData.fileStatus(dbData.fileStatusId);
|
||||
|
||||
// area
|
||||
ddsData.cornerBottomLeft(Core::GeoPosition2D(dbData.position.x(), dbData.position.y()));
|
||||
ddsData.width(dbData.width);
|
||||
ddsData.height(dbData.height);
|
||||
|
||||
QJsonObject obj = QJsonDocument::fromJson(dbData.parameter.toUtf8()).object();
|
||||
ddsData.groupByParty(obj[QStringLiteral("groupByParty")].toBool());
|
||||
|
||||
// convert QJSonArray to std::vector
|
||||
ddsData.chargeTypeIds(fromJsonArray(obj[QStringLiteral("chargeTypeIds")].toArray()));
|
||||
ddsData.mineAreaIds(fromJsonArray(obj[QStringLiteral("mineAreaIds")].toArray()));
|
||||
ddsData.nbcIds(fromJsonArray(obj[QStringLiteral("nbcIds")].toArray()));
|
||||
ddsData.participantIds(fromJsonArray(obj[QStringLiteral("participantIds")].toArray()));
|
||||
ddsData.participantTypes(fromJsonArray(obj[QStringLiteral("participantTypes")].toArray()));
|
||||
ddsData.unitIds(fromJsonArray(obj[QStringLiteral("unitIds")].toArray()));
|
||||
ddsData.participantNames(fromJsonArrayToString(obj[QStringLiteral("participantNames")].toArray()));
|
||||
ddsData.unitNames(fromJsonArrayToString(obj[QStringLiteral("unitNames")].toArray()));
|
||||
ddsData.superiorIds(fromJsonArrayToSuperior(obj[QStringLiteral("superiorIds")].toArray()));
|
||||
ddsData.effectSources(fromJsonArray(obj[QStringLiteral("effectSources")].toArray()));
|
||||
|
||||
return ddsData;
|
||||
}
|
||||
|
||||
|
||||
// -------------------------------------------------------------------------------------------------------
|
||||
|
||||
} // Namespace ReportManagement
|
||||
@@ -0,0 +1,56 @@
|
||||
/**
|
||||
* ReportInfo Object
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
* Created by Hanna E. Rathje, SLSE, 2017-01-18
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <QObject>
|
||||
#include "dds_handler.h"
|
||||
#include <DDS/Core/function_reply_object.h>
|
||||
|
||||
// Generated
|
||||
#include <ReportManagement/rep_db.h>
|
||||
/*
|
||||
namespace NGL
|
||||
{
|
||||
class INGLLogger;
|
||||
}
|
||||
*/
|
||||
namespace ReportManagement
|
||||
{
|
||||
class ObjectReportInfo : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
ObjectReportInfo(const std::shared_ptr<DdsHandler> &ddsHandler,
|
||||
const std::shared_ptr<DatabaseInterface> &db,
|
||||
QObject *parent = nullptr);
|
||||
~ObjectReportInfo();
|
||||
|
||||
Core::FunctionReplyObject createObject(Database::RepReport &dbData);
|
||||
Core::FunctionReplyObject updateObject(const Database::RepReport &dbData);
|
||||
Core::FunctionReplyObject removeObject();
|
||||
Core::FunctionReplyObject changeStatus(const ReportChangeStatusRequest &request);
|
||||
|
||||
qint32 getId() const { return m_data.id; }
|
||||
ReportType getReportType() const { return m_data.reportTypeId; }
|
||||
|
||||
bool isValid() const;
|
||||
|
||||
// convert methods
|
||||
ReportInfo toDdsData(const Database::RepReport &dbData); // db -> dds
|
||||
|
||||
protected Q_SLOTS:
|
||||
void onPublishData();
|
||||
|
||||
private:
|
||||
std::shared_ptr<DdsHandler> m_ddsHandler;
|
||||
std::shared_ptr<DatabaseInterface> m_db;
|
||||
Database::RepReport m_data;
|
||||
LOGGER_T m_logger;
|
||||
|
||||
};
|
||||
}
|
||||
Reference in new issue
Block a user