Skip to content
Snippets Groups Projects
Commit 4966c8c3 authored by Simon Grasse's avatar Simon Grasse
Browse files

fix: incomplete query options, cache read

parent 067a83c8
No related branches found
No related tags found
1 merge request!11Creation of first beta release version
...@@ -22,10 +22,10 @@ class QueryOptions: ...@@ -22,10 +22,10 @@ class QueryOptions:
variable_id: str variable_id: str
statistics: str statistics: str
sampling: str sampling: str
min_data_capture = "0" # TODO check effect on NaNs min_data_capture: str = "0" # TODO check effect on NaNs
metadata_scheme = "basic" metadata_scheme: str = "basic"
limit = "None" limit: str = "None"
format = "by_statistic" format: str = "by_statistic"
@staticmethod @staticmethod
def from_metadata(metadata: Metadata): def from_metadata(metadata: Metadata):
...@@ -45,11 +45,11 @@ class Cache: ...@@ -45,11 +45,11 @@ class Cache:
def __init__(self, cache_dir): def __init__(self, cache_dir):
self.cache_file = cache_dir / "status_endpoints.json" self.cache_file = cache_dir / "status_endpoints.json"
if not self.cache_file.is_file(): # initialize cache if not self.cache_file.is_file(): # initialize cache with dummy values
with open(self.cache_file, "w") as cache: with open(self.cache_file, "w") as cache:
json.dump({"foo": "bar"}, cache) json.dump({"foo": "bar"}, cache)
def __contains__(self, item): def __contains__(self, item: str):
with self.storage_dict() as storage: with self.storage_dict() as storage:
return item in storage.keys() return item in storage.keys()
...@@ -97,7 +97,7 @@ class Connection: ...@@ -97,7 +97,7 @@ class Connection:
) )
def get_status_endpoint(self, query_options: QueryOptions): def get_status_endpoint(self, query_options: QueryOptions):
if query_options in self.cache: if query_options.cache_key in self.cache:
status_endpoint = self.cache.get(query_options.cache_key) status_endpoint = self.cache.get(query_options.cache_key)
try: # test for stale cache try: # test for stale cache
...@@ -107,6 +107,8 @@ class Connection: ...@@ -107,6 +107,8 @@ class Connection:
else: else:
print("load status endpoint from cache") print("load status endpoint from cache")
return status_endpoint return status_endpoint
else:
print("query not in cache")
status_endpoint = self.query_for_status_endpoint(query_options) status_endpoint = self.query_for_status_endpoint(query_options)
return status_endpoint return status_endpoint
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment