6 <li each={name, i in mainTabs} class={select: mainTab === i} onclick={parent.changeTab}>{name}</li>
10 /* global moment, c3, opts */
12 this.mainTab = +sessionStorage.getItem('prevTab');
13 opts.observable.trigger("mainTabChanged", this.mainTab);
15 this.changeTab = function(e) {
16 this.mainTab = e.item.i;
17 sessionStorage.setItem('prevTab', e.item.i);
18 opts.observable.trigger("mainTabChanged", e.item.i);
24 <div id="term" show={enabled}>
25 <ul class="tab tabsub" style="float: left; margin-right: 0.2em">
26 <li each={name, i in rangeTabs} class={select: opts.logRange.val === i} onclick={parent.rangeTabChange}>{name}</li>
28 <div style="padding: 0.2em 0;">
29 <input type="text" id="term_from" style="width: 10em">~<input type="text" id="term_to" style="width: 10em">
46 opts.observable.on("mainTabChanged", function(idx) {
47 self.update({enabled: idx >= 0 && idx < self.logTables});
50 var val = sessionStorage.getItem('logRange');
51 opts.logRange.val = val === null ? 2 : +val;
53 this.init = function() {
54 self.initPicker('#term_from', '#term_to', function() {
55 if (opts.logRange.val === 4)
56 opts.observable.trigger( "logRangeChanged");
60 this.on("mount", this.init);
62 this.rangeTabChange = function(e) {
63 sessionStorage.setItem("logRange", e.item.i);
64 opts.logRange.val = e.item.i;
65 opts.observable.trigger("logRangeChanged");
72 <div each={header, i in tables} show={mainTab === i}>
73 <table class="display compact cell-border" id={"log" + i}>
85 "<th>日付</th><th>海域</th><th>マップ</th><th>マス</th><th>ボス</th><th>ランク</th><th>ドロップ艦種</th><th>ドロップ艦娘", // ドロップ
86 "<th>日付</th><th style=\"min-width: 3.2em;\">海域</th><th>マップ</th><th>マス</th><th>ボス</th><th>ランク</th><th>艦隊行動</th><th>味方陣形</th><th>敵陣形</th><th style=\"min-width: 3.2em;\">敵艦隊</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>大破艦</ht><th style=\"min-width: 2.2em;\">敵艦1</th><th>敵艦1HP</th><th style=\"min-width: 2.2em;\">敵艦2</th><th>敵艦2HP</th><th style=\"min-width: 2.2em;\">敵艦3</th><th>敵艦3HP</th><th style=\"min-width: 2.2em;\">敵艦4</th><th>敵艦4HP</th><th style=\"min-width: 2.2em;\">敵艦5</th><th>敵艦5HP</th><th style=\"min-width: 2.2em;\">敵艦6</th><th>敵艦6HP</th><th>味方制空値</th><th>敵制空値</th><th>制空状態</th>", // 海戦
87 "<th>日付</th><th>結果</th><th>遠征</th><th>燃料</th><th>弾薬</th><th>鋼材</th><th>ボーキ</th><th>開発資材</th><th>高速修復材</th><th>高速建造材</th><th>改修資材</th>", // 遠征
88 "<th>日付</th><th>開発装備</th><th>種別</th><th>燃料</th><th>弾薬</th><th>鋼材</th><th>ボーキ</th><th>秘書艦</th><th>司令部Lv</th>", // 開発
89 "<th>日付</th><th>種類</th><th>名前</th><th>艦種</th><th>燃料</th><th>弾薬</th><th>鋼材</th><th>ボーキ</th><th>開発資材</th><th>空きドック</th><th>秘書艦</th><th>司令部Lv</th>", // 建造
90 "<th>日付</th><th>改修装備</th><th>レベル</th><th>成功</th><th>確実化</th><th>消費装備</th><th>消費数</th><th>燃料</th><th>弾薬</th><th>鋼材</th><th>ボーキ</th><th>開発資材</th><th>改修資材</th><th>秘書艦</th><th>二番艦</th>", // 改修
91 "<th>日付</th><th>燃料</th><th>弾薬</th><th>鋼材</th><th>ボーキ</th><th>高速建造材</th><th>高速修復材</th><th>開発資材</th><th>改修資材</th>" // 戦果
104 this.on("mount", function() {
111 opts.observable.on("mainTabChanged", function(idx) {
112 self.update({mainTab: idx});
116 opts.observable.on("logRangeChanged", function() {
120 this.init = function() {
121 for (var t = 0; t < this.tables.length; t++) {
122 var table = $('#log' + t);
123 self.setHeaderAndFooter(table, self.tables[t]);
124 var dTable = table.DataTable(self.tableOptions(t));
125 self.searchSetup(dTable);
129 this.tableOptions = function(tableId) {
134 order: [[0, "desc"]],
136 lengthMenu: [[50, 100, 200, -1], [50, 100, 200, "All"]],
137 drawCallback: function() {
138 $('#loading').hide();
142 opts.columns = self.dropColumns();
143 } else if (tableId === 1) {
144 opts.columns = self.sortieColumns();
149 this.dropColumns = function() {
150 return [{data: 0}, {data: 1}, {data: 39}, {data: 2}, {data: 3}, {data: 4}, {data: 9}, {data: 10}];
153 this.sortieColumns = function() {
155 for (var i = 0; i < 38; i++) {
157 entries.push({data: 39});
158 if (i === 9 || i === 10)
161 entries.push({data: 38});
162 entries.push({data: i});
167 this.setHeaderAndFooter = function(table, header) {
168 table.find("thead tr").first().html(header);
169 var footer = table.find("tfoot tr");
170 table.find("th").each(function(index) {
172 '<th style="padding: 1px"><input style="min-width: 100%" size="1" type="search" placeholder="Search ' +
173 $(this).text() + '"/></th>');
177 this.searchSetup = function(dTable) {
178 self.setupCellSearch(dTable);
179 self.setupGlobalSearch(dTable);
182 this.setupCellSearch = function(dTable) {
183 dTable.columns().every(function() {
185 that.search(""); // reset
186 $('input', this.footer()).on("input search", function() {
187 that.search(this.value, true, false).draw();
192 this.setupGlobalSearch = function(dTable) {
193 var searchLabel = $(dTable.table().container()).find(".dataTables_filter label").first();
194 searchLabel.html('Search: <input type="search">');
195 searchLabel.children("input").first().on("input search", function() {
196 dTable.search(this.value, true, false).draw();
198 dTable.search(""); // reset
201 this.show = function() {
202 if (this.mainTab >= this.jsons.length)
206 var query = "?from=";
207 switch (opts.logRange.val){
209 from = now.clone().startOf('day').hours(5);
211 from.subtract(1, 'days');
212 query += from.valueOf();
215 from = now.clone().day(1).startOf('day').hours(5);
216 if (now.day() === 0 || now.day() === 1 && now.hour() < 5)
217 from.subtract(1, 'weeks');
218 query += from.valueOf();
221 if (now.hours() >= 22 &&
222 now.date() === now.clone().endOf('month').date()) {
223 from = now.clone().startOf('day').hours(22);
225 from = now.clone().startOf('month').subtract(1, 'days').hours(22);
227 query += from.valueOf();
233 from = $('#term_from').datetimepicker("getValue");
234 var to = $('#term_to').datetimepicker("getValue");
237 query += from.valueOf();
239 query += "&to=" + to.valueOf();
242 $('#loading').show();
243 var url = this.jsons[this.mainTab] + query;
244 $('#log' + this.mainTab).DataTable().ajax.url(url).load();
250 <form id="chart_type" show={mainTabs[mainTab] === "資材グラフ"}>
251 <div style="margin: 0 0 0.5em 1em;">
252 <label><input type="radio" name="chart_type" value="0" checked={opts.chartSpec.type === 0} onchange={chartTypeChange}>連続</label>
253 <label><input type="radio" name="chart_type" value="1" checked={opts.chartSpec.type === 1} onchange={chartTypeChange}>差分</label>
259 opts.chartSpec.type = +sessionStorage.getItem('chartType');
262 this.chartTypeChange = function(e) {
263 opts.chartSpec.type = +e.target.value;
264 sessionStorage.setItem('chartType', opts.chartSpec.type);
265 opts.observable.trigger("chartTypeChanged");
266 opts.observable.trigger("chartSpecChanged");
269 opts.observable.on("mainTabChanged", function(idx) {
270 self.update({mainTab: idx});
276 <div show={mainTabs[mainTab] === "資材グラフ"}>
277 <ul class="tab tabsub" style="float: left; margin-right: 0.2em" show={chartSpec.type === 0}>
278 <li each={name, i in seqChartRanges} class={select: chartSpec.seqRange === i} onclick={parent.rangeTabChange}>{name}</li>
281 <ul class="tab tabsub" style="float: left; margin-right: 0.2em" show={chartSpec.type === 1}>
282 <li each={name, i in diffChartRanges} class={select: chartSpec.diffRange === i} onclick={parent.rangeTabChange}>{name}</li>
284 <div style="padding: 0.2em 0;">
285 <input type="text" id="chart_from" style="width: 10em">~<input type="text" id="chart_to" style="width: 10em">
286 <label><input type="checkbox" id="tooltip" value="" style="margin-left: 2em;" onchange={tooltipChange} checked={opts.chartSpec.tooltip === 1}>ツールチップ</label>
291 this.seqChartRanges = [
300 this.diffChartRanges = [
308 opts.chartSpec.seqRange = +sessionStorage.getItem('seqChartRange');
309 opts.chartSpec.diffRange = +sessionStorage.getItem('diffChartRange');
310 opts.chartSpec.tooltip = +sessionStorage.getItem('chartTooltip');
311 this.chartSpec = opts.chartSpec;
313 this.rangeTabChange = function(e) {
314 if (opts.chartSpec.type === 0) {
315 opts.chartSpec.seqRange = e.item.i;
316 sessionStorage.setItem('seqChartRange', e.item.i);
318 opts.chartSpec.diffRange = e.item.i;
319 sessionStorage.setItem('diffChartRange', e.item.i);
321 opts.observable.trigger("chartSpecChanged");
324 this.tooltipChange = function(e) {
325 opts.chartSpec.tooltip = +e.target.checked;
326 sessionStorage.setItem('chartTooltip', +e.target.checked);
327 opts.observable.trigger("chartSpecChanged");
330 this.useDatePicker = function() {
331 return opts.chartSpec.type === 0 && opts.chartSpec.seqRange === 5 ||
332 opts.chartSpec.type === 1 && opts.chartSpec.diffRange === 4;
337 this.init = function() {
338 self.initPicker('#chart_from', '#chart_to', function() {
339 if (self.useDatePicker())
340 opts.observable.trigger("chartSpecChanged");
346 this.on("mount", self.init);
348 opts.observable.on("mainTabChanged", function(idx) {
349 self.update({mainTab: idx});
352 opts.observable.on("chartTypeChanged", function() {
362 opts.observable.on("chartSpecChanged", function() {
363 if (opts.chartSpec.type === 0)
367 opts.observable.on("chartSizeChanged", function() {
368 if (opts.chartSpec.type === 0)
372 this.header = ["日付", "燃料", "弾薬", "鋼材", "ボーキ", "高速建造材", "高速修復材", "開発資材", "改修資材"];
374 opts.observable.on("offAllLegends", function() {
375 if (opts.chartSpec.type !== 0)
378 self.header.slice(1).forEach(function(c) {
379 self.unselected[c] = true;
383 this.resize = function() {
386 $('#loading').show();
387 setTimeout(function() {
388 self.chart.resize(self.chartSize());
392 this.drawChart = function(data) {
393 var range = this.calcRange(opts.chartSpec.seqRange);
394 if (range.last === 0)
397 $('#loading').show();
399 url: "./資材ログ.json?number=true" +
400 "&from=" + range.first + "&to=" + range.last,
401 success: function(d) { self.drawChart(d); },
402 dataType: "json", cache: false
407 picked = this.pickChartData(data.data, range);
408 picked.data.unshift(self.header);
409 this.drawSeqChart(picked);
412 this.calcRange = function(range) {
414 var last = (new Date()).valueOf();
417 first = moment(last).subtract(24, 'hours').valueOf();
420 first = moment(last).subtract(7, 'days').valueOf();
423 first = moment(last).subtract(1, 'months').valueOf();
426 first = moment(last).subtract(3, 'months').valueOf();
431 var fromDate = $('#chart_from').datetimepicker("getValue");
432 var toDate = $('#chart_to').datetimepicker("getValue");
433 if (fromDate === null || toDate === null)
434 return {first: 0, last:0};
435 first = fromDate.valueOf();
436 last = toDate.valueOf();
439 return {first: first, last: last};
442 this.unselected = {};
444 this.drawSeqChart = function(picked) {
445 var size = this.chartSize();
446 this.chart = c3.generate({
454 xFormat: '%Y-%m-%d %H:%M:%S',
471 show: opts.chartSpec.tooltip
483 format: "%m-%d %H:%M",
493 onclick: function(id) {
494 self.unselected[id] = !self.unselected[id];
495 self.chart.toggle(id);
499 onrendered: function() {
500 $('#loading').hide();
501 opts.observable.trigger("chartRendered");
504 self.chart.hide(Object.keys(self.unselected).filter(function(e) {
505 return self.unselected[e];
509 this.pickChartData = function(data, range) {
513 var first = range.first;
514 var last = range.last;
515 var interval, tickInterval, lastTick;
516 if (last <= first + this.oneDay) {
518 tickInterval = 3600 * 1000;
519 lastTick = last - last % tickInterval;
520 } else if (last <= first + this.oneDay * 21) {
522 tickInterval = this.oneDay;
523 lastTick = this.to5am(last);
524 } else if (last <= first + this.oneDay * 63) {
525 interval = 3600 * 1000;
526 tickInterval = this.oneDay * 7;
527 lastTick = this.to5am(moment(last).day(1).valueOf());
528 } else if (last <= first + this.oneDay * 126) {
529 interval = 3600 * 6000;
530 tickInterval = this.oneDay * 14;
531 lastTick = this.to5am(moment(last).day(1).valueOf());
533 var magn = Math.ceil((last - data[0][0]) / (this.oneDay * 365) / 2);
534 interval = this.oneDay * magn;
535 tickInterval = this.oneDay * 28 * magn;
536 lastTick = this.to5am(moment(last).day(1).valueOf());
539 for (var i = data.length - 1; i >= 0; i--) {
544 var v = date - date % interval;
545 if (lastData !== v) {
546 newdata.unshift(row);
554 for (var tick = lastTick; tick > lastData; tick -= tickInterval) {
555 var str = self.toDateString(moment(tick));
557 grid.unshift({ value: str });
559 return { data: newdata, tick: ticks, grid: grid };
568 opts.observable.on("chartSpecChanged", function() {
569 if (opts.chartSpec.type === 1)
573 opts.observable.on("chartSizeChanged", function() {
574 if (opts.chartSpec.type === 1)
578 this.header = ["日付", "燃料", "弾薬", "鋼材", "ボーキ"];
580 opts.observable.on("offAllLegends", function() {
581 if (opts.chartSpec.type !== 1)
584 self.header.slice(1).forEach(function(c) {
585 self.unselected[c] = true;
589 this.resize = function() {
592 $('#loading').show();
593 setTimeout(function() {
594 self.chart.resize(self.chartSize());
598 this.drawChart = function(data) {
599 var range = this.calcRange(opts.chartSpec.diffRange);
600 if (range.last === 0)
603 $('#loading').show();
605 url: "./資材ログ.json?number=true" +
606 "&from=" + range.first + "&to=" + range.last,
607 success: function(d) { self.drawChart(d); },
608 dataType: "json", cache: false
613 picked = this.pickChartData(data.data, range);
614 picked.data.unshift(self.header);
615 this.drawDiffChart(picked);
618 this.calcRange = function(range) {
620 var last = (new Date()).valueOf();
623 first = moment(last).subtract(1, 'months').valueOf();
626 first = moment(last).subtract(3, 'months').valueOf();
629 first = moment(last).subtract(6, 'months').subtract(1, 'weeks').valueOf();
634 var fromDate = $('#chart_from').datetimepicker("getValue");
635 var toDate = $('#chart_to').datetimepicker("getValue");
636 if (fromDate === null || toDate === null)
637 return {first: 0, last: 0};
638 first = Math.max(first, fromDate.valueOf());
639 last = Math.min(last, toDate.valueOf());
642 return {first: first, last: last};
645 this.unselected = {};
647 this.drawDiffChart = function(picked) {
648 var size = this.chartSize();
649 this.chart = c3.generate({
665 groups: [["燃料", "弾薬", "鋼材", "ボーキ"]]
673 show: opts.chartSpec.tooltip
690 format: picked.monthly ? "%Y-%m" : "%m-%d %H:%M",
697 onclick: function(id) {
698 self.unselected[id] = !self.unselected[id];
699 self.chart.toggle(id);
703 onrendered: function() {
704 $('#loading').hide();
705 opts.observable.trigger("chartRendered");
708 self.chart.hide(Object.keys(self.unselected).filter(function(e) {
709 return self.unselected[e];
713 this.pickChartData = function(data, range) {
717 var first = range.first;
718 var last = range.last;
719 var interval, tickInterval, lastTick;
722 return this.pickMonthlyChartData(data);
723 if (last <= first + this.oneDay * 2 * 31) {
724 interval = this.oneDay;
725 tickInterval = this.oneDay * 2;
726 lastTick = this.to5am(last);
728 } else if (last <= first + this.oneDay * 3 * 31) {
729 interval = this.oneDay;
730 tickInterval = this.oneDay * 7;
731 lastTick = this.to5am(last);
734 interval = this.oneDay * 7;
735 tickInterval = this.oneDay * 28;
736 lastTick = this.to5am(moment(last).day(1).valueOf());
738 if (last <= first + this.oneDay * 6 * 38) {
739 tickInterval = this.oneDay * 14;
743 var lastDate = lastTick;
745 for (var i = data.length - 1; i >= 0; i--) {
754 if (date <= lastDate) {
755 var newrow = [lastDate];
756 for (var r = 1; r < 5; r++) {
757 newrow.push(prevRow[r] - row[r]);
759 newdata.unshift(newrow);
760 lastDate = lastDate - interval;
768 if (tickInterval >= this.oneDay * 7)
769 lastTick = moment(lastTick).day(1).hour(5).minute(0).valueOf();
770 for (var tick = lastTick; tick > lastDate; tick -= tickInterval) {
772 grid.unshift({ value: tick });
774 return { data: newdata, tick: ticks, grid: grid, width: barWidth };
777 this.pickMonthlyChartData = function(data) {
785 for (var i = data.length - 1; i >= 0; i--) {
789 var eom = moment(row[0]).endOf('month');
790 prevRow[0] = eom.valueOf();
791 prevMonth = eom.month();
794 date = new Date(row[0]);
795 if (prevMonth !== date.getMonth()) {
796 var newrow = [prevRow[0]];
797 for (var r = 1; r < 5; r++)
798 newrow.push(prevRow[r] - row[r]);
799 newdata.unshift(newrow);
800 ticks.unshift(prevRow[0]);
801 grid.unshift({ value: prevRow[0] });
803 prevMonth = date.getMonth();
806 if (prevRow && date !== prevRow[0]) {
807 newrow = [prevRow[0]];
808 for (r = 1; r < 5; r++)
809 newrow.push(prevRow[r] - row[r]);
810 newdata.unshift(newrow);
811 ticks.unshift(prevRow[0]);
812 grid.unshift({ value: prevRow[0] });
814 return { monthly: true, data: newdata, tick: ticks, grid: grid, width: 0.5 };
817 </differential-chart>
820 <div show={mainTabs[mainTab] === "資材グラフ"}>
821 <span class="c3-legend-item" id="off-all-legends" style="text-decoration: underline; cursor: pointer; z-index: 10; position: absolute; display: none;" onclick={offAllLegends} >全解除</span>
822 <div id="chart" style="clear: both; margin: 1em;"></div>
829 opts.observable.on("mainTabChanged", function(idx) {
830 self.update({mainTab: idx});
831 if (self.mainTabs[idx] === "資材グラフ")
832 opts.observable.trigger("chartSpecChanged");
835 opts.observable.on("chartRendered", function() {
837 if (opts.chartSpec.type === 0) {
838 legend = $(".c3-legend-item-改修資材>text").offset();
841 legend = $(".c3-legend-item-ボーキ>text").offset();
845 $("#off-all-legends").offset({top: legend.top, left: legend.left + offset}).show();
848 this.offAllLegends = function() {
849 opts.observable.trigger("offAllLegends");
853 $(window).resize(function() {
855 clearTimeout(self.timer);
856 self.timer = setTimeout(function() {
857 if (self.mainTabs[self.mainTab] === "資材グラフ")
858 opts.observable.trigger("chartSizeChanged");
859 else if (self.mainTabs[self.mainTab] === "戦果")
860 opts.observable.trigger("achivementChartSizeChanged");
867 <div show={mainTabs[mainTab] === "戦果"}>
868 <span style="margin-left: 1em;">期間: </span><select style="width: 7em; margin-bottom: 1em;" name="月" onchange={monthChange}>
869 <option each={m, i in months} value={m}>{m}</option>
871 <table id="achivement_table" class="display compact cell-border">
873 <tr><th>日付</th><th>戦果</th><th>EO</th><th>月毎</th></tr>
876 <div id="achivementChart" style="margin: 1em;"></div>
880 this.on("mount", function() {
881 $("#achivement_table").dataTable({
885 order: [[0, "desc"]],
889 drawCallback: function() {
890 $('#loading').hide();
897 opts.observable.on("mainTabChanged", function(idx) {
898 self.update({mainTab: idx});
899 if (self.mainTabs[self.mainTab] === "戦果")
904 this.selectedIndex = 0;
906 this.monthChange = function(event) {
907 this.selectedIndex = event.target.selectedIndex;
908 if (this.selectedIndex === 0) {
915 this.calcResult = function(data) {
917 var expPerAch = 10000 / 7.0;
919 var endOfMonth = moment(0);
922 var endOfYear = moment(0);
924 var carryOverAch = 0;
927 var lastDate = moment(0);
929 var nextDate = moment(0);
930 for (var i = 0; i < data.length; i++) {
932 var date = this.parseDate(row[0]);
933 var exp = row[1] - 0;
935 var isNewYear = date.isSameOrAfter(endOfYear);
936 var isNewMonth = date.isSameOrAfter(endOfMonth);
937 var isNewDate = date.isSameOrAfter(nextDate);
938 if (isNewDate || isNewMonth || isNewYear) {
939 if (lastDate.add(1, 'hours').isSameOrBefore(date)) {
940 // 2時を過ぎて最初のexpを戦果の計算に使うと、2時をまたいだ出撃の戦果が前日に加算される。
941 // そこで2時前のexpを使って戦果を計算するが、2時前のexpが正しく出力されていない場合は
942 // 戦果を正しく計算できない。記録の間隔が1時間以上空いているときは、2時をまたいだ出撃が
943 // 行われていない可能性が高いので計算には今のexpを使うことにする。
944 // これは5時基準で出力された過去のデータで、妥当な戦果を計算するために必要な処理である。
947 if (nextDate.valueOf() !== 0) {
948 var d = isNewDate ? nextDate.subtract(1, 'days') : endOfMonth;
949 var m = d.format("YYYY-MM");
952 this.result[m].push([
953 d.format("YYYY-MM-DD"),
954 ((lastExp - prevExp) / expPerAch).toFixed(1), dayEo,
955 ((lastExp - monthExp) / expPerAch + monthEo + carryOverAch + carryOverEo).toFixed(1)
958 prevExp = lastExp === -1 ? exp : lastExp;
960 endOfYear = date.clone().endOf('year').hour(22).startOf('hour');
961 if (endOfYear.isSameOrBefore(date))
962 endOfYear.add(1, 'year');
963 yearExp = lastExp === -1 ? exp : lastExp;
967 endOfMonth = date.clone().endOf('month');
968 if (date.date() === endOfMonth.date())
969 endOfMonth.add(1, 'months').endOf('month');
970 endOfMonth.hour(22).startOf('hour');
971 monthExp = lastExp === -1 ? exp : lastExp;
972 carryOverEo = monthEo * expPerAch / 50000;
973 carryOverAch = (monthExp - yearExp) / 50000;
975 m = endOfMonth.format("YYYY-MM");
978 this.result[m].push([endOfMonth.format("YYYY-MM 引継"),
979 carryOverAch.toFixed(1), carryOverEo.toFixed(1), (carryOverAch + carryOverEo).toFixed(1)]);
982 nextDate = date.clone().hour(2).startOf('hour');
983 if (date.hour() >= 2)
984 nextDate.add(1, 'days');
985 if (nextDate.date() === 1)
986 nextDate.add(1, 'days');
988 if (date.isBefore(date.clone().endOf('month').hour(22).startOf('hour'))) {
989 // 月末22時から翌0時までのEOのボーナス戦果は消える。
998 this.calcChartData = function() {
1000 for (var month in this.result) {
1001 var data = this.chartData[month] = [];
1002 var result = this.result[month];
1005 data.push(["日付", "戦果", "EO", "月毎"]);
1006 for (var i = 0; i < result.length; i++) {
1007 var row = result[i];
1008 if (row[0].match(/引継/)) {
1010 data.push([0, row[1], row[2], row[3]]);
1013 d = moment(row[0], "YYYY-MM-DD").date();
1015 var ach = (row[3] - eo).toFixed(1);
1016 data.push([d, ach, eo, row[3]]);
1018 var endOfMonth = moment(month, "YYYY-MM").endOf("month").date();
1019 while (d < endOfMonth) {
1021 data.push([d, null, null, null]);
1026 this.chartSize = function() {
1027 var width = Math.max($(window).width() - 6 * this.pxPerEm, 800);
1029 height: width * 0.4,
1034 opts.observable.on("achivementChartSizeChanged", function() {
1037 $('#loading').show();
1038 setTimeout(function() {
1039 self.chart.resize(self.chartSize());
1043 this.showChart = function(month) {
1044 this.chart = c3.generate({
1045 bindto: "#achivementChart",
1046 size: this.chartSize(),
1049 rows: this.chartData[month],
1056 onrendered: function() { $('#loading').hide(); }
1060 this.updateData = function(data) {
1062 $('#loading').show();
1065 success: function(data) {
1066 self.updateData(data.data);
1073 this.calcResult(data);
1074 this.calcChartData();
1075 this.months = Object.keys(this.result).sort(function(a, b) {
1086 this.show = function() {
1087 if (this.result === undefined){
1091 var dt = $('#achivement_table').DataTable();
1093 dt.rows.add(this.result[this.months[this.selectedIndex]]).draw();
1094 this.showChart(this.months[this.selectedIndex]);
1100 <div show={mainTabs[mainTab] === "出撃統計"}>
1102 <ul class="tab tabsub" style="float: left; margin-right: 0.2em">
1103 <li each={tabs} class={select: parent.type === type} onclick={parent.changeTab}>{label}</li>
1106 <div style="padding: 0.2em 0;">
1107 <input type="text" id="sortie_stat_from" style="width: 10em">~<input type="text" id="sortie_stat_to" style="width: 10em">
1110 <div style="clear: both;" show={type === "recent"}>
1112 <table id="sortie_stat_day">
1115 <table id="sortie_stat_week">
1118 <table id="sortie_stat_month">
1122 <div show={type === "range"}>
1123 <table id="sortie_stat_all" style="width: 100%;">
1140 this.type = "recent";
1141 this.changeTab = function(e) {
1142 this.type = e.item.type;
1149 this.on("mount", function() {
1150 $("[id^=sortie]").addClass('display compact cell-border');
1154 opts.observable.on("mainTabChanged", function(idx) {
1155 self.update({mainTab: idx});
1156 if (self.mainTabs[self.mainTab] === "出撃統計")
1160 this.init = function() {
1161 self.initPicker('#sortie_stat_from', '#sortie_stat_to', function() {
1162 if (self.type === "range")
1169 this.loadData = function() {
1171 if (this.type === "recent") {
1172 from = moment().subtract(1, 'months').subtract(1, 'day').valueOf();
1173 to = new Date().valueOf();
1175 var fromDate = $('#sortie_stat_from').datetimepicker("getValue");
1176 var toDate = $('#sortie_stat_to').datetimepicker("getValue");
1177 if (fromDate === null || toDate === null) {
1181 from = fromDate.valueOf();
1182 to = toDate.valueOf();
1185 url: "./海戦・ドロップ報告書.json?from=" + from + "&to=" + to,
1186 success: function(data) { self.show(data.data); },
1187 dataType: "json", cache: false
1191 this.initResult = function() {
1194 if (this.type === "recent") {
1200 r.day.begin = moment(now).hour(5).minute(0).second(0);
1201 if (now.hour() < 5) {
1202 r.day.begin.subtract(1, 'days');
1204 r.week.begin = moment(now).day(1).hour(5).minute(0).second(0);
1205 if (now.day() === 0 || now.day() === 1 && now.hour() < 5) {
1206 r.week.begin.subtract(1, 'weeks');
1208 if (moment(now).endOf('month').date() === now.date() &&
1209 now.hour() >= 22) { // 月末22時以降
1210 r.month.begin = moment(now).hour(22).minute(0).second(0);
1213 moment(now).date(1).subtract(1, 'days').
1214 hour(22).minute(0).second(0);
1217 r = { all: { stat: {} } };
1218 r.all.begin = moment(0);
1223 this.gatherData = function(data) {
1224 var initStat = function() {
1225 return { start: "-", S: 0, A: 0, B: 0, C: 0, D: 0, R: 0 };
1227 var r = this.initResult();
1228 for (var i = 0; i < data.length; i++) {
1230 if (/^基地航空隊/.test(row[11])) {
1233 var date = moment(row[0]);
1235 var isBoss = row[3].indexOf("ボス") !== -1;
1236 var isStart = row[3].indexOf("出撃") !== -1;
1238 for (var j = 22; j < row.length; j++) {
1239 if (/^輸送/.test(row[j]) && /^0\x2f/.test(row[j + 1]))
1242 var item = /アイテム/.test(row[9]) ? /[^+]+$/.exec(row[10])[0] : null;
1246 for (var term in r) {
1247 if (!r.hasOwnProperty(term))
1250 if (to.begin.isAfter(date))
1252 for (var b = 0; b < 4; b++) {
1253 var name = b < 2 ? "合計" : map;
1254 if (b === 1 || b === 3) {
1257 name = name + " - ボス";
1259 var mo = to.stat[name];
1261 mo = to.stat[name] = initStat();
1263 to.stat["合計 - ボス"] = initStat();
1272 if ((b === 0 || b === 2) && isStart) {
1273 if (mo.start === "-")
1283 this.isItemColumn = function(col) {
1284 return !/^(?:map|start|[SABCDR])$/.test(col);
1287 this.sortItemOrder = function(items) {
1288 ["お米", "梅干", "海苔", "お茶"].reverse().forEach(function(item) {
1289 var idx = items.indexOf(item);
1291 items.splice(idx, 1);
1292 items.unshift(item);
1297 this.setupColumns = function(r) {
1298 for (var term in r) {
1299 var columns = [{ data: "map", title: "マップ" },
1300 { data: "start", title: "出撃" },
1301 { data: "S", title: "S" },
1302 { data: "A", title: "A" },
1303 { data: "B", title: "B" },
1304 { data: "C", title: "C" },
1305 { data: "D", title: "D" },
1306 { data: "R", title: "輸送船" }];
1307 if (term === "month")
1310 for (var col in r[term].stat["合計"]) {
1311 if (this.isItemColumn(col))
1314 this.sortItemOrder(items);
1315 items.forEach(function(item) {
1316 columns.push({data: item, title: item});
1318 r[term].columns = columns;
1322 this.fillupItemRecords = function(r) {
1323 for (var term in r) {
1324 for (var col in r[term].stat["合計"]) {
1325 if (!this.isItemColumn(col))
1327 for (var map in r[term].stat) {
1330 if (!r[term].stat[map][col]){
1331 r[term].stat[map][col] = 0;
1338 this.reorderRows = function(r) {
1339 for (var term in r) {
1340 if (!r.hasOwnProperty(term))
1344 for (var map in r[term].stat) {
1345 if (!r[term].stat.hasOwnProperty(map))
1349 var e = r[term].stat[map];
1353 var boss = map + " - ボス";
1354 e = r[term].stat[boss];
1361 r[term].table = table;
1365 this.show = function(data) {
1367 $('#loading').show();
1371 var r = this.gatherData(data);
1372 this.setupColumns(r);
1373 this.fillupItemRecords(r);
1374 this.reorderRows(r);
1375 for (var term in r) {
1376 var table = $("#sortie_stat_" + term);
1377 if ($.fn.dataTable.isDataTable(table))
1378 table.DataTable().destroy();
1379 table.html("<thead><tr>" +
1380 r[term].columns.reduce(function(acc, cur) {
1381 return acc + "<th>" + cur.title + "</th>";
1382 }, "") + "</tr></thead>");
1387 columns: r[term].columns,
1391 $('#loading').hide();