Skip to content

Instantly share code, notes, and snippets.

Avatar

Randy Zwitch randyzwitch

View GitHub Profile
@randyzwitch
randyzwitch / index_string.py
Created Mar 5, 2020
Control Dash loading order
View index_string.py
#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 Mar 5, 2020
Dash Interval example
View interval.py
#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 Mar 5, 2020
Callback example in Dash
View callback.py
#### 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 Mar 4, 2020
Get Telemetry Data query example
View telemetry.py
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 Mar 4, 2020
Dash layout of OmniSci F1 dashboard
View app.py
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 Dec 17, 2019
Beginner example of using BenchmarkTools.jl
View 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 Nov 7, 2019
Insert into statement in OmnISci
View insert_into_omnisci.sql
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 Nov 7, 2019
Baywheels extra column schema
View extra_col.sql
--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 Nov 6, 2019
June 2019 file fails
View june_2019.sql
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 Nov 6, 2019
ALTER TABLE ADD COLUMN in OmniSci
View alter_table.sql
--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;
You can’t perform that action at this time.