Using the Places API I’m wondering if there’s a search filter I can add to query past year+month/week’s data?

Hi, happy new year :slightly_smiling_face: ! I have a question about the patterns API. I know the response comes back with the latest month’s data, but I’m wondering if there’s a search filter I can add to query past year+month/week’s data? thanks in advance!


This topic was automatically generated from Slack. You can find the original thread here.

hi daniel, currently monthly patterns only returns the trailing month. we are working on adding the ability to set monthly ranges in your request.

we do have the ability to query this for weekly data.

query {
  search(filter: { 
    brand: "blue bottle coffee",
    address: {
      city: "San Francisco",
      region: "CA"
    }
  }){
    weekly_patterns(start_date: "2021-09-12" end_date: "2021-10-12") {
      results(first: 10 after: "") {
        edges {
          node {
            placekey
            parent_placekey
            location_name
            street_address
            city
            region
            postal_code
            iso_country_code
            date_range_start
            date_range_end
            raw_visit_counts
            raw_visitor_counts
            visits_by_day { time_interval{ start_time }, visits }
            visits_by_each_hour { time_interval{ start_time }, visits }
            poi_cbg
            visitor_home_cbgs
            visitor_home_aggregation
            visitor_daytime_cbgs
            visitor_country_of_origin
            distance_from_home
            median_dwell
            bucketed_dwell_times
            related_same_day_brand
            related_same_week_brand
          }
        }
      }
    }
  }
}

got it, thanks so much!

@vchen quick question, does the safegraph client’s search function have start_date end_date parameters? I see a “date” parameter, but it would be nice if I could plug in the start_date end_dates directly.

To give some context, I’m doing COVID research comparing business activity in the NYC metro area from 2018 - 2021. So I want to be able to search for all the places in NYC (or all the places within a list of predefined zipcodes) between march 2018 and 2021 and get the raw_visitor_count column. Thanks!

@vchen I’m also realizing the date filter only retrieves one week even if the start_date and end_date contains multiple weeks. Is this working as intended?

here’s my query and i’ve attached a screenshot of my table which shows the start_date_range and end_date_range to not match my query.

query = gql(
    """
    query {
  search(filter: { 
    address: {
      city: "New York",
      region: "NY"
    }
  }){
    weekly_patterns(start_date: "2021-07-12" end_date: "2021-09-12") {
      results(first: 10 after: "") {
        edges {
          node {
            placekey
            parent_placekey
            location_name
            street_address
            city
            region
            postal_code
            date_range_start
            date_range_end
            raw_visit_counts
          }
        }
      }
    }
  }
}
"""
)

result = client.execute(query)
print(result)

the python library is currently running on v1 of our api. we are working to upgrade it to v2 to be able to use the date_start and date_end.

yup, we are providing weekly data for each week individually. we leave it like that so you can normalize the patterns data and aggregate it for arbitrary time periods based on your methodology.

we are always working on improving the experience with the api though, how would you want the data to be returned? (just normalized and sum-ed visit counts? any other fields like home cbgs? etc.)

got it, thanks!

I think the API usage for search’s start_date end_date fields is a bit confusing since I expected the API to return all of the raw_visit_counts within the start_date and end_date range. If the use case (get the first week within the start and end date rage) can’t be changed, perhaps add documentation for the API specifically to clarify this.

For my use case specifically, it would be ideal to be returned normalized and summed visit counts based on the start_date and end_date filters (for instance, I want to see all the raw_visit_counts to a specific McDonald’s between 11-01-2021 and 12-31-2021).

Since this isn’t supported yet, would you recommend me to iterate through all the weeks I’m looking for and sum the raw_visit_counts myself?

yea, you should be able to pull the weekly data over that range with that graphql snippet and then sum the counts.

but will look at what we can do to provide an aggregated response object that provides aggregated fields for the counts

@vchen Hello, I am running into a similar issue and wondered if this has been resolved in the python library yet? One of my use cases is trying to grab the foot traffic to casinos (by state) going back many months. Is this possible using the api in Python?

Or is the solution to run a query for every week that I am interested in and combine them all together at the end?

the best solution would be to run the query from graphql directly for now. also, if you are tryin get monthly data, we just added a new field to help here

query {
  search(filter: {
    address: {
      city: "San Francisco"
      region: "CA"
      iso_country_code: "US"
    } brand: "Blue Bottle Coffee"
  } ) {
    monthly_patterns (start_date: "2021-01-01" end_date: "2021-06-01") {
      results {
        edges {
          node {
            placekey
            date_range_start
            raw_visit_counts
            
          }
        }
      }
    }
  }
}

Thanks! I’ll try this out now

and is it possible to do this with a naic code instead of a specific brand?

(sorry if these are silly questions, I am just now really diving into this)

yup. we have a naics code filter. first also takes in an it and that specifies the counts per request (max 500)

query {
  search(filter: {naics_code: 722515, 
    address: {
      iso_country_code: "US"
    }
  } ) {
    monthly_patterns (start_date: "2021-01-01" end_date: "2021-03-01") {
      results(first: 500 after:"") {
        edges {
          node {
            placekey
            street_address
            city
            postal_code
            region
            location_name
            date_range_start
            raw_visit_counts
            
          }
        }
      }
    }
  }
}

@vchen Thank you, I think that is exactly what I need. However, when running the same commands this morning as were run last night every request, both through requests and sgql.HTTP_Client are returning a 408 error without any data. I have tried changing the api key, copying the code once again from what you wrote, and nothing is producing any data.

:thinking_face: hm, can you try again?

just tried to set your account as a regular unlocked account for api to make sure its not hitting our trial limit