|
POST
|
# 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.
... View more
09-25-2013
09:44 AM
|
0
|
0
|
1499
|
|
POST
|
I have a Python script that starts with a Search Cursor that goes through a File Geodatabase and looks for a unique number and produces a graph and prints it out to a .PDF. The Script works out just fine. BUT - each time I run it - it seems to take longer and longer. The first few times - it produces about 4 .PDFs each minute. Now - when I run it - it goes slower and slower - about 1 .PDF every 2 minutes. Does the Search Cursor produce "Temp" files somewhere that needs to be cleared out? How can I speed this up?
... View more
09-25-2013
09:26 AM
|
0
|
9
|
2086
|
|
POST
|
Jake- Yes - huge help on one of my previous posts to get the Python script to create the graph. Nice to know that there is a bug in the tool/script. I have been trying multiple different things for the past few days to get it to work. I will send a note to Tech Support and see what can be done. Thank you for the help. Chris Chris, I believe I was assisting your before. I think the title of the axis's being lowercase is a bug. I was able to reproduce this same behavior. I would recommend following up with Tech Support. As for the title, you can use the 'getValue' method to retrieve the value of your field. Ex: import arcpy
from arcpy import env
env.overwriteOutput = 1
env.workspace = r"C:\temp\data.gdb"
table = "Meters"
fields = ["METER_NUMBER"]
list = []
rows = arcpy.SearchCursor(table)
for row in rows:
list.append(row.METER_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", "METER_NUMBER = " + str(n))
#get TWACs_Number value
for row in arcpy.SearchCursor(r"in_memory\table_sel"):
TWACs_Number = row.getValue("TWACs_Number")
out_graph_name = n
out_graph_pdf = r"C:\Temp" + "\\" + str(n) + ".pdf"
input_template = r"C:\Temp\KW Demand.grf"
input_data = r"in_memory\table_sel"
# Create the graph
graph = arcpy.Graph()
# Add a vertical bar series to the graph
graph.addSeriesBarVertical(input_data, "KW_DEMAND")
# Specify the title of the left axis
graph.graphAxis[0].title = "KW Demand"
# Specify the title of the bottom axis
graph.graphAxis[2].title = "Meter Number"
# Specify the title of the Graph
graph.graphPropsGeneral.title = TWACs_Number
# Output a graph, which is created in-memory
arcpy.MakeGraph_management(input_template, graph, out_graph_name)
# Save the graph as a PDF
arcpy.SaveGraph_management(out_graph_name, out_graph_pdf, "MAINTAIN_ASPECT_RATIO", 600, 375)
... View more
09-10-2013
10:01 AM
|
0
|
1
|
1344
|
|
POST
|
Having issues with the titles (X-Axis) and (Y-Axis) in my graphs not working properly. I have it set in a Python script to make it "KWH_USAGE" but when the graph is created - it shows "kwh_usage"... Why is it only showing everything as lower case? Also - I want to include the data from a specific field in a feature class to show in the title. So if I have 14884512 in a field called "TWACs_Number" - I want the title to include that. How would I write that? Thank you
... View more
09-10-2013
08:21 AM
|
0
|
3
|
1893
|
|
POST
|
Sorry meant to add that bit in. Where you specify the name of the PDF and use str(n) use str(n)[:-2] Cheers Dave BINGO!!!! That is exactly what I am looking for. The .PDFs are coming out exactly the way they need and are named properly. Thank you I am doing more research on the graph itself.
... View more
09-04-2013
02:06 PM
|
0
|
0
|
1469
|
|
POST
|
Dave- Thank you, but how should that look here??:
for n in list:
arcpy.TableSelect_analysis(table, r"in_memory\table_sel", "TWACs_NUMBER = " + str(n))
out_graph_name = n
out_graph_pdf = r"C:\MEWCo GIS System\Electric Graphs\Electric Meters\F-1 Feeder" + "\\" + str(n) + ".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"
... View more
09-04-2013
01:45 PM
|
0
|
0
|
1469
|
|
POST
|
At this time - I have installed ArcGIS 10.2 and the script is working perfectly. Except (1) thing that I cannot figure out. The field that is being used to name the .PDF is TWACs_NUMBER, which is a "Double" field type. I am having a hard time getting the naming of the .PDF to come out properly. Example: TWACs_Number - 14710787 The way the .PDF is being created: 14710787.0.pdf This is going to make it difficult running the attachment tool because of the .0 at the end since in the table there is no .0 This is what the stand-alone Python script looks like:
import arcpy
import arcpy
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"
list = []
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))
out_graph_name = n
out_graph_pdf = r"C:\MEWCo GIS System\Electric Graphs\Electric Meters\F-1 Feeder" + "\\" + str(n) + ".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"
# 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)
Also - why is it when the .PDF is greated - the graph title and lables are ALL lower case letters? Thank you
... View more
09-04-2013
01:21 PM
|
0
|
0
|
2317
|
|
POST
|
Jake- Thank you for the script for ArcMap 10.0 It looks good - but - I have tried the script in ArcCatalog and ArcMap and each time - it crashes and get the "ArcGIS Desktop has encountered a serious application error and is unable to continue" Error screen.
... View more
08-30-2013
06:45 AM
|
0
|
0
|
2317
|
|
POST
|
Jake, he's running 10.0. The da cursors didn't show up until 10.1. Also, I don't think 10.0 cursors will take a list for the fields, just a formatted string. Okay - I am trying to run this script off of ArcMap 10.0... I am in the process of upgrading to 10.2.... What is the latest Python that I will need?
... View more
08-29-2013
08:22 AM
|
0
|
0
|
2317
|
|
POST
|
Jake- Thank you for that. Close..... However - I am getting this error: <type 'exceptions.AttributeError'>: 'module' object has no attrbute 'da' Failed to execute Here is an update to the script that will perform this for each unique meter number: import arcpy
from arcpy import env
env.overwriteOutput = 1
env.workspace = r"C:\temp\data.gdb"
table = "Meters"
fields = ["METER_NUMBER"]
list = []
with arcpy.da.SearchCursor(table, fields) as cursor:
for row in cursor:
list.append("{0}".format(row[0]))
del cursor, row
#remove duplicates from list
list = dict.fromkeys(list)
list = list.keys()
for n in list:
arcpy.TableSelect_analysis(table, r"in_memory\table_sel", "METER_NUMBER = " + n)
out_graph_name = n
out_graph_pdf = r"C:\Temp" + "\\" + n + ".pdf"
input_template = r"C:\Temp\KW Demand.grf"
input_data = r"in_memory\table_sel"
# Create the graph
graph = arcpy.Graph()
# Add a vertical bar series to the graph
graph.addSeriesBarVertical(input_data, "KW_DEMAND")
# Specify the title of the left axis
graph.graphAxis[0].title = "KW Demand"
# Specify the title of the bottom axis
graph.graphAxis[2].title = "Meter Number"
# Specify the title of the Graph
graph.graphPropsGeneral.title = "KW Demand by Meter"
# Output a graph, which is created in-memory
arcpy.MakeGraph_management(input_template, graph, out_graph_name)
# Save the graph as an image
arcpy.SaveGraph_management(out_graph_name, out_graph_pdf, "MAINTAIN_ASPECT_RATIO", 600, 375) If you want to run this from toolbox, right-click on the script within toolbox > Properties > Parameters tab and delete the parameter previously created.
... View more
08-29-2013
06:54 AM
|
0
|
0
|
2317
|
|
POST
|
Right-click on the Script in the toolbox, click the Source tab, and make sure this is set to the script: [ATTACH=CONFIG]27069[/ATTACH] Also, check to make sure the Parameter is set: [ATTACH=CONFIG]27070[/ATTACH] Then, when you double-click on the Script in the toolbox, you should be presented with the following: [ATTACH=CONFIG]27071[/ATTACH] The user can enter in a meter number, and then an output graph will be created like the one attached. Okay - so far this is an awesome start. I am atleast getting the script to run without any errors and the .PDF is coming out - but the graph is not showing the data.... no worries. This is something for me to build off of...... The thing I want to do is to be able to run a script that will do these for Each meter (around 9500 total) at one time. This current script works for on demand graphs. Thanks alot so far
... View more
08-28-2013
02:56 PM
|
0
|
0
|
2317
|
|
POST
|
Not sure if this makes a difference at all - but I am currently running ArcMap 10.0 and using Python 2.6. I am using IDLE to edit and run the script. Is this making a difference in the code and how its running? I am planning on upgrading to ArcMap 10.2 in the next week.
... View more
08-28-2013
02:10 PM
|
0
|
0
|
4025
|
|
POST
|
You can open ArcMap, and then navigate to C:\temp using the Catalog window. When you double-click on the script within the Toolbox, what do you see? Can you send a screen shot? What meter number did you specify? This is what I see
... View more
08-28-2013
12:32 PM
|
0
|
0
|
4025
|
|
POST
|
Jake- This is a great start - but it doesn't seem to be working according to your instructions. Is it open in ArcMap or ArcCatalog? - Also I dont see a place that asks me to type in a meter number This is an error I get back: Traceback (most recent call last): File "C:\temp\Script1.py", line 8, in <module> arcpy.TableSelect_analysis(table, r"in_memory\table_sel", "METER_NUMBER = " + arcpy.GetParameterAsText(0)) File "C:\Program Files\ArcGIS\Desktop10.0\arcpy\arcpy\analysis.py", line 153, in TableSelect raise e ExecuteError: ERROR 999999: Error executing function. An invalid SQL statement was used. An invalid SQL statement was used. [Meters] An invalid SQL statement was used. [SELECT * FROM Meters WHERE METER_NUMBER = ] Failed to execute (TableSelect).
... View more
08-28-2013
12:23 PM
|
0
|
0
|
4026
|
|
POST
|
Attached is a zip file with an example. Try the following: 1. Extract the zip file to your C:\Temp directory 2. Open ArcMap 3. Under C:\Temp, expand the Data.gdb > Graph toolbox > double-click on the Script 4. Specify a meter number, i.e. 8151830 5. Click OK to execute the tool Within your C:\Temp directory you should have a graph as a PDF. Is this what you are looking for? Jake- This is a great start - but it doesn't seem to be working according to your instructions. Is it open in ArcMap or ArcCatalog? - Also I dont see a place that asks me to type in a meter number
... View more
08-28-2013
11:43 AM
|
0
|
0
|
4026
|
| Title | Kudos | Posted |
|---|---|---|
| 1 | 03-23-2026 10:58 AM | |
| 1 | 11-20-2025 02:52 PM | |
| 1 | 10-30-2025 12:42 PM | |
| 1 | 10-16-2025 10:51 AM | |
| 1 | 08-27-2025 08:47 AM |
| Online Status |
Offline
|
| Date Last Visited |
Thursday
|