Comments (6)
@eliasvitali You can get counts by substituting HEAD for GET for any Direct Access v2 operation. It respects any filter provided. The count is returned in the HTTP headers as X-Query-Record-Count.
However, performance isn't as good as GET because the entire data structure has to be scanned to get an accurate count, so please adjust any TTL you have on the request accordingly.
from direct-access-py.
Ah I see, that is stable enough for my liking, thanks for the suggestion!
from direct-access-py.
Hi @rbastian . Thanks for the super quick reply! I'm not quite sure how to implement your solution, for I'm not using the keywords GET
or HEAD
anywhere, but rather the DirectAccessV2.query()
method. I did however, after quite the rigorous Google keyword search, come across this snippet of code, which appears to be an implemented count method of DirectAccessV2
pbjects. After testing it, it does appear to work; thanks anyways for the help and prompt reply :)
def count(self, dataset, **options):
"""
Get the count of records given a dataset and query options
:param dataset: a valid dataset name. See the Direct Access documentation for valid values
:param options: query parameters as keyword arguments
:return: record count as int
"""
url = self.url + '/' + dataset
response = self.session.head(url, params=options)
count = response.headers.get('X-Query-Record-Count')
return int(count)
from direct-access-py.
Hi @eliasvitali!
There's an existing method in the DirectAccessV2
class to get a count for a query.
@rbastian's suggestion of adjusting any timing for your process still stands! In some cases, it can be a rather long time for the count to return.
Here's an example:
client = DirectAccessV2(client_id, client_secret, api_key)
count = client.count('rigs', deleteddate='null', drilltype='H')
from direct-access-py.
Thank you! Perhaps you can help me solve a mystery, because this is the reason I wanted to return a count:
DirectAccessV2.count('producing-entity-details', upddateddate = 'eq(2020-07-14)')
returns 0DirectAccessV2.count('producing-entity-details', upddateddate = 'eq(2020-07-15)')
returns 0DirectAccessV2.count('producing-entity-details', upddateddate = 'btw(2020-07-14, 2020-07-15)')
returns 7436932
Any idea why this would be? No results on either the 14th or 15th but 7M+ in between?
from direct-access-py.
@eliasvitali that's because there are no records with an updated date that exactly equals (eq()
) only a date without a time, so a count of 0 is correct.
This might not be the most graceful way to handle but here's how I've gotten counts for a single day's update previously:
count = client.count('producing-entity-details', updateddate='btw(2020-07-14T00:00:00, 2020-07-14T23:59:59)')
from direct-access-py.
Related Issues (20)
- Still receiving timeout error HOT 4
- Add to_dataframe method on V2 class
- Add helper methods for relational endpoints HOT 1
- Replace CircleCI with Github Actions
- "Verify=False" argument in DirectAccessV2 causing JSONDecodeError in V1.4.0 HOT 2
- Requesting Example For Use-Case Scenario | Multi-Processing into SQL Server Database HOT 3
- List of possible options for `query` method? HOT 5
- Match `well-origins` with `well-production-values` results` HOT 3
- WARNING Throttled token request. Waiting 60 seconds... HOT 3
- Unable to install directaccess package in FME environment HOT 5
- directaccess WARNING Throttled token request. Waiting 60 seconds... HOT 2
- How can I query specific fields of a dataset? HOT 2
- Differentiate between bad API key and throttled token request
- Finalize to_dataframe()
- Handle HTTP 410 for Version 1
- Remove `links` argument from V2 class init
- enhancement: Completions Query HOT 6
- directaccess.DAQueryException: Non-200 response: 403 Authentication failed HOT 2
- Deprecation warning from urllib3 Retry
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from direct-access-py.