blob: 86261890a736e9d8f6e774ec548f267d6d613476 [file] [log] [blame]
saberian7b5b77b2012-06-04 11:19:43 -07001/*
2 * Copyright (C) 2012 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package android.bordeaux.services;
18
19import java.util.Date;
20import android.util.Log;
21import java.util.HashMap;
22import java.util.Map;
23
24class TimeStatsAggregator extends Aggregator {
25 final String TAG = "TimeStatsAggregator";
26 public static final String CURRENT_TIME = "Current Time";
27 final String EARLY_MORNING = "EarlyMorning";
28 final String MORNING = "Morning";
29 final String NOON = "Noon";
30 final String AFTERNOON = "AfterNoon";
31 final String NIGHT = "Night";
32 final String LATE_NIGHT = "LateNight";
33
34 public String[] getListOfFeatures(){
35 String [] list = new String[1];
36 list[0] = CURRENT_TIME;
37 return list;
38 }
39
40 public Map<String,String> getFeatureValue(String featureName) {
41 HashMap<String,String> m = new HashMap<String,String>();
42 if (featureName.equals(CURRENT_TIME))
43 m.put(CURRENT_TIME, getCurrentTimeLabel());
44 else
45 Log.e(TAG, "There is no Time feature called " + featureName);
46 return (Map) m;
47 }
48
49 private String getCurrentTimeLabel(){
50 Date d = new Date(System.currentTimeMillis());
51 String t = ""; //TODO maybe learn thresholds
52 int h = d.getHours();
53 if ((h > 5) & (h <= 7) )
54 t = EARLY_MORNING;
55 else if ((h > 7) & (h <= 11) )
56 t = MORNING;
57 else if ((h > 11) & (h <= 15))
58 t = NOON;
59 else if ((h > 15) & (h <= 20))
60 t = AFTERNOON;
61 else if ((h > 20) & (h <= 24))
62 t = NIGHT;
63 else if ((h > 0) & (h <= 5))
64 t = LATE_NIGHT;
65 return t;
66 }
67}