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 $('#term_from').datetimepicker({
56 self.datetimepickerOpen = true;
59 if (!self.datetimepickerOpen)
61 self.datetimepickerOpen = false;
62 if (opts.logRange.val === 4)
63 opts.observable.trigger("logRangeChanged");
66 $('#term_to').datetimepicker({
68 self.datetimepickerOpen = true;
71 if (!self.datetimepickerOpen)
73 self.datetimepickerOpen = false;
74 if (opts.logRange.val === 4)
75 opts.observable.trigger("logRangeChanged");
80 this.on("mount", this.init);
82 this.rangeTabChange = function(e) {
83 sessionStorage.setItem("logRange", e.item.i);
84 opts.logRange.val = e.item.i;
85 opts.observable.trigger("logRangeChanged");
92 <div each={header, i in tables} show={mainTab === i}>
93 <table class="display compact cell-border" id={"log" + i}>
102 "<th>日付</th><th>海域</th><th>マップ</th><th>マス</th><th>ボス</th><th>ランク</th><th>ドロップ艦種</th><th>ドロップ艦娘", // ドロップ
103 "<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>", // 海戦
104 "<th>日付</th><th>結果</th><th>遠征</th><th>燃料</th><th>弾薬</th><th>鋼材</th><th>ボーキ</th><th>開発資材</th><th>高速修復材</th><th>高速建造材</th>", // 遠征
105 "<th>日付</th><th>開発装備</th><th>種別</th><th>燃料</th><th>弾薬</th><th>鋼材</th><th>ボーキ</th><th>秘書艦</th><th>司令部Lv</th>", // 開発
106 "<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>", // 建造
107 "<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>", // 改修
108 "<th>日付</th><th>燃料</th><th>弾薬</th><th>鋼材</th><th>ボーキ</th><th>高速建造材</th><th>高速修復材</th><th>開発資材</th><th>改修資材</th>" // 戦果
121 this.on("mount", function() {
122 var records = this.root.querySelectorAll("tr");
123 for (var i = 0; i < records.length; i++)
124 records[i].innerHTML = this.tables[i];
131 opts.observable.on("mainTabChanged", function(idx) {
132 self.update({mainTab: idx});
136 opts.observable.on("logRangeChanged", function() {
140 this.init = function() {
141 for (var t = 0; t < this.tables.length; t++) {
146 order: [[0, "desc"]],
148 lengthMenu: [[50, 100, 200, -1], [50, 100, 200, "All"]],
149 drawCallback: function() {
150 $('#loading').hide();
154 opts.columns = [{data: 0}, {data: 1}, {data: 39}, {data: 2}, {data: 3}, {data: 4}, {data: 9}, {data: 10}];
155 } else if (t === 1) {
157 for (var i = 0; i < 38; i++) {
159 entries.push({data: 39});
160 if (i === 9 || i === 10)
163 entries.push({data: 38});
164 entries.push({data: i});
166 opts.columns = entries;
168 $('#log' + t).dataTable(opts);
172 this.show = function() {
173 if (this.mainTab >= this.jsons.length)
177 var query = "?from=";
178 switch (opts.logRange.val){
180 from = now.clone().startOf('day').hours(5);
182 from.subtract(1, 'days');
183 query += from.valueOf();
186 from = now.clone().startOf('week').hours(5);
187 if (now.hour() < 5 && now.days() === 1)
188 from.subtract(1, 'weeks');
189 query += from.valueOf();
192 if (now.hours() >= 22 &&
193 now.dates() === now.clone().endOf('month').date()) {
194 from = now.clone().hours(22);
196 from = now.clone().startOf('month').subtract(1, 'days').hours(22);
198 query += from.valueOf();
204 from = $('#term_from').datetimepicker("getValue");
205 var to = $('#term_to').datetimepicker("getValue");
208 query += from.valueOf();
210 query += "&to=" + to.valueOf();
213 $('#loading').show();
214 var url = this.jsons[this.mainTab] + query;
215 $('#log' + this.mainTab).DataTable().ajax.url(url).load();
221 <form id="chart_type" show={mainTabs[mainTab] === "資材グラフ"}>
222 <div style="margin: 0 0 0.5em 1em;">
223 <label><input type="radio" name="chart_type" value="0" checked={opts.chartSpec.type === 0} onchange={chartTypeChange}>連続</label>
224 <label><input type="radio" name="chart_type" value="1" checked={opts.chartSpec.type === 1} onchange={chartTypeChange}>差分</label>
230 opts.chartSpec.type = +sessionStorage.getItem('chartType');
233 this.chartTypeChange = function(e) {
234 opts.chartSpec.type = +e.target.value;
235 sessionStorage.setItem('chartType', opts.chartSpec.type);
236 opts.observable.trigger("chartTypeChanged");
237 opts.observable.trigger("chartSpecChanged");
240 opts.observable.on("mainTabChanged", function(idx) {
241 self.update({mainTab: idx});
247 <div show={mainTabs[mainTab] === "資材グラフ"}>
248 <ul class="tab tabsub" style="float: left; margin-right: 0.2em" show={chartSpec.type === 0}>
249 <li each={name, i in seqChartRanges} class={select: chartSpec.seqRange === i} onclick={parent.rangeTabChange}>{name}</li>
252 <ul class="tab tabsub" style="float: left; margin-right: 0.2em" show={chartSpec.type === 1}>
253 <li each={name, i in diffChartRanges} class={select: chartSpec.diffRange === i} onclick={parent.rangeTabChange}>{name}</li>
255 <div style="padding: 0.2em 0;">
256 <input type="text" id="chart_from" style="width: 10em">~<input type="text" id="chart_to" style="width: 10em">
257 <label><input type="checkbox" id="tooltip" value="" style="margin-left: 2em;" onchange={tooltipChange} checked={opts.chartSpec.tooltip === 1}>ツールチップ</label>
262 this.seqChartRanges = [
271 this.diffChartRanges = [
279 opts.chartSpec.seqRange = +sessionStorage.getItem('seqChartRange');
280 opts.chartSpec.diffRange = +sessionStorage.getItem('diffChartRange');
281 opts.chartSpec.tooltip = +sessionStorage.getItem('chartTooltip');
282 this.chartSpec = opts.chartSpec;
284 this.rangeTabChange = function(e) {
285 if (opts.chartSpec.type === 0) {
286 opts.chartSpec.seqRange = e.item.i;
287 sessionStorage.setItem('seqChartRange', e.item.i);
289 opts.chartSpec.diffRange = e.item.i;
290 sessionStorage.setItem('diffChartRange', e.item.i);
292 opts.observable.trigger("chartSpecChanged");
295 this.tooltipChange = function(e) {
296 opts.chartSpec.tooltip = +e.target.checked;
297 sessionStorage.setItem('chartTooltip', +e.target.checked);
298 opts.observable.trigger("chartSpecChanged");
301 this.useDatePicker = function() {
302 return opts.chartSpec.type === 0 && opts.chartSpec.seqRange === 5 ||
303 opts.chartSpec.type === 1 && opts.chartSpec.diffRange === 4;
308 this.init = function() {
309 $('#chart_from').datetimepicker({
311 self.datetimepickerOpen = true;
313 onClose: function() {
314 if (!self.datetimepickerOpen)
316 self.datetimepickerOpen = false;
317 if (self.useDatePicker())
318 opts.observable.trigger("chartSpecChanged");
321 $('#chart_to').datetimepicker({
323 self.datetimepickerOpen = true;
325 onClose: function() {
326 if (!self.datetimepickerOpen)
328 self.datetimepickerOpen = false;
329 if (self.useDatePicker())
330 opts.observable.trigger("chartSpecChanged");
337 this.on("mount", self.init);
339 opts.observable.on("mainTabChanged", function(idx) {
340 self.update({mainTab: idx});
343 opts.observable.on("chartTypeChanged", function() {
353 opts.observable.on("chartSpecChanged", function() {
354 if (opts.chartSpec.type === 0)
358 opts.observable.on("chartSizeChanged", function() {
359 if (opts.chartSpec.type === 0)
363 this.header = ["日付", "燃料", "弾薬", "鋼材", "ボーキ", "高速建造材", "高速修復材", "開発資材", "改修資材"];
365 opts.observable.on("offAllLegends", function() {
366 if (opts.chartSpec.type !== 0)
369 self.header.slice(1).forEach(function(c) {
370 self.unselected[c] = true;
374 this.resize = function() {
377 $('#loading').show();
378 setTimeout(function() {
379 self.chart.resize(self.chartSize());
383 this.drawChart = function(data) {
384 var range = this.calcRange(opts.chartSpec.seqRange);
385 if (range.last === 0)
388 $('#loading').show();
390 url: "./資材ログ.json?number=true" +
391 "&from=" + range.first + "&to=" + range.last,
392 success: function(d) { self.drawChart(d); },
393 dataType: "json", cache: false
398 picked = this.pickChartData(data.data, range);
399 picked.data.unshift(self.header);
400 this.drawSeqChart(picked);
403 this.calcRange = function(range) {
405 var last = (new Date()).valueOf();
408 first = moment(last).subtract(24, 'hours').valueOf();
411 first = moment(last).subtract(7, 'days').valueOf();
414 first = moment(last).subtract(1, 'months').valueOf();
417 first = moment(last).subtract(3, 'months').valueOf();
422 var fromDate = $('#chart_from').datetimepicker("getValue");
423 var toDate = $('#chart_to').datetimepicker("getValue");
424 if (fromDate === null || toDate === null)
425 return {first: 0, last:0};
426 first = fromDate.valueOf();
427 last = toDate.valueOf();
430 return {first: first, last: last};
433 this.unselected = {};
435 this.drawSeqChart = function(picked) {
436 var size = this.chartSize();
437 this.chart = c3.generate({
445 xFormat: '%Y-%m-%d %H:%M:%S',
462 show: opts.chartSpec.tooltip
474 format: "%m-%d %H:%M",
484 onclick: function(id) {
485 self.unselected[id] = !self.unselected[id];
486 self.chart.toggle(id);
490 onrendered: function() {
491 $('#loading').hide();
492 opts.observable.trigger("chartRendered");
495 self.chart.hide(Object.keys(self.unselected).filter(function(e) {
496 return self.unselected[e];
500 this.pickChartData = function(data, range) {
504 var first = range.first;
505 var last = range.last;
506 var interval, tickInterval, lastTick;
507 if (last <= first + this.oneDay) {
509 tickInterval = 3600 * 1000;
510 lastTick = last - last % tickInterval;
511 } else if (last <= first + this.oneDay * 21) {
513 tickInterval = this.oneDay;
514 lastTick = this.to5am(last);
515 } else if (last <= first + this.oneDay * 63) {
516 interval = 3600 * 1000;
517 tickInterval = this.oneDay * 7;
518 lastTick = this.to5am(moment(last).day(1).valueOf());
519 } else if (last <= first + this.oneDay * 126) {
520 interval = 3600 * 6000;
521 tickInterval = this.oneDay * 14;
522 lastTick = this.to5am(moment(last).day(1).valueOf());
524 var magn = Math.ceil((last - data[0][0]) / (this.oneDay * 365) / 2);
525 interval = this.oneDay * magn;
526 tickInterval = this.oneDay * 28 * magn;
527 lastTick = this.to5am(moment(last).day(1).valueOf());
530 for (var i = data.length - 1; i >= 0; i--) {
535 var v = date - date % interval;
536 if (lastData !== v) {
537 newdata.unshift(row);
545 for (var tick = lastTick; tick > lastData; tick -= tickInterval) {
546 var str = self.toDateString(moment(tick));
548 grid.unshift({ value: str });
550 return { data: newdata, tick: ticks, grid: grid };
559 opts.observable.on("chartSpecChanged", function() {
560 if (opts.chartSpec.type === 1)
564 opts.observable.on("chartSizeChanged", function() {
565 if (opts.chartSpec.type === 1)
569 this.header = ["日付", "燃料", "弾薬", "鋼材", "ボーキ"];
571 opts.observable.on("offAllLegends", function() {
572 if (opts.chartSpec.type !== 1)
575 self.header.slice(1).forEach(function(c) {
576 self.unselected[c] = true;
580 this.resize = function() {
583 $('#loading').show();
584 setTimeout(function() {
585 self.chart.resize(self.chartSize());
589 this.drawChart = function(data) {
590 var range = this.calcRange(opts.chartSpec.diffRange);
591 if (range.last === 0)
594 $('#loading').show();
596 url: "./資材ログ.json?number=true" +
597 "&from=" + range.first + "&to=" + range.last,
598 success: function(d) { self.drawChart(d); },
599 dataType: "json", cache: false
604 picked = this.pickChartData(data.data, range);
605 picked.data.unshift(self.header);
606 this.drawDiffChart(picked);
609 this.calcRange = function(range) {
611 var last = (new Date()).valueOf();
614 first = moment(last).subtract(1, 'months').valueOf();
617 first = moment(last).subtract(3, 'months').valueOf();
620 first = moment(last).subtract(6, 'months').subtract(1, 'weeks').valueOf();
625 var fromDate = $('#chart_from').datetimepicker("getValue");
626 var toDate = $('#chart_to').datetimepicker("getValue");
627 if (fromDate === null || toDate === null)
628 return {first: 0, last: 0};
629 first = Math.max(first, fromDate.valueOf());
630 last = Math.min(last, toDate.valueOf());
633 return {first: first, last: last};
636 this.unselected = {};
638 this.drawDiffChart = function(picked) {
639 var size = this.chartSize();
640 this.chart = c3.generate({
656 groups: [["燃料", "弾薬", "鋼材", "ボーキ"]]
664 show: opts.chartSpec.tooltip
681 format: picked.monthly ? "%Y-%m" : "%m-%d %H:%M",
688 onclick: function(id) {
689 self.unselected[id] = !self.unselected[id];
690 self.chart.toggle(id);
694 onrendered: function() {
695 $('#loading').hide();
696 opts.observable.trigger("chartRendered");
699 self.chart.hide(Object.keys(self.unselected).filter(function(e) {
700 return self.unselected[e];
704 this.pickChartData = function(data, range) {
708 var first = range.first;
709 var last = range.last;
710 var interval, tickInterval, lastTick;
713 return this.pickMonthlyChartData(data);
714 if (last <= first + this.oneDay * 2 * 31) {
715 interval = this.oneDay;
716 tickInterval = this.oneDay * 2;
717 lastTick = this.to5am(last);
719 } else if (last <= first + this.oneDay * 3 * 31) {
720 interval = this.oneDay;
721 tickInterval = this.oneDay * 7;
722 lastTick = this.to5am(last);
725 interval = this.oneDay * 7;
726 tickInterval = this.oneDay * 28;
727 lastTick = this.to5am(moment(last).day(1).valueOf());
729 if (last <= first + this.oneDay * 6 * 38) {
730 tickInterval = this.oneDay * 14;
734 var lastDate = lastTick;
736 for (var i = data.length - 1; i >= 0; i--) {
745 if (date <= lastDate) {
746 var newrow = [lastDate];
747 for (var r = 1; r < 5; r++) {
748 newrow.push(prevRow[r] - row[r]);
750 newdata.unshift(newrow);
751 lastDate = lastDate - interval;
759 if (tickInterval >= this.oneDay * 7)
760 lastTick = moment(lastTick).day(1).hour(5).minute(0).valueOf();
761 for (var tick = lastTick; tick > lastDate; tick -= tickInterval) {
763 grid.unshift({ value: tick });
765 return { data: newdata, tick: ticks, grid: grid, width: barWidth };
768 this.pickMonthlyChartData = function(data) {
776 for (var i = data.length - 1; i >= 0; i--) {
780 var eom = moment(row[0]).endOf('month');
781 prevRow[0] = eom.valueOf();
782 prevMonth = eom.month();
785 date = new Date(row[0]);
786 if (prevMonth !== date.getMonth()) {
787 var newrow = [prevRow[0]];
788 for (var r = 1; r < 5; r++)
789 newrow.push(prevRow[r] - row[r]);
790 newdata.unshift(newrow);
791 ticks.unshift(prevRow[0]);
792 grid.unshift({ value: prevRow[0] });
794 prevMonth = date.getMonth();
797 if (prevRow && date !== prevRow[0]) {
798 newrow = [prevRow[0]];
799 for (r = 1; r < 5; r++)
800 newrow.push(prevRow[r] - row[r]);
801 newdata.unshift(newrow);
802 ticks.unshift(prevRow[0]);
803 grid.unshift({ value: prevRow[0] });
805 return { monthly: true, data: newdata, tick: ticks, grid: grid, width: 0.5 };
808 </differential-chart>
811 <div show={mainTabs[mainTab] === "資材グラフ"}>
812 <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>
813 <div id="chart" style="clear: both; margin: 1em;"></div>
820 opts.observable.on("mainTabChanged", function(idx) {
821 self.update({mainTab: idx});
822 if (self.mainTabs[idx] === "資材グラフ")
823 opts.observable.trigger("chartSpecChanged");
826 opts.observable.on("chartRendered", function() {
828 if (opts.chartSpec.type === 0) {
829 legend = $(".c3-legend-item-改修資材>text").offset();
832 legend = $(".c3-legend-item-ボーキ>text").offset();
836 $("#off-all-legends").offset({top: legend.top, left: legend.left + offset}).show();
839 this.offAllLegends = function() {
840 opts.observable.trigger("offAllLegends");
844 $(window).resize(function() {
846 clearTimeout(self.timer);
847 self.timer = setTimeout(function() {
848 if (self.mainTabs[self.mainTab] === "資材グラフ")
849 opts.observable.trigger("chartSizeChanged");
850 else if (self.mainTabs[self.mainTab] === "戦果")
851 opts.observable.trigger("achivementChartSizeChanged");
858 <div show={mainTabs[mainTab] === "戦果"}>
859 <span style="margin-left: 1em;">期間: </span><select style="width: 7em; margin-bottom: 1em;" name="月" onchange={monthChange}>
860 <option each={m, i in months} value={m}>{m}</option>
862 <table id="achivement_table" class="display compact cell-border">
864 <tr><th>日付</th><th>戦果</th><th>EO</th><th>月毎</th></tr>
867 <div id="achivementChart" style="margin: 1em;"></div>
871 this.on("mount", function() {
872 $("#achivement_table").dataTable({
876 order: [[0, "desc"]],
880 drawCallback: function() {
881 $('#loading').hide();
888 opts.observable.on("mainTabChanged", function(idx) {
889 self.update({mainTab: idx});
890 if (self.mainTabs[self.mainTab] === "戦果")
895 this.selectedIndex = 0;
897 this.monthChange = function(event) {
898 this.selectedIndex = event.target.selectedIndex;
899 if (this.selectedIndex === 0) {
906 this.calcResult = function(data) {
908 var expPerAch = 10000 / 7.0;
910 var endOfMonth = moment(0);
913 var endOfYear = moment(0);
915 var carryOverAch = 0;
918 var lastDate = moment(0);
920 var nextDate = moment(0);
921 for (var i = 0; i < data.length; i++) {
923 var date = this.parseDate(row[0]);
924 var exp = row[1] - 0;
926 var isNewYear = date.isSameOrAfter(endOfYear);
927 var isNewMonth = date.isSameOrAfter(endOfMonth);
928 var isNewDate = date.isSameOrAfter(nextDate);
929 if (isNewDate || isNewMonth || isNewYear) {
930 if (lastDate.add(1, 'hours').isSameOrBefore(date)) {
931 // 2時を過ぎて最初のexpを戦果の計算に使うと、2時をまたいだ出撃の戦果が前日に加算される。
932 // そこで2時前のexpを使って戦果を計算するが、2時前のexpが正しく出力されていない場合は
933 // 戦果を正しく計算できない。記録の間隔が1時間以上空いているときは、2時をまたいだ出撃が
934 // 行われていない可能性が高いので計算には今のexpを使うことにする。
935 // これは5時基準で出力された過去のデータで、妥当な戦果を計算するために必要な処理である。
938 if (nextDate.valueOf() !== 0) {
939 var d = isNewDate ? nextDate.subtract(1, 'days') : endOfMonth;
940 var m = d.format("YYYY-MM");
943 this.result[m].push([
944 d.format("YYYY-MM-DD"),
945 ((lastExp - prevExp) / expPerAch).toFixed(1), dayEo,
946 ((lastExp - monthExp) / expPerAch + monthEo + carryOverAch + carryOverEo).toFixed(1)
949 prevExp = lastExp === -1 ? exp : lastExp;
951 endOfYear = date.clone().endOf('year').hour(22).startOf('hour');
952 if (endOfYear.isSameOrBefore(date))
953 endOfYear.add(1, 'year');
954 yearExp = lastExp === -1 ? exp : lastExp;
958 endOfMonth = date.clone().endOf('month');
959 if (date.date() === endOfMonth.date())
960 endOfMonth.add(1, 'months').endOf('month');
961 endOfMonth.hour(22).startOf('hour');
962 monthExp = lastExp === -1 ? exp : lastExp;
963 carryOverEo = monthEo * expPerAch / 50000;
964 carryOverAch = (monthExp - yearExp) / 50000;
966 m = endOfMonth.format("YYYY-MM");
969 this.result[m].push([endOfMonth.format("YYYY-MM 引継"),
970 carryOverAch.toFixed(1), carryOverEo.toFixed(1), (carryOverAch + carryOverEo).toFixed(1)]);
973 nextDate = date.clone().hour(2).startOf('hour');
974 if (date.hour() >= 2)
975 nextDate.add(1, 'days');
976 if (nextDate.date() === 1)
977 nextDate.add(1, 'days');
979 if (date.isBefore(date.clone().endOf('month').hour(22).startOf('hour'))) {
980 // 月末22時から翌0時までのEOのボーナス戦果は消える。
989 this.calcChartData = function() {
991 for (var month in this.result) {
992 var data = this.chartData[month] = [];
993 var result = this.result[month];
996 data.push(["日付", "戦果", "EO", "月毎"]);
997 for (var i = 0; i < result.length; i++) {
999 if (row[0].match(/引継/)) {
1001 data.push([0, row[1], row[2], row[3]]);
1004 d = moment(row[0], "YYYY-MM-DD").date();
1006 var ach = (row[3] - eo).toFixed(1);
1007 data.push([d, ach, eo, row[3]]);
1009 var endOfMonth = moment(month, "YYYY-MM").endOf("month").date();
1010 while (d < endOfMonth) {
1012 data.push([d, null, null, null]);
1017 this.chartSize = function() {
1018 var width = Math.max($(window).width() - 6 * this.pxPerEm, 800);
1020 height: width * 0.4,
1025 opts.observable.on("achivementChartSizeChanged", function() {
1028 $('#loading').show();
1029 setTimeout(function() {
1030 self.chart.resize(self.chartSize());
1034 this.showChart = function(month) {
1035 this.chart = c3.generate({
1036 bindto: "#achivementChart",
1037 size: this.chartSize(),
1040 rows: this.chartData[month],
1047 onrendered: function() { $('#loading').hide(); }
1051 this.updateData = function(data) {
1053 $('#loading').show();
1056 success: function(data) {
1057 self.updateData(data.data);
1064 this.calcResult(data);
1065 this.calcChartData();
1066 this.months = Object.keys(this.result).sort(function(a, b) {
1077 this.show = function() {
1078 if (this.result === undefined){
1082 var dt = $('#achivement_table').DataTable();
1084 dt.rows.add(this.result[this.months[this.selectedIndex]]).draw();
1085 this.showChart(this.months[this.selectedIndex]);
1091 <div show={mainTabs[mainTab] === "出撃統計"}>
1093 <ul class="tab tabsub" style="float: left; margin-right: 0.2em">
1094 <li each={tabs} class={select: parent.type === type} onclick={parent.changeTab}>{label}</li>
1097 <div style="padding: 0.2em 0;">
1098 <input type="text" id="sortie_stat_from" style="width: 10em">~<input type="text" id="sortie_stat_to" style="width: 10em">
1101 <div style="clear: both;" show={type === "recent"}>
1103 <table id="sortie_stat_day">
1106 <table id="sortie_stat_week">
1109 <table id="sortie_stat_month">
1113 <div show={type === "range"}>
1114 <table id="sortie_stat_all" style="width: 100%;">
1131 this.type = "recent";
1132 this.changeTab = function(e) {
1133 this.type = e.item.type;
1140 this.on("mount", function() {
1141 $("[id^=sortie]").addClass('display compact cell-border');
1145 opts.observable.on("mainTabChanged", function(idx) {
1146 self.update({mainTab: idx});
1147 if (self.mainTabs[self.mainTab] === "出撃統計")
1151 this.init = function() {
1152 this.initDatePicker();
1155 this.initDatePicker = function() {
1156 $('#sortie_stat_from').datetimepicker({
1157 onShow: function() {
1158 self.datetimepickerOpen = true;
1160 onClose: function() {
1161 if (!self.datetimepickerOpen)
1163 self.datetimepickerOpen = false;
1164 if (self.type === "range")
1168 $('#sortie_stat_to').datetimepicker({
1169 onShow: function() {
1170 self.datetimepickerOpen = true;
1172 onClose: function() {
1173 if (!self.datetimepickerOpen)
1175 self.datetimepickerOpen = false;
1176 if (self.type === "range")
1184 this.loadData = function() {
1186 if (this.type === "recent") {
1187 from = moment().subtract(1, 'months').subtract(1, 'day').valueOf();
1188 to = new Date().valueOf();
1190 var fromDate = $('#sortie_stat_from').datetimepicker("getValue");
1191 var toDate = $('#sortie_stat_to').datetimepicker("getValue");
1192 if (fromDate === null || toDate === null) {
1196 from = fromDate.valueOf();
1197 to = toDate.valueOf();
1200 url: "./海戦・ドロップ報告書.json?from=" + from + "&to=" + to,
1201 success: function(data) { self.show(data.data); },
1202 dataType: "json", cache: false
1206 this.initResult = function() {
1209 if (this.type === "recent") {
1215 r.day.begin = moment(now).hour(5).minute(0).second(0);
1216 if (now.hour() < 5) {
1217 r.day.begin.subtract(1, 'days');
1219 r.week.begin = moment(now).day(1).hour(5).minute(0).second(0);
1220 if (now.day() === 0 || now.day() === 1 && now.hour() < 5) {
1221 r.week.begin.subtract(1, 'weeks');
1223 if (moment(now).endOf('month').date() === now.date() &&
1224 now.hour() >= 22) { // 月末22時以降
1225 r.month.begin = moment(now).hour(22).minute(0).second(0);
1228 moment(now).date(1).subtract(1, 'days').
1229 hour(22).minute(0).second(0);
1232 r = { all: { stat: {} } };
1233 r.all.begin = moment(0);
1238 this.gatherData = function(data) {
1239 var initStat = function() {
1240 return { start: "-", S: 0, A: 0, B: 0, C: 0, D: 0, R: 0 };
1242 var r = this.initResult();
1243 for (var i = 0; i < data.length; i++) {
1245 var date = moment(row[0]);
1247 var isBoss = row[3].indexOf("ボス") !== -1;
1248 var isStart = row[3].indexOf("出撃") !== -1;
1250 for (var j = 22; j < row.length; j++) {
1251 if (/^輸送/.test(row[j]) && /^0\x2f/.test(row[j + 1]))
1254 var item = /アイテム/.test(row[9]) ? /[^+]+$/.exec(row[10])[0] : null;
1258 for (var term in r) {
1259 if (!r.hasOwnProperty(term))
1262 if (to.begin.isAfter(date))
1264 for (var b = 0; b < 4; b++) {
1265 var name = b < 2 ? "合計" : map;
1266 if (b === 1 || b === 3) {
1269 name = name + " - ボス";
1271 var mo = to.stat[name];
1273 mo = to.stat[name] = initStat();
1275 to.stat["合計 - ボス"] = initStat();
1284 if ((b === 0 || b === 2) && isStart) {
1285 if (mo.start === "-")
1295 this.isItemColumn = function(col) {
1296 return !/^(?:map|start|[SABCDR])$/.test(col);
1299 this.sortItemOrder = function(items) {
1300 ["お米", "梅干", "海苔", "お茶"].reverse().forEach(function(item) {
1301 var idx = items.indexOf(item);
1303 items.splice(idx, 1);
1304 items.unshift(item);
1309 this.setupColumns = function(r) {
1310 for (var term in r) {
1311 var columns = [{ data: "map", title: "マップ" },
1312 { data: "start", title: "出撃" },
1313 { data: "S", title: "S" },
1314 { data: "A", title: "A" },
1315 { data: "B", title: "B" },
1316 { data: "C", title: "C" },
1317 { data: "D", title: "D" },
1318 { data: "R", title: "輸送船" }];
1319 if (term === "month")
1322 for (var col in r[term].stat["合計"]) {
1323 if (this.isItemColumn(col))
1326 this.sortItemOrder(items);
1327 items.forEach(function(item) {
1328 columns.push({data: item, title: item});
1330 r[term].columns = columns;
1334 this.fillupItemRecords = function(r) {
1335 for (var term in r) {
1336 for (var col in r[term].stat["合計"]) {
1337 if (!this.isItemColumn(col))
1339 for (var map in r[term].stat) {
1342 if (!r[term].stat[map][col]){
1343 r[term].stat[map][col] = 0;
1350 this.reorderRows = function(r) {
1351 for (var term in r) {
1352 if (!r.hasOwnProperty(term))
1356 for (var map in r[term].stat) {
1357 if (!r[term].stat.hasOwnProperty(map))
1361 var e = r[term].stat[map];
1365 var boss = map + " - ボス";
1366 e = r[term].stat[boss];
1373 r[term].table = table;
1377 this.show = function(data) {
1379 $('#loading').show();
1383 var r = this.gatherData(data);
1384 this.setupColumns(r);
1385 this.fillupItemRecords(r);
1386 this.reorderRows(r);
1387 for (var term in r) {
1388 var table = $("#sortie_stat_" + term);
1389 if ($.fn.dataTable.isDataTable(table))
1390 table.DataTable().destroy();
1391 table.html("<thead><tr>" +
1392 r[term].columns.reduce(function(acc, cur) {
1393 return acc + "<th>" + cur.title + "</th>";
1394 }, "") + "</tr></thead>");
1399 columns: r[term].columns,
1403 $('#loading').hide();