Skip to content

Commit

Permalink
Add limit and channels to requests
Browse files Browse the repository at this point in the history
  • Loading branch information
oscgonfer committed Nov 27, 2024
1 parent 6f71767 commit 2acb466
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 12 deletions.
10 changes: 4 additions & 6 deletions scdata/device/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,8 @@ async def load(self, cache=None, convert_units=True,
frequency = self.options.frequency
clean_na = self.options.clean_na
resample = self.options.resample
limit = self.options.limit
channels = self.options.channels
cached_data = DataFrame()

# Only case where cache makes sense
Expand Down Expand Up @@ -323,6 +325,8 @@ async def load(self, cache=None, convert_units=True,
max_date = max_date,
frequency = frequency,
clean_na = clean_na,
limit = limit,
channels = channels,
resample = resample)
else:
self.handler.get_data(
Expand All @@ -336,7 +340,6 @@ async def load(self, cache=None, convert_units=True,
self.data = self.handler.data

# Wrap it all up
# TODO Avoid doing this if not needed?
self.loaded = self.__load_wrapup__(cached_data=cached_data)
self.processed = False

Expand All @@ -346,11 +349,6 @@ def __load_wrapup__(self, cached_data=None):

if self.data is not None:
if not self.data.empty:
if self.options.max_amount is not None:
# TODO Dirty workaround
logger.info(f'Trimming dataframe to {self.options.max_amount} rows')
self.data=self.data.dropna(axis = 0, how='all').head(self.options.max_amount)

# Convert names
self.__convert_names__()
# Convert units
Expand Down
3 changes: 2 additions & 1 deletion scdata/models/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ class DeviceOptions(BaseModel):
resample: Optional[bool] = False
min_date: Optional[str] = None
max_date: Optional[str] = None
max_amount: Optional[int] = None
limit: Optional[int] = None
channels: Optional[List[str]] = []
convert_units: Optional[bool] = True
convert_names: Optional[bool] = True

Expand Down
16 changes: 11 additions & 5 deletions tests/all/devices/test_sc_device_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,28 @@ def test_sc_device_all():
uuid = "80e684e5-359f-4755-aec9-30fc0c84415f"
min_date = '2022-09-10T00:00:00Z'
blueprint = 'sc_air'
limit = 500
channels = ['Sensirion SHT31 - Temperature', 'Sensirion SHT31 - Humidity', 'ICS43432 - Noise']

d = sc.Device(blueprint=blueprint,
params=sc.APIParams(id=id),
options=sc.DeviceOptions(
min_date=min_date,
frequency=frequency)
frequency=frequency,
channels=channels,
limit=limit)
)

load_status = asyncio.run(d.load())

j = d.handler.json
m = d.data.index[0].tz_convert('UTC').strftime('%Y-%m-%dT%H:%M:%SZ')
s = d.data.shape
process_status = d.process()

assert d.blueprint == blueprint, resp.text
assert load_status == True, resp.text
assert process_status == True, resp.text
assert j.uuid == uuid, resp.text
assert d.blueprint == blueprint
# assert s == (500, 3) #TODO - add when reading on staging
assert load_status == True
assert process_status == False #Force this to False
assert j.uuid == uuid
assert m == min_date

0 comments on commit 2acb466

Please sign in to comment.