-
-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from hackforla/dev
Dev
- Loading branch information
Showing
3 changed files
with
94 additions
and
43 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,53 @@ | ||
from configparser import ConfigParser | ||
from sqlalchemy.types import Integer, Text, String, DateTime, Float | ||
from sqlalchemy import create_engine | ||
import sqlalchemy as db | ||
import pandas as pd | ||
from datetime import datetime as dt | ||
import numpy as np | ||
import json | ||
|
||
|
||
class frequency(object): | ||
def __init__(self, config=None): | ||
def __init__(self, config=None, tableName="ingest_staging_table"): | ||
self.config = config | ||
self.dbString = None if not self.config else self.config['Database']['DB_CONNECTION_STRING'] | ||
self.table = tableName | ||
self.data = None | ||
pass | ||
|
||
def freq_query(self): | ||
engine = create_engine(self.dbString) | ||
def freq_view_all(self, serviced=False): | ||
""" | ||
Returns the request type and associated dates for all data | ||
Sorted by request type, followed by created date, service date (if applicable), and then closed date | ||
""" | ||
# Todo: implement condition for serviced date | ||
engine = db.create_engine(self.dbString) | ||
|
||
query = "SELECT requesttype, createddate, closeddate FROM %s" % self.table | ||
df = pd.read_sql_query(query, con=engine) | ||
|
||
df['closeddate'] = pd.to_datetime(df['closeddate']) | ||
df = df.sort_values(by=['requesttype', 'createddate', 'closeddate']) | ||
|
||
return df.to_json(orient="records") | ||
|
||
def freq_aggregate(self): | ||
engine = db.create_engine(self.dbString) | ||
|
||
query = "SELECT requesttype FROM %s" % (self.table) | ||
df = pd.read_sql_query(query, con=engine) | ||
|
||
connection = engine.connect() | ||
query = "SELECT row_to_json(row(status)) \ | ||
FROM ingest_staging_table" | ||
result = connection.execute(query) | ||
connection.close() | ||
request_counts = df['requesttype'].value_counts() | ||
print(np.dtype(request_counts)) | ||
|
||
# for request in request_types: | ||
# print(df[request].value_counts()) | ||
return df['requesttype'].value_counts() | ||
|
||
return result | ||
|
||
if __name__ == "__main__": | ||
frequer = frequency() | ||
freq = frequency() | ||
config = ConfigParser() | ||
config.read("../setting.cfg") | ||
frequer.config = config | ||
frequer.dbString = config['Database']['DB_CONNECTION_STRING'] | ||
frequer.freq_query() | ||
freq.config = config | ||
freq.dbString = config['Database']['DB_CONNECTION_STRING'] | ||
freq.freq_aggregate() |
This file contains 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