Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 22 additions & 6 deletions src/main/common/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { LogEntry } from "../../shared/console/ConsoleDB";
import { StatEntry } from "./stats/StatsDB";
import { OverlayLayout } from "../xmds/response/schedule/events/overlayLayout";
import { scheduleCriteriaManager } from "../../shared/scheduleCriteria/scheduleCriteriaManager";
import { geoLocationManager } from "./geoLocationManager";

export function getLayoutIds(layouts: ScheduleLayoutsType[] | OverlayLayout[]): number[] {
return layouts.reduce((a: number[], b) => {
Expand Down Expand Up @@ -314,7 +315,7 @@ export function submitLogsXmlString(log: LogEntry) {
return xmlString;
}

export function submitStatXmlString(statObj: StatEntry) {
export function submitStatXmlString(statObj: StatEntry, recordGeoLocation = false) {
let statXml = '<stat ' +
'fromdt="' + statObj.fromdt + '" ' +
'todt="' + statObj.todt + '" ' +
Expand All @@ -330,22 +331,37 @@ export function submitStatXmlString(statObj: StatEntry) {
}

if (statObj.type !== 'event') {
const engagementTags: string[] = [];

const activeCriteria = scheduleCriteriaManager.getActiveCriteria();
const criteriaKeys = Object.keys(activeCriteria);

if (criteriaKeys.length > 0) {
let tags = '';
let criteriaTag = '';
for (const key of criteriaKeys) {
const criterion = activeCriteria[key];
if (!criterion) continue;
tags = tags === ''
criteriaTag = criteriaTag === ''
? 'CRITERIA|' + criterion.metric + ':' + criterion.value
: tags + ', ' + criterion.metric + ':' + criterion.value;
: criteriaTag + ', ' + criterion.metric + ':' + criterion.value;
}
if (criteriaTag !== '') {
engagementTags.push(criteriaTag);
}
}

if (recordGeoLocation) {
const { latitude, longitude } = geoLocationManager.getCurrentLocation();
if (latitude !== null && longitude !== null && !(latitude === 0 && longitude === 0)) {
engagementTags.push('LOCATION:' + latitude + ':' + longitude);
}
}

if (engagementTags.length > 0) {
statXml += '>' +
'<engagements>' +
'<engagement tag="' + tags + '" duration="0" count="1"></engagement>' +
engagementTags.map(tag =>
'<engagement tag="' + tag + '" duration="0" count="1"></engagement>'
).join('') +
'</engagements>' +
'</stat>';

Expand Down
1 change: 1 addition & 0 deletions src/main/config/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ export class Config {
this.settings['sizeX'] = registerDisplay.getSetting('sizeX', 0);
this.settings['sizeY'] = registerDisplay.getSetting('sizeY', 0);
this.settings['sendCurrentLayoutAsStatusUpdate'] = registerDisplay.getSetting('sendCurrentLayoutAsStatusUpdate', false);
this.settings['isRecordGeoLocationOnProofOfPlay'] = registerDisplay.getSetting('isRecordGeoLocationOnProofOfPlay', false) === '1';
this.state.displayStatus = registerDisplay.status || 0;

await this.saveCms();
Expand Down
7 changes: 4 additions & 3 deletions src/main/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -900,16 +900,17 @@ const initXmdsEventHandlers = async function (config: Config, xmr: Xmr) {
return;
}

const recordGeoLocation = config.getSetting('isRecordGeoLocationOnProofOfPlay', false) === true;
let statsXmlString = '';
stats.map((stat) => {
statsXmlString += submitStatXmlString(stat);
statsXmlString += submitStatXmlString(stat, recordGeoLocation);
});

xmds.submitStats(statsXmlString).then((success) => {

console.debug('[Xmds::submitStats] Stats submitted to CMS');
// If response succeeded, then delete pushed logs
if (success) {
// If response succeeded, then delete pushed logs
if (success) {
console.log('[Xmds::submitStats] Deleting pushed stats, count = ' + stats.length);

popStats.clearSubmitted(stats);
Expand Down
Loading