Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
toargridding
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
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
esde
toar-public
toargridding
Commits
98f9a3e5
Commit
98f9a3e5
authored
1 year ago
by
Simon Grasse
Browse files
Options
Downloads
Patches
Plain Diff
add: Subclass for archiving query results as zipfiles
parent
54d6e591
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!11
Creation of first beta release version
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
toargridding/toar_rest_client.py
+30
-0
30 additions, 0 deletions
toargridding/toar_rest_client.py
with
30 additions
and
0 deletions
toargridding/toar_rest_client.py
+
30
−
0
View file @
98f9a3e5
...
...
@@ -4,6 +4,7 @@ from zipfile import ZipFile
from
dataclasses
import
dataclass
,
asdict
from
contextlib
import
contextmanager
import
json
from
pathlib
import
Path
import
requests
import
pandas
as
pd
...
...
@@ -180,3 +181,32 @@ class AnalysisService:
with
zip_file
.
open
(
f
"
{
data_file
}
.csv
"
)
as
f
:
s_stream
=
io
.
StringIO
(
f
.
read
().
decode
(
"
utf-8
"
))
return
pd
.
read_csv
(
s_stream
,
comment
=
"
#
"
,
index_col
=
0
)
class
AnalysisServiceDownload
(
AnalysisService
):
def
__init__
(
self
,
status_endpoint
,
cache_dir
,
sample_dir
:
Path
,
use_downloaded
=
True
):
super
().
__init__
(
status_endpoint
,
cache_dir
)
self
.
sample_dir
=
sample_dir
self
.
use_downloaded
=
use_downloaded
def
get_timeseries_and_metadata
(
self
,
metadata
:
Metadata
):
filename
=
self
.
sample_dir
/
self
.
get_sample_file_name
(
metadata
)
query_options
=
QueryOptions
.
from_metadata
(
metadata
)
needs_fresh_download
=
(
not
self
.
use_downloaded
)
or
(
not
filename
.
is_file
())
if
needs_fresh_download
:
content
=
self
.
connection
.
get
(
query_options
)
with
open
(
filename
,
"
w+b
"
)
as
downloaded_file
:
downloaded_file
.
write
()
with
open
(
filename
,
"
r+b
"
)
as
data_file
:
content
=
data_file
.
read
()
timeseries
,
timeseries_metadata
=
self
.
load_data
(
content
,
metadata
)
return
timeseries
,
timeseries_metadata
@staticmethod
def
get_sample_file_name
(
metadata
:
Metadata
):
return
f
"
data/
{
metadata
.
statistic
}
_
{
metadata
.
time
.
sampling
}
_
{
metadata
.
time
.
start
.
date
()
}
_
{
metadata
.
time
.
end
.
date
()
}
.zip
"
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