Check if string is a number - constraints

================
| Person |
|--------------|
|- id : String |
|--------------|
================
I have class Person with property id that is String type. I have to check that id is a number that contains 11 digits. I thinking about something like this:
context Person::id:String
inv: self.id->forAll(l|l.oclIsTypeOf(Integer))
and
self.id.size() = 11
but I have feeling that is not correct.
EDIT.
Now im sure it's not correct,
l.oclIsTypeOf(Integer) always return false, because is oclIsTypeOf should be only called on OclAny, when id is a String type.
EDIT 2. (Solution)
I solved it like this:
context Person::id:String
inv: not self.id.toInteger().oclIsInvalid()
and
self.id.size() = 11
Solution provided by Vincent Aranega below should works too

There is not so much methods on String, but the toInteger one can help you there. It returns the Integer value of a String or Invalid if the string cannot be converted to an Integer. So:
context Person::id:String
inv: not self.id.toInteger().oclIsUndefined()
and self.id.size() = 11
should do the trick! (tested with success in Acceleo)

Related

KQL ipv4_is_in_range with datatable

Good day,
Attempting to check IPAddress from SiginLogs with a datatable. I am able to perform the Scalar function ipv4_is_in_range() with a single value. Ips are changed for privacy
ex:
ipv4_is_in_range(IPAddress, '127.0.0.255/24')
When I try to use a declared datatable it does not recognize the values and returns nothing.
ex:
let srcIPs = datatable (checkIP:string) ['127.0.0.1/24'];
SigninLogs
| union srcIPs
| where ipv4_is_in_range( IPAddress, checkIP)
or
let srcIPs = datatable (checkIP:string) [
'127.0.0.1/24',
'8.8.8.8',
'1.1.1.1/16'
];
SigninLogs
| union srcIPs
| where ipv4_is_in_range( IPAddress, checkIP)
if I replace the 'where' with 'extend' I will get one IP address that does show correctly but will include another IP address that is not within that range.
My question is how do I get the function to recognize the values from srcIPs correctly?
#Michael. I went a head a revisited that document and reattempted. The workspace still shows and error when I hover ipv4_lookup stating it is not defined. YET. It still ran, something I didn't attempt. Now the code looks like.
let IP_Data = datatable(network:string)
[
"127.0.0.1",
"8.8.8.8/24",
"192.168.0.1",
"10.0.240.255/21"
];
SigninLogs
| evaluate ipv4_lookup(IP_Data, IPAddress, network)
| where UserType == "Member"
| project-reorder IPAddress, UserPrincipalName
So this code got me what I was looking for. TY all for your assistance.
Answering my own question with working code for record.

Strange behavior with todatetime function

| extend CommandTimeStamp = tostring(customDimensions['CommandTimeStamp'])
| extend originalValue = CommandTimeStamp
| extend constantValue = "11/16/2021 6:04:17 AM +00:00"
| project originalValue, constantValue, equals = (CommandTimeStamp == constantValue), originalTime = CommandTimeStamp, timeColum1 = todatetime(constantValue), timeColum2 = todatetime(CommandTimeStamp)
Get Result:
The last column is empty. It is strange.
Can someone explain it? It blocks us a lot.
the list of supported datetime formats is available here: https://learn.microsoft.com/en-us/azure/data-explorer/kusto/query/scalar-data-types/datetime
the format you're using isn't included in that list, and you may want to first manipulate it in the origin, or using query functions, prior to casting it using todatetime()
the fact that casting the constant string literal works is because it's handled in a separate code path, that (currently) happens to support undocumented formats.

kusto query with dynamic object value without key

I have a lot of data looking like
{"tuesday":"<30, 60>"}
{"friday":"<0, 5>"}
{"saturday":"<5, 10>"}
{"friday":"<0, 5>"}
{"saturday":"<5, 10>"}
{"sunday":"0"}
{"monday":"<0, 5>"}
All i want is the value regardless of the key.
My query:
customEvents
| where name == "eventName"
| extend d = parse_json(tostring(customDimensions.['Properties']))
| project d
| take 7
d is a dynamic object and I can do d.monday for the value, but I'd like to get the value without the key. Is this possible with Kusto?
Thanks
for the case of a single-property as you've demonstrated above, using the parse operator could work:
datatable(d:dynamic)
[
,dynamic({"tuesday":"<30, 60>"})
,dynamic({"friday":"<0, 5>"})
,dynamic({"saturday":"<5, 10>"})
,dynamic({"friday":"<0, 5>"})
,dynamic({"saturday":"<5, 10>"})
,dynamic({"sunday":"0"})
,dynamic({"monday":"<0, 5>"})
]
| parse d with * ':"' value '"' *
| project value
Notes:
In case your values are not necessarily encapsulated in double quotes (e.g. are numerics), then you should be able to specify kind=regex for the parse operator, and use a conditional expression for the existence of the double quotes.
In case you have potentially more than 1 property per property bag, using extract_all() is an option.
Relevant Docs:
https://learn.microsoft.com/en-us/azure/kusto/query/parseoperator
https://learn.microsoft.com/en-us/azure/kusto/query/extractallfunction

How to use OracleDataReader to retrieve schema data and display it the way i want?

I have a table which looks like the following:
date code name score set
09/09/12 967873 Team A 24 1
09/09/12 967873 Team B 22 1
09/09/12 967873 Team A 21 2
09/09/12 967873 Team B 16 2
02/04/12 965454 Team X 21 1
02/04/12 965454 Team Y 19 1
02/04/12 965454 Team X 21 2
02/04/12 965454 Team Y 19 2
you guessed it right! it's a volleyball match! however, I would like my output to be in a single line (I already have retrieved the above table from database). For example:
date code Teams Set-1 Set-2 Set-3
09/09/12 967873 Team A VS.Team B 24-22 21-16 -
and so on....
I would like to use vb.net dataReader and html tables/dataset to put the above table in the right format for the user, but having trouble with the algorithm.
**Notice that the game could have a third set as well
Thanks,
... This could be overkill, but I would do this by just creating a custom object where you can parse out the data the way you need it.
For example:
Public Class VolleyBallData
Public Property dbDate As String
Public Property dbCode As String
Private _Teams(2) As String
Public WriteOnly Property dbTeams As String
Set(ByVal value As String)
_Teams = Value.Split({" VS."}, StringSplitOptions.None)
End Set
End Property
Private _Set1(2) As String
Public WriteOnly Property dbSet1 As String
Set(ByVal value As String)
_Set1 = Value.Split({"-"}, StringSplitOptions.None)
End Set
End Property
...
Then, you could just create an output function from your custom object that outputs the data in exactly the way you need it into, say, a List(of DataRow), given that you know that each first element in each array is Team 1's data and each second element is Team 2's.
Then just add those rows to your parent datatable.
Or, quite honestly, you could just as easily do this via functions... I just like custom objects for data validation purposes.
Hope this makes sense...

Comparing two non-numeric values, selecting lower in ASP.NET/VB.NET

I am updating an application I've written used by my employer, a University, to allow students to register for their desired residence hall.
I'm working on a new feature that will allow students to "partner" with another student - so that when one or the other registers for a room, the other student will be registered as well.
Now, let us say we have John Doe and James Doe - and they partner with each other for room registration. The time when students is staggered based on their current class level. I need a way to determine (without a billion IF..THEN statements) which student has the lower class level. The values for class level are FR, SO, JR, SR, 5SR (from most junior to most senior).
In the above example, John Doe might be a FR while James Doe may be a SR. Neither James nor John should be allowed to register until FR's are allowed to register - since that is the partnerships "base" class level.
Essentially I want to do something like:
IF John_Doe_Class_Level < James_Doe_Class_Level Then
Partnership_Class_Level = John_Doe_Class_Level
Else
Partnernship_Class_Level = James_Doe_Class_Level
End If
Any idea how to accomplish this effectively?
Where do you define your class levels? If it is in the code, use enums with associated numeric values.
Public Enum ClassLevel As Integer
FR = 0
SO = 1
JR = 2
End Enum
Public Class Student
Public Property Name As String
Public Property Level As ClassLevel
End Class
Public Sub TestIt(ByVal studentA As Student, ByVal studentB As Student)
If studentA.Level > studentB.Level Then
' dostuff
End If
End Sub
I know I'm clearly missing something, but if you assign these class levels to an enum, why wouldn't the above work?
public enum ClassLevel
{
FR=1,
SO=2,
JR=2,
SR=3,
5SR=4
}
etc
IF John_Doe.ClassLevel < JamesDoe.Class_Level Then
Partnership.Class_Level = John_Doe.ClassLevel
Else
Partnernship.Class_Level = James_Doe.ClassLevel
End If
I would run the values through function that returns a number then compare those values to each other. Something like...
IF numericClassLevel(John_Doe_Class_Level) < numericClassLevel(John_Doe_Class_Level) Then
Partnership_Class_Level = John_Doe_Class_Level
Else
Partnernship_Class_Level = James_Doe_Class_Level
End If
public function numericClassLevel(strClassLevel) as integer
select case strLevel
case "FR"
return 1
etc.
end select
end function

Resources