2 * Copyright (c) 2016 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 #include <SensorRecorderTypes.h>
19 #include "TypesInternal.h"
20 #include "PedometerQuerier.h"
23 "SUM(" KEY_WALK_STEPS " + " KEY_RUN_STEPS ") AS " KEY_STEPS ", " \
24 "SUM(" KEY_WALK_STEPS ") AS " KEY_WALK_STEPS ", " \
25 "SUM(" KEY_RUN_STEPS ") AS " KEY_RUN_STEPS ", " \
26 "SUM(" KEY_DISTANCE ") AS " KEY_DISTANCE ", " \
27 "SUM(" KEY_CALORIES ") AS " KEY_CALORIES ", " \
28 "MIN(" KEY_START_TIME ") AS " KEY_START_TIME ", " \
29 "MAX(" KEY_END_TIME ") AS " KEY_END_TIME
33 PedometerQuerier::PedometerQuerier(ContextProvider *provider, Json option) :
34 Querier(provider, option)
38 PedometerQuerier::~PedometerQuerier()
42 int PedometerQuerier::query(int startTime, int endTime)
44 char *sql = sqlite3_mprintf(
45 "SELECT " PROJECTION \
46 " FROM " PEDOMETER_RECORD \
47 " WHERE " KEY_END_TIME " > %llu AND " KEY_END_TIME " <= %llu",
48 SEC_TO_MS(static_cast<uint64_t>(startTime)), SEC_TO_MS(static_cast<uint64_t>(endTime)));
50 int ret = Querier::query(sql);
56 int PedometerQuerier::query(int startTime, int endTime, int anchor, int interval)
58 char *sql = sqlite3_mprintf(
59 "SELECT " PROJECTION \
60 " FROM " PEDOMETER_RECORD \
61 " WHERE " KEY_END_TIME " > %llu AND " KEY_END_TIME " <= %llu" \
62 " GROUP BY ROUND((" KEY_END_TIME " - %llu) / %llu + 0.5)" \
63 " ORDER BY " KEY_END_TIME " ASC",
64 SEC_TO_MS(static_cast<uint64_t>(startTime)), SEC_TO_MS(static_cast<uint64_t>(endTime)),
65 SEC_TO_MS(static_cast<uint64_t>(anchor)), SEC_TO_MS(static_cast<uint64_t>(interval)));
67 int ret = Querier::query(sql);