Playn text wrapping and style issue - styles

As in Effect.shadow() is deprecated in PlayN1.3.So i had something like this before :
TextFormat textFormat = new TextFormat(myFont, textWidth, Alignment.LEFT, colorCode, Effect.shadow(-16777216, shadowX, shadowY));
So i changed it to this :
TextFormat textFormat = new TextFormat();
textFormat.withFont(myFont);
textFormat.withWrapping(textWidth, Alignment.LEFT);
I dont want shadow now.It's ok but i did not get previous like result.Hold on.dont think now.Then i changed this code to this:
TextFormat textFormat = new TextFormat().withFont(myFont).withWrapping(textWidth, Alignment.LEFT);
It gives me result as previous except shadow which i dont care now.If i am not wrong this is one line representation of above code.Is not it?
So why it worked and above code did not.Any conceptual difference is there? Anyone can explain please!
//note: dont worry about variables(textWidth,myFont)they are nothing to do with this.

TextFormat objects are immutable. When you call textFormat.withFont(myFont) that returns a new TextFormat instance, which the code above is throwing away. If you want the first code to work you need to write it like this:
TextFormat format = new TextFormat();
format = format.withFont(myFont);
format = format.withWrapping(textWidth, Alignment.LEFT);

Related

Saving a complex dictionary into a excel file

i have a problem with saving a complex dictionary into an excel file.
This is my code so far:
attention_relevance = model.get_attention(test)
attentionres = []
for key in attention_relevance.keys():
attentionres.append(attention_relevance[key])
dfattention = pd.DataFrame(attentionres)
dfattention.to_excel(r'/savepath/attention.xlsx', index = False)
The dictionary i would like to save is called "attention_relevance".
The code is running without any error messages, but in the excel-file some of the values are not written, instead they are replaced by "...".
Like this:
[[[0.02923768 0.02157122 0.02464608 ... 0.06667057 0.03331407 0.0075733 ].
How can I fix this? I need all the values in there.
Anyone who can help?
Thank you very much!
Hinnerk8
you seem to be saving a list in a list, not a dictionary or just 1 list.
or you can try
np.squeeze(attentionres)
and then save the file it would also work

How can I emphasize an impex macro if it is part of a string?

How can I emphasize an impex macro if it is part of a string?
We can do something like this:
$prefix=alpha
$contentCatalog=$prefixContentCatalog
... and $contentCatalog will return "alphaContentCatalog".
Can I make the macro more explicit with something like:
$contentCatalog={$prefix}ContentCatalog
... so that I can immediately see that the macro is $prefix? Is there a syntax for this? (NOTE: The curly brace is just an example. This syntax/symbol doesn't exist for this purpose)
Another example: If I have something like below, it becomes confusing:
$prefix=electronics
$contentCatalog=$prefixContentCatalog
$contentCatalogFolderName=$contentCatalogFolder
But it can be easier to understand if it can be written as:
$prefix=electronics
$contentCatalog={$prefix}ContentCatalog
$contentCatalogFolderName={$contentCatalog}Folder
Hhmmm, unfortunately I don't think there is anything for this. I only see some workarounds like special naming for macro variables:
$_prefix_=electronics
$_contentCatalog_=$_prefix_ContentCatalog
$contentCatalogFolderName=$_contentCatalog_Folder
there is an alternate way to customize the micro via injecting property in local.properties and using ConfigPropertyImportProcessor.
UPDATE GenericItem[processor = de.hybris.platform.commerceservices.impex.impl.ConfigPropertyImportProcessor]; pk[unique = true]
$contentCatalog = $config-ly.br.content.catalog
$contentCV = catalogVersion(CatalogVersion.catalog(Catalog.id[default = $contentCatalog]), CatalogVersion.version[default = Staged])[default = $contentCatalog:Staged]
and entries should be added in local.properties.
ly.br.content.catalog=TestContentCatalog
Note:This is useful when we have multi-country.

Convert a string to array in velocity

I have a velocity variable, like this:
$cur_record.getFieldValue("SelectRoles", $locale)
that is supposed to be an array. If I print its value, (just by putting $cur_record.getFieldValue("SelectRoles", $locale) in the code) i get:
["Accountant","Cashier"]
now, i want to iterate those 2 values, Accountant and Cashier, but it seems to be a String, not an Array, how can i convert that to an array so I can iterate it?..
I have tried to iterate it, but does not work, like this:
#foreach($bla_role in $cur_record.getFieldValue("SelectRoles", $locale))
$bla_role
#end
Also tried to get the value, as if it were an array, does not work either:
$cur_record.getFieldValue("SelectRoles", $locale).get(0)
I've tried setting it to another variable, like this:
#set($roleval = $cur_record.getFieldValue("SelectRoles", $locale))
$roleval.get(0)
but it does not work, but if i set a string, as the value is printed (the value hard coded), it does work!, like this:
#set($roleval = ["Accountant","Cashier"])
$roleval.get(0)
I dont know if I have to escape something, or I am missing something, can some one help me?
thank you!
You're trying to parse a String array that was previously serialized to String.
The following snippet uses substring, split and replace String methods to parse it.
#set($roleval = '["Accountant","Cashier"]')
#set($rolevalLengthMinusOne = $roleval.length() - 1)
#set($roles = $roleval.substring(1, $rolevalLengthMinusOne).split(","))
#foreach($role in $roles)
<h1>$role.replace('"',"")</h1>
#end
At first I tried to use #evaluate to parse it, but I ended up with these String methods.

Object Initializer Formatting

Which setting(s) in Resharper 8 are reformatting my object initializer like this? (i.e. with the comma on it's own line).
var snowDepthProcessor = new DataProcessor<SnowDepthModel>
{
Name = "Snow Depth"
,
DataRetriever = snowReportRetriever
,
Parser = new SnowDepthParser()
,
...
};
I've tried every combination of settings I can find/think of; I do want the lines chopped but I don't want the comma to be on its own line.
I share your pain. I've to admit my solution is just partial because it needs change style from what you'd like to use to
List<string> demo = new List<string>
{
"a",
"b",
"c"
}
Then formatting is not changed. I'd also much rather use syntax you've described so I've created R# ticket https://youtrack.jetbrains.com/issue/RSRP-453704 but until it's resolved this is only way how suppress that (it behave in same way even in latest R#10)
EDIT: Good news. Seems to be fixed since R# 2017.1

How to write a compound IF statement checking two sets of two values

I know the title is confusing, but I can't figure our how to word it properly. I'm trying to figure out how to properly format a compound conditional in an IF statement in Excel. It's for a school project that's due tomorrow.
I already have something like this
=if(AND(b152="oval.jpg",c152="q'")OR(AND(b152="triangle.jpg", c153="p'")), "Correct", "Incorrect")
In psuedocode I want it to run something like this:
if (b152=="oval.jpg" && c152=="q'") or (b152=="triangle.jpg", c153="p'"):
print("YES!")
else
print("False!")
I know I'm missing something here. My current excel code returns false even if the conditions are true. Thanks ahead of time!
OR is a function in Excel, like AND. Try something like this:
=if(OR(AND(b152 = "oval.jpg", c152 = "q'"), AND(b152 = "triangle.jpg", c153 = "p'")), "Correct", "Incorrect")

Resources