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
@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 } |
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
# 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]) |
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
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 | |
}) | |
} |
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
@webapp.route('/calendar') | |
def plot_d3_calendar(): | |
return render_template("calendar.html", calendarMap = calendarMap) |
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
{% extends "base.html" %} | |
{% block title %} Calendar View {% endblock %} | |
{% block content %} | |
{% with calendarMap=calendarMap %} | |
{% include "buttons.html" %} | |
{% endwith %} |
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
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) { |
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
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 |
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
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)), |
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 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 |
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
""" | |
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', |