The reference doc says that the size constraint:
Uses a Groovy range to restrict the size of a collection or number or
the length of a String.
When I put a size constraint on an integer, I get a warning
Property [prop] of domain class TheClass has type
[java.lang.Integer] and doesn't support constraint [size]. This
constraint will not be checked during validation.
Is the doc wrong?
I know I could use range but it would generally be easier to be able to specify the amount of digits in the number rather than the actual value (like a social security number must have 7 digits or whatever it is, rather than making a range of 1000000 - 9999999).
If you want the number of digits, make sure it's positive and has a certain length:
myInteger( validator: {
return it > 0 && (it.toString.length) == 7
})
I found the answer whilst searching JIRA: http://jira.codehaus.org/browse/GRAILS-947. The doc is wrong.
We don't need minSize, maxSize and size constraints for numeric fields
anymore since this functionality is on min, max and range constraints
respective. So we marking these constraints (for numeric fields only)
as deprecated in 0.5 and will remove it in 0.6.
Looks like it's up to the custom validator.
You can also use max to constrain an integer like myIntProp(max:9999999)
As you pointed out in your Jira link, I think the correct answer for this is to use the range constraint for Integers.
I think this is a simple as replacing size with range.
Related
I'm sort of new to Web2py. I have a system that's working just fine, but I want to make an improvement regarding visualization. There's a couple of fields that use numbers (defined as double in their respective define_table methods) to represent currency, but I want them to also show with a separator for thousands, such as 183,403,293.34. I checked some documentation, but I couldn't find a direct way to handle this form of customization, though I could be missing something.
Any suggestions regarding this? Cheers!
First, if representing currency, you should use the decimal field type rather than double (some calculations using double values may yield incorrect results due to the use of floating point representations internally). However, if using SQLite, there is no distinction between decimal and double, so in that case, you might want to multiply all values by 100 and instead store integers.
In any case, to display a given numeric value with thousands separators in Python, you can do:
'{:,}'.format(myvalue)
For more details, see https://stackoverflow.com/a/10742904/440323 and https://stackoverflow.com/a/21208495/440323.
If you are using the values via web2py functionality that makes use of the field's represent function (e.g., the grid or the .render() method), you can define a custom represent function, such as:
Field('amount', 'decimal(12, 2)',
represent=lambda v, r: '{:,}'.format(v) if v is not None else '')
You could use the Python function of the locale module:
{{= locale.format ('%. 2f', your_value, grouping = True)}}
g.V(123).property('myProperty', myproperty? myProperty: null)
Here myProperty is of integer type and I wish to save an empty value for 'myProperty'.
I know null is not supported. Is there another alternative to achieve the same? (I can't save the value as 0 either)
As there is no notion of null in TinkerPop (for now) I'm afraid that you either have to remove the property or define some sort of constant to represent it. You say that you can't use "zero" but perhaps you could use something like Integer.MIN_VALUE or something? Or, if you are using a graph that doesn't have an explicit schema you could set it to a non-integer value like a "null" string? I can't reall think of any other workarounds.
In CoreImage a CIFilter has both a set of Max/Min values and a set of SliderMax/Min values.
The documentation for the Max/Min says "The maximum/minimum value for a filter parameter" and the SliderMax/Min says "The maximum/minimum value, specified as a floating-point value, to use for a slider that controls input values for a filter parameter."
I'm wondering why these might be different values, as they are, for example, for the inputAngle parameter of CIHueAdjust, where max/min are 0/0 but sliderMax/Min is 3.14/-3.14?
And also what is the use of having the max/min values at 0/0 like they are for most of the filters?
I would wager that a value of 0 means there is no max/min, that any value representable by the datatype is valid for the filter.
As for why there's a separate slider value, it's because what you present to the user is often different than what's accepted. For example, the CIHueAdjust may accept any value for the actual adjustment, but a slider presented to the user has no reason to go outside the range of -3.14..3.14 (because anything outside this range is equivalent to a value inside the range).
I'm using SMOTE to oversample my dataset (affected by class imbalance). Some of my attributes have integer values, others have only two decimals but SMOTE creates new instances with many decimals. So to solve this problems I thought to use NumericCleaner Filter and set the number of decimals I desire. This seems to work but I've got problems with missing values. Each missing values is replaced with a 0.0 value, I need to evaluate my model using missing values in dataset. So how can I use NumericCleaner (or other filters that permit to round values) and keep my missing values?
Very interesting question. Okay, here is the solution:
use SMOTE to oversample the minority group (this produces decimal points but the missing values remain missing values)
then select weka filter->unsupervised->attribute->NumericTransform
then click on this filter and set the attribute instances (where you are having decimal points features) and in the methodName instead of "abs", put "ceil".
I hope that solves the problem.
Using gnumeric, how do I sum the positive values in a range, without
creating a new column?
I'm thinking something along the lines of:
SUM(B21:B25, #>0&)
or
SUM(SELECT(B21:B25, #>0&))
"#>0&" is Mathematica-ese for a function returning true if its
argument is greater than 0, false otherwise.
More generically: how do I apply an aggregate function to cells in a
range that meet a specific condition?
Try using the SUMIF function:
=SUMIF(B21:B25, ">0")
The gnumeric documentation linked above doesn't contain very much detail on the usage of the SUMIF function. The documentation claims that it is Excel compatible, so you may have some luck reading the documentation for Excel's SUMIF function if you want any more information.