gladstonemrm / FusionLifestyle

Issues relating to open data from Fusion Lifestyle
0 stars 0 forks source link

Collecting slots for WHLASWEEKDAY #4

Open loalf opened 6 years ago

loalf commented 6 years ago

Hello, I'm working at MyLocalPitch on a small proof of concept to see how we could use RDPE and opportunity data to populate our calendars. In particular, I'd like to fetch slots information for this pitch, https://www.mylocalpitch.com/london/venue/new-river-sport-fitness/football-7-a-side-36067, which I reckon matches this facilityUse: https://fusion-lifestyle-openactive.azurewebsites.net/api/facilityUses/WHLASWEEKDAY.

In order to fetch slots information I'm using the following small python script:

from requests import get

url = "http://fusion-lifestyle-openactive.azurewebsites.net/api/slots"
facility = "http://fusion-lifestyle-openactive.azurewebsites.net/api/facilityUses/WHLASWEEKDAY"

data = get(url).json()
items = data['items']

while len(items) > 0:
    for item in items:

        if 'data' not in item:
            continue

        facilityUse = item['data']['beta:facilityUse']
        if facilityUse == facility:
            print(item['data']['startDate'])
            print(item['data']['endDate'])
            print(item['data']['beta:inventoryLevel'])

    url = data['next']
    data = get(url).json()
    items = data['items']
    print(url)

I was wondering if you think this is the right approach when it comes to collecting this information.

On a different note, I wonder what's the meaning of the afterChangeNumber number in the query string. I initially thought it was the timestamp for the changes but then I realized it's not so I am curious whether this number has a meaning.

nickevansuk commented 6 years ago

Hey @loalf afterChangeNumber is part of the RPDE (see video here: https://youtu.be/yHZS24xzY-8, and spec here).

There's a tutorial on reading RPDE feeds here: https://docs.google.com/document/d/1JW4GXXWOfJIFhAhzaCh-VU2AQm-O8Mk1NU4fZiuHZTA/edit (feedback welcome, please do comment directly on the doc for anything that's unclear!)

After you're read these you'll see that you are only currently pulling a single page of data, and will need to poll the /slots feed to get updates.

loalf commented 6 years ago

Hey @nickevansuk thank you for your comments, I found the RPDE video really good.

Is there any way to get slots just for a given facilityUse. At MyLocalPitch due to the specifics of our commercial agreement, we might want to display data in our website for, let's say, football, but not tennis.

On a different note, when pulling data from http://fusion-lifestyle-openactive.azurewebsites.net/api/slotsit goes all the way back to the beginning of time. Most of the information here is stale since we (at MyLocalPitch) have no much interest in past slots. It'd be great if we could query data from a given point in time. For the python script I posted in the issue description, it takes around 1h to process the whole feed up to the last page. I can see this becoming an issue if an API has been up for a few years and a new data consumer decides to process this data.