I'm using a for loop with a list of variables to create multiple plots against one variable each plot has an item in the list iterated in the for loop against the variable "PUMP FAILURE (1 or 0)"
ATTEMPT
ListOfVariables = ['Volumetric Flow Meter 1', 'Volumetric Flow Meter 2', 'Pump Speed (RPM)', 'Pump Torque', 'Ambient Temperature', 'Horse Power', 'Pump Efficiency']
for item in ListOfVariables:
first_axis = dataframe_raw[item].plot
second_axis = first_axis.twinx()
second_axis.plot(dataframe_raw['PUMP FAILURE (1or 0)'], color='teal')
plt.title(item)
plt.show()
ERROR
3 for item in ListOfVariables:
4 first_axis = dataframe_raw[item].plot
----> 5 second_axis = first_axis.twinx()
6 second_axis.plot(dataframe_raw['PUMP FAILURE (1or 0)'], color='teal')
7 plt.title(item)
AttributeError: 'PlotAccessor' object has no attribute 'twinx'
Related
I have a simple graph with few nodes and these nodes have attributes such as "type" and "demand".
def mygraph():
G = nx.Graph()
G.add_nodes_from([("N1", {"type":"parent","demand": 10}),
("N2"{"type":"parent","demand": 12}),
("N3", {"type":"parent","demand": 25}),
("S1", {"type":"server","demand": 12}),
("S2,{"type":"server","demand": 20})])
I am passing this graph to another function in pyomo library. The dummy pyomo function is as follows:
def mymodel():
g=mygraph()
**VARIABLES**
model.const1 = Constraint(my constraint1)
model.const2 = Constraint(my constraint2)
model.obj1 = Objective(my objective)
status = SolverFactory('glpk')
results = status.solve(model)
assert_optimal_termination(results)
model.display()
mymodel()
I am trying to:
In graph function mygraph():, I need to find the total number of nodes in the graph G with attribute type==parent.
In pyomo function mymodel():, I need to create the number new of VARIABLES equal to the number of nodes with attribute type==parent. So in the case above, my program must create 3 new variables, since 3 nodes have attribute type==parent in my graph function. The values of these newly created variables will be accessed from the demand attribute of the same node thus, it should be something like this;
new_var1=demand of node1 (i.e., node1_demand=10 in this case)
new_var2=demand of node2 (i.e., node2_demand=12)
new_var3=demand of node3 (i.e., node2_demand=25)
For the first part you can loop over the nodes:
sum(1 for n,attr in G.nodes(data=True) if attr['type']=='parent')
# 3
# or to get all types
from collections import Counter
c = Counter(attr['type'] for n,attr in G.nodes(data=True))
# {'parent': 3, 'server': 2}
c['parent']
# 3
c['server']
# 2
For the second part (which also gives you the answer of the first part of you check the length):
{n: attr['demand'] for n,attr in G.nodes(data=True) if attr['type']=='parent'}
# or
[attr['demand'] for n,attr in G.nodes(data=True) if attr['type']=='parent']
Output:
{'N1': 10, 'N2': 12, 'N3': 25}
# or
[10, 12, 25]
instanciating attributes
def mymodel():
g = mygraph()
nodes = [attr['demand']
for n,attr in G.nodes(data=True)
if attr['type']=='parent']
# initialize model?
for i,n in enumerate(nodes, start=1):
setattr(model, f'const{1}', Constraint(something with n))
# ...
how to jmeter calculate response data value
example
Number of thread = 3
Ramp Up = 1
Loop Count = 1
Thread 1 value extract = 3
Thread 2 value extract = 7
Thread 3 value extract = 10
how to get total = 3+7+10 = 20
Add JSR223 PostProcessor after the extractor and put the following code where
props.put('value_' + ctx.getThreadNum(), vars.get('extracted_value'))
Then somewhere in tearDown Thread Group you can use the following expression to get the sum of all values of properties which start with value_
props.entrySet().findAll {prop -> prop.getKey().startsWith('value_')}.collect {prop -> prop.getValue() as int}.sum()
More information about what do these props, ctx and vars mean: Top 8 JMeter Java Classes You Should Be Using with Groovy
I have a Visual Basic 6 form with a MSFlexGrid control inside, which takes data from a record set(ADODB) and displays them.
Before starting the copy of data to the FlexGrid, I'm trying to set the rows count, depending on records count. Also I have a collection which contains columns' names, then I can get the number of columns from here.
The following is a code snippet:
v_colsCount = UBound(aCols) + 2 // aCols = array with columns' names
v_regCount = rs.RecordCount // rs = my ADODB record set
myFlexGrid.Rows = 0 // for cleaning rows from a previous display
myFlexGrid.Rows = IIf(v_regCount > 0, v_regCount + 1, 2)
myFlexGrid.Cols = v_colsCount
myFlexGrid.FixedRows = 1
myFlexGrid.FixedCols = 0
There are 7532 rows and 52 columns. The problem comes when I run the application and try to execute this part of the code (fill the FlexGrid with data from the record set):
For iRow = 1 To v_regCount
For iCol = 0 To v_colsCount -2
sAux = ConvStr(rs.Fields(aCols(iCol)).Value)
myFlexGrid.TextMatrix(iRow, iCol) = sAux
I notice that
v_regCount = 7532 but v_colsCount = 2 ,
and I get an error ("Substring out of range"). If I swap the settings order (i.e. if I set myFlexGrid.Cols after set myFlexGrid.Rows), then
v_regCount = 0 and v_colsCount = 52
I don't understand why I can't set rows and columns count at the same time.
Any ideas?
Thanks in advance
I am trying to run this code in QTP which is for deleting records from a grid. This code
dgRows = SwfWindow("PWC - [PWC]").SwfWindow("Region Master").SwfTable("dgMaster").RowCount
For i = 1 To dgRows
SwfWindow("PWC - [PWC]").SwfWindow("Region Master").SwfTable("dgMaster").SelectCell i-1,0
'row of data grid begins with 0, hence i -1
SwfWindow("PWC - [PWC]").SwfWindow("Region Master").SwfButton("DELETE").Click
Swfwindow("PWC - [PWC]").SwfWindow("Region Master").SwfWindow("RegionMaster").SwfButton("Insert").Click
deleteCode = closePrompt()
If deleteCode = 15 Then 'closePrompt returns 15 when record is successfully deleted
i = i - 1 'As record is deleted, grid has lost one record and for loop will exit early by one record or throw error.
dgoRows = SwfWindow("PWC - [PWC]").SwfWindow("Region Master").SwfTable("dgMaster").RowCount
End If
Next
This piece of code runs from 1 to number of rows in a grid (dgRows).
If there are 3 rows, it will run thrice and delete records if possible. If 1 record is deleted,
the grid loses a record. Hence I am trying to adjust the value of i and dgRows by the code
i = i - 1 'As record is deleted, grid has lost one record and
for loop will exit early by one record or throw error.
dgoRows = SwfWindow("PWC - [PWC]").SwfWindow("Region Master").SwfTable("dgMaster").RowCount
'Updating new value of dgRows so that QTP does not click on a row for value of i that does not
exist.
I try to illustrate the issues I am facing with this piece of code
dgRows = SwfWindow("PWC - [PWC]").SwfWindow("Region
Master").SwfTable("dgMaster").RowCount
After row is deleted, it does not dynamically get the no of rows in the grid when the for loop iterates. Hence i value becomes equal to 3 rows but actually in the grid there is one row as 2 records have been deleted, thus QTP tries to click on a cell with i value 3 but doesn't find it and throws an error.
Can anyone tell me why doesn't ("dgMaster").RowCount update itself or how to update it when the for loop runs next?
In VBScript a for loop only evaluates the limit once.
Proof:
limit = 4
For i = 1 to limit
limit = limit - 1
document.write(i & " - " & limit & "<br>")
Next
Output:
1 - 3
2 - 2
3 - 1
4 - 0
You should use a While loop instead
dgRows = SwfWindow("PWC - [PWC]").SwfWindow("Region Master").SwfTable("dgMaster").RowCount
i = 1 ' I would use 0 but I'm keeping the code as close to original as possible
While i <= dgRows
i = i + 1
SwfWindow("PWC - [PWC]").SwfWindow("Region Master").SwfTable("dgMaster").SelectCell i-1,0
'row of data grid begins with 0, hence i -1
SwfWindow("PWC - [PWC]").SwfWindow("Region Master").SwfButton("DELETE").Click
Swfwindow("PWC - [PWC]").SwfWindow("Region Master").SwfWindow("RegionMaster").SwfButton("Insert").Click
deleteCode = closePrompt()
If deleteCode = 15 Then 'closePrompt returns 15 when record is successfully deleted
i = i - 1 'As record is deleted, grid has lost one record and for loop will exit early by one record or throw error.
dgoRows = SwfWindow("PWC - [PWC]").SwfWindow("Region Master").SwfTable("dgMaster").RowCount
End If
WEnd
Alrightie, so I'm building an CSV file this time with ruby. The outer loop will run up to length of num_of_loops, but it runs for an entire set rather than up to the specified row. I want to change the first column of a CSV file to a new name for each row.
If I do this:
class_days = %w[Wednesday Thursday Friday]
num_of_loops = (num_of_loops / class_days.size).ceil
num_of_loops.times {
["Wednesday","Thursday","Friday"].each do |x|
data[0] = x
data[4] = classname()
# Write all to file
#
csv << data
end
}
Then the loop will run only 3 times for a 5 row request.
I'd like it to run the full 5 rows such that instead of stopping at Wed/Thurs/Fri it goes to Wed/Thurs/Fri/Wed/Thurs instead.
class_days = %w[Wednesday Thursday Friday]
num_of_loops.times do |i|
data[0] = class_days[i % class_days.size]
data[4] = classname
csv << data
end
The interesting part is here:
class_days[i % class_days.size]
We need an index into class_days that is between 0 and class_days.size - 1. We can get that with the % (modulo) operator. That operator yields the remainder after dividing i by class_days.size. This table shows how it works:
i i % 3
0 0
1 1
2 2
3 0
4 1
5 2
...
The other key part is that the times method yields indices starting with 0.