gui done for now

This commit is contained in:
Tyrel Souza 2015-07-17 16:50:29 -04:00
parent 94d0b3f3ae
commit 5ef0de2b4d
2 changed files with 38 additions and 13 deletions

View File

@ -6,12 +6,9 @@ import subprocess
import pandas as pd import pandas as pd
from dateutil.relativedelta import relativedelta from dateutil.relativedelta import relativedelta
import Tkinter as tk
L = logging.getLogger(__name__) L = logging.getLogger(__name__)
from utils import get_dropbox_dir
class AttributionReport(object): class AttributionReport(object):
def __init__(self, months=6, footer_length=None): def __init__(self, months=6, footer_length=None):
@ -41,7 +38,8 @@ class AttributionReport(object):
self.salesforce_df = None self.salesforce_df = None
self.deposit_df = None self.deposit_df = None
self.output_dir = None
self.frames = None
def _get_dataframe_by_extension(self, path, date_cols): def _get_dataframe_by_extension(self, path, date_cols):
""" """
@ -61,7 +59,13 @@ class AttributionReport(object):
def set_dataframe_sf(self, fname): def set_dataframe_sf(self, fname):
self.salesforce_df = None self.salesforce_df = None
salesforce_df = self._get_dataframe_by_extension(fname, date_cols=[4, 5]) try:
salesforce_df = self._get_dataframe_by_extension(fname, date_cols=[self.SF_DATE_COLUMN, ])
except IndexError:
return False
except:
raise
if set(self.REQUIRED_SF_COLUMNS) < set(salesforce_df.columns): if set(self.REQUIRED_SF_COLUMNS) < set(salesforce_df.columns):
self.salesforce_df = salesforce_df self.salesforce_df = salesforce_df
return True return True
@ -70,7 +74,12 @@ class AttributionReport(object):
def set_dataframe_deposit(self, fname): def set_dataframe_deposit(self, fname):
self.deposit_df = None self.deposit_df = None
deposit_df = self._get_dataframe_by_extension(fname, date_cols=[7, 8]) try:
deposit_df = self._get_dataframe_by_extension(fname, date_cols=[self.DP_DATE_COLUMN, ])
except IndexError:
return False
except:
raise
if set(self.REQUIRED_DP_COLUMNS) < set(deposit_df.columns): if set(self.REQUIRED_DP_COLUMNS) < set(deposit_df.columns):
self.deposit_df = deposit_df self.deposit_df = deposit_df
return True return True
@ -162,7 +171,7 @@ class AttributionReport(object):
filtered_df = self.deposit_df.ix[start:end] filtered_df = self.deposit_df.ix[start:end]
# Variables for short names, and not having to type index a lot. # Variables for short names, and not having to type index a lot.
pi_name = unicode(sf_row['First Name'].map(unicode) + " " + sf_row['Last Name']) pi_name = unicode(sf_row['First Name']) + " " + unicode(sf_row['Last Name'])
pi_org = sf_row['Account Name'] pi_org = sf_row['Account Name']
# Get matches by the PI's name # Get matches by the PI's name
@ -185,9 +194,11 @@ class AttributionReport(object):
) )
def run(self): def run(self):
frames = self.get_attribution_dataframes() self.frames = None
self.frames = self.get_attribution_dataframes()
for key, df in frames: def save(self):
for key, df in self.frames:
fname = '{0}_Attribution_Report_{1}_Match.xlsx'.format(datetime.date.today(), key) fname = '{0}_Attribution_Report_{1}_Match.xlsx'.format(datetime.date.today(), key)
xls_path = os.path.join(self.output_dir, fname) xls_path = os.path.join(self.output_dir, fname)

22
main.py
View File

@ -19,9 +19,12 @@ class AttributeGUI(tk.Tk):
'dp_label': u"<Deposit Export File...>", 'dp_label': u"<Deposit Export File...>",
'output_label': u"<Output directory...>" 'output_label': u"<Output directory...>"
} }
self.reset()
def reset(self):
self.initGUI() self.initGUI()
self.report = AttributionReport(months=6, footer_length=6) # TODO MAKE MONTHS A DROPDOWN self.report = AttributionReport(months=6, footer_length=6) # TODO MAKE MONTHS A DROPDOWN
self._check_ready_to_run()
def initGUI(self): def initGUI(self):
self.title('Attribution Report') self.title('Attribution Report')
@ -154,16 +157,27 @@ class AttributeGUI(tk.Tk):
initialdir=get_dropbox_dir(), initialdir=get_dropbox_dir(),
) )
if self.output_directoryname: if self.output_directoryname:
self.report.set_output_dir(self.output_directoryname)
self.output_frame.output_label_var.set(self.output_directoryname) self.output_frame.output_label_var.set(self.output_directoryname)
self._check_ready_to_run() self._check_ready_to_run()
def _check_ready_to_run(self): def _check_ready_to_run(self):
if self.report.salesforce_df and self.report.deposit_df and self.report.output_dir: if self.report.salesforce_df is not None and self.report.deposit_df is not None and self.report.output_dir:
pass self.run_frame.run_button.config(state=tk.NORMAL)
else:
self.run_frame.run_button.config(state=tk.DISABLED)
self.update()
def run_click(self): def run_click(self):
pass try:
self.report.run()
self.report.save()
except Exception, e:
tkMessageBox.showerror("EXCEPTION", str(e))
self.quit()
return
self.reset()
def main(): def main():
app = AttributeGUI() app = AttributeGUI()