Skip to content
Snippets Groups Projects
Commit f9858929 authored by Wilbur, Spencer Franklin's avatar Wilbur, Spencer Franklin
Browse files

I removed an unecessary call to FilterApiQuery from within Data.py. I also...

I removed an unecessary call to FilterApiQuery from within Data.py. I also added validation to the FilterApiQuery.py. Rather than using super I opted to add the validation to this file beacuse sampling_period was ignored from the base class i.e. DataApiQuery and this is why the REQUEST_LIMIT was being ignored.
parent 448708a8
No related branches found
No related tags found
1 merge request!340Adding a few changes to FDSNFActory regarding the FDSNNoDataException. I also...
......@@ -12,7 +12,7 @@ from .Observatory import OBSERVATORY_INDEX, ASL_OBSERVATORY_INDEX
DEFAULT_ELEMENTS = ["X", "Y", "Z", "F"]
REQUEST_LIMIT = 345600
REQUEST_LIMIT = 3456000 # Increased the request limit by 10x what was decided by Jeremy
VALID_ELEMENTS = [e.id for e in ELEMENTS]
......@@ -149,13 +149,3 @@ class DataApiQuery(BaseModel):
raise ValueError(f"Request exceeds limit ({samples} > {REQUEST_LIMIT})")
# otherwise okay
return values
# The new class inheriting everything except input/output_sampling period from DataApiQuery
class FilterDataApiQuery(DataApiQuery):
input_sampling_period: SamplingPeriod = SamplingPeriod.SECOND
output_sampling_period: SamplingPeriod = SamplingPeriod.MINUTE
# Remove inherited fields that we don't need
class Config:
fields = {"sampling_period": {"exclude": True}, "data_host": {"exclude": True}}
from .DataApiQuery import DataApiQuery, SamplingPeriod
from .DataApiQuery import DataApiQuery, SamplingPeriod, REQUEST_LIMIT
from pydantic import root_validator
"""This script contains the class inheriting everything except input/output_sampling
period from the DataApiQuery class. This is where more specific functionailty
......@@ -12,3 +13,26 @@ class FilterApiQuery(DataApiQuery):
# Remove inherited fields that we don't need for this specific endpoint
class Config:
fields = {"sampling_period": {"exclude": True}}
@root_validator
def validate_combinations(cls, values):
starttime, endtime, elements, format, input_sampling_period = (
values.get("starttime"),
values.get("endtime"),
values.get("elements"),
values.get("format"),
values.get("input_sampling_period"),
)
if len(elements) > 4 and format == "iaga2002":
raise ValueError("No more than four elements allowed for iaga2002 format.")
if starttime > endtime:
raise ValueError("Starttime must be before endtime.")
# Calculate the number of samples based on the input sampling period
samples = int(len(elements) * (endtime - starttime) / input_sampling_period)
# Validate the request size
if samples > REQUEST_LIMIT:
raise ValueError(f"Request exceeds limit ({samples} > {REQUEST_LIMIT})")
return values
......@@ -13,7 +13,6 @@ from .Observatory import ASL_OBSERVATORY_INDEX
from .DataApiQuery import (
DEFAULT_ELEMENTS,
DataApiQuery,
FilterDataApiQuery,
DataType,
OutputFormat,
SamplingPeriod,
......
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