Skip to content

Commit

Permalink
Merge pull request #13 from djw8605/fix-pivot
Browse files Browse the repository at this point in the history
Fixing pivot table and a few fixes for Tim
  • Loading branch information
djw8605 authored Feb 15, 2022
2 parents 95b4215 + 7719a74 commit 37b4f1c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
20 changes: 12 additions & 8 deletions gracc_osg_reports/MonthlySitesViewReporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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

Expand All @@ -162,7 +163,9 @@ def format_report(self):
# Figure out the percentage of the month we have completed
now = datetime.datetime.now()
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):
Expand All @@ -171,12 +174,13 @@ 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]
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()


Expand Down
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
gracc-reporting
elasticsearch_dsl
requests
numpy
pandas

0 comments on commit 37b4f1c

Please sign in to comment.