Ticket #3403: 3403_statistic_tracker_proposal_v2.patch
File 3403_statistic_tracker_proposal_v2.patch, 2.4 KB (added by , 7 years ago) |
---|
-
binaries/data/mods/public/simulation/components/StatisticsTracker.js
1 1 function StatisticsTracker() {} 2 2 3 const UPDATE_SEQUENCE_INTERVAL = 30000; // 30 seconds 4 3 5 StatisticsTracker.prototype.Schema = 4 6 "<a:component type='system'/><empty/>"; 5 7 … … 142 144 this.lootCollected = 0; 143 145 this.peakPercentMapControlled = 0; 144 146 this.teamPeakPercentMapControlled = 0; 147 148 let cmpTimer = Engine.QueryInterface(SYSTEM_ENTITY, IID_Timer); 149 if (!cmpTimer) 150 return; 151 this.updateTimer = cmpTimer.SetInterval( 152 this.entity, IID_StatisticsTracker, "updateSequences", 0, UPDATE_SEQUENCE_INTERVAL, { 153 "startTime": cmpTimer.GetTime() 154 } 155 ); 145 156 }; 146 157 147 158 /** … … 160 171 }; 161 172 }; 162 173 163 StatisticsTracker.prototype.GetStatistics = function()174 StatisticsTracker.prototype.GetStatisticsWithoutSequences = function() 164 175 { 165 176 return { 166 177 "unitsTrained": this.unitsTrained, … … 195 206 }; 196 207 }; 197 208 209 StatisticsTracker.prototype.GetStatistics = function() 210 { 211 let data = this.GetStatisticsWithoutSequences(); 212 data.sequences = this.sequences; 213 return data; 214 } 215 198 216 /** 199 217 * Increments counter associated with certain entity/counter and type of given entity. 200 218 * @param cmpIdentity The entity identity component … … 492 510 this.teamPeakPercentMapControlled = newPercent; 493 511 }; 494 512 513 StatisticsTracker.prototype.PushValue = function(fromData, toData) 514 { 515 if (typeof fromData == "object") 516 for (let prop in fromData) 517 { 518 if (typeof toData[prop] != "object") 519 { 520 toData[prop] = []; 521 toData[prop].push(fromData[prop]); 522 } 523 else 524 this.PushValue(fromData[prop], toData[prop]); 525 } 526 else 527 toData.push(fromData); 528 }; 529 530 StatisticsTracker.prototype.updateSequences = function(data) 531 { 532 let cmpTimer = Engine.QueryInterface(SYSTEM_ENTITY, IID_Timer); 533 if (!cmpTimer) 534 return; 535 let deltaTime = (cmpTimer.GetTime() - data.startTime) / 1000; 536 537 if (!this.sequences) 538 { 539 deltaTime = 0; 540 this.sequences = clone(this.GetStatisticsWithoutSequences()); 541 this.sequences.time = []; 542 } 543 544 this.sequences.time.push(deltaTime); 545 this.PushValue(this.GetStatisticsWithoutSequences(), this.sequences); 546 } 547 495 548 Engine.RegisterComponentType(IID_StatisticsTracker, "StatisticsTracker", StatisticsTracker);