From b343351d6fe13a57a299c70b06c23420e5b9fa52 Mon Sep 17 00:00:00 2001 From: Argn0 Date: Fri, 8 Dec 2017 21:23:58 +0100 Subject: [PATCH 1/2] cap ward lifespans and exclude wards from average if didnt expire before game ended --- src/components/Match/Vision/VisionLog.jsx | 10 +++++++--- src/components/Match/matchColumns.jsx | 8 +++++--- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/components/Match/Vision/VisionLog.jsx b/src/components/Match/Vision/VisionLog.jsx index 325e294bdb..04749ccdcc 100644 --- a/src/components/Match/Vision/VisionLog.jsx +++ b/src/components/Match/Vision/VisionLog.jsx @@ -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'; @@ -76,7 +77,10 @@ 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); @@ -84,8 +88,8 @@ const generateData = match => (log) => { ...match.players[log.player], type: , enter_time: formatSeconds(log.entered.time), - left_time: formatSeconds(log.left && log.left.time) || '-', - duration: {formatSeconds(duration)}, + left_time: formatSeconds(((log.left && log.left.time) || (match && match.duration)) - discrepancy) || '-', + duration: {formatSeconds(duration - discrepancy)}, killer: wardKiller, placement: logWard(log), }; diff --git a/src/components/Match/matchColumns.jsx b/src/components/Match/matchColumns.jsx index 2c80538d77..3755daa8ba 100644 --- a/src/components/Match/matchColumns.jsx +++ b/src/components/Match/matchColumns.jsx @@ -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) { From 32f02aa518febf2c3c58ca70c25016c1ccdc852d Mon Sep 17 00:00:00 2001 From: Argn0 Date: Fri, 8 Dec 2017 21:33:30 +0100 Subject: [PATCH 2/2] lint --- src/components/Match/Vision/VisionLog.jsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/components/Match/Vision/VisionLog.jsx b/src/components/Match/Vision/VisionLog.jsx index 04749ccdcc..97d67649fb 100644 --- a/src/components/Match/Vision/VisionLog.jsx +++ b/src/components/Match/Vision/VisionLog.jsx @@ -77,10 +77,10 @@ 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) || (match && match.duration - 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 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);