Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Karakas
SWP_SS24_Wetterdaten_sammeln
Commits
78bf573f
Commit
78bf573f
authored
Jun 11, 2024
by
EnesKarakas
Browse files
csv done
parent
811241e3
Changes
3
Hide whitespace changes
Inline
Side-by-side
frontend/src/components/weather/currentData.js
View file @
78bf573f
...
...
@@ -77,9 +77,32 @@ const Currentdata = (props) => {
};
const
jsonToCsv
=
(
json
)
=>
{
const
keys
=
Object
.
keys
(
json
);
const
values
=
Object
.
values
(
json
);
return
`
${
keys
.
join
(
"
,
"
)}
\n
${
values
.
join
(
"
,
"
)}
`
;
const
rows
=
[];
// Funktion, um die Header und die Werte zu extrahieren
function
processObject
(
obj
,
parentKey
=
""
)
{
const
keys
=
Object
.
keys
(
obj
);
keys
.
forEach
((
key
)
=>
{
const
newKey
=
parentKey
?
`
${
parentKey
}
_
${
key
}
`
:
key
;
if
(
typeof
obj
[
key
]
===
"
object
"
&&
!
Array
.
isArray
(
obj
[
key
]))
{
processObject
(
obj
[
key
],
newKey
);
}
else
{
rows
.
push
({
key
:
newKey
,
value
:
obj
[
key
]
});
}
});
}
// JSON verarbeiten
processObject
(
json
);
// Header und Werte trennen
const
headers
=
rows
.
map
((
row
)
=>
row
.
key
).
join
(
"
;
"
);
const
values
=
rows
.
map
((
row
)
=>
row
.
value
).
join
(
"
;
"
);
// CSV-Zeilen erstellen
const
csv
=
`
${
headers
}
\n
${
values
}
`
;
return
csv
;
};
return
(
...
...
frontend/src/components/weather/historicalWeatherData.js
View file @
78bf573f
...
...
@@ -79,9 +79,32 @@ const HistoricalWeatherData = (props) => {
};
const
jsonToCsv
=
(
json
)
=>
{
const
keys
=
Object
.
keys
(
json
);
const
values
=
Object
.
values
(
json
);
return
`
${
keys
.
join
(
"
,
"
)}
\n
${
values
.
join
(
"
,
"
)}
`
;
const
rows
=
[];
// Funktion, um die Header und die Werte zu extrahieren
function
processObject
(
obj
,
parentKey
=
""
)
{
const
keys
=
Object
.
keys
(
obj
);
keys
.
forEach
((
key
)
=>
{
const
newKey
=
parentKey
?
`
${
parentKey
}
_
${
key
}
`
:
key
;
if
(
typeof
obj
[
key
]
===
"
object
"
&&
!
Array
.
isArray
(
obj
[
key
]))
{
processObject
(
obj
[
key
],
newKey
);
}
else
{
rows
.
push
({
key
:
newKey
,
value
:
obj
[
key
]
});
}
});
}
// JSON verarbeiten
processObject
(
json
);
// Header und Werte trennen
const
headers
=
rows
.
map
((
row
)
=>
row
.
key
).
join
(
"
;
"
);
const
values
=
rows
.
map
((
row
)
=>
row
.
value
).
join
(
"
;
"
);
// CSV-Zeilen erstellen
const
csv
=
`
${
headers
}
\n
${
values
}
`
;
return
csv
;
};
return
(
...
...
frontend/src/components/weather/weatherForecastData.js
View file @
78bf573f
...
...
@@ -77,10 +77,34 @@ const WeatherForecastData = (props) => {
};
const
jsonToCsv
=
(
json
)
=>
{
const
keys
=
Object
.
keys
(
json
);
const
values
=
Object
.
values
(
json
);
return
`
${
keys
.
join
(
"
,
"
)}
\n
${
values
.
join
(
"
,
"
)}
`
;
const
rows
=
[];
// Funktion, um die Header und die Werte zu extrahieren
function
processObject
(
obj
,
parentKey
=
""
)
{
const
keys
=
Object
.
keys
(
obj
);
keys
.
forEach
((
key
)
=>
{
const
newKey
=
parentKey
?
`
${
parentKey
}
_
${
key
}
`
:
key
;
if
(
typeof
obj
[
key
]
===
"
object
"
&&
!
Array
.
isArray
(
obj
[
key
]))
{
processObject
(
obj
[
key
],
newKey
);
}
else
{
rows
.
push
({
key
:
newKey
,
value
:
obj
[
key
]
});
}
});
}
// JSON verarbeiten
processObject
(
json
);
// Header und Werte trennen
const
headers
=
rows
.
map
((
row
)
=>
row
.
key
).
join
(
"
;
"
);
const
values
=
rows
.
map
((
row
)
=>
row
.
value
).
join
(
"
;
"
);
// CSV-Zeilen erstellen
const
csv
=
`
${
headers
}
\n
${
values
}
`
;
return
csv
;
};
return
(
<
div
className
=
"
home-container
"
>
<
div
className
=
"
thq-grid-5
"
>
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment