-
Notifications
You must be signed in to change notification settings - Fork 7
/
Avg.cpp
executable file
·70 lines (56 loc) · 1.94 KB
/
Avg.cpp
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
/***************************************************************************
* (c) 2008-2011 Aleksandar Topuzović *
* <aleksandar.topuzovic@fer.hr>, <aleksandar.topuzovic@gmail.com> *
***************************************************************************/
#include "beagle/GP.hpp"
#include "Avg.hpp"
#include "util.hpp"
#include <sstream>
#include <cmath>
#include <fstream>
using namespace Beagle;
// Ime AVG
Avg::Avg() :
Beagle::GP::Primitive(1, "AVG")
{ }
#ifdef BEAGLE_HAVE_RTTI
// Argumenti tipa Double
const std::type_info* Avg::getArgType(unsigned int inN, Beagle::GP::Context& ioContext) const
{
Beagle_AssertM(inN < 1);
return &typeid(UInt);
}
// Povratna vrjednost double
const std::type_info* Avg::getReturnType(Beagle::GP::Context& ioContext) const
{
return &typeid(Double);
}
#endif // BEAGLE_HAVE_RTTI
// Vraca srednju vrjednost dionice kroz period
void Avg::execute(GP::Datum& outDatum, GP::Context& ioContext)
{
Double& lResult = castObjectT<Double&>(outDatum);
UInt lArg;
get1stArgument(lArg, ioContext);
trading::Context& aContext = castObjectT<trading::Context&>(ioContext);
sqlite3 *database; // Baza podataka
database = aContext.database;
std::ostringstream interval;
interval << lArg;
string sql = "SELECT AVG(ZADNJA) FROM ZSE WHERE DIONICA=UPPER('";
sql += aContext.dionica; // Dionica
sql += "') AND DATUM BETWEEN DATE('";
sql += aContext.datum;
sql += "','-";
sql += interval.str(); // Vremenski interval
sql += " day') AND DATE('";
sql += aContext.datum; // Trenutni datum
sql += "');";
//std::cout << sql << std::endl;
sqlite3_stmt *preparedStatement;
SQLITE_PREPARE_STATEMENT_TEST(preparedStatement, sql, database);
SQLITE_STEP_TEST(preparedStatement);
lResult = sqlite3_column_double(preparedStatement,0);
sqlite3_finalize(preparedStatement);
//std::cout << "AVG:" << lResult << std::endl;
}