# Name: Electric Meter Demand Graphs - Usage.py
# Description: Python script to take a single TWACs Meter and create a Usage Graphs per Feeder
# Date Created: Tuesday, September 17th, 2013 @ 1:20 PM
# Date Modified: Tuesday, September 17th, 2013 @ 1:20 PM
# Author: C. Wafstet #94 - Modern Electric Water Company (Spokane, WA)
import arcpy
import arcpy
import logging
from arcpy import env
env.overwriteOutput = 1
env.workspace = r"C:\MEWCo GIS System\Electric System\MEWCo_Electric_Model-LOCAL.gdb"
table = "SERVICE_METERS_DEMAND_F1FEEDER_ABC"
list = []
# if run in ArcGIS Desktop, show messages, also print to log
def log(method, msg):
print msg
method(msg)
logging.basicConfig(
level=logging.INFO,
format='%(asctime)s %(levelname)-s %(message)s',
datefmt='%a, %d %b %Y %H:%M:%S',
filename='MakeGraph.log',
filemode='w'
)
log(logging.info, "Creation of Graphs Started")
rows = arcpy.SearchCursor(table)
for row in rows:
list.append(row.TWACs_NUMBER)
del row, rows
# Remove duplicates from list
list = dict.fromkeys(list)
list = list.keys()
for n in list:
arcpy.TableSelect_analysis(table, r"in_memory\table_sel", "TWACs_NUMBER = " + str(n))
# Get TWACs_Number value
for row in arcpy.SearchCursor(r"in_memory\table_sel"):
METER_NUMBER = row.getValue("METER_NUMBER")
out_graph_name = n
out_graph_pdf = r"C:\MEWCo GIS System\Electric Graphs\Electric Meters\Usage Graphs\F-1 Feeder" + "\\" + str(n)[:-2] + "-Usage" + ".pdf"
input_template = r"C:\MEWCo GIS System\Electric Graphs\GIS Graph Temps\ELECTRIC METER DEMAND - KWH USAGE.grf"
input_data = r"in_memory\table_sel"
# Create the Graph
graph = arcpy.Graph()
# Add a Vertical Bar series to the graph - KWH Usage
graph.addSeriesBarVertical(input_data, "KWH_USAGE")
# Specify the title of the Left Axis
graph.graphAxis[0].title = "KWH_USAGE"
# Specify the title of the Bottom Axis
graph.graphAxis[2].title = "BILLING_PERIOD"
# Specify the title of the Graph
graph.graphPropsGeneral.title = "KWH Usage by Electric TWACs Number: " + METER_NUMBER
# Output a graph, which is created in-memory
arcpy.MakeGraph_management(input_template, graph, out_graph_name)
# Save the graph as an .PDF
arcpy.SaveGraph_management(out_graph_name, out_graph_pdf, "MAINTAIN_ASPECT_RATIO", 600, 375)
log(logging.info, "Creation of Graphs Complete")
The code works just fine.... I worked on it for awhile to make it work the way I want it too. It just seems like - each time I run it - it takes longer and longer.