public static JSONObject AggregatedData(Socket s, String aggregation, String readingType, int id) {
        JSONObject query = new JSONObject(); //sent to server
        JSONObject params = new JSONObject(); //added to query
        JSONObject returned = new JSONObject(); // returned from the server

        if (id == 1) { //this is when its called from the main menu
            /*Group id if given*/
            while (true) {
                System.out.println("Please enter in the group to query by their group ID. Enter 0 for all data. (Enter to confirm):");
                Scanner scan = new Scanner(System.in);
                String groupNo = scan.nextLine();
                if (isInteger(groupNo)) { //check if input is a valid integer
                    if (Integer.parseInt(groupNo) == 0) {
                        break;
                    } else {
                        params.put("group_id", Integer.parseInt(groupNo)); //place into params if given
                        break;
                    }
                } else {
                    System.out.println("Not an valid integer, assuming 0");
                }
            }

            params.put("type", readingType); //place in passes readin type - temp humidity light

            params.put("aggregation", aggregation); //what stat they require, mean,max, etc.

            /*Time from*/
            System.out.println("Please enter the time from which you want readings (yyyy-mm-dd hh:mm:ss):");
            params.put("time_from", new Scanner(System.in).nextLine());
            //params.put("time_from", "2013-01-01 01:01:01"); //hardcoded for testing

            /*Time to*/
            System.out.println("Please enter the time to which you want readings (yyyy-mm-dd hh:mm:ss):");
            params.put("time_to", new Scanner(System.in).nextLine());
            //params.put("time_to", "2013-04-10 23:55:01"); //hardcoded for testing

        } else { //when its called from graphStatData()
            params.put("type", readingType);
            params.put("aggregation", aggregation);
        }

        /*build the query sent to server*/
        query.put("method", "aggregate");
        query.put("group_id", group_id);
        query.put("params", params);

        returned = new JSONObject(GetReplyFromServer(query, s));

        return returned;
    }