Skip to content

Commit

Permalink
Merge 607c659 into 9ac6b3a
Browse files Browse the repository at this point in the history
  • Loading branch information
twheys committed Aug 30, 2018
2 parents 9ac6b3a + 607c659 commit 24a3bd8
Show file tree
Hide file tree
Showing 104 changed files with 12,843 additions and 10,784 deletions.
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
language: python

python:
- "2.7"
- "3.3"
- "3.4"
- "3.5"
Expand Down
10 changes: 8 additions & 2 deletions fireant/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,8 @@
# coding: utf-8
__version__ = '{major}.{minor}.{patch}'.format(major=0, minor=19, patch=3)
# noinspection PyUnresolvedReferences
from .database import *
# noinspection PyUnresolvedReferences
from .slicer import *
# noinspection PyUnresolvedReferences
from .slicer.widgets import *

__version__ = '1.0.0.dev50'
17 changes: 0 additions & 17 deletions fireant/dashboards/__init__.py

This file was deleted.

76 changes: 0 additions & 76 deletions fireant/dashboards/managers.py

This file was deleted.

117 changes: 0 additions & 117 deletions fireant/dashboards/schemas.py

This file was deleted.

9 changes: 3 additions & 6 deletions fireant/database/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
# coding: utf-8

from .database import Database
from .base import Database
from .mysql import MySQLDatabase
from .redshift import RedshiftDatabase
from .postgresql import PostgreSQLDatabase
from .vertica import (Vertica,
VerticaDatabase)
from .redshift import RedshiftDatabase
from .vertica import VerticaDatabase
24 changes: 17 additions & 7 deletions fireant/database/database.py → fireant/database/base.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,28 @@
# coding: utf-8

import pandas as pd

from pypika import Query
from pypika import (
Query,
enums,
functions as fn,
terms,
)


class Database(object):
"""
WRITEME
"""
# The pypika query class to use for constructing queries
query_cls = Query

slow_query_log_min_seconds = 15

def connect(self):
raise NotImplementedError

def trunc_date(self, field, interval):
raise NotImplementedError

def date_add(self, date_part, interval, field):
def date_add(self, field: terms.Term, date_part: str, interval: int):
""" Database specific function for adding or subtracting dates """
raise NotImplementedError

Expand All @@ -25,6 +32,9 @@ def fetch(self, query):
cursor.execute(query)
return cursor.fetchall()

def fetch_dataframe(self, query):
def to_char(self, definition):
return fn.Cast(definition, enums.SqlTypes.VARCHAR)

def fetch_data(self, query):
with self.connect() as connection:
return pd.read_sql(query, connection)
return pd.read_sql(query, connection, coerce_float=True, parse_dates=True)
24 changes: 13 additions & 11 deletions fireant/database/mysql.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
# coding: utf-8
import pandas as pd
from pypika import (
Dialects,
MySQLQuery,
enums,
functions as fn,
terms,
)

from fireant.database import Database
from .base import Database


class Trunc(terms.Function):
Expand Down Expand Up @@ -51,25 +52,26 @@ def __init__(self, database=None, host='localhost', port=3306,
def connect(self):
import pymysql

return pymysql.connect(
host=self.host, port=self.port, db=self.database,
user=self.user, password=self.password,
charset=self.charset,
cursorclass=pymysql.cursors.Cursor,
)
return pymysql.connect(host=self.host, port=self.port, db=self.database,
user=self.user, password=self.password,
charset=self.charset,
cursorclass=pymysql.cursors.Cursor)

def fetch(self, query):
with self.connect().cursor() as cursor:
cursor.execute(query)
return cursor.fetchall()

def fetch_dataframe(self, query):
def fetch_data(self, query):
return pd.read_sql(query, self.connect())

def trunc_date(self, field, interval):
return Trunc(field, interval)
return Trunc(field, str(interval))

def date_add(self, date_part, interval, field):
def to_char(self, definition):
return fn.Cast(definition, enums.SqlTypes.CHAR)

def date_add(self, field, date_part, interval):
# adding an extra 's' as MySQL's interval doesn't work with 'year', 'week' etc, it expects a plural
interval_term = terms.Interval(**{'{}s'.format(str(date_part)): interval, 'dialect': Dialects.MYSQL})
return DateAdd(field, interval_term)
Loading

0 comments on commit 24a3bd8

Please sign in to comment.