module.exports = o => { with(o) return `<!DOCTYPE html>`+
`<body>
<link rel="stylesheet" href="/history.css"/>
<div class="container detail">
<h1>Tilastoja - ${location ? location : 'Kaikki paikat'}</h1>
    <ul>
        <li><a href="/historia">Kaikki</a></li>
        ${rates.locations.map(location=>`<li><a href="/historia/${location}">${location}</a></li>`).join('')}
    </ul>
<h2>Myymättä jääneet kentät päivämäärittäin</h2>
<table>
    <thead>
    <tr>
        <th>Pvm</th>
        ${times.map(time=>`
        <th>
            <div>${time}</div>
        </th>
        `).join('')}
    </tr>
    </thead>
    <tbody>
    ${dates.map(date=>`
    <tr class="day${date.dateTime.getDay()}">
        <th>${date.formattedDate}</th>
        ${times.map(time=> {
        const allAvailabilityForDate = findAvailabilityForDate(date.dateTime, time)
        const availabilityForDate = location ?
        _.get(allAvailabilityForDate.find(a=>a.location === location), 'available', 0) :
        _.sum(allAvailabilityForDate.map(a=>a.available))
        const rgb = 255 - availabilityForDate * 15
        return `
        <td style="background:rgb(${rgb},${rgb},255)" title="${time}, vapaana ${availabilityForDate}"></td>
        `
        }).join('')}
    </tr>
    `).join('')}

    </tbody>
</table>
<h2>Myymättä jääneet kentät viikonpäivittäin</h2>
<div class="ct-chart ct-perfect-fourth chartData"></div>
<ul class="ct-legend">
    <li class="ct-series-b"><span class="legendBox"></span>Ma</li>
    <li class="ct-series-c"><span class="legendBox"></span>Ti</li>
    <li class="ct-series-d"><span class="legendBox"></span>Ke</li>
    <li class="ct-series-e"><span class="legendBox"></span>To</li>
    <li class="ct-series-f"><span class="legendBox"></span>Pe</li>
    <li class="ct-series-g"><span class="legendBox"></span>La</li>
    <li class="ct-series-a"><span class="legendBox"></span>Su</li>
</ul>

<h2>Kenttien hinnat eri viikonpäivinä</h2>

<div class="ct-chart ct-perfect-fourth rates"></div>

<ul class="ct-legend">
    ${rates.locations.map((location, i)=>`<li class="ct-series-${String.fromCharCode('a'.charCodeAt(0)+i)}"><span class="legendBox"></span>${location}</li>`).join('')}
</ul>
        <script>window.chartData = ${JSON.stringify(weeklyAvailability)}</script>
<script>window.rates= ${JSON.stringify(rates)}</script>
<script src="/history.min.js"></script>
    </div>
</body>
</html>`}

@@ -2378,16 +2378,561 @@
  %3C/div%3E%0A
+%3Cscript%3E%0A    (function (i, s, o, g, r, a, m) %7B%0A        i%5B'GoogleAnalyticsObject'%5D = r;%0A        i%5Br%5D = i%5Br%5D %7C%7C function () %7B%0A                (i%5Br%5D.q = i%5Br%5D.q %7C%7C %5B%5D).push(arguments)%0A            %7D, i%5Br%5D.l = 1 * new Date();%0A        a = s.createElement(o),%0A            m = s.getElementsByTagName(o)%5B0%5D;%0A        a.async = 1;%0A        a.src = g;%0A        m.parentNode.insertBefore(a, m)%0A    %7D)(window, document, 'script', '//www.google-analytics.com/analytics.js', 'ga');%0A%0A    ga('create', 'UA-67013989-1', 'auto');%0A    ga('send', 'pageview');%0A%3C/script%3E%0A
 %3C/body%3E%0A

Add analytics tag for history page