Sunday 21 May 2017

How to fasten the data based on dates?

Here is my JSON data:

    [
      {
        "_id": "2017/4/7",
        "category": "science",
        "presenties ": 20,
        "absentee": 1
      },
      {
        "_id": "2017/4/19",
        "category": "science",
        "presenties ": 11,
        "absentee": 32
      },
      {
        "_id": "2017/4/19",
        "category": "Commerce",
        "presenties ": 10,
        "absentee": 32
      },

      {
        "_id": "2017/4/7",
        "category": "Arts",
        "presenties ": 20,
        "absentee": 16
      },
      {
        "_id": "2017/4/19",
        "category": "Arts",
        "presenties ": 10,
        "absentee": 21
      }
    ]

I would like to display : 1) Percentages of presenties and absentee per category for each day, i tried aggregate function so am getting the total presenties and absentees

[{
        "_id": "2017/4/7",
        "total_presenties ": 40,
        "total_absentee": 17
      },
      {
        "_id": "2017/4/19",
        "total_presenties ": 31,
        "total_absentee": 85
      }
    ]

2)but need to mention that percentage in to the above JSON according to the dates like this

[{
            "_id": "2017/4/7",
                "category": "science",
                "presenties ": 10,
                "absentee": 21
               "presenties_Precentage":xx%
               "absentees_Precentage": xx%
          },{"_id": "2017/4/7",
                "category": "commerce",
                "presenties ": 10,
                "absentee": 21
               "presenties_Precentage":xx%
               "absentees_Precentage": xx%},{
                "_id": "2017/4/19",
                "category": "Arts",
                "presenties ": 10,
                "absentee": 21
               "presenties_Precentage":xx%
               "absentees_Precentage": xx%
              }]

please help me here to complete this task



via Schüler

No comments:

Post a Comment