Skip to content

Instantly share code, notes, and snippets.

View randyzwitch's full-sized avatar

Randy Zwitch randyzwitch

View GitHub Profile
@randyzwitch
randyzwitch / index_string.py
Created March 5, 2020 20:38
Control Dash loading order
#https://github.com/omnisci/F1-demo/blob/726c56ba4e8c878abeef81b7cf680bd4d36a4bd2/f1dash/app.py#L36-L55
# helps load css at the footer, to avoid having default react css overwrite
app.index_string = '''
<!DOCTYPE html>
<html>
<head>
{%metas%}
<title>{%title%}</title>
{%favicon%}
</head>
@randyzwitch
randyzwitch / interval.py
Created March 5, 2020 20:04
Dash Interval example
#https://github.com/omnisci/F1-demo/blob/726c56ba4e8c878abeef81b7cf680bd4d36a4bd2/f1dash/track.py#L56-L60
#dcc.Interval creates an object with no display characteristics, triggering a callback every 'interval' seconds
#for anything listening for the id 'track-interval'
trackgraph = html.Div([
dcc.Graph(id='track-graph',
config={
'displayModeBar': True
}
),
#controls when track and telemetry updates
@randyzwitch
randyzwitch / callback.py
Created March 5, 2020 16:14
Callback example in Dash
#### THIS IS A SUMMARY, THIS FILE WILL NOT RUN AS-IS ####
#### INPUTS to build_telemetry_chart ####
#https://github.com/omnisci/F1-demo/blob/726c56ba4e8c878abeef81b7cf680bd4d36a4bd2/f1dash/controls.py#L9-L32
#### reference lap: build list dynamically with callback
reflapmenu = dcc.Dropdown(
id='reflapmenu',
searchable=False,
clearable=False,
style=dict(minWidth = '250px', paddingRight = '15px', borderRadius = 0)
@randyzwitch
randyzwitch / telemetry.py
Created March 4, 2020 20:17
Get Telemetry Data query example
def get_telemetry_data(sessionuid, lapstarttime, lapendtime, playercarindex, metric):
conn = pymapd.connect(host = host, user = user, password = password, dbname = dbname, port = port)
## get telemetry data
## by specifying the timestamps and sessionuid, it implies a single track
tele = f"""select
packettime,
max({metric}) as {metric}
from gtc_cartelemetry_v2
@randyzwitch
randyzwitch / app.py
Created March 4, 2020 18:26
Dash layout of OmniSci F1 dashboard
app = dash.Dash(__name__, external_stylesheets = [dbc.themes.DARKLY])
app.title = "OmniSci Grand Prix | Converge 2019"
app.config['suppress_callback_exceptions'] = True
server = app.server
body = dbc.Container([
dbc.Row([track, leaderboard]),
dbc.Row([telemetry, menubox])
],
className="mt-4",
@randyzwitch
randyzwitch / benchmarktools.jl
Created December 17, 2019 00:48
Beginner example of using BenchmarkTools.jl
#From the post: https://randyzwitch.com/benchmarktools-julia-benchmarking/
using Random, OmniSci, BenchmarkTools, Base.Threads
#change defaults, since examples long-running
BenchmarkTools.DEFAULT_PARAMETERS.seconds = 200
BenchmarkTools.DEFAULT_PARAMETERS.samples = 5
#generate test data
gendata(x, T) = [rand(typemin(T):typemax(T)) for y in 1:x]
int64_10x6 = gendata(10^6, Int64)
@randyzwitch
randyzwitch / insert_into_omnisci.sql
Created November 7, 2019 17:43
Insert into statement in OmnISci
insert into baywheels_tripdata
select
duration_sec,
start_time,
end_time,
start_station_id,
start_station_name,
start_station_latitude,
start_station_longitude,
end_station_id,
@randyzwitch
randyzwitch / extra_col.sql
Last active November 7, 2019 17:25
Baywheels extra column schema
--201906 and 201907 files have extra blank column
CREATE TABLE baywheels_tripdata_extracol(
duration_sec INTEGER,
start_time TIMESTAMP,
end_time TIMESTAMP,
start_station_id SMALLINT,
start_station_name TEXT ENCODING DICT,
start_station_latitude FLOAT,
start_station_longitude FLOAT,
end_station_id SMALLINT,
@randyzwitch
randyzwitch / june_2019.sql
Created November 6, 2019 21:56
June 2019 file fails
omnisql> copy baywheels_tripdata from 's3://baywheels-data/201905-baywheels-tripdata.csv.zip';
Result
Loaded: 182163 recs, Rejected: 0 recs in 2.440000 secs
omnisql> copy baywheels_tripdata from 's3://baywheels-data/201906-baywheels-tripdata.csv.zip';
Result
Loader truncated due to reject count. Processed : 0 recs, Rejected: 191772 recs in 8.323000 secs
@randyzwitch
randyzwitch / alter_table.sql
Created November 6, 2019 21:46
ALTER TABLE ADD COLUMN in OmniSci
--add column bike_share_for_all_trip, which starts with Jan 2018 file
ALTER TABLE baywheels_tripdata ADD COLUMN bike_share_for_all_trip TEXT ENCODING DICT;