Shopify liquid: Compare settings array with metafield value - shopify

I am trying to find a solution for the following problem. I have a list of lenses with different powers. They are starting from -12.00 and going up to +8.00. For the most part, they are 0.50 apart from the next one (6.00, 6.50, 7.00 s.o.).
I have a list with all the possible powers stored under settings, in an array. And then for each available brand of lenses it has a metafield with the minimum available power and the maximum one.
I envisioned it as a comparison, display only the powers from settings that are between these limits. However, I hit a limitation. I can't store 6.5 for example in a metafield as a number, it can only be a string and it makes it hard to compare the settings value with this one.
I tried to use a math filter (times), but the number is rounded. If I have "6.5" and I use times filter, I get "6".
Questions:
1. How would you do this?
2. How can I make sure that each value, if it is not a string, have two decimal places? (e.g. 6.50)

Let's say the metafield is like this product.metafields.power.value = 6.5. Do this:
{% assign power_value = product.metafields.power.value | plus: 0 %}
Boom. power_value is now a number.

Related

NetSuite Grab any inventory numbers with lowercase letters in them

I am trying to make a saved search that shows any inventory numbers with lowercase letter(s) in it. I have tried the following formula but am not having any luck, I have tried using the match parameter but don't want to specify a position for where the lowercase letter may occur, could anyone tell me what I'm doing wrong and what I need to do to correct it?
REGEXP_INSTR({inventorynumber},'%[a-z]%')
I have this in a numeric formula criteria where it is not equal to 0.
In NetSuite Saved Search you do not need to use the wild card (%) with the character class ([]). The following 2 options should work.
REGEXP_INSTR({entityid},'[a-z]')
REGEXP_INSTR({entityid},'[[:lower:]]')

Empty array returned when calling AlphaVantage APIs for NASDAQ tickers

I cannot get any NASDAQ data from the Alpha Vantage TIME_SERIES_DAILY, TIME_SERIES_DAILY_ADJUSTED or TIME_SERIES_INTRADAY -- the returned array is always empty regardless of the equity or index symbol I use:
{}
This is the call I made to get that array:
https://www.alphavantage.co/query?function=TIME_SERIES_DAILY_ADJUSTED&symbol=NASDAQ:^IXIC&interval=15min
Notice I've used the NASDAQ: prefix. I've also tried using NSQ: instead -- with exactly the same results. I don't get this issue when calling for LSE (LON:) or NYSE (NYSE:) data.
I've tried a range of valid and invalid equity ticker symbols (e.g. GOOGL, MSFT) with either the same empty array result returned (if a valid ticker) or an expected error message returned (if an invalid ticker).
Am I doing something wrong here? Is NASDAQ listed using some other random collection of letters?
I've noticed some inconsistency between real-life ticker symbols, and the AV ticker symbols -- often enough that I've created a translation table so I can represent domain-useful information rather than AV-useful information. I'm hoping I'm just using an incorrect or outdated reference to NASDAQ to call the API.
Your help is much appreciated in advance!
TLDR;
Just look up the symbol (ie. AAPL or GOOGL). The IXIC is an index, Alpha Vantage currently does not cover indexes.
Further notes:
Quotes from Alpha Vantage are aggregated, so any price you're getting won't be the price from what it's traded on the NASDAQ, but a quote of what the price is across exchanges.
If you're looking for a specific symbol, you can check for what it's listed as using the search endpoint.
Example here

Using and displaying more than 2 decimal places

I want to use more than 2 decimal places to make calculations with my MS Project project.
So far i wasn't able to find any resource which tells how to show more than 2 decimal in a field (like Work or cost, for example), neither how to truncate numbers instead of rounding them (lets say, USD 12.357 to USD 12.35 instead of USD 12.36).
Is there any way of doing this? It could be through VBA or any method you can come up with.
You can use more than 2 decimal places, just not in the user interface.
The UI truncates displayed and entered values to 2 decimals. However, values entered and accessed via VBA do not have this limitation.
For example, using the Intermediate window (VBA), enter the cost for the first two tasks of the active project and then request the values to prove they are stored as entered, up to 16 digits:
ActiveProject.Tasks(1).Cost = 0.1234567890123456789
ActiveProject.Tasks(2).Cost = 123456789012.123456789
? ActiveProject.Tasks(1).Cost
0.123456789012346
? ActiveProject.Tasks(2).Cost
123456789012.123
To show the value in the UI as stored, customize a text field using the Format function:

I want to remove unwanted symbols from a column in my dataframe. How do I go about doing this? (I'm using Python)

[1]: https://i.stack.imgur.com/FYgSp.png [1]
I've included a link to an image of the head of my dataframe. As you can see, the prices column has periods, commas, dollar signs, as well as prices in different currency.
I would like to iterate through all the elements in the prices column and remove everything except for numbers. Moreover, the only number I want is the number that shows the price of an object in Canadian currency.
Here is the code I've tried
df['prices']=df['prices'].map(lambda x: x.strip('.,'))
This didn't work. I've also tried the following
df['prices']=df['prices'].map(lambda x: x.lstrip('.,').rstrip('CA'))
which also didn't work.
What would you suggest I do? If you could also explain why you use the code that you use, then that would help me immensely in learning the Python language. :)
Try using:
df['prices']=df['prices'].apply(lambda x: re.sub('[^0-9]+', ‘’, x))
Edit: I missed the part where you said you want just the canadian currency. So assuming the the middle part (CA1234) is the format for canadian currency,
df['prices']=df['prices'].apply(lambda x: float(x.split(“,”)[1][2:]))

Handling measurement units in NSTextField

I am creating a test application to calculate the area of a rectangle.This application uses NSTextField control to get the length and breadth of rectangle.
The user is expected to enter a string value which will include units of length as well (Sample Values 2.5 inches, 1500 mm).
I want NSTextField to convert the value in centimeters (cm) automatically so that it displays the converted value (in cm) as soon as the text field looses focus.
For Eg:
User Enters length as: 1500 mm
As soon as user goes to next text field to enter breadth, the length field displays
Displayed Value: 150 cm
How can we achieve this?
I think you want to use the delegate method, controlTextDidEndEditing:, which is sent to your text field's delegate when the editing is finished. Once you get the string from the field editor, you'll need to parse it somehow to find the units (how you parse it depends on what all you need to find). If you have a small number of things you're hunting for, like cm, mm, m, then you could probably just use rangeOfString: and test for 0 length to find out what units were entered. BTW, you should do your math correctly too -- 1500mm = 150 cm
I would consider a different approach, using a UIPicker to display the available units, and have them enter the number separately.
Otherwise, you'll have to do all this parsing. Don't see the point of parsing. Plus, if they make a mistake spelling the units, or use different ways of indicating it, then you would have to account for that as well. Depends on your application, but if the user has to type the units out anyway, it might be more convenient for them to use a UIPicker.