How to use Resolve over custom domain - wolfram-mathematica

A = {1,2,3,4}
ForAll[x, Element[A,x], x+1>0 ]
Resolve[%]
The above code gives me the following error:
Unable to resolve the domain or region membership condition {1,2,3,4}[Element]x.

I think you have the arguments to Element[A,x] backwards, because A is your domain and x is an element of that domain. Just reversing those is not sufficient to eliminate the error message, but this appears to be enough.
A = {1,2,3,4};
ForAll[x, Element[x,Integers]&&0<x<5, x+1>0 ];
Resolve[%]
which returns True

Related

Powerautomate Parsing JSON Array

I've seen the JSON array questions here and I'm still a little lost, so could use some extra help.
Here's the setup:
My Flow calls a sproc on my DB and that sproc returns this JSON:
{
"ResultSets": {
"Table1": [
{
"OrderID": 9518338,
"BasketID": 9518338,
"RefID": 65178176,
"SiteConfigID": 237
}
]
},
"OutputParameters": {}
}
Then I use a PARSE JSON action to get what looks like the same result, but now I'm told it's parsed and I can call variables.
Issue is when I try to call just, say, SiteConfigID, I get "The output you selected is inside a collection and needs to be looped over to be accessed. This action cannot be inside a foreach."
After some research, I know what's going on here. Table1 is an Array, and I need to tell PowerAutomate to just grab the first record of that array so it knows it's working with just a record instead of a full array. Fair enough. So I spin up a "Return Values to Virtual Power Agents" action just to see my output. I know I'm supposed to use a 'first' expression or a 'get [0] from array expression here, but I can't seem to make them work. Below are what I've tried and the errors I get:
Tried:
first(body('Parse-Sproc')?['Table1/SiteConfigID'])
Got: InvalidTemplate. Unable to process template language expressions in action 'Return_value(s)_to_Power_Virtual_Agents' inputs at line '0' and column '0': 'The template language function 'first' expects its parameter be an array or a string. The provided value is of type 'Null'. Please see https://aka.ms/logicexpressions#first for usage details.'.
Also Tried:
body('Parse-Sproc')?['Table1/SiteconfigID']
which just returns a null valued variable
Finally I tried
outputs('Parse-Sproc')?['Table1']?['value'][0]?['SiteConfigID']
Which STILL gives me a null-valued variable. It's the worst.
In that last expression, I also switched the variable type in the return to pva action to a string instead of a number, no dice.
Also, changed 'outputs' in that expression for 'body' .. also no dice
Here is a screenie of the setup:
To be clear: the end result i'm looking for is for the system to just return "SiteConfigID" as a string or an int so that I can pipe that into a virtual agent.
I believe this is what you need as an expression ...
body('Parse-Sproc')?['ResultSets']['Table1'][0]?['SiteConfigID']
You can see I'm just traversing down to the object and through the array to get the value.
Naturally, I don't have your exact flow but if I use your JSON and load it up into Parse JSON step to get the schema, I am able to get the result. I do get a different schema to you though so will be interesting to see if it directly translates.

Passing variable as a parameter for Set-MpPreference

I'm trying to configure Windows Defender via Set-MpPreference.
This is my code:
$ASRIds = "01443614-cd74-433a-b99e-2ecdc07bfc25,92E97FA1-2EDF-4476-BDD6-9DD0B4DDDC7B"
$ASRValues = "1,1"
Set-MpPreference -AttackSurfaceReductionRules_Ids $ASRIds -AttackSurfaceReductionRules_Actions $ASRValues
however, I am getting error
Set-MpPreference : Cannot process argument transformation on parameter 'AttackSurfaceReductionRules_Actions'. Cannot
convert value "1,1" to type "Microsoft.PowerShell.Cmdletization.GeneratedTypes.MpPreference.ASRRuleActionType[]".
Error: "Cannot convert value "1,1" to type
"Microsoft.PowerShell.Cmdletization.GeneratedTypes.MpPreference.ASRRuleActionType". Error: "Unable to match the
identifier name 1,1 to a valid enumerator name. Specify one of the following enumerator names and try again:
Disabled, Enabled, AuditMode""
At line:1 char:96
+ ... tionRules_Ids $ASRIds -AttackSurfaceReductionRules_Actions $ASRValues
+ ~~~~~~~~~~
+ CategoryInfo : InvalidData: (:) [Set-MpPreference], ParameterBindingArgumentTransformationException
+ FullyQualifiedErrorId : ParameterArgumentTransformationError,Set-MpPreference
I know that this can be done directly like this:
Set-MpPreference -AttackSurfaceReductionRules_Ids 1443614-cd74-433a-b99e-2ecdc07bfc25,92E97FA1-2EDF-4476-BDD6-9DD0B4DDDC7B -AttackSurfaceReductionRules_Actions 1,1
but passing it as variable is a necessary part of my project. Is there anything I can do to make the variables work?
One by one (working with only one attack surface reduction rule at the time) works, but Windows Defender disabled the other rules if you enable just one. So I need to have multiple IDs in the variable at the same time.
Thanks
I'm guessing this is not liking the fact that you're passing a string - try passing an array arrays:
$ASRIds = #("01443614-cd74-433a-b99e-2ecdc07bfc25","92E97FA1-2EDF-4476-BDD6-9DD0B4DDDC7B")
$ASRValues = #(1,1)
Troubleshooting Notes
The [] in your error is telling us it is expecting an array
...Microsoft.PowerShell.Cmdletization.GeneratedTypes.MpPreference.ASRRuleActionType[]...
This part is telling us it's trying to match the whole string 1,1 to an enumerator - it should be matching one at a time.
Unable to match the identifier name 1,1 to a valid enumerator name
I'm guessing you want to specify Enabled? Consider this, to make your code more readable: $ASRValues = #('Enabled','Enabled')
Specify one of the following enumerator names and try again:
Disabled, Enabled, AuditMode
As for the error in the comments, well...

Using Twilio SDK, Call Array of Numbers Consecutively Until Someone Picks Up

I'm working on building a call center functionality that when receiving an inbound call, it dials through a list of agent's phone numbers (as determined by a separate piece of code) and on the first number connection we break out of the code and run a separate function to connect the agent into a queue where the customer is waiting. This is being built in Laravel 5.7 since there are some other future dashboards that are being created and I wanted to place it in the code the team is going to use.
The initial customer queueing and connecting the agent to the call seems to be working.
I am looking for help with the following code:
public function findAgentByPriority($agentCount) {
$twilio = new Client(env('TWILIO_SID'),env('TWILIO_SECRET'));
// test numbers
$agentArr[] = ["agent" => env('TWILIO_TEST_AGENT1')];
$agentArr[] = ["agent" => env('TWILIO_TEST_AGENT2')];
// $agentArr = json_encode($agentArr);
//build the array by querying /api/v1/agile/users
$numbers = $agentArr;
// this part of the code will call one person after the next
// call the next number
if($agentCount == NULL){
$agentCount = count($numbers);
echo "in if<br>";
$call = $twilio->calls
->create(
$numbers[0],
env('TWILIO_MAIN_NUMBER'),
[
"url" => "https://{$_SERVER['HTTP_HOST']}/ivr/connect-agent",
"statusCallback" => "https://{$_SERVER['HTTP_HOST']}/ivr/next-agent?c=$agentCount",
"timeout" => 20
]
);
}elseif($agentCount > 0){
// when we run out of numbers move out of the loop
$agentCount = 0;
}else{
// when we run out of numbers move out of the loop
}
// once there are no more agents that were logged in today we
// will move to dial cell phone fallback for 40s
// and last we'll call on the voicemail function
}
And here is our connectAgent function that the connect-agent route is calling.
public function connectAgent() {
$response = new Twiml\VoiceResponse;
$dequeue = $response->dial('');
$dequeue->queue('main');
}
I was thinking basically have the "statusCallback" shoot to a new method when we read that there was "no-answer" and call the next number in line. I don't know how to keep track of what numbers are left by passing a variable through the callback. Would setting it into a database be better and do something like look for any remaining arrayIDs where records still exist and dial down the next one? I could establish the array and it's parameters in the database on the first function call.
I could avoid the issue of two people calling at once and messing up the code by just building out different arrayIDs and only going through one set at a time.
Any guidance is appreciated!
UPDATE
PHP's server was causing infinite loops. Moving testing to my vagrant box has resolved this so now I can call on the Laravel route from the same server without issue. This along with the answer of passing an array through the callback has helped me solve this problem. Updated code to follow for reference.
this following issue helped me figure out the second request getting stuck issue: Calling route from same server causes an infinite loop
Twilio developer evangelist here.
What you could do is add the current number as a query parameter to the statusCallback URL. That way, when the callback is called you can find that number in your list of numbers and then move on to the next one. This way you don't need to store anything in the database.
Let me know if that helps at all.

How to print validation error outside of field constructor in Play framework 2

How can I show a validation error for a form field outside of a field constructor in Play framework 2? Here is what I tried:
#eventForm.("name").error.message
And I get this error:
value message is not a member of Option[play.api.data.FormError]
I'm confused because in the api docs it says message is a member of FormError. Also this works fine for global errors:
#eventForm.globalError.message
You can get a better grasp of it checking Form's sourcecode here
Form defines an apply method:
def apply(key: String): Field = Field(
this,
key,
constraints.get(key).getOrElse(Nil),
formats.get(key),
errors.collect { case e if e.key == key => e },
data.get(key))
That, as said in the doc, returns any field, even if it doesn't exist. And a Field has an errors member which returns a Seq[FormError]:
So, you could do something like that (for the Seq[FormError]):
eventForm("name").errors.foreach { error =>
<div>#error.message</div>
}
Or (for the Option[FormError])
eventForm("name").error.map { error =>
<div>#error.message</div>
}
Or, you could use Form errors:
def errors(key: String): Seq[FormError] = errors.filter(_.key == key)
And get all errors of a given key. Like this (for the Seq[FormError]):
eventForm.errors("name").foreach { error =>
<div>#error.message</div>
}
Or (for the Option[FormError])
eventForm.error("name").map { error =>
<div>#error.message</div>
}
If you want more details, check the source code. It's well written and well commented.
Cheers!
EDIT:
As biesior commented: to show human readable pretty messages with different languages you have to check how play works I18N out here
To be thorough you're probably going to have to deal with I18N. It's not hard at all to get it all working.
After reading the documentation you may still find yourself a bit consufed. I'll give you a little push. Add a messages file to your conf folder and you can copy its content from here. That way you'll have more control over the default messages. Now, in your view, you should be able to do something like that:
eventForm.errors("name").foreach { error =>
<div>#Messages(error.message, error.args: _*)</div>
}
For instance, if error.message were error.invalid it would show the message previously defined in the conf/messages file Invalid value. args define some arguments that your error message may handle. For instance, if you were handling an error.min, an arg could be the minimum value required. In your message you just have to follow the {n} pattern, where n is the order of your argument.
Of course, you're able to define your own messages like that:
error.futureBirthday=Are you sure you're born in the future? Oowww hay, we got ourselves a time traveler!
And in your controller you could check your form like that (just one line of code to show you the feeling of it)
"year" -> number.verifying("error.furtureBirthday", number <= 2012) // 2012 being the current year
If you want to play around with languages, just follow the documentation.
Cheers, again!
As you said yourself, message is a member of FormError, but you have an Option[FormError]. You could use
eventForm("name").error.map(_.message).getOrElse("")
That gives you the message, if there is an error, and "" if there isn't.

Getting error: **Enumeration yielded no results**

I'm getting the error Enumeration yielded no results while doing:
IEnumerable<Proxy> pxys = this._ticket.AllProxies.Where(p => p.IfBusy.Equals(false));
The reason you would get that error message is one of 2 reasons, either this._ticket.AllProxies contains no items (e.g. it is an empty collection) or none of the proxies in the collection have a value of false for their IfBusy property.

Resources