Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
mdata_app
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Machine Data
mdata_app
Commits
92f9d6fd
Commit
92f9d6fd
authored
Jun 13, 2023
by
Leah Tacke genannt Unterberg
Browse files
Options
Downloads
Patches
Plain Diff
attempting to work with temp files where necessary and work in memory otherwise
parent
071f83b6
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
4
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
pages/export_page.py
+24
-35
24 additions, 35 deletions
pages/export_page.py
pages/upload_page.py
+16
-11
16 additions, 11 deletions
pages/upload_page.py
poetry.lock
+392
-618
392 additions, 618 deletions
poetry.lock
pyproject.toml
+2
-2
2 additions, 2 deletions
pyproject.toml
with
434 additions
and
666 deletions
pages/export_page.py
+
24
−
35
View file @
92f9d6fd
import
os
import
tempfile
import
mdata.core.machine_data_def
as
mdd
import
mdata.file_formats.csv.shared
import
streamlit
as
st
from
mdata.file_formats.csv
import
write_machine_data
from
mdata.file_formats.csv
.exporting
import
write_machine_data
_custom
from
mdata.file_formats.hdf
import
write_machine_data_h5
st
.
title
(
'
Machine Data File Export & Conversions
'
)
...
...
@@ -16,41 +17,29 @@ else:
st
.
header
(
'
File Format Exports
'
)
st
.
subheader
(
'
CSV
'
)
c1
,
c2
=
st
.
columns
(
2
)
with
c1
:
c11
,
c12
=
st
.
columns
(
2
)
with
c11
:
do_csv_export
=
st
.
button
(
'
Export as CSV
'
)
with
c12
:
ht
=
st
.
selectbox
(
'
Header file type
'
,
[
'
json
'
,
'
csv
'
])
with
c2
:
c21
,
c22
=
st
.
columns
(
2
)
header_download
=
c21
.
empty
()
csv_download
=
c22
.
empty
()
st
.
subheader
(
'
HDF
'
)
header_format
=
st
.
selectbox
(
'
Header file type
'
,
mdata
.
file_formats
.
csv
.
shared
.
HeaderFileFormats
)
do_csv_export
=
st
.
button
(
'
Convert to CSV
'
)
header_download
=
st
.
empty
()
csv_download
=
st
.
empty
()
c1
,
c2
=
st
.
columns
(
2
)
with
c1
:
do_hdf_export
=
st
.
button
(
'
Export as HDF
'
)
with
c2
:
st
.
subheader
(
'
HDF
'
)
do_hdf_export
=
st
.
button
(
'
Convert to HDF
'
)
hdf_download
=
st
.
empty
()
if
do_csv_export
:
write_machine_data
(
'
temp/temp
'
,
md
,
header_type
=
ht
)
st
.
session_state
[
'
did_csv_export
'
]
=
True
with
tempfile
.
NamedTemporaryFile
(
'
w+
'
,
newline
=
''
)
as
hf
:
with
tempfile
.
NamedTemporaryFile
(
'
w+
'
,
newline
=
''
)
as
df
:
write_machine_data_custom
(
hf
,
df
,
md
,
header_format
=
header_format
)
hf
.
seek
(
0
)
df
.
seek
(
0
)
header_download
.
download_button
(
'
download header
'
,
hf
.
file
,
f
'
converted_header.
{
header_format
}
'
,
mime
=
f
'
text/
{
header_format
}
'
)
csv_download
.
download_button
(
'
download csv file
'
,
df
.
file
,
'
converted_data.csv
'
,
mime
=
f
'
text/csv
'
)
elif
do_hdf_export
:
write_machine_data_h5
(
'
temp/temp.h5
'
,
md
)
hf
=
f
'
temp/temp_header.
{
ht
}
'
df
=
'
temp/temp_data.csv
'
if
os
.
path
.
exists
(
hf
)
and
os
.
path
.
exists
(
df
):
with
open
(
hf
,
'
r
'
)
as
header_file
:
header_download
.
download_button
(
'
download header
'
,
header_file
,
f
'
converted_header.
{
ht
}
'
)
with
open
(
df
,
'
r
'
)
as
csv_file
:
csv_download
.
download_button
(
'
download csv file
'
,
csv_file
,
'
converted_data.csv
'
)
h5f
=
'
temp/temp.h5
'
if
os
.
path
.
exists
(
h5f
):
with
open
(
h5f
,
'
rb
'
)
as
hdf_file
:
hdf_download
.
download_button
(
'
download h5 file
'
,
hdf_file
,
'
converted.h5
'
)
with
tempfile
.
NamedTemporaryFile
(
'
w+b
'
)
as
hdf
:
write_machine_data_h5
(
hdf
.
file
,
md
)
hdf
.
seek
(
0
)
hdf_download
.
download_button
(
'
download h5 file
'
,
hdf
.
file
,
'
converted.h5
'
)
This diff is collapsed.
Click to expand it.
pages/upload_page.py
+
16
−
11
View file @
92f9d6fd
import
os
import
tempfile
import
streamlit
as
st
from
mdata.file_formats.csv
import
read_machine_data
from
mdata.file_formats.hdf
import
read_machine_data_h5
...
...
@@ -24,22 +24,27 @@ elif import_type == 'hdf':
# @st.experimental_memo
def
import_hdf
(
f
):
fn
=
os
.
path
.
join
(
'
uploads
'
,
f
.
name
)
with
open
(
fn
,
'
wb
'
)
as
fd
:
fd
.
write
(
f
.
getbuffer
())
fd
.
flush
()
return
read_machine_data_h5
(
fn
)
with
tempfile
.
NamedTemporaryFile
()
as
fp
:
fp
.
write
(
f
.
getbuffer
())
fp
.
seek
(
0
)
md
=
read_machine_data_h5
(
fp
.
file
)
return
md
# fn = os.path.join('uploads', f.name)
# with open(fn, 'wb') as fd:
# fd.write(f.getbuffer())
# fd.flush()
# return read_machine_data_h5(fn)
# @st.experimental_memo
def
import_csv
(
hf
,
df
):
header_
type
=
None
header_
format
=
None
if
'
csv
'
in
hf
.
type
:
header_
type
=
'
csv
'
header_
format
=
'
csv
'
elif
'
json
'
in
hf
.
type
:
header_
type
=
'
json
'
assert
header_
type
is
not
None
return
read_machine_data
(
hf
,
df
,
validity_checking
=
Fals
e
,
header_
type
=
header_
type
)
header_
format
=
'
json
'
assert
header_
format
is
not
None
return
read_machine_data
(
hf
.
getvalue
(),
df
.
getvalue
()
,
validity_checking
=
Tru
e
,
header_
format
=
header_
format
)
@st.cache_data
...
...
This diff is collapsed.
Click to expand it.
poetry.lock
+
392
−
618
View file @
92f9d6fd
This diff is collapsed.
Click to expand it.
pyproject.toml
+
2
−
2
View file @
92f9d6fd
...
...
@@ -11,12 +11,12 @@ license = "MIT"
[tool.poetry.dependencies]
python
=
"^3.9,!
=
3.9
.
7
"
cvxopt
=
"^1.3"
streamlit
=
"^1.2
1
"
streamlit
=
"^1.2
3
"
# mdata = "^0.1.0"
mdata
=
{
path
=
"C:/Users/Leah/PycharmProjects/mdata"
,
develop
=
true
}
# mdata = { git = "https://git-ce.rwth-aachen.de/leah.tgu/mdata.git", branch = "master" }
seaborn
=
"^0.12.2"
plotly
=
"^5.1
4.1
"
plotly
=
"^5.1
5
"
tsdownsample
=
"^0.1.2"
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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!
Save comment
Cancel
Please
register
or
sign in
to comment