def task_app(event: TaskEvent, api: Api): api.get_dataset( provider='corva', dataset='wits', query={ 'asset_id': event.asset_id, }, sort={'timestamp': 1}, limit=1, fields='data,metadata', )
def gamma_depth(event: StreamTimeEvent, api: Api) -> None: event = parse_event(event=event) if not event: return # no exception handling. if request fails, lambda will be reinvoked. raw_drillstrings = api.get_dataset( provider='corva', dataset=SETTINGS.drillstring_collection, query={ "asset_id": event.asset_id, "_id": { "$in": list(event.drillstring_ids) } }, sort={"timestamp": 1}, limit=100, fields="_id,data", ) drillstrings = pydantic.parse_obj_as(List[Drillstring], raw_drillstrings) id_to_drillstring = { drillstring.id: drillstring for drillstring in drillstrings } # type: Dict[str, Drillstring] actual_gamma_depths = [] for record in event.records: # build actual gamma depth for each record gamma_depth_val = record.data.bit_depth # The record may be tagged with a drillstring, # that gets deleted before the Lambda run. # Data about this drillstring won't be received from the api, # thus missing from the dict. drillstring = id_to_drillstring.get(record.metadata.drillstring_id) if drillstring and (mwd_with_gamma_sensor := drillstring.mwd_with_gamma_sensor): gamma_depth_val = ( record.data.bit_depth - mwd_with_gamma_sensor.gamma_sensor_to_bit_distance) actual_gamma_depths.append( ActualGammaDepth( asset_id=event.asset_id, collection=SETTINGS.actual_gamma_depth_collection, company_id=event.company_id, data=ActualGammaDepthData( gamma_depth=gamma_depth_val, bit_depth=record.data.bit_depth, gamma_ray=record.data.gamma_ray, ), provider=SETTINGS.provider, timestamp=record.timestamp, version=SETTINGS.version, ))
def task_app(event: TaskEvent, api: Api): api.get('/v2/pads', headers={'header': 'header-value'}) # <1> api.get('/v2/pads', timeout=5) # <2>
def task_app(event: TaskEvent, api: Api): api.post('/v2/pads', data={'key': 'val'}) # <1> <5> api.delete('/v2/pads/123') # <2> api.put('/api/v1/data/provider/dataset/', data={'key': 'val'}) # <3> <5> api.patch('/v2/pads/123', data={'key': 'val'}) # <4> <5>
def task_app(event: TaskEvent, api: Api): response = api.get('/v2/pads') # <1> api.get('/v2/pads', params={'company': 1}) # <2> response.json() # <3>
def gamma_depth(event: ScheduledEvent, api: Api) -> None: # no exception handling. if request fails, lambda will be reinvoked. raw_records = api.get_dataset( provider='corva', dataset=SETTINGS.wits_collection, query={ 'asset_id': event.asset_id, 'timestamp': { '$gte': event.start_time, '$lte': event.end_time, }, 'metadata.drillstring': { '$exists': True, '$ne': None }, }, sort={'timestamp': 1}, limit=1000, ) records = pydantic.parse_obj_as(List[WitsRecord], raw_records) if not records: # return early if no records received return event = GammaDepthEvent(records=records) # no exception handling. if request fails, lambda will be reinvoked. raw_drillstrings = api.get_dataset( provider='corva', dataset=SETTINGS.drillstring_collection, query={ 'asset_id': event.asset_id, '_id': { '$in': list(event.drillstring_ids) }, }, sort={'timestamp': 1}, limit=100, ) drillstrings = pydantic.parse_obj_as(List[Drillstring], raw_drillstrings) id_to_drillstring = { drillstring.id: drillstring for drillstring in drillstrings } # type: Dict[str, Drillstring] actual_gamma_depths = [] for record in event.records: # build actual gamma depth for each record gamma_depth_val = record.data.bit_depth # the record may be tagged with a drillstring, # that gets deleted before the Lambda run. # data about this drillstring won't be received from the api, # thus missing from the dict drillstring = id_to_drillstring.get(record.metadata.drillstring_id) if drillstring and (mwd_with_gamma_sensor := drillstring.mwd_with_gamma_sensor): gamma_depth_val = ( record.data.bit_depth - mwd_with_gamma_sensor.gamma_sensor_to_bit_distance) actual_gamma_depths.append( ActualGammaDepth( asset_id=record.asset_id, collection=SETTINGS.actual_gamma_depth_collection, company_id=record.company_id, data=ActualGammaDepthData( gamma_depth=gamma_depth_val, bit_depth=record.data.bit_depth, gamma_ray=record.data.gamma_ray, ), provider=SETTINGS.provider, timestamp=record.timestamp, version=SETTINGS.version, ))
def task_app(event: TaskEvent, api: Api): api.get('/v2/pads') # <1> api.get('/api/v1/data/provider/dataset/') # <2> api.get('https://api.corva.ai/v2/pads') # <3>