Skip to content

Commit fd7677e

Browse files
authored
Merge pull request #1379 from Argn0/lifespan
cap ward lifespans and exclude some wards from average
2 parents ff6a66a + 32f02aa commit fd7677e

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

src/components/Match/Vision/VisionLog.jsx

+7-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import React from 'react';
22
import PropTypes from 'prop-types';
33
import styled from 'styled-components';
4+
import items from 'dotaconstants/build/items.json';
45
import { threshold, formatSeconds } from 'utility';
56
import Table from 'components/Table';
67
import strings from 'lang';
@@ -76,16 +77,19 @@ function logWard(log) {
7677

7778
const generateData = match => (log) => {
7879
const wardKiller = (log.left && log.left.player1) ? heroTd(match.players[log.left.player1]) : '';
79-
const duration = log.left ? log.left.time - log.entered.time : '';
80+
const duration = (log.left && log.left.time - log.entered.time) || (match && match.duration - log.entered.time);
81+
82+
// necessary until https://github.com/odota/parser/pull/3 is implemented
83+
const discrepancy = duration - Math.min(items[`ward_${log.type}`].attrib.find(x => x.key === 'lifetime').value, duration);
8084

8185
const durationColor = log.type === 'observer' ? durationObserverColor(duration) : durationSentryColor(duration);
8286

8387
return {
8488
...match.players[log.player],
8589
type: <img height="29" src={`${process.env.REACT_APP_API_HOST}/apps/dota2/images/items/ward_${log.type}_lg.png`} alt="" />,
8690
enter_time: formatSeconds(log.entered.time),
87-
left_time: formatSeconds(log.left && log.left.time) || '-',
88-
duration: <span style={{ color: durationColor }}>{formatSeconds(duration)}</span>,
91+
left_time: formatSeconds(((log.left && log.left.time) || (match && match.duration)) - discrepancy) || '-',
92+
duration: <span style={{ color: durationColor }}>{formatSeconds(duration - discrepancy)}</span>,
8993
killer: wardKiller,
9094
placement: logWard(log),
9195
};

src/components/Match/matchColumns.jsx

+5-3
Original file line numberDiff line numberDiff line change
@@ -1058,9 +1058,11 @@ const computeAverage = (row, type) => {
10581058
const totalDuration = [];
10591059
row[`${type}_log`].forEach((ward) => {
10601060
const findTime = row[`${type}_left_log`].find(x => x.ehandle === ward.ehandle);
1061-
const leftTime = (findTime && findTime.time) || row.duration;
1062-
const duration = Math.min(Math.max(leftTime - ward.time, 0), maxDuration);
1063-
totalDuration.push(duration);
1061+
const leftTime = (findTime && findTime.time) || false;
1062+
if (leftTime !== false) { // exclude wards that did not expire before game ended from average time
1063+
const duration = Math.min(Math.max(leftTime - ward.time, 0), maxDuration);
1064+
totalDuration.push(duration);
1065+
}
10641066
});
10651067
let sum = 0;
10661068
for (let i = 0; i < totalDuration.length; i += 1) {

0 commit comments

Comments
 (0)