質問編集履歴
2
最終結果の追加
title
CHANGED
File without changes
|
body
CHANGED
@@ -156,7 +156,15 @@
|
|
156
156
|
|
157
157
|
ifによる条件分岐 → undefinedになってしまいエラーがでてしまう。
|
158
158
|
|
159
|
+
###最終的にどうなってほしいのか
|
160
|
+
以下のような形式のCSVファイルでの書き出しを行いたい
|
161
|
+
■■■■■ t8 t9 t10 t11 t12 t13 t14 t15 t16
|
162
|
+
NE_spring prital, shadow, shadow, shadow, shadow, shadow, shadow, shadow, shadow
|
163
|
+
NE_summer prital, shadow, shadow, shadow, shadow, shadow, shadow, shadow, shadow
|
164
|
+
NE_winter shadow, shadow, shadow, shadow, shadow, shadow, shadow, shadow, shadow
|
159
165
|
|
166
|
+
以下略
|
167
|
+
|
160
168
|
### 補足情報(FW/ツールのバージョンなど)
|
161
169
|
|
162
170
|
ここにより詳細な情報を記載してください。
|
1
具体的な例、ソースコードの修正
title
CHANGED
File without changes
|
body
CHANGED
@@ -6,21 +6,33 @@
|
|
6
6
|
Jsonデータから取得した値をループ処理で連想配列にしたいと考えています。
|
7
7
|
その際に時間と方角と季節をfilterして存在するものはjsonからstateの値を抜き出し、存在しないものはnoneという値を入れたいと考えています。
|
8
8
|
|
9
|
+
具体的な例
|
9
10
|
---
|
11
|
+
data.json内のshadowDataを direction,seasonでfilterをかける
|
12
|
+
|
10
|
-
|
13
|
+
↓
|
14
|
+
|
15
|
+
一致したデータを個別に配列化
|
16
|
+
(方角 NEの季節 spring配列、方角 NEの季節 summer配列のように…)
|
17
|
+
|
18
|
+
↓
|
19
|
+
|
11
|
-
|
20
|
+
配列化したデータの中身を確認、存在するデータの時間を見て、連想配列にstateを格納、存在しないデータの時間はすべてnoneにする。
|
12
|
-
|
21
|
+
|
13
22
|
{"time":"8:00", "season":"spring", "direction":"NE", "state":"partial"},
|
14
|
-
|
23
|
+
↓NEのspring には 8:00 のみ存在
|
15
|
-
{"8:00":"pratial","9:00":"none","10:00":"none","11:00":"none","12:00":"none","13:00":"none","14:00":"none","15:00":"none","16:00":"none" }
|
24
|
+
NE_spring{"8:00":"pratial","9:00":"none","10:00":"none","11:00":"none","12:00":"none","13:00":"none","14:00":"none","15:00":"none","16:00":"none" },
|
25
|
+
NE_summer{"8:00":"pratial","9:00":"none","10:00":"none","11:00":"none","12:00":"none","13:00":"none","14:00":"none","15:00":"none","16:00":"none" }.....以下略
|
16
26
|
|
17
|
-
{"time":"15:00", "season":"spring", "direction":"NW", "state":"shadow"},
|
18
|
-
{"time":"16:00", "season":"spring", "direction":"NW", "state":"partial"},
|
19
|
-
|
27
|
+
↓
|
20
|
-
{"8:00":"none","9:00":"none","10:00":"none","11:00":"none","12:00":"none","13:00":"none","14:00":"none","15:00":"shadow","16:00":"praital" }
|
21
28
|
|
29
|
+
(作成した連想配列をループ処理で参照してCSVで列として書き出し)
|
30
|
+
|
31
|
+
というプログラムを考えておりましたが自分の知識不足でうまく配列化、データの取り出しができずCSVを書き出した際undefinedになってしまいまっています。
|
32
|
+
|
33
|
+
|
22
34
|
### 発生している問題・エラーメッセージ
|
23
|
-
季節と方角毎にフィルターをかけ
|
35
|
+
季節と方角毎にフィルターをかけるところまでは成功しましたがそこから先がわかりません…
|
24
36
|
|
25
37
|
```
|
26
38
|
エラーメッセージ
|
@@ -29,23 +41,45 @@
|
|
29
41
|
### 該当のソースコード
|
30
42
|
|
31
43
|
```JavaScript
|
44
|
+
let i = 0;
|
45
|
+
let n = 0;
|
46
|
+
let b = 0;
|
32
47
|
let replaceTime = [];
|
33
48
|
let replaceDirection = [];
|
34
49
|
let getShadowData = [];
|
50
|
+
let replaceState = [];
|
35
51
|
let replaceText = '';
|
36
52
|
|
37
|
-
for(let i in
|
53
|
+
for(let i in timeData) {
|
38
|
-
replaceTime[i] = 'T' +
|
54
|
+
replaceTime[i] = 'T' + timeData[i].replace(/:00/g, '');
|
39
55
|
}
|
56
|
+
var csv = '\ufeff' + '&shadowData=DIR_SEASON' + ',' + replaceTime +'\n'
|
40
57
|
|
41
|
-
for(let i in
|
58
|
+
for(let i in directionData) {
|
59
|
+
replaceDirection[i] = directionData[i].direction
|
60
|
+
getShadowData = shadowData.filter(x => x.direction == directionData[i].direction)
|
61
|
+
for(let n in seasonData) {
|
62
|
+
replaceText = replaceDirection[i] + '_' + seasonData[n].season;
|
63
|
+
replaceState.push(getShadowData.filter(x => x.season == seasonData[n].season));
|
64
|
+
}
|
65
|
+
}
|
66
|
+
directionData.forEach(el => {
|
42
67
|
replaceDirection[i] = this.directionData[i].direction
|
43
68
|
for(let n in this.seasonData) {
|
44
69
|
replaceText = replaceDirection[i] + '_' + this.seasonData[n].season
|
70
|
+
for (let b in replaceText) {
|
45
|
-
|
71
|
+
var line = '\ufeff' + replaceText + ',' + replaceState[b].state +'\n'
|
72
|
+
}
|
73
|
+
csv += line
|
46
74
|
}
|
75
|
+
i++
|
47
|
-
}
|
76
|
+
})
|
77
|
+
|
78
|
+
let blob = new Blob([csv], { type: 'text/csv' });
|
79
|
+
let link = document.createElement('a')
|
80
|
+
link.href = window.URL.createObjectURL(blob)
|
48
|
-
|
81
|
+
link.download = 'shadowData.csv'
|
82
|
+
link.click()
|
49
83
|
```
|
50
84
|
```data.json
|
51
85
|
"timeData": [
|
@@ -74,8 +108,48 @@
|
|
74
108
|
{"time":"16:00", "season":"summer", "direction":"NW", "state":"partial"},
|
75
109
|
{"time":"15:00", "season":"winter", "direction":"NW", "state":"partial"},
|
76
110
|
{"time":"16:00", "season":"winter", "direction":"NW", "state":"partial"},
|
77
|
-
~~~~以下略~~~~~
|
78
111
|
|
112
|
+
{"time":"8:00", "season":"spring", "direction":"SE", "state":"partial"},
|
113
|
+
{"time":"9:00", "season":"spring", "direction":"SE", "state":"partial"},
|
114
|
+
{"time":"10:00", "season":"spring", "direction":"SE", "state":"partial"},
|
115
|
+
{"time":"11:00", "season":"spring", "direction":"SE", "state":"partial"},
|
116
|
+
{"time":"12:00", "season":"spring", "direction":"SE", "state":"partial"},
|
117
|
+
{"time":"13:00", "season":"spring", "direction":"SE", "state":"partial"},
|
118
|
+
{"time":"8:00", "season":"summer", "direction":"SE", "state":"partial"},
|
119
|
+
{"time":"9:00", "season":"summer", "direction":"SE", "state":"partial"},
|
120
|
+
{"time":"10:00", "season":"summer", "direction":"SE", "state":"partial"},
|
121
|
+
{"time":"11:00", "season":"summer", "direction":"SE", "state":"partial"},
|
122
|
+
{"time":"12:00", "season":"summer", "direction":"SE", "state":"partial"},
|
123
|
+
{"time":"8:00", "season":"winter", "direction":"SE", "state":"partial"},
|
124
|
+
{"time":"9:00", "season":"winter", "direction":"SE", "state":"partial"},
|
125
|
+
{"time":"10:00", "season":"winter", "direction":"SE", "state":"partial"},
|
126
|
+
{"time":"11:00", "season":"winter", "direction":"SE", "state":"partial"},
|
127
|
+
{"time":"12:00", "season":"winter", "direction":"SE", "state":"partial"},
|
128
|
+
{"time":"13:00", "season":"winter", "direction":"SE", "state":"partial"},
|
129
|
+
{"time":"14:00", "season":"winter", "direction":"SE", "state":"partial"},
|
130
|
+
|
131
|
+
{"time":"10:00", "season":"spring", "direction":"SW", "state":"partial"},
|
132
|
+
{"time":"11:00", "season":"spring", "direction":"SW", "state":"partial"},
|
133
|
+
{"time":"12:00", "season":"spring", "direction":"SW", "state":"partial"},
|
134
|
+
{"time":"13:00", "season":"spring", "direction":"SW", "state":"partial"},
|
135
|
+
{"time":"14:00", "season":"spring", "direction":"SW", "state":"partial"},
|
136
|
+
{"time":"15:00", "season":"spring", "direction":"SW", "state":"partial"},
|
137
|
+
{"time":"16:00", "season":"spring", "direction":"SW", "state":"partial"},
|
138
|
+
{"time":"12:00", "season":"summer", "direction":"SW", "state":"partial"},
|
139
|
+
{"time":"13:00", "season":"summer", "direction":"SW", "state":"partial"},
|
140
|
+
{"time":"14:00", "season":"summer", "direction":"SW", "state":"partial"},
|
141
|
+
{"time":"15:00", "season":"summer", "direction":"SW", "state":"partial"},
|
142
|
+
{"time":"16:00", "season":"summer", "direction":"SW", "state":"partial"},
|
143
|
+
{"time":"8:00", "season":"winter", "direction":"SW", "state":"partial"},
|
144
|
+
{"time":"9:00", "season":"winter", "direction":"SW", "state":"partial"},
|
145
|
+
{"time":"10:00", "season":"winter", "direction":"SW", "state":"partial"},
|
146
|
+
{"time":"11:00", "season":"winter", "direction":"SW", "state":"partial"},
|
147
|
+
{"time":"12:00", "season":"winter", "direction":"SW", "state":"partial"},
|
148
|
+
{"time":"13:00", "season":"winter", "direction":"SW", "state":"partial"},
|
149
|
+
{"time":"14:00", "season":"winter", "direction":"SW", "state":"partial"},
|
150
|
+
{"time":"15:00", "season":"winter", "direction":"SW", "state":"partial"},
|
151
|
+
{"time":"16:00", "season":"winter", "direction":"SW", "state":"partial"}
|
152
|
+
|
79
153
|
```
|
80
154
|
|
81
155
|
### 試したこと
|