From 8bfb01719e0b9cf72ed9b1dacac64bc668f7e88a Mon Sep 17 00:00:00 2001 From: Derek Weitzel Date: Mon, 31 Jan 2022 19:47:18 -0600 Subject: [PATCH 1/2] Fixing pivot table and a few fixes for Tim --- gracc_osg_reports/MonthlySitesViewReporter.py | 19 +++++++++++-------- requirements.txt | 2 ++ 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/gracc_osg_reports/MonthlySitesViewReporter.py b/gracc_osg_reports/MonthlySitesViewReporter.py index 59ba359..52956e0 100644 --- a/gracc_osg_reports/MonthlySitesViewReporter.py +++ b/gracc_osg_reports/MonthlySitesViewReporter.py @@ -5,6 +5,7 @@ from collections import defaultdict import argparse import pandas as pd +import numpy as np import datetime import calendar import dateutil.parser @@ -50,7 +51,7 @@ def __init__(self, config_file, start, end=None, end=end, **kwargs) #self.report_type = "MonthlySites" - self.title = "OSG site hours by month as of {}".format(datetime.datetime.now().strftime("%Y-%m-%d")) + self.title = "OSG site pilot hours across all VOs by month as of {}".format(datetime.datetime.now().strftime("%Y-%m-%d")) self.logger.info("Report Type: {0}".format(self.report_type)) def run_report(self): @@ -146,7 +147,7 @@ def recurseBucket(curData, curBucket, index, data): df['EndTime'] = df['EndTime'].dt.date # Use a pivot table to create a good table with the columns as time - table = pd.pivot_table(df, columns=["EndTime"], values=["CoreHours"], index=["OIM_Site"], fill_value=0.0) + table = pd.pivot_table(df, columns=["EndTime"], values=["CoreHours"], index=["OIM_Site"], fill_value=0.0, aggfunc=np.sum) table.columns = table.columns.get_level_values(1) return table @@ -160,9 +161,11 @@ def format_report(self): table = self.generate_report_file() # Figure out the percentage of the month we have completed - now = datetime.datetime.now() + now = self.end_time days_in_month = calendar.monthrange(now.year, now.month)[1] - percentage = float(now.day) / float(days_in_month) + + # Scale up the partial month to the full month + percentage = float(days_in_month) / float(now.day) # Convert the headers to just YYYY-MM def date_to_yeardate(date): @@ -171,10 +174,10 @@ def date_to_yeardate(date): results = map(date_to_yeardate, table.columns) table.columns = results - # Multiply the last full month by the percent completed - full_month = table.columns.values.tolist()[-2] - multiplied_column = table[table.columns[-2]] * percentage - table.insert(len(table.columns)-1, "{} * {:.2f}".format(full_month, percentage), multiplied_column) + # Multiply the partial month by the percentage + partial_month = table.columns.values.tolist()[-1] + multiplied_column = table[table.columns[-1]] * percentage + table.insert(len(table.columns), "{} * {:.2f}".format(partial_month, percentage), multiplied_column) print(table.reset_index().to_csv(index=False)) return table.reset_index() diff --git a/requirements.txt b/requirements.txt index 6f8140c..9564555 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,5 @@ gracc-reporting elasticsearch_dsl requests +numpy +pandas From 7719a745128d1bd491cd8196966f21f041fc8756 Mon Sep 17 00:00:00 2001 From: Derek Weitzel Date: Mon, 14 Feb 2022 20:17:21 -0600 Subject: [PATCH 2/2] Remove partial month completely --- gracc_osg_reports/MonthlySitesViewReporter.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/gracc_osg_reports/MonthlySitesViewReporter.py b/gracc_osg_reports/MonthlySitesViewReporter.py index 52956e0..e1fbc2a 100644 --- a/gracc_osg_reports/MonthlySitesViewReporter.py +++ b/gracc_osg_reports/MonthlySitesViewReporter.py @@ -161,7 +161,7 @@ def format_report(self): table = self.generate_report_file() # Figure out the percentage of the month we have completed - now = self.end_time + now = datetime.datetime.now() days_in_month = calendar.monthrange(now.year, now.month)[1] # Scale up the partial month to the full month @@ -176,10 +176,11 @@ def date_to_yeardate(date): # Multiply the partial month by the percentage partial_month = table.columns.values.tolist()[-1] - multiplied_column = table[table.columns[-1]] * percentage - table.insert(len(table.columns), "{} * {:.2f}".format(partial_month, percentage), multiplied_column) + table[table.columns[-1]] = table[table.columns[-1]] * percentage + table = table.rename(columns= {partial_month:"{} * {:.2f}".format(partial_month, percentage)}) + #table.insert(len(table.columns), "{} * {:.2f}".format(partial_month, percentage), multiplied_column) - print(table.reset_index().to_csv(index=False)) + #print(table.reset_index().to_csv(index=False)) return table.reset_index()