Neural Bikes Backend
Backend service written in Node.JS, helps manage the data for Neural Bikes, a bike sharing availability prediction service. All the data is uploaded to Apple's CloudKit servers.
This collection of scrips upload the actual availability for the day and the predictionstailored for each station. The data is uploaded to Apple's iCloud servers and then the users can get the data from the app or web.
This is not a solution for everybody but a sample to show how this project works and provide another example on how to use CloudKit.JS.
upload_data.js: Uploads data for every station, queries InfluxDB
Run every ten minutes, queries the InfluxDB database for trhe availability for that day.
- Get all the available stations in the InfluxDB database.
SHOW TAG VALUES FROM bikes WITH KEY = station_name
Query today's availabilty for each station.
Connect and authenticate to CloudKit.
recordChangeTagfor each station. If none is retrieved no record was found in the database for that station.
Construct the new record with the updated values and the
recordChangeTagif needed and upload it to CloudKit
Just if needed all the available records can be deleted from either the development or production environment using the
- Server-to-Server Key: Allows this server-side application to read and write data in the public database of an iCloud container and environment.
- API Token: Allows a web frontend to send request to the iCloud container and environment
This script is run as a
cronjob so it uploads the data every
Xminutes, to run it:
node today.js development/production city DATABASE