OSDN Git Service

タイマーで発生した例外を捕捉する
[kancollesniffer/KancolleSniffer.git] / LogViewer / index.html
index 642413b..f618258 100644 (file)
@@ -4,16 +4,16 @@
 <meta charset="utf-8">
 <title>各種報告書 - KancolleSniffer</title>
 
-<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
-<script src="//cdnjs.cloudflare.com/ajax/libs/datatables/1.10.7/js/jquery.dataTables.min.js"></script>
-<link rel="stylesheet" type="text/css" href="//cdnjs.cloudflare.com/ajax/libs/datatables/1.10.7/css/jquery.dataTables.min.css">
-<script src="//cdnjs.cloudflare.com/ajax/libs/d3/3.5.3/d3.min.js"></script>
-<script src="//cdnjs.cloudflare.com/ajax/libs/c3/0.4.10/c3.min.js"></script>
-<link rel="stylesheet" type="text/css" href="//cdnjs.cloudflare.com/ajax/libs/c3/0.4.10/c3.min.css">
-<script src="//cdnjs.cloudflare.com/ajax/libs/moment.js/2.9.0/moment.min.js"></script>
-<script src="//cdnjs.cloudflare.com/ajax/libs/jqueryui/1.11.4/jquery-ui.min.js"></script>
-<link rel="stylesheet" type="text/css" href="//ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/themes/smoothness/jquery-ui.css">
-<script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/i18n/datepicker-ja.min.js"></script>
+<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
+<script src="https://cdnjs.cloudflare.com/ajax/libs/datatables/1.10.7/js/jquery.dataTables.min.js"></script>
+<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/datatables/1.10.7/css/jquery.dataTables.min.css">
+<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.3/d3.min.js"></script>
+<script src="https://cdnjs.cloudflare.com/ajax/libs/c3/0.4.11/c3.min.js"></script>
+<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/c3/0.4.11/c3.min.css">
+<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.9.0/moment.min.js"></script>
+<script src="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.11.4/jquery-ui.min.js"></script>
+<link rel="stylesheet" type="text/css" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/themes/smoothness/jquery-ui.css">
+<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/i18n/datepicker-ja.min.js"></script>
 <style>
 body {
     font-family:'Lucida Grande','Hiragino Kaku Gothic ProN', Meiryo, sans-serif;
@@ -26,6 +26,8 @@ body {
 .tab li.select {background: #ccc;}
 .contents {list-style-type: none; margin: 0em; padding: 0em;}
 .hide {display: none;}
+.c3 .tick {font-family:'Lucida Grande','Hiragino Kaku Gothic ProN', Meiryo, sans-serif; font-size: 12px;}
+.c3-legend-item {font-family:'Lucida Grande','Hiragino Kaku Gothic ProN', Meiryo, sans-serif; font-size: 14px;}
 #loading {
     width: 48px;
     height: 48px;
@@ -87,7 +89,7 @@ function initTables()
             opts.columns = [{data: 0}, {data: 1}, {data: 2}, {data: 3}, {data: 4}, {data: 9}, {data: 10}];
         } else if (t == 1) {
             var entries = [];
-            for (i = 0; i < 35; i++) {
+            for (i = 0; i < 38; i++) {
                 if (i == 9 || i == 10)
                     continue;
                 entries.push({data: i})
@@ -114,6 +116,119 @@ function to5am(tick)
     return tick - tick % (3600 * 24000) - 3600 * 4000;
 }
 
+var selectedTable = 0;
+var seqChartRange = 0;
+var diffChartRange = 0;
+var chartType = 0;
+var showChart = false;
+var currentPickedData;
+
+function drawChart(data)
+{
+    if (data == null) {
+        $('#loading').show();
+        $.get("./資材ログ.json?time=" + Date.now(), function (data) { drawChart(data);}, "json");
+        return;
+    }
+    if (chartType == 0) {
+        var picked = pickChartData(data.data, seqChartRange);
+        var header = ["日付","燃料","弾薬","鋼材","ボーキ","高速建造材","高速修復材","開発資材","改修資材"];
+        picked.data.unshift(header);
+        drawSeqChart(picked);
+        currentPickedData = picked;
+    } else {
+        var picked = pickDiffChartData(data.data, diffChartRange);
+        var header = ["日付","燃料","弾薬","鋼材","ボーキ"];
+        picked.data.unshift(header);
+        drawDiffChart(picked)
+        currentPickedData = picked;
+    }
+}
+
+function redrawChart()
+{
+    if (!currentPickedData)
+        return;
+    $('#loading').show();
+    setTimeout(function() {
+        if (chartType == 0)
+            drawSeqChart(currentPickedData);
+        else
+            drawDiffChart(currentPickedData);
+    });
+}
+
+var timer;
+$(window).resize(function() {
+    if (timer)
+        clearTimeout(timer);
+    timer = setTimeout(function() {
+        if (showChart)
+            redrawChart();
+    }, 200);
+});
+
+function chartSize()
+{
+    var pxPerEm = Number($('#chart').css('fontSize').match(/(\d*(\.\d*)?)px/)[1]);
+    return {
+        height: Math.max($(document).height() - 15 * pxPerEm, 400),
+        width: Math.max($(document).width() - 6 * pxPerEm, 800)
+    };
+}
+
+function drawSeqChart(picked)
+{
+    size = chartSize();
+    var chart = c3.generate({
+        bindto: '#chart',
+        size: {
+            height: size.height,
+            width: size.width
+        },
+        data: {
+            x: '日付',
+            xFormat: '%Y-%m-%d %X',
+            rows: picked.data,
+            axes: {
+                燃料: 'y',
+                弾薬: 'y',
+                鋼材: 'y',
+                ボーキ: 'y',
+                高速建造材: 'y2',
+                高速修復材: 'y2',
+                開発資材: 'y2',
+                改修資材: 'y2'
+            }
+        },
+        point: {
+            show: false
+        },
+        tooltip: {
+            show: $('#tooltip').prop('checked')
+        },
+        grid: {
+            x: {
+                lines: picked.grid
+            }
+        },
+        axis: {
+            x: {
+                type: 'timeseries',
+                tick: {
+                    rotate: 30,
+                    format: function (x) { return moment(x).format("MM-DD HH:mm"); },
+                    values: picked.tick
+                },
+            },
+            y2: {
+                show: true
+            }
+        },
+        onrendered: function () { $('#loading').hide(); }
+    });
+}
+
 function pickChartData(data, range)
 {
     var newdata = [];
@@ -134,9 +249,12 @@ function pickChartData(data, range)
         first = moment(last).subtract(1, 'months').valueOf();
         break;
     case 3:
-        first = moment(data[0][0]).valueOf();
+        first = moment(last).subtract(3, 'months').valueOf();
         break;
     case 4:
+        first = moment(data[0][0]).valueOf();
+        break;
+    case 5:
         fromDate = $('#chart_from').datepicker("getDate");
         toDate = $('#chart_to').datepicker("getDate");
         if (fromDate == null || toDate == null)
@@ -159,10 +277,14 @@ function pickChartData(data, range)
         interval = 3600 * 2000;
         tickInterval = oneDay * 7;
         lastTick = to5am(moment(last).day(1).valueOf());
-    } else {
+    } else if (last <= first + oneDay * 126) {
         interval = 3600 * 12000;
         tickInterval = oneDay * 14;
         lastTick = to5am(moment(last).day(1).valueOf());
+    } else {
+        interval = 3600 * 24000;
+        tickInterval = oneDay * 28;
+        lastTick = to5am(moment(last).day(1).valueOf());
     }
     var last_data;
     for (var i = data.length - 1; i >= 0; i--) {
@@ -189,24 +311,14 @@ function pickChartData(data, range)
     return { data: newdata, tick: ticks, grid: grid };
 }
 
-var selectedTable = 0;
-var selectedRange = 0;
-
-function drawChart(data)
+function drawDiffChart(picked)
 {
-    if (data == null) {
-        $('#loading').show();
-        $.get("./資材ログ.json?time=" + Date.now(), function (data) { drawChart(data);}, "json");
-        return;
-    }
-    picked = pickChartData(data.data, selectedRange);
-    var header = ["日付","燃料","弾薬","鋼材","ボーキ","高速建造材","高速修復材","開発資材","改修資材"];
-    picked.data.unshift(header);
+    size = chartSize();
     var chart = c3.generate({
         bindto: '#chart',
         size: {
-            height: 400,
-            width: 800
+            height: size.height,
+            width: size.width
         },
         data: {
             x: '日付',
@@ -217,14 +329,14 @@ function drawChart(data)
                 弾薬: 'y',
                 鋼材: 'y',
                 ボーキ: 'y',
-                高速建造材: 'y2',
-                高速修復材: 'y2',
-                開発資材: 'y2',
-                改修資材: 'y2'
-            }
+            },
+            type: 'bar',
+            groups: [["燃料", "弾薬", "鋼材", "ボーキ"]]
         },
-        point: {
-            show: false
+        bar: {
+                width: {
+                    ratio: picked.width
+              }
         },
         tooltip: {
             show: $('#tooltip').prop('checked')
@@ -232,6 +344,11 @@ function drawChart(data)
         grid: {
             x: {
                 lines: picked.grid
+            },
+            y: {
+                lines: [
+                    {value: 0}
+                ]
             }
         },
         axis: {
@@ -242,16 +359,99 @@ function drawChart(data)
                     format: function (x) { return moment(x).format("MM-DD HH:mm"); },
                     values: picked.tick
                 },
-                height: 60
             },
-            y2: {
-                show: true
-            }
         },
         onrendered: function () { $('#loading').hide(); }
     });
 }
 
+function pickDiffChartData(data, range)
+{
+    var newdata = [];
+    var ticks = [];
+    var grid = [];
+    var first = moment(data[0][0]).valueOf();
+    var last = moment(data[data.length - 1][0]).valueOf();
+    var interval, tickInterval, lastTick;
+    const oneDay = 3600 * 24 * 1000;
+    switch (range) {
+    case 0:
+        first = moment(last).subtract(1, 'months').valueOf();
+        break;
+    case 1:
+        first = moment(last).subtract(3, 'months').valueOf();
+        break;
+    case 2:
+        first = moment(last).subtract(6, 'months').subtract(1, 'weeks').valueOf();
+        break;
+    case 3:
+        first = moment(data[0][0]).valueOf();
+        break;
+    case 4:
+        fromDate = $('#chart_from').datepicker("getDate");
+        toDate = $('#chart_to').datepicker("getDate");
+        if (fromDate == null || toDate == null)
+            return { data: [], tick: [], grid: [] };
+        from = fromDate.valueOf() + 3600 * 5000;
+        to = toDate.valueOf() + oneDay + 3600 * 5000;
+        first = Math.max(first, from);
+        last = Math.min(last, to);
+        break;
+    }
+    if (last <= first + oneDay * 2 * 31) {
+        interval = oneDay;
+        tickInterval = oneDay * 2;
+        lastTick = to5am(last);
+        barWidth = 0.3;
+    } else if (last <= first + oneDay * 3 * 31) {
+        interval = oneDay;
+        tickInterval = oneDay * 7;
+        lastTick = to5am(last);
+        barWidth = 0.1;
+    } else {
+        interval = oneDay * 7;
+        tickInterval = oneDay * 28;
+        lastTick = to5am(moment(last).day(1).valueOf());
+        barWidth = 0.1;
+        if (last <= first + oneDay * 6 * 38){
+            tickInterval = oneDay * 14;
+            barWidth = 0.3;
+        }
+    }
+    var last_date = lastTick;
+    var prev_row;
+    for (var i = data.length - 1; i >= 0; i--) {
+        var row = data[i];
+        var date = parseDate(row[0]).valueOf();
+        if (date > first && date <= last) {
+            if (!prev_row) {
+                prev_row = row;
+                continue;
+            }
+            if (date <= last_date) {
+                var newrow = [prev_row[0]];
+                for (var r = 1; r < 5; r++) {
+                    newrow.push(prev_row[r] - row[r] )
+                }
+                newdata.unshift(newrow);
+                last_date = last_date - interval;
+                prev_row = row;
+            }
+        } else {
+            break;
+        }
+    }
+    if (tickInterval >= oneDay * 7)
+        lastTick = moment(lastTick).day(1).hour(5).minute(0).valueOf();
+    for (var tick = lastTick; tick > last_date; tick -= tickInterval)
+    {
+        var str = toString(moment(tick));
+        ticks.unshift(str);
+        grid.unshift({value: str});
+    }
+    return { data: newdata, tick: ticks, grid: grid, width: barWidth };
+}
+
 function setSortieStat(data) {
     if (!data) {
         $('#loading').show();
@@ -322,11 +522,22 @@ function setSortieStat(data) {
     }
     for (term in r) {
         var table = [];
+        var pushed = {};
         for (map in r[term].stat)
         {
+            if (pushed[map])
+                continue;
             var e = r[term].stat[map];
             e.map = map;
             table.push(e);
+            pushed[map] = 1;
+            boss = map + " - ボス";
+            e = r[term].stat[boss];
+            if (!e)
+                continue;
+            e.map = boss;
+            table.push(e);
+            pushed[boss] = 1;
         }
         var dt = $("#sortie_stat_" + term).DataTable();
         dt.clear();
@@ -368,10 +579,12 @@ function initSortieStat()
 function selectTopTab(i)
 {
     var chart = tables;
+    showChart = false;
     if (i < tables) {
         selectedTable = i;
         showLog();
     } else if (i == chart) {
+        showChart = true;
         drawChart();
     } else if (i == chart + 1) {
         setSortieStat();
@@ -395,14 +608,38 @@ function initAction()
         selectTopTab(i);
         sessionStorage.setItem('prevTab', i);
     });
-    $('.tab1 li').click(function() {
-        var tab = $('.tab1 li');
+    $('#range_seq li').click(function() {
+        var tab = $('#range_seq li');
         var i = tab.index(this);
-        selectedRange = i;
+        seqChartRange = i;
+        chartType = 0;
         drawChart();
         tab.removeClass('select');
         tab.eq(i).addClass('select');
-        sessionStorage.setItem('prevRange', i);
+        sessionStorage.setItem('prevSeqRange', i);
+    });
+    $('#range_diff li').click(function() {
+        var tab = $('#range_diff li');
+        var i = tab.index(this);
+        diffChartRange = i;
+        chartType = 1;
+        drawChart();
+        tab.removeClass('select');
+        tab.eq(i).addClass('select');
+        sessionStorage.setItem('prevDiffRange', i);
+    });
+    $('input[name="chart_type"]:radio').change(function() {
+        if ($(this).val() == 0) {
+            $("#range_seq").show();
+            $("#range_diff").hide();
+            chartType = 0;
+        } else {
+            $("#range_seq").hide();
+            $("#range_diff").show();
+            chartType = 1;
+        }
+        drawChart();
+        sessionStorage.setItem('chartType', $(this).val());
     });
     $('#tooltip').change(function() {
         drawChart();
@@ -424,13 +661,19 @@ function initTableDatePicker()
 function initChartDatePicker()
 {
     $('#chart_from').datepicker({
-        onClose: function() {if (selectedRange == 4) drawChart();}
+        onClose: function() {if (useChartDatePicker()) drawChart();}
     })
     $('#chart_to').datepicker({
-        onClose: function() {if (selectedRange == 4) drawChart();}
+        onClose: function() {if (useChartDatePicker()) drawChart();}
     });
 }
 
+function useChartDatePicker()
+{
+    return (chartType == 0 && seqChartRange == 5) ||
+        (chartType == 1 && diffChartRange == 4);
+}
+
 $(function() {
     $.fn.dataTable.ext.errMode = 'throw';
     initAction();
@@ -439,15 +682,30 @@ $(function() {
     $('table').addClass('display compact cell-border');
     initTables();
     initSortieStat();
-    var range = sessionStorage.getItem('prevRange');
-    selectedRange = range == null ? 0 : +range;
-    $('.tab1 li').eq(range).addClass('select');
+    var type = sessionStorage.getItem('chartType');
+    chartType = type == null ? 0 : +type;
+    var range = sessionStorage.getItem('prevSeqRange');
+    seqChartRange = range == null ? 0 : +range;
+    range = sessionStorage.getItem('prevDiffRange');
+    seqDiffRange = range == null ? 0 : +range;
+    $('input[name="chart_type"]:radio').eq(chartType).prop("checked", true);
+    if (chartType == 0) {
+        $('#range_seq').show()
+        $('#range_diff').hide()
+    } else {
+        $('#range_seq').hide()
+        $('#range_diff').show()
+    }
+    $('#range_diff li').removeClass('select');
+    $('#range_diff li').eq(diffChartRange).addClass('select');
+    $('#range_seq li').removeClass('select');
+    $('#range_seq li').eq(seqChartRange).addClass('select');
     var prev = sessionStorage.getItem('prevTab');
     selectTopTab(prev == null ? 0 : +prev);
 });
 </script>
 
-<div id="loading"><img src="http://kancollesniffer.osdn.jp/ajax-loader.gif" alt="読み込み中..."></div>
+<div id="loading"><img src="https://kancollesniffer.osdn.jp/ajax-loader.gif" alt="読み込み中..."></div>
 
 <ul class="tab tab0">
 <li>ドロップ</li>
@@ -481,7 +739,7 @@ $(function() {
 <li class="hide">
 <table id="log1">
 <thead>
-<tr><th>日付</th><th>海域</th><th>マス</th><th>ボス</th><th>ランク</th><th>艦隊行動</th><th>味方陣形</th><th>敵陣形</th><th>敵艦隊</th><th>味方艦1</th><th>味方艦1HP</th><th>味方艦2</th><th>味方艦2HP</th><th>味方艦3</th><th>味方艦3HP</th><th>味方艦4</th><th>味方艦4HP</th><th>味方艦5</th><th>味方艦5HP</th><th>味方艦6</th><th>味方艦6HP</th><th>敵艦1</th><th>敵艦1HP</th><th>敵艦2</th><th>敵艦2HP</th><th>敵艦3</th><th>敵艦3HP</th><th>敵艦4</th><th>敵艦4HP</th><th>敵艦5</th><th>敵艦5HP</th><th>敵艦6</th><th>敵艦6HP</th></tr>
+<tr><th>日付</th><th>海域</th><th>マス</th><th>ボス</th><th>ランク</th><th>艦隊行動</th><th>味方陣形</th><th>敵陣形</th><th>敵艦隊</th><th>味方艦1</th><th>味方艦1HP</th><th>味方艦2</th><th>味方艦2HP</th><th>味方艦3</th><th>味方艦3HP</th><th>味方艦4</th><th>味方艦4HP</th><th>味方艦5</th><th>味方艦5HP</th><th>味方艦6</th><th>味方艦6HP</th><th>敵艦1</th><th>敵艦1HP</th><th>敵艦2</th><th>敵艦2HP</th><th>敵艦3</th><th>敵艦3HP</th><th>敵艦4</th><th>敵艦4HP</th><th>敵艦5</th><th>敵艦5HP</th><th>敵艦6</th><th>敵艦6HP</th><th>味方制空値</th><th>敵制空値</th><th>制空状態</th></tr>
 </thead>
 </table>
 
@@ -521,18 +779,32 @@ $(function() {
 </table>
 
 <li class="hide">
-<ul class="tab tab1" style="float: left; margin-right: 2px;">
+<form id="chart_type">
+<div style="margin: 0px 0px 0.5em 1em;">
+<label><input type="radio" name="chart_type" value="0" checked="checked">連続</label>
+<label><input type="radio" name="chart_type" value="1">差分</label>
+</div>
+</form>
+<ul class="tab tab1" id="range_seq" style="float: left; margin-right: 0.2em">
 <li>一日</li>
 <li>一週間</li>
 <li>一か月</li>
+<li>三か月</li>
 <li>すべて</li>
 <li>期間指定</li>
 </ul>
+<ul class="tab tab1" id="range_diff" style="float: left; margin-right: 0.2em">
+<li>一か月(日)</li>
+<li>三か月(日)</li>
+<li>半年(週)</li>
+<li>すべて(週)</li>
+<li>期間指定</li>
+</ul>
 <div style="padding: 0.2em 0em;">
 <input type="text" id="chart_from" style="width: 7em">~<input type="text" id="chart_to" style="width: 7em">
 <label><input type="checkbox" id="tooltip" value="" style="margin-left: 2em;">ツールチップ</label>
 </div>
-<div id="chart" style="clear: both; width: 800px; margin: 1em;"></div>
+<div id="chart" style="clear: both; margin: 1em;"></div>
 
 <li class="hide">
 <h3>今日</h3>