I am playing around with elm-css.
Most of the things work as I expect them.
But I am not able to give a correct value to the Css.opacity function.
Here is what I have tried:
Css.opacity 0.5
which gives the error:
Function `opacity` is expecting the argument to be:
Css.Number compatible
But it is:
Float
The Css.Number is a type alias in the following form:
type alias Number compatible =
{ compatible | value : String, number : Compatible }
But I don't understand how to create a valid value for the Css.opacity function...
You can create input for opacity by using one of the "unitless" functions, like Css.int or Css.num. For example:
-- 42% opaque
translucent = Css.opacity (Css.num 0.42)
It is "unitless" because the CSS property of opacity does not define a unit like px or percent.
Related
I have a column called "Bakery Activity" whose values are all JSONs that look like this:
{"flavors": [
{"d4js95-1cc5-4asn-asb48-1a781aa83": "chocolate"},
{"dc45n-jnsa9i-83ysg-81d4d7fae": "peanutButter"}],
"degreesToCook": 375,
"ingredients": {
"d4js95-1cc5-4asn-asb48-1a781aa83": [
"1nemw49-b9s88e-4750-bty0-bei8smr1eb",
"98h9nd8-3mo3-baef-2fe682n48d29"]
},
"numOfPiesBaked": 1,
"numberOfSlicesCreated": 6
}
I'm trying to extract the number of pies baked with a regex function in Tableau. Specifically, this one:
REGEXP_EXTRACT([Bakery Activity], '"numOfPiesBaked":"?([^\n,}]*)')
However, when I try to throw this calculated field into my text table, I get an error saying:
ERROR: function regexp_matches(jsonb, unknown) does not exist;
Error while executing the query
Worth noting is that my data source is PostgreSQL, which Tableau regex functions support; not all of my entries have numOfPiesBaked in them; when I run this in a simulator I get the correct extraction (actually, I get "numOfPiesBaked": 1" but removing the field name is a problem for another time).
What might be causing this error?
In short: Wrong data type, wrong function, wrong approach.
REGEXP_EXTRACT is obviously an abstraction layer of your client (Tableau), which is translated to regexp_matches() for Postgres. But that function expects text input. Since there is no assignment cast for jsonb -> text (for good reasons) you have to add an explicit cast to make it work, like:
SELECT regexp_matches("Bakery Activity"::text, '"numOfPiesBaked":"?([^\n,}]*)')
(The second argument can be an untyped string literal, Postgres function type resolution can defer the suitable data type text.)
Modern versions of Postgres also have regexp_match() returning a single row (unlike regexp_matches), which would seem like the better translation.
But regular expressions are the wrong approach to begin with.
Use the simple json/jsonb operator ->>:
SELECT "Bakery Activity"->>'numOfPiesBaked';
Returns '1' in your example.
If you know the value to be a valid integer, you can cast it right away:
SELECT ("Bakery Activity"->>'numOfPiesBaked')::int;
I found an easier way to handle JSONB data in Tableau.
Firstly, make a calculated field from the JSONB field and convert the field to a string by using str([FIELD_name]) command.
Then, on the calculated field, make another calculated field and use function:
REGEXP_EXTRACT([String_Field_Name], '"Key_to_be_extracted":"?([^\n,}]*)')
The required key-value pair will form the second caluculated field.
I'm modeling a count up/down timer. After the origin date is set, the timer displays how much time has passed since-, or remains till that origin date.
type OriginDefined
= Up Date
| Down Date
type Origin
= OriginDefined
| OriginUndefined
type Model
= Tick OriginDefined
| Edit Origin
Thus, the timer is ticking only when the origin date is defined. When the origin is edited though, it may or may not be previously defined.
Now I need a function to return the defaultValue for the date input, when we're in the Edit mode.
dateInputDefaultValue : Origin -> String
dateInputDefaultValue origin =
case origin of
OriginUndefined ->
""
OriginDefined ->
...
Here I struggle to destructure the origin further as an Up date or Down date. In the 2nd branch of the case expression the compiler refuses to treat the origin as anything more specific than just an Origin.
Here's an Ellie https://ellie-app.com/3zKCcX87wa1/0
How should I deal with a model like that? Should I model in a different way?
Your types compile, but you have two different definitions of OriginDefined: One is a type called OriginDefined which has two constructors, Up and Down. The other is a parameterless constructor on the type Origin.
My hunch is that you were trying to get the OriginDefined constructor on Origin to carry a value of type OriginDefined. In order to do that, you would have to define a parameter of type OriginDefined on the OriginDefined constructor:
type Origin
= OriginDefined OriginDefined
| OriginUndefined
Now you have a type that is isomorphic to Elm's Maybe type, so perhaps it would be less confusing and more idiomatic to remove the OriginDefined type and replace the definition of Origin with this:
type Origin
= Up Date
| Down Date
Now you can use Maybe in the places you were previously using defined/undefined nomenclature:
type Model
= Tick (Maybe Origin)
| Edit Origin
Pattern matching on Maybe Origin could look like this:
dateInputDefaultValue : Maybe Origin -> String
dateInputDefaultValue origin =
case origin of
Nothing ->
""
Just (Up date) ->
"…"
Just (Down date) ->
"…"
I am trying to get a column in a dataframe form float to string. I have tried
df = readtable("data.csv", coltypes = {String, String, String, String, String, Float64, Float64, String});
but I got complained
syntax: { } vector syntax is discontinued
I also have tried
dfB[:serial] = string(dfB[:serial])
but it didn't work either. So, I'd like to know what would be the proper approach to change column data type in Julia.
thx
On your first attempt, Julia tells you what the problem is - you can't make a vector with {}, you need to use []. Also, the name of the keyword argument should be eltypes rather than coltypes.
On the second try, you don't have a float, you have a Vector of floats. So to change the type you need to change the type of all elements. In Julia, elementwise operations on vectors are generalized by the 'dot' syntax, e.g. string.(collect(dfB[:serial])) . The collect is needed currently to cast the DataArray to a normal Array first – this will fail if the DataArray contains NAs. IMHO the DataFrames interface is still rather wonky, so expect a few headaches like this ATM.
I am trying to pass through an int value as a prop.
So if I call:
<job-cards-create :jobno="1203"></job-cards-create>
I get:
But if I add even one '0' infront:
<job-cards-create :jobno="01203"></job-cards-create>
It gives:
What is going on? Am I missing something?
This is because your number 01203 is being interpreted as an octal number due to the leading zero. Check out these examples:
01203 === 643 // true
01203.toString() // "643"
Here is some documentation on octals in JS
Do you really need it to be a number? It doesn't look like you're going to be performing any calculations on it. Just knock off the v-bind and use a string literal instead:
<job-cards-create jobno="01203"></job-cards-create>
In my plugin I get property as an input parameter. I'm trying to get property value at particular cell. I've checked that value at the cell is really defined, but I get Nan.
Code sample:
double permValueCell;
Index3 TestIndex = new Index3(54,8,7);
permValueCell = _propPermeability[TestIndex];
Firstly I thought that there is some problem in getting property as parameter, but during debug I saw that description section of the property displays a correct name. What can be wrong ?
In Petrel, the cell index seen in the UI is not the same as stored in Ocean.
You can convert between the two by using the ModelingUnitSystem class in Petrel 2014.
Look at :
Slb.Ocean.Petrel.ModelingUnitSystem.ConvertIndexFromUI
Slb.Ocean.Petrel.ModelingUnitSystem.ConvertIndexToUI