Skip to content

Commit

Permalink
Merge pull request #1379 from Argn0/lifespan
Browse files Browse the repository at this point in the history
cap ward lifespans and exclude some wards from average
  • Loading branch information
howardchung authored Dec 9, 2017
2 parents ff6a66a + 32f02aa commit fd7677e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
10 changes: 7 additions & 3 deletions src/components/Match/Vision/VisionLog.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React from 'react';
import PropTypes from 'prop-types';
import styled from 'styled-components';
import items from 'dotaconstants/build/items.json';
import { threshold, formatSeconds } from 'utility';
import Table from 'components/Table';
import strings from 'lang';
Expand Down Expand Up @@ -76,16 +77,19 @@ function logWard(log) {

const generateData = match => (log) => {
const wardKiller = (log.left && log.left.player1) ? heroTd(match.players[log.left.player1]) : '';
const duration = log.left ? log.left.time - log.entered.time : '';
const duration = (log.left && log.left.time - log.entered.time) || (match && match.duration - log.entered.time);

// necessary until https://github.com/odota/parser/pull/3 is implemented
const discrepancy = duration - Math.min(items[`ward_${log.type}`].attrib.find(x => x.key === 'lifetime').value, duration);

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

return {
...match.players[log.player],
type: <img height="29" src={`${process.env.REACT_APP_API_HOST}/apps/dota2/images/items/ward_${log.type}_lg.png`} alt="" />,
enter_time: formatSeconds(log.entered.time),
left_time: formatSeconds(log.left && log.left.time) || '-',
duration: <span style={{ color: durationColor }}>{formatSeconds(duration)}</span>,
left_time: formatSeconds(((log.left && log.left.time) || (match && match.duration)) - discrepancy) || '-',
duration: <span style={{ color: durationColor }}>{formatSeconds(duration - discrepancy)}</span>,
killer: wardKiller,
placement: logWard(log),
};
Expand Down
8 changes: 5 additions & 3 deletions src/components/Match/matchColumns.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -1058,9 +1058,11 @@ const computeAverage = (row, type) => {
const totalDuration = [];
row[`${type}_log`].forEach((ward) => {
const findTime = row[`${type}_left_log`].find(x => x.ehandle === ward.ehandle);
const leftTime = (findTime && findTime.time) || row.duration;
const duration = Math.min(Math.max(leftTime - ward.time, 0), maxDuration);
totalDuration.push(duration);
const leftTime = (findTime && findTime.time) || false;
if (leftTime !== false) { // exclude wards that did not expire before game ended from average time
const duration = Math.min(Math.max(leftTime - ward.time, 0), maxDuration);
totalDuration.push(duration);
}
});
let sum = 0;
for (let i = 0; i < totalDuration.length; i += 1) {
Expand Down

0 comments on commit fd7677e

Please sign in to comment.