Skip to content

Commit

Permalink
#50 @diff
Browse files Browse the repository at this point in the history
  • Loading branch information
yegor256 committed Nov 3, 2017
1 parent 3eb0f77 commit 8b83191
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
22 changes: 20 additions & 2 deletions src/main/resources/org/jpeek/index-post.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,30 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
-->
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://www.w3.org/1999/xhtml" version="2.0">
<xsl:variable name="score">
<xsl:choose>
<xsl:when test="/index/metric">
<xsl:value-of select="sum(/index/metric/score) div count(/index/metric)"/>
</xsl:when>
<xsl:otherwise>
<xsl:text>0</xsl:text>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:template match="/index">
<xsl:copy>
<xsl:attribute name="score">
<xsl:value-of select="format-number($score,'0.0000')"/>
</xsl:attribute>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="metric">
<xsl:copy>
<xsl:attribute name="diff">
<xsl:choose>
<xsl:when test="metric">
<xsl:value-of select="format-number(sum(metric/score) div count(metric), '0.0000')"/>
<xsl:when test="$score != 0">
<xsl:value-of select="((score - $score) div $score)"/>
</xsl:when>
<xsl:otherwise>
<xsl:text>0</xsl:text>
Expand Down
7 changes: 3 additions & 4 deletions src/main/resources/org/jpeek/index.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -266,24 +266,23 @@ SOFTWARE.
</xsl:choose>
</xsl:attribute>
<xsl:value-of select="format-number(score,'0.00')"/>
<xsl:variable name="diff" select="((score - /metrics/@score) div /metrics/@score)"/>
<span class="under">
<xsl:attribute name="style">
<xsl:text>font-weight:normal;</xsl:text>
<xsl:text>color:</xsl:text>
<xsl:choose>
<xsl:when test="abs($diff) &gt; 0.25">
<xsl:when test="abs(@diff) &gt; 0.25">
<xsl:text>red</xsl:text>
</xsl:when>
<xsl:when test="abs($diff) &gt; 0.15">
<xsl:when test="abs(@diff) &gt; 0.15">
<xsl:text>orange</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:text>gray</xsl:text>
</xsl:otherwise>
</xsl:choose>
</xsl:attribute>
<xsl:value-of select="format-number($diff * 100, '#')"/>
<xsl:value-of select="format-number(@diff * 100, '#')"/>
<xsl:text>%</xsl:text>
</span>
</td>
Expand Down

0 comments on commit 8b83191

Please sign in to comment.