Splitting a string to view stats - json

If I wanted to convert the stats in json to a readable list, how would I do that?
For example,
{
"player_stat_summary": [
{
"id": 1,
"stats": {
"id": 1,
"average_node_capture_assist": 0,
"max_node_neutralize_assist": 0,
"total_minion_kills": 0,
"max_champions_killed": 0,
"total_champion_kills": 0,
"average_champions_killed": 0,
"average_num_deaths": 0,
"max_node_capture": 0,
"max_objective_player_score": 0,
"total_neutral_minions_killed": 0,
"max_assists": 0,
"average_combat_player_score": 0,
"max_node_capture_assist": 0,
"average_objective_player_score": 0,
"max_team_objective": 0,
"total_assists": 0,
"average_node_capture": 0,
"average_total_player_score": 0,
"average_team_objective": 0,
"average_node_neutralize": 0,
"max_node_neutralize": 0,
"average_node_neutralize_assist": 0,
"average_assists": 0,
"max_total_player_score": 0,
"max_combat_player_score": 0,
"total_turrets_killed": 0,
"total_node_neutralize": 0,
"total_node_capture": 0
},
"player_stat_summary_type": "Coop",
"wins": 100,
"losses": 0
}
],
"time_stamp": "2015-05-22T15:54:43.069814Z",
"summoner_id": 0
}

You don't say what language you are using.
Assuming JS.
you can use JSON.parse(text)
so assuming that your JSON string is stored in a variable called text
var stats= JSON.parse(text);
console.log(stats.player_stat_summary[0].id);
> 1
However, it looks like that's not a string at all,but is actually already an object. You're just not assigning it to a variable. If this is the case, just assign it to a variable and use it as I did above, no need for JSON.parse(text);
e.g.
stats={....};
console.log(stats.player_stat_summary[0].id);
> 1

If you want to iterate over the stats and emit an HTML list you could do something like the following:
var stats = {
"player_stat_summary": [
{
"id": 1,
"stats": {
"id": 1,
"average_node_capture_assist": 0,
"max_node_neutralize_assist": 0,
"total_minion_kills": 0,
"max_champions_killed": 0,
"total_champion_kills": 0,
"average_champions_killed": 0,
"average_num_deaths": 0,
"max_node_capture": 0,
"max_objective_player_score": 0,
"total_neutral_minions_killed": 0,
"max_assists": 0,
"average_combat_player_score": 0,
"max_node_capture_assist": 0,
"average_objective_player_score": 0,
"max_team_objective": 0,
"total_assists": 0,
"average_node_capture": 0,
"average_total_player_score": 0,
"average_team_objective": 0,
"average_node_neutralize": 0,
"max_node_neutralize": 0,
"average_node_neutralize_assist": 0,
"average_assists": 0,
"max_total_player_score": 0,
"max_combat_player_score": 0,
"total_turrets_killed": 0,
"total_node_neutralize": 0,
"total_node_capture": 0
},
"player_stat_summary_type": "Coop",
"wins": 100,
"losses": 0
}
],
"time_stamp": "2015-05-22T15:54:43.069814Z",
"summoner_id": 0
}
function emitStats(s) {
// create a new UL
var list = document.createElement('ul');
// iterate over the properties
Object.keys(s).forEach(function(statName) {
// create an LI for the property
var el = document.createElement('li');
// fill it with the stat name and value
el.innerHTML = statName.replace(/_/g,' ') + ": " + s[statName];
// add it to the UL
list.appendChild(el);
});
// add the UL to the document.
document.getElementById('content').appendChild(list);
}
// loop over each entry in stats.player_stat_summary
for(var i = 0; i < stats.player_stat_summary.length; i++ ) {
// invoke emitStats, passing the entry's stats property.
emitStats(stats.player_stat_summary[i].stats);
}
<div id="content"></div>

Related

How to change elasticsearch status from yellow to green?

I'm having only one node, I set the replica to 0 and shards to 1 by using below script:
PUT /my_temp_index
{
"settings": {
"number_of_shards" : 1,
"number_of_replicas" : 0
}
}
output:
{
"cluster_name": "KMT",
"status": "yellow",
"timed_out": false,
"number_of_nodes": 1,
"number_of_data_nodes": 1,
"active_primary_shards": 452,
"active_shards": 452,
"relocating_shards": 0,
"initializing_shards": 0,
"unassigned_shards": 451,
"delayed_unassigned_shards": 0,
"number_of_pending_tasks": 0,
"number_of_in_flight_fetch": 0,
"task_max_waiting_in_queue_millis": 0,
"active_shards_percent_as_number": 50.055370985603545
}
should I have to restart elasticsearch after the changes?
You have only changed the number of replicas for a single index + the property names are wrong (missing the index. prefix).
You need to run the same query on all indices instead
PUT /*/_settings
{
"index": {
"number_of_replicas" : 0
}
}

Convert from ThreeJS geometry format 3 to 4: dealing with faces

I am having some problems with migration from ThreeJS geometry format 3 to 4. More specifically, i would like to manually create a surface in model.json file, but i don't get it to work.
in geometry format 3, the following code creates a single surface:
{
"faces": [1, 0, 1, 2, 3],
"metadata": {
"faces": 1
},
"vertices": [0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0]
}
Can some-one help me how to convert this to format 4?
The only example on geometry format 4 i could find was this one: https://github.com/mrdoob/three.js/wiki/JSON-Geometry-format-4
This is the equivalent code in json-geometry format 4:
{
"vertices": [0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0],
"normals": [],
"uvs": [],
"faces": [ 1, 0, 1, 2, 3]
}

Displaying a json string to html div

To access the information in a tag in a list, how would I do so? Could I use dot notation? Javascript is being used in the backend and javascript is being used in the frontend.
HTML:
<div>{{ GameData }}</div>
JAVASCRIPT:
{
"player_stat_summary": [
{
"id": 1,
"stats": {
"id": 1,
"average_node_capture_assist": 0,
"max_node_neutralize_assist": 0,
"total_minion_kills": 0,
"max_champions_killed": 0,
"total_champion_kills": 0,
"average_champions_killed": 0,
"average_num_deaths": 0,
"max_node_capture": 0,
"max_objective_player_score": 0,
"total_neutral_minions_killed": 0,
"max_assists": 0,
"average_combat_player_score": 0,
"max_node_capture_assist": 0,
"average_objective_player_score": 0,
"max_team_objective": 0,
"total_assists": 0,
"average_node_capture": 0,
"average_total_player_score": 0,
"average_team_objective": 0,
"average_node_neutralize": 0,
"max_node_neutralize": 0,
"average_node_neutralize_assist": 0,
"average_assists": 0,
"max_total_player_score": 0,
"max_combat_player_score": 0,
"total_turrets_killed": 0,
"total_node_neutralize": 0,
"total_node_capture": 0
},
"player_stat_summary_type": "Coop",
"wins": 100,
"losses": 0
}
],
"time_stamp": "2015-05-22T15:54:43.069814Z",
"summoner_id": 0
}
You can use dot notation as well as string notation. For example, in the given data, you can access the first object of the data as
GameData.player_stat_summary[0]
OR
GameData["player_stat_summary"][0]
You can any property of "player_stat_summary" as:
GameData.player_stat_summary[0].id
OR
GameData["player_stat_summary"][0]["id"]
Similarly more hierarchy can be accessed.

Getting valurs froM JSON objects that have the same object string name

I'm getting my JSON object from the RIOT games API. Here is part of the JSON I get back:
{
"modifyDate": 1431043986000,
"champions": [
{
"id": 110,
"stats": {
"totalDeathsPerSession": 9,
"totalSessionsPlayed": 1,
"totalDamageTaken": 16507,
"totalQuadraKills": 0,
"totalTripleKills": 0,
"totalMinionKills": 164,
"maxChampionsKilled": 2,
"totalDoubleKills": 0,
"totalPhysicalDamageDealt": 101747,
"totalChampionKills": 2,
"totalAssists": 2,
"mostChampionKillsPerSession": 2,
"totalDamageDealt": 105995,
"totalFirstBlood": 0,
"totalSessionsLost": 1,
"totalSessionsWon": 0,
"totalMagicDamageDealt": 4248,
"totalGoldEarned": 7932,
"totalPentaKills": 0,
"totalTurretsKilled": 0,
"mostSpellsCast": 0,
"maxNumDeaths": 9,
"totalUnrealKills": 0
}
},
{
"id": 113,
"stats": {
"totalDeathsPerSession": 6,
"totalSessionsPlayed": 1,
"totalDamageTaken": 39226,
"totalQuadraKills": 0,
"totalTripleKills": 0,
"totalMinionKills": 75,
"maxChampionsKilled": 5,
"totalDoubleKills": 1,
"totalPhysicalDamageDealt": 28711,
"totalChampionKills": 5,
"totalAssists": 8,
"mostChampionKillsPerSession": 5,
"totalDamageDealt": 177132,
"totalFirstBlood": 0,
"totalSessionsLost": 1,
"totalSessionsWon": 0,
"totalMagicDamageDealt": 120299,
"totalGoldEarned": 12544,
"totalPentaKills": 0,
"totalTurretsKilled": 1,
"mostSpellsCast": 0,
"maxNumDeaths": 6,
"totalUnrealKills": 0
}
},
and so on for all of the champions in the game (there are around 150). If I wanted to calculate the total win/loss ratio or percent, I would have to find the total of "totalSessionsLost" and "totalSessionsWon". How would I go about totaling all of the values for this?
Thanks
var total_win = 0,
total_lost = 0,
champions = yourjsonobj.champions;
for (var i = 0; i < champions.length; i++) {
total_win += champions[i].totalSessionsWon;
total_lost += champions[i].totalSessionsLost;
}

Possibly Encrypted "a href" Links at TripAdvisor

On TripAdvisor.com attraction pages, the link to the website of the attraction seems to be encrypted in some way. Here is an example:
<span class="taLnk hvrIE6" onclick="ta.trackEventOnPage('AttractionContactInfo',
'Website', 1755031, 1); ta.util.cookie.setPIDCookie(15190);
ta.call('ta.util.link.targetBlank', event, this
{'aHref':'LqMWJQiMnYQQoqnQQxGEcQQoqnQQbIIEJnISiCQQoqnQQeVsSVuWJQzZYUWJQpEcYGII26XombQQoqnQQQQoqnqgoqnQQQQoqnQQQQoqnQQQQoqnqgoqnQQQQoqnQQEVMIGVJIEV9pCyTptGiuQQoqnQQQQoqnxioqnQQQQoqnQQniaWJQzhY3mJnJUUJXomoAvoJJB', 'isAsdf':true})">
Website
</span>
How is this link made and what might be the reason for doing so?
The aHref value is an encrypted URL that can be decrypted using the TripAdvisor asdf() Javascript function. For example, using the Javascript console in Firefox, type the following while at www.tripadvisor.com:
console.log(asdf('encrypted URL'));
An example:
console.log(asdf('LqMWJQzZYUWJQpEcYGII26XombQQoqnQQQQoqnqgoqnQQQQoqnQQQQoqnQQQQoqnqgoqnQQQQoqnQQuuuQQoqnQQQQoqnxioqnQQQQoqnQQEitVuiiMqxQQoqnQQQQoqnxioqnQQQQoqnQQniaQQoqnQQQQoqnqgoqnQQQQoqnQQVCQQoqnQQQQoqnqgoqnQQQQoqnQQIGVQQoqnQQQQoqnqHoqnQQQQoqnQQnJEcgcVQQoqnQQQQoqnqHoqnQQQQoqnQQCVuQQoqnQQQQoqnqHoqnQQQQoqnQQgiE9QQoqnQQQQoqnqgoqnQQQQoqnQQMSCSCyQQoqnQQQQoqnqgoqnQQQQoqnQQHVaVcaJCtQQoqnQQQQoqnqHoqnQQQQoqnQQHJEWJQzhYUMo3JKHkmKnVmJVdUB'));
Gives the following (append to http://tripadvisor.com):
/ShowUrl-a_partnerKey.1-a_url.http%253A__5F____5F__2F__5F____5F____5F____5F__2F__5F____5F__www__5F____5F__2E__5F____5F__rosewoodhotels__5F____5F__2E__5F____5F__com__5F____5F__2F__5F____5F__en__5F____5F__2F__5F____5F__the__5F____5F__2D__5F____5F__carlyle__5F____5F__2D__5F____5F__new__5F____5F__2D__5F____5F__york__5F____5F__2F__5F____5F__dining__5F____5F__2F__5F____5F__bemelmans__5F____5F__2D__5F____5F__bar-a_urlKey.1d56a0b730ce3ae41.html
The source of the TripAdvisor asdf() function:
function asdf(d) {
var h = {
"": ["&", "=", "p", "6", "?", "H", "%", "B", ".com", "k", "9", ".html", "n", "M", "r", "www.", "h", "b", "t", "a", "0", "/", "d", "O", "j", "http://", "_", "L", "i", "f", "1", "e", "-", "2", ".", "N", "m", "A", "l", "4", "R", "C", "y", "S", "o", "+", "7", "I", "3", "c", "5", "u", 0, "T", "v", "s", "w", "8", "P", 0, "g", 0],
q: [0, "__3F__", 0, "Photos", 0, "https://", ".edu", "*", "Y", ">", 0, 0, 0, 0, 0, 0, "`", "__2D__", "X", "<", "slot", 0, "ShowUrl", "Owners", 0, "[", "q", 0, "MemberProfile", 0, "ShowUserReviews", '"', "Hotel", 0, 0, "Expedia", "Vacation", "Discount", 0, "UserReview", "Thumbnail", 0, "__2F__", "Inspiration", "V", "Map", ":", "#", 0, "F", "help", 0, 0, "Rental", 0, "Picture", 0, 0, 0, "hotels", 0, "ftp://"],
x: [0, 0, "J", 0, 0, "Z", 0, 0, 0, ";", 0, "Text", 0, "(", "x", "GenericAds", "U", 0, "careers", 0, 0, 0, "D", 0, "members", "Search", 0, 0, 0, "Post", 0, 0, 0, "Q", 0, "$", 0, "K", 0, "W", 0, "Reviews", 0, ",", "__2E__", 0, 0, 0, 0, 0, 0, 0, "{", "}", 0, "Cheap", ")", 0, 0, 0, "#", ".org"],
z: [0, "Hotels", 0, 0, "Icon", 0, 0, 0, 0, ".net", 0, 0, "z", 0, 0, "pages", 0, "geo", 0, 0, 0, "cnt", "~", 0, 0, "]", "|", 0, "tripadvisor", "Images", "BookingBuddy", 0, "Commerce", 0, 0, "partnerKey", 0, "area", 0, "Deals", "from", "\\", 0, "urlKey", 0, "'", 0, "WeatherUnderground", 0, "MemberSign", "Maps", 0, "matchID", "Packages", "E", "Amenities", "Travel", ".htm", 0, "!", "^", "G"]
};
var b = "";
for (var a = 0; a < d.length; a++) {
var j = d.charAt(a);
var f = j;
if (h[j] && a + 1 < d.length) {
a++;
f += d.charAt(a)
} else {
j = ""
}
var g = getOffset(d.charCodeAt(a));
if (g < 0 || typeof h[j][g] == "String") {
b += f
} else {
b += h[j][g]
}
}
return b}
And the source of the getOffset() function referred to from asdf():
function getOffset(a) {
if (a >= 97 && a <= 122) {
return a - 61
}
if (a >= 65 && a <= 90) {
return a - 55
}
if (a >= 48 && a <= 71) {
return a - 48
}
return -1}
It could possibly be done to prevent screen scrapers and robots from automatically generating traffic to other sites.
Some server side code generated this and it's used for tracking, statistics and setting some cookie values etc.
Trip advisor will be able to determine what links were clicked and also share this information with the attraction (i.e. 50 people accessed your website from the Trip Advisor website etc)
Hope it's useful