GivingForecast Python Script

To install this script, copy all of the code below. Create a new Python document in Special Content using the name GivingForecast. Then paste the code into editor and save.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#Roles=Finance

from System import DateTime

Html = model.TextContent('GivingForecastHtml')
Style = model.TextContent('GivingForecastStyleHtml')
data = model.DynamicDataFromJson(model.TextContent('GivingForecastData'))

def FmtNumber(value):
    fmt = "N0".format()
    return "" if value== None else value.ToString(fmt)

def SafeDiv(num, dem):
    return float(num) / dem if dem > 0 else 0.0

def NewRow(row, combined):
    return '<th>{}</th><td>{:,d}</td><td>{:,d}</td><td>{:.1%}</td><td>{:,.0f}</td><td>{:.1%}</td><td>{:,.0f}</td>'.format(
        model.SpaceCamelCase(row.RowType), 
        row.FamilyCnt, 
        row.RecurringCnt, 
        SafeDiv(row.RecurringCnt, row.FamilyCnt), 
        row.MonthlyAmt, 
        SafeDiv(row.MonthlyAmt, combined.MonthlyAmt),
        row.MonthlyAmt * 12)

memberrow = NewRow(data.Member, data.Combined)
nonmemberrow = NewRow(data.NonMember, data.Combined)
combinedrow = NewRow(data.Combined, data.Combined)
print Html.format(
    style=Style,
    monthly=data.Combined.MonthlyAmt,
    projected=data.Combined.MonthlyAmt * 12,
    member=memberrow, 
    nonmember=nonmemberrow, 
    combined=combinedrow)

# the following is only used in development 
#Html = model.Content('C:/dev/bvcmsdocs/source/CustomProgramming/Python/Scripts/Giving/Forecast/Files/Content/GivingForecastHtml.text.html')
#Style = model.Content('C:/dev/bvcmsdocs/source/CustomProgramming/Python/Scripts/Giving/Forecast/Files/Content/GivingForecastStyleHtml.text.html')
#runfrom=C:/dev/bvcmsdocs/source/CustomProgramming/Python/Scripts/Giving/Forecast/Files/Content/GivingForecast.py

© 2019 TouchPoint Software, LLC.  All rights reserved.