Giter Club home page Giter Club logo

Comments (6)

rbastian avatar rbastian commented on June 14, 2024 1

@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.

eliasvitali avatar eliasvitali commented on June 14, 2024 1

Ah I see, that is stable enough for my liking, thanks for the suggestion!

from direct-access-py.

eliasvitali avatar eliasvitali commented on June 14, 2024

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.

wchatx avatar wchatx commented on June 14, 2024

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.

eliasvitali avatar eliasvitali commented on June 14, 2024

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 0
  • DirectAccessV2.count('producing-entity-details', upddateddate = 'eq(2020-07-15)') returns 0
  • DirectAccessV2.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.

wchatx avatar wchatx commented on June 14, 2024

@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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.