How can one convert an environment variable to a string in groovy - groovy

In a jenkins file pipeline I have:
def task = readJSON(file: 'ecs/task-definition.json')
echo "Read Task Definition: $task"
task.containerDefinitions[0].image="${AWS_VERSION_IMAGE}"
echo "New Task Definition With Image Is: $task"
In the output value of the second echo statement i get:
New Task Definition With Image Is: [name:proxy, image:[bytes:[48, 48, 55, 49, 50, 54, 53, 56, 51, 55, 53, 55, 46, 100, 107, 114, 46]]
where AWS_VERSION_IMAGE is an environment variable defined as AWS_VERSION_IMAGE = "${AWS_DOCKER_REGISTRY}:${VERSION_TAG}" in an environment block.

Thanks for the replies, I ended up fixing the issue by using String instead of def like this:
String image = "${AWS_VERSION_IMAGE}"
task.containerDefinitions[0].image=image
Now it works.

Related

How to add and concate two variables in same list

array = [[1676, 196, 159, 29, 'invoice'], [1857, 198, 108, 28, 'date:']]
width = 159+108 = 267
height = 29+28 = 57
label = invoice date:
Required solution: [1676, 196, 267, 57, 'invoice date:']
Is there any solution to concatenate string and add numbers in same list
Assuming your other lines are for your own notes/testing, and your "required solution" is a typo, you can use zip like so:
array = [[1676, 196, 159, 29, 'invoice'], [1857, 198, 108, 28, 'date:']]
res = []
for x, y in zip(array[0], array[1]): # compare values at each index
if isinstance(x, str): # check to see if x is a string
res.append(x + ' ' + y) # add a space if x is a string
else:
res.append(x + y) # add the two integers if x is not a string
print(res)
[3533, 394, 267, 57, 'invoice date:']
Note that the concatenation above will only work if you are sure that the same indices will have strings vs. integers.

Remove title from ScatterChart

I would like to know how to be able to assign a name just to a serie of data (using a scatterchart), without getting the same serie's name as title of the chart. I would like to get just the series name as legend and NOT chart title at all.
I realized that autoTitleDeleted needs to have a value of 1.
So, consulting documentation I found that ´chartContainer´ is the class to implement the aforementioned option. Therefore, I import the class and apply it as next:
from openpyxl import Workbook
from openpyxl.chart import (
ScatterChart,
Reference,
Series,
)
from openpyxl.chart.chartspace import ChartContainer
wb = Workbook()
ws = wb.active
rows = [
["Size", "Batch 1", "Batch 2"],
[2, 40, 30],
[3, 40, 25],
[4, 50, 30],
[5, 30, 25],
[6, 25, 35],
[7, 20, 40],
]
for row in rows:
ws.append(row)
chart2 = ScatterChart()
chart2.x_axis.title = "Size"
chart2.y_axis.title = "Percentage"
xvalues = Reference(ws, min_col = 1, min_row = 2, max_row = 7)
values = Reference(ws, min_col = 3, min_row = 1, max_row = 7)
series1 = Series(values, xvalues)
chart2.series.append(series1)
chart2 = ChartContainer(autoTitleDeleted = 1)
ws.add_chart(chart2, "J10")
wb.save("Ex1.xlsx")
However, next error comes up:
`runfile('C:/Users/Administrador/Desktop/Pre-Try/Ex1/Ex1.py', wdir='C:/Users/Administrador/Desktop/Pre-Try/Ex1')
Traceback (most recent call last):
File "", line 1, in
runfile('C:/Users/Administrador/Desktop/Pre-Try/Ex1/Ex1.py', wdir='C:/Users/Administrador/Desktop/Pre-Try/Ex1')
File "C:\ProgramData\Anaconda3\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 827, in runfile
execfile(filename, namespace)
File "C:\ProgramData\Anaconda3\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 110, in execfile
exec(compile(f.read(), filename, 'exec'), namespace)
File "C:/Users/Administrador/Desktop/Pre-Try/Ex1/Ex1.py", line 46, in
wb.save("Ex1.xlsx")
File "C:\ProgramData\Anaconda3\lib\site-packages\openpyxl\workbook\workbook.py", line 397, in save
save_workbook(self, filename)
File "C:\ProgramData\Anaconda3\lib\site-packages\openpyxl\writer\excel.py", line 294, in save_workbook
writer.save()
File "C:\ProgramData\Anaconda3\lib\site-packages\openpyxl\writer\excel.py", line 276, in save
self.write_data()
File "C:\ProgramData\Anaconda3\lib\site-packages\openpyxl\writer\excel.py", line 76, in write_data
self._write_worksheets()
File "C:\ProgramData\Anaconda3\lib\site-packages\openpyxl\writer\excel.py", line 219, in _write_worksheets
self._write_drawing(ws._drawing)
File "C:\ProgramData\Anaconda3\lib\site-packages\openpyxl\writer\excel.py", line 142, in _write_drawing
self._archive.writestr(drawing.path[1:], tostring(drawing._write()))
File "C:\ProgramData\Anaconda3\lib\site-packages\openpyxl\drawing\spreadsheet_drawing.py", line 296, in _write
self._rels.append(rel)
UnboundLocalError: local variable 'rel' referenced before assignment`
I do not really understand this error. If you could help would be grateful!
chart2 = ChartContainer(autoTitleDeleted = 1)
This the problem: you must use openpyxl chart objects so that the library can manage the plumbing between objects: charts are very complicated objects and we try and hide some of the complexity Your idea is correct - to set the value to True – but that won't work like this because a ChartContainer doesn't know how to add itself to the XLSX package.
As a workaround it's probably easiest create a title with an empty string. Otherwise you could submit a PR that allows the mapping of the autoTitleDeleted attribute from chartContainers to charts and vice versa.

Get row name of elements that are greater than a threshold user each column in matrix python

I am new to python , please can you help me.
enter image description here
I have read in an xlsx file and added headers to it
header = ['S.No', 'Name', 'Science', 'english','History','art','Maths']
df = pd.read_excel('matrix.xlsx', header=None, names=header)
I would like to extract the student who achieved 85 and above, I would like it to look like the this:
roy[history,art,maths]
john[art,maths]
dave[art,math]
This is the code of how the excel file looks like to help
p = pd.DataFrame.from_items([('Roy', [80, 75, 85, 90, 95]), ('John', [75, 80, 75, 85, 100]), ('Dave', [80, 80, 80, 90, 95, ])],
orient='index', columns=['Science', 'English', 'History', 'Arts', 'Maths'])
Thank you

Python 3 Error: TypeError: unsupported operand type(s) for +=: 'int' and 'str'

I am trying to code a Standard Deviation project and have run into an error, I will leave my code below. Not sure what exactly is causing this error, if anyone can please leave a correction or how to fix this below I would greatly appreciate it.
Billy = {
'Homework':[76, 88, 90, 95, 54],
'Quiz':[89, 97, 54],
'Test':[78, 89]
}
Martha = {
'Homework':[74, 66, 90, 100, 98],
'Quiz':[67, 80, 99],
'Test':[88, 98]
}
Robert = {
'Homework':[89, 76, 65, 99, 87],
'Quiz':[88, 98, 73],
'Test':[81, 92]
}
#Sum
def grades_sum(homework):
total = 0
for grade in homework:
total += grade
return total
print(grades_sum(Billy))
#Average
def grades_average(grades):
sum_of_grades = grades_sum(grades)
average = sum_of_grades / float(len(grades))
return average
It is returning the following errors:
Traceback (most recent call last):
File "python", line 26, in <module>
File "python", line 23, in grades_sum
TypeError: unsupported operand type(s) for +=: 'int' and 'str'
You cannot simply call grades_sum(Billy). Billy is a dictionnary and you need a list
you can either do:
grades_sum(Billy['Homework'])
or
def grades_sum(student, key):
total = 0
for grade in student[key]:
total += grade
return total
grades_sum('Billy', 'Homework')
I hope it helps,

Can't read integers value in Cassandra

I have a simple column family 'Users'
System.out.println(" read User");
long timestamp = System.currentTimeMillis();
clientA.insert(ByteBuffer.wrap("mike".getBytes()), new ColumnParent("Users"),
new Column(ByteBuffer.wrap("email".getBytes())).setValue(ByteBuffer.wrap("mike#gmail.com".getBytes())).setTimestamp(timestamp)
, ConsistencyLevel.ONE);
clientA.insert(ByteBuffer.wrap("mike".getBytes()), new ColumnParent("Users"),
new Column(ByteBuffer.wrap("totalPosts".getBytes())).setValue(ByteBuffer.allocate(4).putInt(27).array()).setTimestamp(timestamp)
, ConsistencyLevel.ONE);
SlicePredicate predicate = new SlicePredicate();
predicate.setSlice_range(new SliceRange(ByteBuffer.wrap(new byte[0]), ByteBuffer.wrap(new byte[0]), false, 10));
ColumnParent parent = new ColumnParent("Users");
List<ColumnOrSuperColumn> results = clientA.get_slice(ByteBuffer.wrap("mike".getBytes()),
parent,
predicate,
ConsistencyLevel.ONE);
for (ColumnOrSuperColumn result : results) {
Column column = result.column;
System.out.println(new String(column.getName()) + " -> "+ new String(column.getValue())+", "+column.getValue().length);
}
it returns
read User
email -> mike#gmail.com, 14
totalPosts ->
So totalPosts can't be read with the thrift client
with cassandra-cli
[default#test] get Users['mike']['totalPosts'];
=> (column=totalPosts, value=0000001b, timestamp=1336493080621)
Elapsed time: 10 msec(s).
How can I retrieve this Integer value with Java thrift client?
using cassandra 1.1
edit:
it seems due to this part
for (ColumnOrSuperColumn result : results) {
Column column = result.column;
System.out.println(new String(column.getName()) + " -> "+Arrays.toString(column.getValue()));
}
returns
email -> [109, 105, 107, 101, 64, 103, 109, 97, 105, 108, 46, 99, 111, 109]
totalPosts -> [0, 0, 0, 27]
Your column values are being returned as bytes, the same way you're inserting them. So the value for the 'email' column is [109, 105, 107, 101, 64, 103, 109, 97, 105, 108, 46, 99, 111, 109], which interpreted as ascii is mike#gmail.com. And the number 27 which you write into the ByteBuffer as [0, 0, 0, 27] (via the putint call) comes out the same way.
If you absolutely have to be using the raw thrift interface, you'll probably want to retrieve your totalPosts int using ByteBuffer.getInt(). But if at all possible, I recommend using a library to wrap around the ugliness of the thrift interface, which should take care of value serialization issues like this. Maybe look at Hector, or skip the old interface entirely and go straight to CQL with Cassandra-JDBC.

Resources