如何从JSON计算x,y和z值 [英] How to calculate x, y and z values from JSON

查看:83
本文介绍了如何从JSON计算x,y和z值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

I have json data format given below. From this data I need to display group11 emotions only in 3D charts.So i need x ,y and z value.how to get these values please give me some logic.we can use anything from this given json.




What I have tried
x-Emotion name(Supremacy, Arrogance)
y-Emotion count(how many times repeated)
z-Emotion duration(in minutes)





我尝试过:





What I have tried:

JSON
{
"status":"success",
"result":{
"duration":"15034.88",
"sessionStatus":"Done",
"analysisSegments":[{
"offset":0,
"duration":10000,
"end":10000,
"analysis":{
"Temper":{
"Value":"62.00",
"Group":"medium",
"Score":"59.00"
},
"Valence":{
"Value":"96.00",
"Group":"positive",
"Score":"94.00"
},
"Arousal":{
"Value":"98.00",
"Group":"high",
"Score":"97.00"
},
"Vad":{
"Voiced":"70.00"
},
"Mood":{
"Group7":{
"Primary":{
"Id":1,
"Phrase":"Angry"
},
"Secondary":{
"Id":3,
"Phrase":"Enthusiastic"
}
},
"Group11":{
"Primary":{
"Id":11,
"Phrase":"Supremacy, Arrogance"
},
"Secondary":{
"Id":1,
"Phrase":"Creative, Passionate"
}
},
"Group21":{
"Primary":{
"Id":9,
"Phrase":"egoism"
},
"Secondary":{
"Id":18,
"Phrase":"motivation"
}
},
"Composite":{
"Primary":{
"Id":143,
"Phrase":"Insistence and stubbornness. Possibly childishness."
},
"Secondary":{
"Id":5,
"Phrase":"Ambitious. Assertiveness to achieve goals."
}
}
}
}
},
{
"offset":5000,
"duration":10000,
"end":15000,
"analysis":{
"Temper":{
"Value":"63.00",
"Group":"medium",
"Score":"57.00"
},
"Valence":{
"Value":"89.00",
"Group":"positive",
"Score":"84.00"
},
"Arousal":{
"Value":"94.00",
"Group":"high",
"Score":"91.00"
},
"Vad":{
"Voiced":"62.00"
},
"Mood":{
"Group7":{
"Primary":{
"Id":1,
"Phrase":"Angry"
},
"Secondary":{
"Id":3,
"Phrase":"Enthusiastic"
}
},
"Group11":{
"Primary":{
"Id":11,
"Phrase":"Supremacy, Arrogance"
},
"Secondary":{
"Id":6,
"Phrase":"Leadership, Charisma"
}
},
"Group21":{
"Primary":{
"Id":8,
"Phrase":"dominance"
},
"Secondary":{
"Id":18,
"Phrase":"motivation"
}
},
"Composite":{
"Primary":{
"Id":107,
"Phrase":"Possessiveness. Ownership. Authoritative."
},
"Secondary":{
"Id":41,
"Phrase":"Strong drive."
}
}
}
}
}
],"analysisSummary":{
"AnalysisResult":{
"Temper":{
"Mode":"medium",
"ModePct":"100.00"
},
"Valence":{
"Mode":"positive",
"ModePct":"100.00"
},
"Arousal":{
"Mode":"high",
"ModePct":"100.00"
}
}
}
}
}




json parse
var counter4=0;
var val4 =0;
var val4minute =0;
   var phrase = rawdata[i]["analysis"]["Mood"]["Group11"]["Primary"]["Phrase"];
      if (phrase == "Supremacy, Arrogance") {
  counter4++;
 val4 = counter4 * 10000;
 val4minute = Math.floor(val4 / 60000);
}




Here x is "Supremacy, Arrogance" counter4 is y axis and val4minute is z axis

but this logic is wrong can any one give me a better logic.

推荐答案

我会创建o​​bj等等
I would create the object
{ phrase: "", count: 0, duration: t }





,通过JSON并计算短语(如果这是你唯一感兴趣的话,你可以使用过滤器来获得至高无上的傲慢)。如果你需要每次单独,而不是持续时间:t使用数组,你添加每个时间实例持续时间:[]

在这种情况下你的对象看起来像



, go through JSON and count the phrases (you can use filter for supremacy arrogance if that is the only one you're interested in). If you need each time separately, instead of duration: t use array into which you add each time instance duration: []
In this case your object would look like

{phrase: "Supremacy, Arrogance", count: 3, duration: [t1, t2, t3] }


这篇关于如何从JSON计算x,y和z值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆