-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.cpp
More file actions
111 lines (95 loc) · 3.58 KB
/
main.cpp
File metadata and controls
111 lines (95 loc) · 3.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
/**
* @file main.cpp
* @author clecoued <[email protected]>
* @version 1.0
*
*
* @section LICENSE
*
* Sleep Stage Algorithm
* Copyright (C) 2017 Aura Healthcare
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
* @section DESCRIPTION
*
* refer to Overview.mkd to get a detailed description of the algorithm
*/
#include <iostream>
#include <fstream>
#include <json/json.h>
#include <json/value.h>
#include <vector>
#include "boost/date_time/posix_time/posix_time.hpp"
#include "SleepStageAlgorithm.hpp"
const static int TimeIntervalLength = 120; // in seconds
const static int TimeIntervalShift = 20; //in seconds
void moveInterval(boost::posix_time::ptime& oIntervalStart,
boost::posix_time::ptime& oIntervalEnd,
std::vector<DataSamplePtr>& oCurrentIntervalSamples,
int iTimeIntervalShift )
{
oIntervalStart += boost::posix_time::seconds(iTimeIntervalShift);
oIntervalEnd += boost::posix_time::seconds(iTimeIntervalShift);
//std::cout << "Move Interval Before - " << oCurrentIntervalSamples.size() << std::endl;
std::vector<DataSamplePtr>::iterator it;
for(it = oCurrentIntervalSamples.begin(); it != oCurrentIntervalSamples.end(); it++)
{
if((*it)->getTimestamp() < oIntervalStart)
{
oCurrentIntervalSamples.erase(it);
it--;
}
else
{
break;
}
}
//std::cout << "Move Interval After - " << oIntervalStart << " " << oIntervalEnd << " " << oCurrentIntervalSamples.size() << std::endl;
}
int main ()
{
// parse json data from file
Json::Value lSleepDataJson;
std::ifstream lSleepDataStream("data/PartialNight-01-08.json", std::ifstream::binary);
lSleepDataStream >> lSleepDataJson;
// initialize interval
boost::posix_time::ptime lIntervalStart = DateHelper::jsonToPtime(lSleepDataJson[0]);
//initialTimestamp = lIntervalStart;
boost::posix_time::ptime lIntervalEnd = lIntervalStart + boost::posix_time::seconds(TimeIntervalLength);
//std::cout << lIntervalStart << " " << lIntervalEnd << std::endl;
Json::Value lCurrentSample;
boost::posix_time::ptime lCurrentSampleTimestamp;
std::vector<DataSamplePtr> lCurrentSamplesInInterval;
SleepStageAlgorithm * lSleepStageAlgorithm = new SleepStageAlgorithm();
for(int i = 0; i < lSleepDataJson.size(); i++)
{
lCurrentSample = lSleepDataJson[i];
lCurrentSampleTimestamp = DateHelper::jsonToPtime(lCurrentSample);
// fullfill data samples on a specific interval [lIntervalStart, lIntervalStart + TimeWindowSize]
if(lCurrentSampleTimestamp < lIntervalEnd)
{
DataSamplePtr lDataSamplePtr(new DataSample(lCurrentSample));
lCurrentSamplesInInterval.push_back(lDataSamplePtr);
}
// process data and move to next interval
else
{
lSleepStageAlgorithm->processSamples(lIntervalStart, lIntervalEnd, lCurrentSamplesInInterval);
moveInterval(lIntervalStart, lIntervalEnd, lCurrentSamplesInInterval, TimeIntervalShift);
}
}
delete lSleepStageAlgorithm;
return 0;
}