Skip to content

Instantly share code, notes, and snippets.

View randyzwitch's full-sized avatar

Randy Zwitch randyzwitch

View GitHub Profile
@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 / seaborn-stacked-bar.py
Created September 8, 2014 21:08
Python Seaborn Stacked Bar Chart
import pandas as pd
from matplotlib import pyplot as plt
import matplotlib as mpl
import seaborn as sns
%matplotlib inline
#Read in data & create total column
stacked_bar_data = pd.read_csv("C:\stacked_bar.csv")
stacked_bar_data["total"] = stacked_bar_data.Series1 + stacked_bar_data.Series2
SELECT
CAST(hist.x as int) as bin_center,
CAST(hist.y as bigint) as bin_height
FROM (select
histogram_numeric(salary, 20) as salary_hist
from
sample_08) a
LATERAL VIEW explode(salary_hist) exploded_table as hist;
--Results
@randyzwitch
randyzwitch / python-pypy-julia.py
Last active August 9, 2021 11:38
Python vs. PyPy vs. Julia comparison - Factorials & Looping
#Python/pypy
import math
def smallestdivisall(n):
for i in xrange(1, math.factorial(n)+1):
for j in xrange(1, n+1):
if i % j != 0:
break
elif j == n:
return i
@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 / 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,