gui done for now
This commit is contained in:
parent
94d0b3f3ae
commit
5ef0de2b4d
|
@ -6,12 +6,9 @@ import subprocess
|
|||
|
||||
import pandas as pd
|
||||
from dateutil.relativedelta import relativedelta
|
||||
import Tkinter as tk
|
||||
|
||||
L = logging.getLogger(__name__)
|
||||
|
||||
from utils import get_dropbox_dir
|
||||
|
||||
|
||||
class AttributionReport(object):
|
||||
def __init__(self, months=6, footer_length=None):
|
||||
|
@ -41,7 +38,8 @@ class AttributionReport(object):
|
|||
|
||||
self.salesforce_df = None
|
||||
self.deposit_df = None
|
||||
|
||||
self.output_dir = None
|
||||
self.frames = None
|
||||
|
||||
def _get_dataframe_by_extension(self, path, date_cols):
|
||||
"""
|
||||
|
@ -61,7 +59,13 @@ class AttributionReport(object):
|
|||
|
||||
def set_dataframe_sf(self, fname):
|
||||
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):
|
||||
self.salesforce_df = salesforce_df
|
||||
return True
|
||||
|
@ -70,7 +74,12 @@ class AttributionReport(object):
|
|||
|
||||
def set_dataframe_deposit(self, fname):
|
||||
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):
|
||||
self.deposit_df = deposit_df
|
||||
return True
|
||||
|
@ -162,7 +171,7 @@ class AttributionReport(object):
|
|||
filtered_df = self.deposit_df.ix[start:end]
|
||||
|
||||
# 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']
|
||||
|
||||
# Get matches by the PI's name
|
||||
|
@ -185,9 +194,11 @@ class AttributionReport(object):
|
|||
)
|
||||
|
||||
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)
|
||||
|
||||
xls_path = os.path.join(self.output_dir, fname)
|
||||
|
|
22
main.py
22
main.py
|
@ -19,9 +19,12 @@ class AttributeGUI(tk.Tk):
|
|||
'dp_label': u"<Deposit Export File...>",
|
||||
'output_label': u"<Output directory...>"
|
||||
}
|
||||
self.reset()
|
||||
|
||||
def reset(self):
|
||||
self.initGUI()
|
||||
self.report = AttributionReport(months=6, footer_length=6) # TODO MAKE MONTHS A DROPDOWN
|
||||
self._check_ready_to_run()
|
||||
|
||||
def initGUI(self):
|
||||
self.title('Attribution Report')
|
||||
|
@ -154,16 +157,27 @@ class AttributeGUI(tk.Tk):
|
|||
initialdir=get_dropbox_dir(),
|
||||
)
|
||||
if self.output_directoryname:
|
||||
self.report.set_output_dir(self.output_directoryname)
|
||||
self.output_frame.output_label_var.set(self.output_directoryname)
|
||||
self._check_ready_to_run()
|
||||
|
||||
def _check_ready_to_run(self):
|
||||
if self.report.salesforce_df and self.report.deposit_df and self.report.output_dir:
|
||||
pass
|
||||
if self.report.salesforce_df is not None and self.report.deposit_df is not None and self.report.output_dir:
|
||||
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):
|
||||
pass
|
||||
|
||||
try:
|
||||
self.report.run()
|
||||
self.report.save()
|
||||
except Exception, e:
|
||||
tkMessageBox.showerror("EXCEPTION", str(e))
|
||||
self.quit()
|
||||
return
|
||||
self.reset()
|
||||
|
||||
def main():
|
||||
app = AttributeGUI()
|
||||
|
|
Loading…
Reference in New Issue
Block a user