获取具有特定日期

时间:2016-12-17 14:01:18

标签: javascript json algorithm

我有一些麻烦要解决一个问题,这个问题与算法有关,然后用特定的语言。 基本上我有一个像这样的Json对象:

 {
  "channel":
  {
    "id": 9,
    "name": "my_house",
    "description": "Netduino Plus connected to sensors around the house",
    "latitude": "40.44",
    "longitude": "-79.996",
    "field1": "Light",
    "field2": "Outside Temperature",
    "created_at": "2010-12-13T20:20:06-05:00",
    "updated_at": "2014-02-26T12:43:04-05:00",
    "last_entry_id": 6060625
  },
  "feeds":
  [
    {
      "created_at": "2014-02-26T12:42:49-05:00",
      "entry_id": 6060624,
      "field1": "188",
      "field2": "25.902335456475583"
    },
    {
      "created_at": "2014-02-26T12:43:04-05:00",
      "entry_id": 6060625,
      "field1": "164",
      "field2": "25.222929936305732"
    }
  ]
}

我想创建一个基于不同日期的图表(created_at)我想跟踪最后一个日期我的意思是,我想从每个日期获取最后一个字段,想象我有10个字段都使用created_at:17/12/2016我想保留最后一个,然后继续迭代并从每个日期拿走最后一个,我该怎么办?

我现在试过这个

 var dataInicial = separaData(dados.feeds[0].created_at);
        console.log(dataInicial);
        var dataPointsConst = []; // para construir o objeto JSON para servir o gráfico
        var somatorio;
        for(var x = 0;x<dados.feeds.length;x++){
                var data = separaData(dados.feeds[x].created_at);
                console.log(data[0]);
                console.log(dataInicial[0]);
                if(data[0] == dataInicial[0]){
                    somatorio = parseInt(dados.feeds[x].field1) + parseInt(dados.feeds[x].field2) + parseInt(dados.feeds[x].field3) + parseInt(dados.feeds[x].field4) + parseInt(dados.feeds[x].field5) + parseInt(dados.feeds[x].field6) + parseInt(dados.feeds[x].field7) + parseInt(dados.feeds[x].field8);
                }
                else{
                    dataPointsConst.push({x:data[0],y:somatorio});
                    dataInicial = data[0].created_at;
                }
        }

0 个答案:

没有答案