This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE TABLE IF NOT EXISTS "bitdotio/simple_pipeline"."ca_covid_data_join" ( | |
date date, | |
county TEXT, | |
fips TEXT, | |
cases INTEGER, | |
deaths INTEGER, | |
pct_vaccinations_complete REAL, | |
num_vaccinations_complete INTEGER, | |
total_population INTEGER, | |
population_16plus INTEGER, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Activate the venv and navigate to the location of main.py | |
source venv/bin/activate | |
cd simple_pipeline | |
# Uncomment the line below if you would like to re-run the population data pipeline | |
# The population data is only updated annually by the Census Bureau | |
# python main.py -local_source -name acs_population_counties \ | |
# acs_5yr_population_data.csv bitdotio/simple_pipeline.population_counties | |
python main.py -name nyt_cases_counties \ | |
'https://raw.githubusercontent.com/nytimes/covid-19-data/master/us-counties.csv' \ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { Client } = require('pg'); | |
const client = new Client({ | |
database: 'bitdotio', | |
host: 'db.bit.io', | |
port: 5432, | |
user: '<YOUR USERNAME HERE>', | |
password: '<YOUR PASSWORD HERE>' | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import serial | |
ser = serial.Serial('/dev/ttyUSB0') | |
message = ser.read(10) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from datetime import datetime | |
def create_record(sample, measurement_config, period): | |
"""Create a record for insertion to a database.""" | |
record = {'location': 'outside of house'} | |
record['sensor_id'] = parse_value(sample[0], 'little', [6, 2]) | |
record['datetime'] = str(datetime.utcnow()) | |
for measurement, parse_args in config['measurements'].items(): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def parse_value(message, byte_order, start_byte, num_bytes, scale=None): | |
"""Returns a number from a sequence of bytes.""" | |
value = message[start_byte: start_byte + num_bytes] | |
value = int.from_bytes(value, byteorder=byte_order) | |
value = value * scale if scale else value | |
return value |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Aligns with logged columns in config.yaml | |
-- Update the first line with your table name | |
CREATE TABLE "air_quality_log_test/air_quality"."pm_measurements" ( | |
"datetime" timestamp with time zone, | |
"location" text, | |
"sensor_id" integer, | |
"pm_2_5" real, | |
"pm_10" real | |
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import bitdotio | |
columns = ['datetime', 'location', 'sensor_id', 'pm_2_5', 'pm_10'] | |
record_list = [record[col] for col in columns] | |
bit = bitdotio.bitdotio(BITDOTIO_API_KEY) | |
# Replace the line below with your schema-qualified table name | |
qualified_table = '"air_quality_log_test/air_quality"."pm_measurements"' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Connect to bit.io | |
import bitdotio | |
bit_conn = bitdotio.bitdotio(<YOUR_BITIO_KEY>) | |
# You can use the connection with the bit module, here we list repos | |
from bitdotio import bit | |
bit.list(bit_conn) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Create a repo | |
import bitdotio | |
# Connect to bit.io | |
b = bitdotio.bitdotio(<YOUR_BITIO_KEY>) | |
# Construct a repo object | |
r = bitdotio.model.repo.Repo(name='my_new_repo', | |
description='My new repository.', | |
is_private=True) |