Ticket #3403: 3403_statistic_tracker_proposal.patch
File 3403_statistic_tracker_proposal.patch, 2.5 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 this.sequences = 0; 148 149 let cmpTimer = Engine.QueryInterface(SYSTEM_ENTITY, IID_Timer); 150 if (!cmpTimer) 151 return; 152 this.updateTimer = cmpTimer.SetInterval( 153 this.entity, IID_StatisticsTracker, "updateSequences", 0, UPDATE_SEQUENCE_INTERVAL, { 154 "startTime": cmpTimer.GetTime() 155 } 156 ); 145 157 }; 146 158 147 159 /** … … 160 172 }; 161 173 }; 162 174 163 StatisticsTracker.prototype.GetStatistics = function()175 StatisticsTracker.prototype.GetStatisticsWithoutSequences = function() 164 176 { 165 177 return { 166 178 "unitsTrained": this.unitsTrained, … … 195 207 }; 196 208 }; 197 209 210 StatisticsTracker.prototype.GetStatistics = function() 211 { 212 let data = this.GetStatisticsWithoutSequences(); 213 data.sequences = this.sequences; 214 return data;} 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 this.sequences = clone(this.GetStatisticsWithoutSequences()); 540 this.sequences.time = []; 541 } 542 543 this.sequences.time.push(deltaTime); 544 this.PushValue(this.GetStatisticsWithoutSequences(), this.sequences); 545 } 546 495 547 Engine.RegisterComponentType(IID_StatisticsTracker, "StatisticsTracker", StatisticsTracker);