JSON Statments and Syntax for Machine Learning - json

How do I do statements in JSON? E.g. If, and, or, else? I GENUINELY can't find how to or the syntax. Anyhow, here is my attempt building off my other question; trying to get a script to-re-execute after winning or losing against the A.I. I'm creating for Street Fighter II CE: How to repeat a Machine Learning script using a For Loop?. Has many issues according to PyCharm Community Edition - but I have no idea what...
{
"done": {
"variables": {
"continuetimer": {
"op": "equal",
"reference": 10
}
}
},
"reward": {
"variables": {
"score": {
"reward": 1.0
}
}
},
"crop": [0, 16, 256, 200]
}
'if' : {"done": break}
if ("done") {
break;
} else {
("continuetime"")}

Related

Why Isn't my custom entity shooting fireballs? (Minecraft Bedrock Addon Making)

I'm fairly new in making addons for Minecraft Bedrock, and right now I'm trying to make an addon that adds the "Wildfire" mob from the Minecon votes. And I basically got everything right I got the model, the animations and the melee attack. But, for some reason the "Wildfire" won't shoot the "fireballs" I basically copied the code from the vanilla Minecraft entity Blaze code. I've searched everywhere but no luck since theres not much topics/q&a on Minecraft Bedrock. I have no idea why this won't work. Please help me, thanks in advance!
"mode_switcher": {
"minecraft:target_nearby_sensor": {
"inside_range": 2.0,
"outside_range": 3.0,
"must_see": true,
"on_inside_range": {
"event": "switch_to_melee",
"target": "self"
},
"on_outside_range": {
"event": "switch_to_ranged",
"target": "self"
}
}
},
"ranged_mode": {
"minecraft:behavior.ranged_attack": {
"priority": 3,
"burst_shots": 3,
"burst_interval": 0.3,
"charge_charged_trigger": 0.0,
"charge_shoot_trigger": 4.0,
"attack_interval_min": 3.0,
"attack_interval_max": 5.0,
"attack_radius": 16.0
},
"minecraft:shooter": {
"def": "minecraft_small_fireball"
}
},
"events": {
"minecraft:entity_spawned": {
"add": {
"component_groups": [
"mode_switcher"
]
}
},
"switch_to_melee": {
"remove": {
"component_groups": [
"ranged_mode"
]
},
"add": {
"component_groups": [
"melee_mode"
]
}
},
"switch_to_ranged": {
"remove": {
"component_groups": [
"melee_mode"
]
},
"add": {
"component_groups": [
"ranged_mode"
]
}
},
"minecraft:on_hurt_event": {
"add": {
"component_groups": [
"mode_switcher"
]
}
}
}
This is not all the code Its just the code that's related to it. Please tell me if you want all of the code.
I finally solved it. Well I guess not solve it because im still not to sure on what the problem was but, what I did was I used the code from the blaze in the Minecraft Beta version. That fixed it the only difference I found was that in the "ranged_mode" the "minecraft:shooter" component was before the "minecraft:behavior_ranged_attack".
You may have been mixing code from multiple format versions like I did before I realized that there was a difference. It could also be possible that you didn't make its attack range large enough, I also didn't see any code that selects a target for it to target. For any attacks to work you will need to make it select a target first. It look like you have only included code that allows it to swap attack types for a selected target. Keep this in mind when making behaviors in the future.

How to call stored painless script function in elastisearch

I am trying to use an example from
https://www.elastic.co/guide/en/elasticsearch/reference/6.4/modules-scripting-using.html
I have created a function and saved it.
POST http://localhost:9200/_scripts/calculate-score
{
"script": {
"lang": "painless",
"source": "ctx._source.added + params.my_modifier"
}
}
Try to call saved function
POST http://localhost:9200/users/user/_search
{
"query": {
"script": {
"script": {
"id": "calculate-score",
"params": {
"my_modifier": 2
}
}
}
}
}
And it returns an error: Variable [ctx] is not defined. I tried to use doc['added'] but received the same error. Please help me understand how to call the function.
You should try using doc['added'].value, let me explain you why and how. In short, because painless scripting language is rather simple but obscure.
Why can't ES find ctx variable?
The reason it cannot find ctx variable is because this painless script runs in "filter context" and such variable is not available in filter context. (If you are curious, there were 18 types of painless context as of ES 6.4).
In filter context there are only two variables available:
params (Map, read-only)
User-defined parameters passed in as part of the query.
doc (Map, read-only)
Contains the fields of the current document where each field is a List of values.
It should be enough to use doc['added'].value in your case:
POST /_scripts/calculate-score
{
"script": {
"lang": "painless",
"source": "doc['added'].value + params.my_modifier"
}
}
Should, because there will be another problem if we try to execute it (exactly like you did):
"type": "script_exception",
"reason": "runtime error",
"script_stack": [
"doc['added'].value + params.my_modifier",
"^---- HERE"
],
"script": "calculate-score",
"lang": "painless",
"caused_by": {
"type": "class_cast_exception",
"reason": "cannot cast def [long] to boolean"
}
Because of its context, this script is expected to return a boolean:
Return
boolean
Return true if the current document should be returned as a
result of the query, and false otherwise.
At this point we can understand why the script you were trying to execute did not make much sense for Elasticsearch: it is supposed to tell if a document matches a script query or not. If a script returns an integer, Elasticsearch wouldn't know if it is true or false.
How to make a stored script work in filter context?
As an example we can use the following script:
POST /_scripts/calculate-score1
{
"script": {
"lang": "painless",
"source": "doc['added'].value > params.my_modifier"
}
}
Now we can access the script:
POST /users/user/_search
{
"query": {
"script": {
"script": {
"id": "calculate-score1",
"params": {
"my_modifier": 2
}
}
}
}
}
And it will return all documents where added is greater than 2:
"hits": [
{
"_index": "users",
"_type": "user",
"_id": "1",
"_score": 1,
"_source": {
"name": "John Doe",
"added": 40
}
}
]
This time the script returned a boolean and Elasticsearch managed to use it.
If you are curious, range query can do the same job, without scripting.
Why do I have to put .value after doc['added']?
If you try to access doc['added'] directly you may notice that the error message is different:
POST /_scripts/calculate-score
{
"script": {
"lang": "painless",
"source": "doc['added'] + params.my_modifier"
}
}
"type": "script_exception",
"reason": "runtime error",
"script_stack": [
"doc['added'] + params.my_modifier",
" ^---- HERE"
],
"script": "calculate-score",
"lang": "painless",
"caused_by": {
"type": "class_cast_exception",
"reason": "Cannot apply [+] operation to types [org.elasticsearch.index.fielddata.ScriptDocValues.Longs] and [java.lang.Integer]."
}
Once again painless shows us its obscurity: when accessing the field 'added' of the document, we obtain an instance of org.elasticsearch.index.fielddata.ScriptDocValues.Longs, which Java Virtual Machine denies to add to an integer (we can't blame Java here).
So we have to actually call .getValue() method, which, translated in painless, is simply .value.
What if I want to change that field in a document?
What if you want to add 2 to field added of some document, and save the updated document? Update API can do this.
It operates in update context, which actually has got ctx variable defined, which in turn has access to the original JSON document via ctx['_source'].
We might create a new script:
POST /_scripts/add-some
{
"script": {
"lang": "painless",
"source": "ctx['_source']['added'] += params.my_modifier"
}
}
Now we can use it:
POST /users/user/1/_update
{
"script" : {
"id": "add-some",
"params" : {
"my_modifier" : 2
}
}
}
Why the example from the documentation doesn't work?
Apparently, because it is wrong. This script (from this documentation page):
POST _scripts/calculate-score
{
"script": {
"lang": "painless",
"source": "Math.log(_score * 2) + params.my_modifier"
}
}
is later executed in filter context (in a search request, in a script query), and, as we now know, there is no _score variable available.
This script would kind of make sense only in score context, when running a funtion_score query which allows to twiggle the relevance score of the documents.
Final note
I would like to mention that in general, it's recommended to avoid using scripts because their performance is poor.

Error in Targeting Company Shares Using JSON

I'm trying to Target company shares (https://developers.linkedin.com/documents/targeting-company-shares) using json with LinkedIn Rest Api.
My JSON object (https://developers.linkedin.com/forum/targeting-example-using-multiple-targeting-parameters-and-json) looks like :
{
"visibility": {
"code": "anyone"
},
"comment": "Targeting Shares",
"share-target-reach": {
"share-targets": {
"share-target": [{
"code": "geos",
"tvalues": {
"tvalue": "as"
}
}, {
"code": "companySizes",
"tvalues": {
"tvalue": "201-500"
}
}]
}
}
}
But this isn't working, i'm getting the following error :
{
"errorCode": 0,
"message": "Malformed json document. Encountered unexpected array.",
"requestId": "DRWYRUVMBJ",
"status": 400,
"timestamp": 1423283491818
}
I'm not able to figure out where's the problem??
I have been playing around with this for awhile now and near as I can tell the below format will work. Basically you have to remove all the arrays, I have tried them at every level and they always cause the malformed json error. I still have no idea how to target multiple sections at once though, since the official documentation on this is very wrong. The only way I figured this part out is by doing a whole lot of guessing.
{
"visibility": {
"code": "anyone"
},
"comment": "Targeting Shares",
"share-target-reach": {
"share-targets": {
"share-target": {
"code": "geos",
"tvalues": {"tvalue": "as"}
}
}
}

Attempt by method 'System.Web.Helpers.Json.Decode(System.String)' to access field 'System.Web.Helpers.Json._serializer' failed

I have the following JSON;
{
"b2c": {
"languages": {
"de": {
"models": {
"t300": {
"name": "Aveo",
"bodyTypes": {
"t300-4d-my13": {
"trimLevels": {
"lt": {
"name": "LT",
"variants": {
"1.2_16V_86_Gas_MT": {
"name": "1.2 MT",
"price": {
"EUR": {
"value": 13990,
"formatted": "13.990,00 €"
}
},
"infoFeatures": {
"fuel_consumption_extra_urban#consumption": {
"name": "Kraftstoffverbrauch außerorts ",
"value": "4.6",
"formatted": "4,6"
},
"top_speed#kilometer_per_hour": {
"name": "Höchstgeschwindigkeit",
"value": "171",
"formatted": "171"
}
},
"images": null,
"documents": null
}
}
}
}
}
}
}
}
}
}
}
}
The values of b2c, de, t300, t300-4d-my13, It etc.. are dynamic but languages, models, bodyTypes, trimLevels, variants, inforFeatures, images and documents would remain same.
I need to extract all to access values like languages.["de"], models.["t300"].name, timeLevels.["It"], Variants and infoFeatures, as these keys [""] are dynamics so I am not sure what to refer.
I have tried,
var jsonSerializer = new JsonSerializer();
dynamic dynamicObject = jsonSerializer.Deserialize(new JsonTextReader(new StringReader(jsonString)));
//var level1 = dynamicObject.b2c
I have looked this as well
Deserialize JSON into C# dynamic object?
and tried
var dynamicObject = Json.Decode(jsonString);
but receiving following error;
Attempt by method 'System.Web.Helpers.Json.Decode(System.String)' to access field 'System.Web.Helpers.Json._serializer' failed.
For us it helped to uncheck "Enable the Visual Studio hosting process" in the Project properties > Debug tab, from the top answer to Attempt by method 'System.Web.Helpers.Json..cctor()' to access method 'System.Web.Helpers.Json.CreateSerializer()' failed
A general solution would be to use something like Json.net and serialize to C# Object - this is very flexible, and does not conflict with the dynamic nature of the json object coming from the client.
This error seems to occur when you have multiple projects with different versions of assemblies; eg, if you have JSON.NET 4.5.1 in one project and 5.0.6 in another. Things seem to get sorted if you make sure the same versions exist everywhere in the solution.

Using Oracle UCM JSON data in fullcalendar?

Is there a way to fetch data from Oracle UCM's JSON option and use this in Full Calendar. I createed a service to return data from calendar data in UCM, and want to display the events using fullcalendar.
Here is an example feed that I get back:
"ResultSets": {
{
"SQLLMCal": {
"fields": [
{ "name": "SINGLE_ELEMENT" },
{ "name": "Start" },
{ "name": "SCHOOL_TYPE" },
{ "name": "SCHOOL_TYPE_ID" },
{ "name": "Title" },
{ "name": "ENTRY_SIDE_GROUP" }
],
"rows": [
[
"141",
"3/17/11 12:00 AM",
"Elementary",
"3",
"Big Burger",
"1"
]
]
}
}
}
Thanks, Ken
need to parse your own data using a custom events function:
http://arshaw.com/fullcalendar/docs/event_data/events_function/
Okay, great example of "problem exists between keyboard and chair"! I just had to stare at the documentation and the answer was right there.
In my code, I have the following:
events: function(callback) {
By definition, this MUST be
events: function(start, end, callback) {
Once I added the start and end parameters, everything worked perfectly.
Thank you Adam for pointing me the the right direction!
Ken