Skip to content

Instantly share code, notes, and snippets.

View robert8138's full-sized avatar

Robert Chang robert8138

  • Airbnb
  • San Francisco
View GitHub Profile
@property
def serialize(self):
'''return as a json object so we can use it in RESTful API'''
return {'id': self.id,
'date': self.date.strftime("%Y-%m-%d"),
'duration': self.duration,
'event_type': self.event_type,
'event_name': self.event_name }
# API endpoints
@webapp.route('/api/all')
def api_all():
events = Events.query.all()
return jsonify(json_list = [event.serialize() for event in events])
@webapp.route('/api/<event_type>')
def api_by_event_type(event_type):
events = Events.query.filter_by(event_type = event_type).all()
return jsonify(json_list = [event.serialize() for event in events])
function makeGraph(eventType) {
url = "http://127.0.0.1:5000/api/".concat(eventType)
d3.json(url, function(error, data) {
// d3 code to create bar/line/pie charts
})
}
@webapp.route('/calendar')
def plot_d3_calendar():
return render_template("calendar.html", calendarMap = calendarMap)
{% extends "base.html" %}
{% block title %} Calendar View {% endblock %}
{% block content %}
{% with calendarMap=calendarMap %}
{% include "buttons.html" %}
{% endwith %}
Object.keys(window.calendarMap).forEach(function(key){
document.getElementById(key)
.addEventListener(‘click’, function(){
makeCalendar(key);
});
});
// ... a bunch of D3 code to set up my calendar visualization ... //
function makeCalendar(eventType) {
@robert8138
robert8138 / zipline_example.conf
Last active April 10, 2018 14:14
Zipline example
source: {
type: hive
query:"""
SELECT
id_listing as listing
, dim_city as city
, dim_country as country
, dim_is_active as is_active
, CONCAT(ds, ' 23:59:59.999') as ts
FROM
@robert8138
robert8138 / pipeline_example.py
Created June 19, 2017 00:39
Pipeline Example
transforms = []
transforms.append(
('select_binary', ColumnSelector(features=binary))
)
transforms.append(
('numeric', ExtendedPipeline([
('select', ColumnSelector(features=numeric)),
('impute', Imputer(missing_values='NaN', strategy='mean', axis=0)),
@robert8138
robert8138 / ml_automator_example.py
Created June 19, 2017 01:17
ML Automator Example
def fit(X_train, y_train):
import multiprocessing
from ml_helpers.sklearn_extensions import DenseMatrixConverter
from ml_helpers.data import split_records
from xgboost import XGBRegressor
global model
model = {}
n_subset = N_EXAMPLES
@robert8138
robert8138 / airflow_toy_example_dag.py
Last active October 26, 2020 05:49
A toy example DAG
"""
A DAG definition file in Airflow, written in Python.
"""
from datetime import datetime, timedelta
from airflow.models import DAG # Import the DAG class
from airflow.operators.bash_operator import BashOperator
from airflow.operators.sensors import TimeDeltaSensor
default_args = {
'owner': 'you',