I am trying to extract any property name containing "cpu" and "usageRatio" from the following Json using Jayway JsonPath, but so far I have been out of luck.
Checked their documentation and could not find a solution. Any ideas?
To be clear, I would like to extract cpu usage ration for all cpu's in a dynamict fashion (there can be many cores):
{
"entries" : {
"cpu.0_1.user" : {
"lastUpdateMicros" : 1493578024979676,
"value" : 10167446,
"updateType" : "MOVING_AVERAGE"
},
"cpu.0_1.idle" : {
"value" : 277255191,
"lastUpdateMicros" : 1493578024979652,
"updateType" : "MOVING_AVERAGE"
},
"disk.usr.usageRatio" : {
"value" : 0.871294498443604,
"lastUpdateMicros" : 1493578024990246,
"updateType" : "BASIC"
},
"disk.shared.usedSpace" : {
"updateType" : "BASIC",
"lastUpdateMicros" : 1493578024990318,
"value" : 707563520
},
"disk.var.log.availableSpace" : {
"lastUpdateMicros" : 1493578024990355,
"value" : 7224614912,
"updateType" : "BASIC"
},
"disk.usr.local.www.guiserverroot.usr.local.www.guiserver.availableSpace" : {
"value" : 2369658880,
"lastUpdateMicros" : 1493578024990398,
"updateType" : "BASIC"
},
"cpu.0_0.idle" : {
"value" : 265264234,
"lastUpdateMicros" : 1493578024979593,
"updateType" : "MOVING_AVERAGE"
},
"cpu.0_1.usageRatio" : {
"value" : 0.07,
"lastUpdateMicros" : 1493578024979635,
"updateType" : "MOVING_AVERAGE"
},
"cpu.0_0.usageRatio" : {
"lastUpdateMicros" : 1493578024979564,
"value" : 0.12,
"updateType" : "MOVING_AVERAGE"
}
}
Yes, I know the Json structure sucks but sadly I don't have access to change it.
/Patrik
Related
$json = file_get_contents('php://input');
is not returning any result
sample JSON I was supposed to get from my payment gateway is here (sorry I couldn't post sample code here please see comment)
https://uat-paco.s3.ap-southeast-1.amazonaws.com/HTML-based-docs/CorePaymentAPI/2022-04-25-Et01x9/APIs/Payment.html#_inline_response_202_data
{
"version" : "1.0.0",
"apiResponse" : {
"responseMessageID" : "fadaba8f-b02c-4ff4-a8f0-2e5ce9873185",
"responseToRequestMessageID" : "e952828c-6d19-4a08-92e4-1bc47e1945a2",
"responseCode" : "PC-B050000",
"responseDescription" : "Success",
"responseDateTime" : "2016-08-29T09:12:34.001+0000",
"responseTime" : 2400,
"marketingDescription" : "Payment is success. Thank you for purchase."
},
"data" : {
"paymentIncompleteResult" : {
"officeGroupId" : "string",
"officeId" : "string",
"transactionDateTime" : "2016-08-29T09:12:34.001+0000",
"orderNo" : "684105191128073630",
"productDescription" : "URRT55",
"invoiceNo2C2P" : "FPX054658",
"pspReferenceNo" : "W32UPVAPCP260543864232",
"controllerInternalID" : "f81d4fae-7dec-11d0-a765-00a0c91e6bf6",
"paymentStatusInfo" : {
"paymentStatus" : "A",
"paymentStep" : "PA",
"lastUpdatedDTTM" : "2016-08-29T09:12:35.001+0000"
},
"paymentType" : "CC-VI",
"paymentExpiryDateTime" : "2016-08-30T23:59:59.999+0000",
"channelCode" : "WEBPAY",
"agentCode" : "FPX_SBIA",
"mcpFlag" : "N",
"mcpDetails" : {
"mcpType" : "DCC",
"fxRate" : {
"fxRate" : 32.9,
"markUp" : 1.2,
"convertedAmount" : {
"amountText" : "000000006135",
"currencyCode" : "USD",
"decimalPlaces" : 2,
"amount" : 61.349694
},
"fxProviderId" : "FXP0001",
"fxDate" : "2016-08-29T09:12:34.001+0000"
}
},
"merchantIdForMCP" : "4572325756",
"transactionAmount" : {
"amountText" : "000000999950",
"currencyCode" : "THB",
"decimalPlaces" : 2,
"amount" : 9999.5
},
"settlementAmount" : {
"amountText" : "000000999950",
"currencyCode" : "THB",
"decimalPlaces" : 2,
"amount" : 9999.5
},
"customFieldList" : [ {
"fieldName" : "ExternalID5",
"fieldValue" : "AMADEUS"
} ],
"aresACSChallenge" : {
"transStatus" : "C",
"acsURL" : "https://uatemvco.2c2p.com/challenge",
"creq" : "Base64url encoded form data"
},
"authentication3DSVersion" : "2.1.0",
"availablePaymentTypes" : [ "CC-VI", "CC-CA" ],
"untokenizedStoredCardList" : [ {
"storedCardUniqueID" : "string",
"isExpired" : true,
"cardNumber" : "401200XXXXXX3335",
"cardExpiryMMYY" : "1124",
"cvvCode" : "123",
"payerName" : "Attasit Txxxxxx",
"issuerBankCountry" : "TH",
"issuerBankName" : "JPMORGAN CHASE BANK N.A."
} ]
},
"paymentPage" : {
"paymentPageURL" : "https://demo-paco.2c2p.com/payment/form",
"validTillDateTime" : "2016-08-29T09:12:34.001+0000"
}
}
}
This is for upateOne() query in mongodb..
According to me there are not any mistakes in the down given code but the error pops up saying:
" missing } after property list :"
The braces are fully intact, the colons are on and the commas are provided correctly..
Please if anyone could help me with this issue??
db.movieDetails.updateOne(
{
"title":"The Martian"
},
{
$push : {
"reviews":{
$each : [
{
"rating" : 0.5,
"date" : ISODate("2016-01-12T07:00:00Z"),
"reviewer" : "Yabo A.",
"text" : "reviewText2"
},
{
"rating" : 5,
"date" : ISODate("2016-01-12T09:00:00Z"),
"reviewer" : "Kristina Z.",
"text" : "reviewText3"
},
{
"rating" : 2.5,
"date" : ISODate("2015-10-26T04:00:00Z"),
"reviewer" : "Matthew Samuel",
"text" : "reviewText4"
},
{
"rating" : 9.5,
"date" : ISODate("2015-11-23T04:00:00Z"),
"reviewer" : "Mahendra Singh Dhoni",
"text" : "reviewText5"
},
{
"rating" : 7.5,
"date" : ISODate("2016-12-27T09:00:00Z"),
"reviewer" : "Himesh Reshamiya",
"text" : "reviewText6"
},
{
"rating" : 8
"date" : ISODate("2015-10-26T04:00:00Z"),
"reviewer" : "Latish Malinga",
"text" : "reviewText7"
}
]
}
}
}
)
In the last document here you are missing a comma:
{
"rating" : 8
"date" : ISODate("2015-10-26T04:00:00Z"),
"reviewer" : "Latish Malinga",
"text" : "reviewText7"
}
Adding a comma after 8 will fix it.
I have following collection in mongodb-
> db.games.find().pretty();
{
"_id" : ObjectId("5db06c02e08772b58596ec72"),
"name" : "Cricket",
"genre" : "sport",
"rating" : 10
}
{
"_id" : ObjectId("5db06c02e08772b58596ec73"),
"name" : "Football",
"genre" : "sport",
"rating" : 100,
"achievement" : "champion",
"games" : [
{
"score" : 20
},
{
"score" : 30
},
{
"score" : 22
},
{
"score" : 145
}
]
}
{
"_id" : ObjectId("5db06c02e08772b58596ec74"),
"name" : "Ludo",
"genre" : "indoor",
"rating" : 1
}
{
"_id" : ObjectId("5db06c02e08772b58596ec75"),
"name" : "Badminton",
"genre" : "indoor",
"rating" : 60,
"games" : [
{
"score" : 34
},
{
"score" : 12
},
{
"score" : 50
}
]
}
{
"_id" : ObjectId("5db06c02e08772b58596ec76"),
"name" : "Swimming",
"genre" : "water",
"rating" : 50
}
{
"_id" : ObjectId("5db06c02e08772b58596ec77"),
"name" : "Running",
"genre" : "atheletics",
"rating" : 70
}
{
"_id" : ObjectId("5db06c02e08772b58596ec78"),
"name" : "Shotput",
"genre" : "atheletics",
"rating" : 66
}
I want to sum of scores for each game in the collection. For this I am trying to implement map reduce as follows -
> db.games.mapReduce( function(){emit(this.name,this.score)}, function(key,values) {return Array.sum(values)}, {out:"out_scores"});
{
"result" : "out_scores",
"timeMillis" : 330,
"counts" : {
"input" : 7,
"emit" : 7,
"reduce" : 0,
"output" : 7
},
"ok" : 1
}
But the values in the resulting collection as undefined as follows -
db.out_scores.find().pretty();
{ "_id" : "Badminton", "value" : undefined }
{ "_id" : "Cricket", "value" : undefined }
{ "_id" : "Football", "value" : undefined }
{ "_id" : "Ludo", "value" : undefined }
{ "_id" : "Running", "value" : undefined }
{ "_id" : "Shotput", "value" : undefined }
{ "_id" : "Swimming", "value" : undefined }
I am expecting sum of values of scores for each game. What am I doing wrong here?
Perhaps this query might help?
db.games.aggregate(
[
{ $unwind: { path: "$games", preserveNullAndEmptyArrays: true }},
{ $group: {
_id: "$name",
score: { $sum: "$games.score" }
}}
])
Results:
{ "_id" : "Shotput", "score" : 0 }
{ "_id" : "Running", "score" : 0 }
{ "_id" : "Ludo", "score" : 0 }
{ "_id" : "Swimming", "score" : 0 }
{ "_id" : "Badminton", "score" : 96 }
{ "_id" : "Football", "score" : 217 }
{ "_id" : "Cricket", "score" : 0 }
** If still want to use mapreduce...**
The root problem is nested data. Need to refer to the data from the games.score perspective. The mapping function of map reduce requires this logic.
db.games.mapReduce( function(){
var sum_of_score = 0;
if (this.games != undefined) {
for (var i=0; i<this.games.length; i++) {
sum_of_score += this.games[i].score;
}
}
emit(this.name, sum_of_score)
}, function(key, values) { }, {out:"out_scores"});
Query:
db.out_scores.find()
Results:
{ "_id" : "Badminton", "value" : 96 }
{ "_id" : "Cricket", "value" : 0 }
{ "_id" : "Football", "value" : 217 }
{ "_id" : "Ludo", "value" : 0 }
{ "_id" : "Running", "value" : 0 }
{ "_id" : "Shotput", "value" : 0 }
{ "_id" : "Swimming", "value" : 0 }
i have a collection with this documents:
{
"_id" : BinData(3,"utMu84VFQk+p6LOEE3Ia3w=="),
"DepartDate" : ISODate("2017-08-14T02:00:00.000+02:00"),
"Origin" : {
"Code" : "MIL",
"City" : "Milano",
"Country" : "IT"
},
"Destination" : {
"Code" : "TIA",
"City" : "Tirana",
"Country" : "AL"
},
"ReturnDate" : ISODate("2017-08-21T18:05:00.000+02:00"),
"SearchDate" : ISODate("2017-07-15T02:00:00.000+02:00"),
"Duration" : 150,
"Price" : "376.79",
"PriceCents" : 37679,
"Currency" : "EUR",
},
{
"_id" : BinData(3,"utMu845468+p6Lertya3w=="),
"DepartDate" : ISODate("2017-08-14T02:00:00.000+02:00"),
"Origin" : {
"Code" : "AOI",
"City" : "Ancona",
"Country" : "IT"
},
"Destination" : {
"Code" : "TIA",
"City" : "Tirana",
"Country" : "AL"
},
"ReturnDate" : ISODate("2017-08-21T18:05:00.000+02:00"),
"SearchDate" : ISODate("2017-07-15T02:00:00.000+02:00"),
"Duration" : 100,
"Price" : "376.79",
"PriceCents" : 37679,
"Currency" : "EUR",
},
.........
.........
I want to group by ONLY Destination.City and return an object with
Destination.City, Destination.Code and count. Like this example:
/* 1 */
{
"_id" : {
"Code" : "PMO",
"City" : "Palermo",
"Country" : "IT"
},
"count" : 184564.0
},
/* 2 */
{
"_id" : {
"Code" : "CAG",
"City" : "Cagliari",
"Country" : "IT"
},
"count" : 130873.0
},
......
......
I tried with this query (i use MongoBooster):
db.parsed_data.aggregate([
{ "$match" : { "Destination.Country" : "IT", "Segments" : { "$elemMatch" : { "Carrier" : "AZ" } } } },
{ "$group" : { "_id" : { "City" : "$Destination.City"}, "count" : { "$sum" : 1 } } },
{ "$project" : {"Destination.Code" : 1, "Destination.City" : 1, "Destination.Country" : 1 }},
{ "$sort" : { "count" : -1 } },
{ "$limit" : 9 }])
It returns grouped by City but it shows only the City Name.
In this way:
/* 1 */
{
"_id" : {
"City" : "Lampedusa"
}
},
/* 2 */
{
"_id" : {
"City" : "Trieste"
}
},
This is not correct.
How can i group by ONLY the Destination.City and return an object with
Destination.City, Destination.Code and count?
Thx
the response is like the following format
{
"human_man" :
[
{"id" : "12345", "value" : "4567"},
{ "id" : "0000", "value" : "qwer"}
],
"human_woman" :
[
{"id" : "5454", "value" : "6565"},
{ "id" : "7878", "value" : "884"}
],
............................................
}
I want to catch the response for all matches , meaning....
if I use,
response.human_man ::: i would be catching--> [ {"id" : "12345", "value" : "4567"}, { "id" : "0000", "value" : "qwer"}]
if I use,
response.human_woman ::: i would be catching--> [{"id" : "5454", "value" : "6565"}, { "id" : "7878", "value" : "884"}]
so I want to know how to catch the response the type is
response.human_* (it should catch response.human_man & response.human_woman)
hope you guys understood the question.. :)
fast replies would be appreciated
Try this :)
var object = {
"human_man" :
[
{"id" : "12345", "value" : "4567"},
{ "id" : "0000", "value" : "qwer"}
],
"human_woman" :
[
{"id" : "5454", "value" : "6565"},
{ "id" : "7878", "value" : "884"}
]
};
for(var key in object) {
if(/^human_/.test(key))
console.log(object[key]);
}