Adding multiple values in multiple entries via jq - jq

Suppose I have some json formatted something like this (I've removed the bits I'm not interested in, I can filter those out):
{
"name": "db1",
"size": 40000,
"items": 500,
"mutations": 2,
"tombstones": 4,
"views_count": 8,
"fts_count": 0,
"index_count": 0,
"analytics_count": 0
}
{
"name": "db2",
"size": 11,
"items": 900,
"mutations": 3,
"tombstones": 0,
"views_count": 0,
"fts_count": 0,
"index_count": 0,
"analytics_count": 0
}
{
"name": "db1",
"size": 10,
"items": 6,
"mutations": 5,
"tombstones": 0,
"views_count": 0,
"fts_count": 0,
"index_count": 1,
"analytics_count": 0
}
How can I get a summary of all the elements of the entry, but only for each name (here we can see db1 mentioned twice so I'd like something like this):
{
"name": "db1",
"size": 40010,
"items": 506,
"mutations": 8,
"tombstones": 4,
"views_count": 8,
"fts_count": 0,
"index_count": 1,
"analytics_count": 0
}
{
"name": "db2",
"size": 11,
"items": 900,
"mutations": 3,
"tombstones": 0,
"views_count": 0,
"fts_count": 0,
"index_count": 0,
"analytics_count": 0
}
This is a subset of the complete json which has around 18000 lines (but there's only 11 names).

--slurp the input to get an array and then use group_by to make groups (arrays) according to any criteria (.name in your case). If you want just one for each name, take one (e.g. the first) of each such group. Finally, apply [] to disassemble the surrounding array.
jq --slurp 'group_by(.name) | map(first)[]'
{
"name": "db1",
"size": 40000,
"items": 500,
"mutations": 2,
"tombstones": 4,
"views_count": 8,
"fts_count": 0,
"index_count": 0,
"analytics_count": 0
}
{
"name": "db2",
"size": 11,
"items": 900,
"mutations": 3,
"tombstones": 0,
"views_count": 0,
"fts_count": 0,
"index_count": 0,
"analytics_count": 0
}
Demo
Note: With a little bit of more effort, you could also --stream (and then reduce) the input (instead of using --slurp) but 18000 lines isn't that big for memories nowadays, so I thought this would be the more reasonable approach.

Related

CosmosDB Upsert gives status code 449 even when there is no conflict

A .NET 6 application Upserts documents to CosmosDB.
I get many debug messages (not all writes)
DocDBTrace Error: 0 : DocumentClientException with status code 449, message: Message: {"Errors":["Conflicting request to resource has been attempted. Retry to avoid conflicts."]}
the ids of the documents are Guid instances and there are no unique keys in the container (so no conflicts).
What could it be?
EDIT
partitionKey = id
//F#
let write database container items =
let container = client.GetContainer(database, container)
items
|> Seq.map (fun item -> container.UpsertItemAsync(item))
|> Seq.toArray
|> Task.WhenAll
Data sample
{
"RESPONSE": [
{
"IntradayTickResponse": {
"CorrelationID": "ESM2 Index:intraday",
"TimeReceived": "2022-05-05T01:19:38.338794Z",
"tickData": {
"eidData": null,
"tickData": [
{
"time": {
"DayOfMonth": 5,
"Hour": 0,
"MicroSecond": 0,
"MilliSecond": 0,
"Minute": 37,
"Month": 5,
"NanoSecond": 0,
"Parts": 2046,
"PicoSecond": 0,
"Second": 7,
"TimezoneOffsetMinutes": 0,
"Year": 2022
},
"type": "TRADE",
"value": 4292.5,
"size": 2,
"conditionCodes": "TSUM"
},
{
"time": {
"DayOfMonth": 5,
"Hour": 0,
"MicroSecond": 0,
"MilliSecond": 0,
"Minute": 37,
"Month": 5,
"NanoSecond": 0,
"Parts": 2046,
"PicoSecond": 0,
"Second": 19,
"TimezoneOffsetMinutes": 0,
"Year": 2022
},
"type": "TRADE",
"value": 4292.75,
"size": 2,
"conditionCodes": "TSUM"
},
{
"time": {
"DayOfMonth": 5,
"Hour": 0,
"MicroSecond": 0,
"MilliSecond": 0,
"Minute": 37,
"Month": 5,
"NanoSecond": 0,
"Parts": 2046,
"PicoSecond": 0,
"Second": 19,
"TimezoneOffsetMinutes": 0,
"Year": 2022
},
"type": "TRADE",
"value": 4292.75,
"size": 1,
"conditionCodes": "TSUM"
},
{
"time": {
"DayOfMonth": 5,
"Hour": 0,
"MicroSecond": 0,
"MilliSecond": 0,
"Minute": 37,
"Month": 5,
"NanoSecond": 0,
"Parts": 2046,
"PicoSecond": 0,
"Second": 19,
"TimezoneOffsetMinutes": 0,
"Year": 2022
},
"type": "TRADE",
"value": 4292.75,
"size": 1,
"conditionCodes": "TSUM"
},
{
"time": {
"DayOfMonth": 5,
"Hour": 0,
"MicroSecond": 0,
"MilliSecond": 0,
"Minute": 37,
"Month": 5,
"NanoSecond": 0,
"Parts": 2046,
"PicoSecond": 0,
"Second": 19,
"TimezoneOffsetMinutes": 0,
"Year": 2022
},
"type": "TRADE",
"value": 4292.75,
"size": 1,
"conditionCodes": "TSUM"
},
...
"id": "87fdc18a-61f2-4c43-a7a8-2904b14e6596",
"_rid": "maszAOGSZkYwAgAAAAAAAA==",
"_self": "dbs/maszAA==/colls/maszAOGSZkY=/docs/maszAOGSZkYwAgAAAAAAAA==/",
"_etag": "\"00000000-0000-0000-601e-3057eca901d8\"",
"_attachments": "attachments/",
"_ts": 1651713578
}

How to prevent two NPCs from damaging each other with their AoE spells in Azerothcore?

I am running a local server of Azerothcore with rev. 3716ddf3e4e1 2021-05-25 18:05:13 +0200 (master branch).
I have created two custom NPCs and added them to my DB with the following code:
INSERT INTO `creature_template` (`entry`, `difficulty_entry_1`, `difficulty_entry_2`, `difficulty_entry_3`, `KillCredit1`, `KillCredit2`, `modelid1`, `modelid2`, `modelid3`, `modelid4`, `name`, `subname`, `gossip_menu_id`, `minlevel`, `maxlevel`, `exp`, `faction`, `npcflag`, `speed_walk`, `speed_run`, `scale`, `rank`, `dmgschool`, `DamageModifier`, `BaseAttackTime`, `RangeAttackTime`, `BaseVariance`, `RangeVariance`, `unit_class`, `unit_flags`, `unit_flags2`, `dynamicflags`, `family`, `trainer_type`, `trainer_spell`, `trainer_class`, `trainer_race`, `type`, `type_flags`, `lootid`, `pickpocketloot`, `skinloot`, `PetSpellDataId`, `VehicleId`, `mingold`, `maxgold`, `AIName`, `MovementType`, `InhabitType`, `HoverHeight`, `HealthModifier`, `ManaModifier`, `ArmorModifier`, `RacialLeader`, `movementId`, `RegenHealth`, `mechanic_immune_mask`, `spell_school_immune_mask`, `flags_extra`, `ScriptName`, `VerifiedBuild`) VALUES
(1112001, 0, 0, 0, 0, 0, 3456, 0, 0, 0, 'Mob1', '', 0, 43, 43, 0, 63, 0, 1, 1.14286, 3, 3, 0, 30, 2000, 2000, 1, 1, 1, 32832, 2048, 0, 0, 0, 0, 0, 0, 7, 4, 0, 0, 0, 0, 0, 50000, 60000, 'SmartAI', 1, 3, 1, 100, 1, 1, 0, 0, 1, 0, 0, 256, '', 12340),
(1112003, 0, 0, 0, 0, 0, 21443, 0, 0, 0, 'Mob2', '', 0, 42, 42, 0, 63, 0, 1, 1.14286, 1, 1, 0, 10, 2000, 2000, 1, 1, 1, 0, 2048, 0, 0, 0, 0, 0, 0, 6, 0, 4860, 0, 0, 0, 0, 297, 393, 'SmartAI', 1, 3, 1, 60, 1, 1, 0, 0, 1, 650854271, 0, 0, '', 12340);
Once i let Mob1 cast spell Death and Decay, Mob2 will take damage from it once they walk across it. How can i prevent the mobs from damaging each other, but only do damage to players instead?
Have you tried to set the two NPC to an allied faction that is also an enemy faction for the player ?

the right way of react native matrix 2d?

I have a css3 tansform like
transform: matrix(1, 0, 0, 1, 5, 5);
so what's the react native "matrix array" is?
matrix1: [
1, 0, 0,
0, 1, 0,
5, 5, 1
]
matrix2: [
1, 0, 0,
1, 5, 5,
0, 0, 1
]
matrix3:[
1, 0, 5,
0, 1, 5,
0, 0, 1
]
all not right in the view....
React Native uses 3D matrixes so your matrixes need to be 4x4. See https://github.com/facebook/react-native/blob/master/Libraries/Utilities/MatrixMath.js for details.
React Native also offers a function to decompose your matrices into transformations: https://github.com/facebook/react-native/blob/master/Libraries/Utilities/MatrixMath.js#L571
Be careful to have the same format of 4x4 row-major matrices

Amchart X axis position and fill to axis

I am using AmChartXY to draw graph areas, here is the fiddle:
https://jsfiddle.net/ap60fhsu/1/
var chart = AmCharts.makeChart("chartdiv", {
"type": "xy",
"autoMarginOffset": 20,
"dataProvider": [{
"ax": 0,
"ay": 0,
"bx": 0,
"by": 0,
}, {
"ax": 8,
"ay": 1,
"bx": 12,
"by": -2,
},
{
"ax": 32,
"ay": 9,
"bx": 35,
"by": -1,
},
{
"ax": 45,
"ay": 6,
"bx": 45,
"by": -2,
},
{
"ax": 60,
"ay": 2,
"bx": 60,
"by": -2,
},
{
"ax": 70,
"ay": 0,
"bx": 70,
"by": 0,
},
{
"ax": 75,
"ay": 0,
"bx": 72,
"by": 0,
},
{
"ax": 85,
"ay": 6,
"bx": 80,
"by": -1,
},
{
"ax": 90,
"ay": 0,
"bx": 90,
"by": 0,
}],
"valueAxes": [ {
"position": "bottom",
"axisAlpha": 0,
"dashLength": 1,
"id": "x",
"title": "X Axis"
}, {
"axisAlpha": 0,
"dashLength": 1,
"position": "left",
"id": "y",
"title": "Y Axis"
}],
"plotAreaBorderAlpha": 1,
"startDuration": 1,
"graphs": [ {
"balloonText": "x:[[x]] y:[[y]]",
"fillAlphas": 0.3,
"fillToAxis": "x",
"lineAlpha": 1,
"xField": "ax",
"yField": "ay",
"lineColor": "#FF6600"
}, {
"balloonText": "x:[[x]] y:[[y]]",
"lineAlpha": 1,
"fillToAxis": "x",
"fillAlphas": 0.3,
"xField": "bx",
"yField": "by",
"lineColor": "#FCD202"
}],
"marginLeft": 64,
"marginBottom": 60,
"chartScrollbar": {},
"chartCursor": {},
"export": {
"enabled": true,
"position": "bottom-right"
}
});
As you see I have negative values for Y axis, this makes the X axis fall down from Y=0 to Y=-4 and when I use fillToAxis: x, expecting that the graph fill areas will be areas bounded with graphs and X axis corresponding to the value Y=0, I get another result. How can I move the X axis to the Y=0, or at least get the fill area result as I expect?
Thanks in advance

Getting Object's name in stdClass

I have a string like this.
{
"type": "item",
"version": "3.10.3",
"basic": {
"name": "",
"rune": {
"isrune": false,
"tier": 1,
"type": "red"
},
"gold": {
"base": 0,
"total": 0,
"sell": 0,
"purchasable": false
},
"group": "",
"description": "",
"colloq": ";",
"plaintext": "",
"consumeable": false,
"stacks": 1,
"depth": 1,
"consumed": false,
"consumeOnFull": false,
"from": [],
"into": [],
"specialRecipe": 0,
"inStore": true,
"hideFromAll": false,
"requiredChampion": "",
"stats": {
"FlatHPPoolMod": 0,
"rFlatHPModPerLevel": 0,
"FlatMPPoolMod": 0,
"rFlatMPModPerLevel": 0,
"PercentHPPoolMod": 0,
"PercentMPPoolMod": 0,
"FlatHPRegenMod": 0,
"rFlatHPRegenModPerLevel": 0,
"PercentHPRegenMod": 0,
"FlatMPRegenMod": 0,
"rFlatMPRegenModPerLevel": 0,
"PercentMPRegenMod": 0,
"FlatArmorMod": 0,
"rFlatArmorModPerLevel": 0,
"PercentArmorMod": 0,
"rFlatArmorPenetrationMod": 0,
"rFlatArmorPenetrationModPerLevel": 0,
"rPercentArmorPenetrationMod": 0,
"rPercentArmorPenetrationModPerLevel": 0,
"FlatPhysicalDamageMod": 0,
"rFlatPhysicalDamageModPerLevel": 0,
"PercentPhysicalDamageMod": 0,
"FlatMagicDamageMod": 0,
"rFlatMagicDamageModPerLevel": 0,
"PercentMagicDamageMod": 0,
"FlatMovementSpeedMod": 0,
"rFlatMovementSpeedModPerLevel": 0,
"PercentMovementSpeedMod": 0,
"rPercentMovementSpeedModPerLevel": 0,
"FlatAttackSpeedMod": 0,
"PercentAttackSpeedMod": 0,
"rPercentAttackSpeedModPerLevel": 0,
"rFlatDodgeMod": 0,
"rFlatDodgeModPerLevel": 0,
"PercentDodgeMod": 0,
"FlatCritChanceMod": 0,
"rFlatCritChanceModPerLevel": 0,
"PercentCritChanceMod": 0,
"FlatCritDamageMod": 0,
"rFlatCritDamageModPerLevel": 0,
"PercentCritDamageMod": 0,
"FlatBlockMod": 0,
"PercentBlockMod": 0,
"FlatSpellBlockMod": 0,
"rFlatSpellBlockModPerLevel": 0,
"PercentSpellBlockMod": 0,
"FlatEXPBonus": 0,
"PercentEXPBonus": 0,
"rPercentCooldownMod": 0,
"rPercentCooldownModPerLevel": 0,
"rFlatTimeDeadMod": 0,
"rFlatTimeDeadModPerLevel": 0,
"rPercentTimeDeadMod": 0,
"rPercentTimeDeadModPerLevel": 0,
"rFlatGoldPer10Mod": 0,
"rFlatMagicPenetrationMod": 0,
"rFlatMagicPenetrationModPerLevel": 0,
"rPercentMagicPenetrationMod": 0,
"rPercentMagicPenetrationModPerLevel": 0
},
"tags": [],
"maps": {
"1": true,
"8": true,
"10": true,
"12": true
}
},
"data": {
"1001": {
"name": "Boots of Speed",
"group": "BootsNormal",
"description": "<groupLimit>Limited to 1.</groupLimit><br><br><unique>UNIQUE Passive - Enhanced Movement:</unique> +25 Movement Speed<br><br><i>(Unique Passives with the same name don't stack.)</i>",
"colloq": ";",
"plaintext": "Slightly increases Movement Speed",
"into": [
"3006",
"3047",
"3020",
"3158",
"3111",
"3117",
"3009"
],
"image": {
"full": "1001.png",
"sprite": "item0.png",
"group": "item",
"x": 0,
"y": 0,
"w": 48,
"h": 48
},
"gold": {
"base": 325,
"purchasable": true,
"total": 325,
"sell": 227
},
"tags": [
"MOVEMENT",
"BOOTS"
],
"stats": {
"FlatMovementSpeedMod": 25
}
},
"1004": {
"name": "Faerie Charm",
"description": "<stats>+3 Mana Regen per 5 seconds</stats>",
"colloq": ";",
"plaintext": "Slightly increases Mana Regen",
"into": [
"3037",
"3096",
"3028",
"3070",
"3073",
"1080",
"3165"
],
"image": {
"full": "1004.png",
"sprite": "item0.png",
"group": "item",
"x": 48,
"y": 0,
"w": 48,
"h": 48
},
"gold": {
"base": 180,
"purchasable": true,
"total": 180,
"sell": 126
},
"tags": [
"MANAREGEN"
],
"stats": {
"FlatMPRegenMod": 0.6
}
},
"1006": {
its going like this I'm trying to get 1006 from "1006: { but i cant
$iveri = $iresponse->body;
foreach($iveri->data as $esya)
{
print($esya);
}
Because it's object, but i want it's name but i cant find a way to get that can you help me, I'm building database from that like getting values insade it and they will their id's they are id's of items so they cant be auto assing they had to be like in array.
1006 in your example is a key value, you need to slightly modify your loop syntax:
foreach($ivery->data as $key=>$esya) {
print $key; // This will be '1006'
print $esya;
}

Resources