-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[WIP] cxx, easymoney concept history
- Loading branch information
Showing
13 changed files
with
503 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
#include "../../../src/actions/emconcepthistory.hpp" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
#include "../../../src/controllers/emconcepthistorycontroller.h" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
#include "../../../src/models/emconcepthistory.h" |
1 change: 1 addition & 0 deletions
1
cxx/include/abquant/models/mongoobjects/emconcepthistoryobject.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
#include "../../../../src/models/mongoobjects/emconcepthistoryobject.h" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
#include "abquant/controllers/emconcepthistorycontroller.h" | ||
|
||
#include "abquant/models/emconcepthistory.h" | ||
|
||
void EmConceptHistoryController::index() | ||
{ | ||
auto emconcepthistoryList = EmConceptHistory::getAll(); | ||
texport(emconcepthistoryList); | ||
render(); | ||
} | ||
|
||
void EmConceptHistoryController::show(const QString& id) | ||
{ | ||
auto emconcepthistory = EmConceptHistory::get(id); | ||
texport(emconcepthistory); | ||
render(); | ||
} | ||
|
||
void EmConceptHistoryController::create() | ||
{ | ||
switch (httpRequest().method()) { | ||
case Tf::Get: | ||
render(); | ||
break; | ||
|
||
case Tf::Post: { | ||
auto emconcepthistory = httpRequest().formItems("emconcepthistory"); | ||
auto model = EmConceptHistory::create(emconcepthistory); | ||
|
||
if (!model.isNull()) { | ||
QString notice = "Created successfully."; | ||
tflash(notice); | ||
redirect(urla("show", model.id())); | ||
} else { | ||
QString error = "Failed to create."; | ||
texport(error); | ||
texport(emconcepthistory); | ||
render(); | ||
} | ||
break; | ||
} | ||
|
||
default: | ||
renderErrorResponse(Tf::NotFound); | ||
break; | ||
} | ||
} | ||
|
||
void EmConceptHistoryController::save(const QString& id) | ||
{ | ||
switch (httpRequest().method()) { | ||
case Tf::Get: { | ||
auto model = EmConceptHistory::get(id); | ||
if (!model.isNull()) { | ||
auto emconcepthistory = model.toVariantMap(); | ||
texport(emconcepthistory); | ||
render(); | ||
} | ||
break; | ||
} | ||
|
||
case Tf::Post: { | ||
QString error; | ||
auto model = EmConceptHistory::get(id); | ||
|
||
if (model.isNull()) { | ||
error = | ||
"Original data not found. It may have been updated/removed by another " | ||
"transaction."; | ||
tflash(error); | ||
redirect(urla("save", id)); | ||
break; | ||
} | ||
|
||
auto emconcepthistory = httpRequest().formItems("emconcepthistory"); | ||
model.setProperties(emconcepthistory); | ||
if (model.save()) { | ||
QString notice = "Updated successfully."; | ||
tflash(notice); | ||
redirect(urla("show", model.id())); | ||
} else { | ||
error = "Failed to update."; | ||
texport(error); | ||
texport(emconcepthistory); | ||
render(); | ||
} | ||
break; | ||
} | ||
|
||
default: | ||
renderErrorResponse(Tf::NotFound); | ||
break; | ||
} | ||
} | ||
|
||
void EmConceptHistoryController::remove(const QString& id) | ||
{ | ||
if (httpRequest().method() != Tf::Post) { | ||
renderErrorResponse(Tf::NotFound); | ||
return; | ||
} | ||
|
||
auto emconcepthistory = EmConceptHistory::get(id); | ||
emconcepthistory.remove(); | ||
redirect(urla("index")); | ||
} | ||
|
||
// Don't remove below this line | ||
T_DEFINE_CONTROLLER(EmConceptHistoryController) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#ifndef EMCONCEPTHISTORYCONTROLLER_H | ||
#define EMCONCEPTHISTORYCONTROLLER_H | ||
|
||
#include "abquant/controllers/applicationcontroller.h" | ||
|
||
class T_CONTROLLER_EXPORT EmConceptHistoryController : public ApplicationController | ||
{ | ||
Q_OBJECT | ||
public: | ||
EmConceptHistoryController() : ApplicationController() {} | ||
|
||
public slots: | ||
void index(); | ||
void show(const QString& id); | ||
void create(); | ||
void save(const QString& id); | ||
void remove(const QString& id); | ||
}; | ||
|
||
#endif // EMCONCEPTHISTORYCONTROLLER_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,199 @@ | ||
#include "abquant/models/emconcepthistory.h" | ||
|
||
#include <TreeFrogModel> | ||
|
||
#include "abquant/models/mongoobjects/emconcepthistoryobject.h" | ||
|
||
EmConceptHistory::EmConceptHistory() : TAbstractModel(), d(new EmConceptHistoryObject()) | ||
{ | ||
d->open = 0; | ||
d->close = 0; | ||
d->high = 0; | ||
d->low = 0; | ||
d->volume = 0; | ||
d->amount = 0; | ||
d->amplitude = 0; | ||
d->rise_fall_pct = 0; | ||
d->rise_fall_amt = 0; | ||
d->turnover = 0; | ||
d->date_stamp = 0; | ||
} | ||
|
||
EmConceptHistory::EmConceptHistory(const EmConceptHistory& other) : TAbstractModel(), d(other.d) {} | ||
|
||
EmConceptHistory::EmConceptHistory(const EmConceptHistoryObject& object) | ||
: TAbstractModel(), d(new EmConceptHistoryObject(object)) | ||
{ | ||
} | ||
|
||
EmConceptHistory::~EmConceptHistory() | ||
{ | ||
// If the reference count becomes 0, | ||
// the shared data object 'EmConceptHistoryObject' is deleted. | ||
} | ||
|
||
QString EmConceptHistory::id() const { return d->_id; } | ||
|
||
QString EmConceptHistory::date() const { return d->date; } | ||
|
||
void EmConceptHistory::setDate(const QString& date) { d->date = date; } | ||
|
||
double EmConceptHistory::open() const { return d->open; } | ||
|
||
void EmConceptHistory::setOpen(double open) { d->open = open; } | ||
|
||
double EmConceptHistory::close() const { return d->close; } | ||
|
||
void EmConceptHistory::setClose(double close) { d->close = close; } | ||
|
||
double EmConceptHistory::high() const { return d->high; } | ||
|
||
void EmConceptHistory::setHigh(double high) { d->high = high; } | ||
|
||
double EmConceptHistory::low() const { return d->low; } | ||
|
||
void EmConceptHistory::setLow(double low) { d->low = low; } | ||
|
||
double EmConceptHistory::volume() const { return d->volume; } | ||
|
||
void EmConceptHistory::setVolume(double volume) { d->volume = volume; } | ||
|
||
double EmConceptHistory::amount() const { return d->amount; } | ||
|
||
void EmConceptHistory::setAmount(double amount) { d->amount = amount; } | ||
|
||
double EmConceptHistory::riseFallPct() const { return d->rise_fall_pct; } | ||
|
||
void EmConceptHistory::setRiseFallPct(double riseFallPct) { d->rise_fall_pct = riseFallPct; } | ||
|
||
double EmConceptHistory::riseFallAmt() const { return d->rise_fall_amt; } | ||
|
||
void EmConceptHistory::setRiseFallAmt(double riseFallAmt) { d->rise_fall_amt = riseFallAmt; } | ||
|
||
double EmConceptHistory::turnover() const { return d->turnover; } | ||
|
||
void EmConceptHistory::setTurnover(double turnover) { d->turnover = turnover; } | ||
|
||
QString EmConceptHistory::mktCode() const { return d->mkt_code; } | ||
|
||
void EmConceptHistory::setMktCode(const QString& mktCode) { d->mkt_code = mktCode; } | ||
|
||
double EmConceptHistory::dateStamp() const { return d->date_stamp; } | ||
|
||
void EmConceptHistory::setDateStamp(double dateStamp) { d->date_stamp = dateStamp; } | ||
|
||
EmConceptHistory& EmConceptHistory::operator=(const EmConceptHistory& other) | ||
{ | ||
d = other.d; // increments the reference count of the data | ||
return *this; | ||
} | ||
|
||
bool EmConceptHistory::upsert(const QVariantMap& criteria) | ||
{ | ||
auto* obj = dynamic_cast<TMongoObject*>(modelData()); | ||
return (obj) ? obj->upsert(criteria) : false; | ||
} | ||
|
||
EmConceptHistory EmConceptHistory::create(const QString& date, double open, double close, double high, double low, | ||
double volume, double amount, double amplitude, double riseFallPct, | ||
double riseFallAmt, double turnover, const QString& mktCode, double dateStamp) | ||
{ | ||
EmConceptHistoryObject obj; | ||
obj.date = date; | ||
obj.open = open; | ||
obj.close = close; | ||
obj.high = high; | ||
obj.low = low; | ||
obj.volume = volume; | ||
obj.amount = amount; | ||
obj.amplitude = amplitude; | ||
obj.rise_fall_pct = riseFallPct; | ||
obj.rise_fall_amt = riseFallAmt; | ||
obj.turnover = turnover; | ||
obj.mkt_code = mktCode; | ||
obj.date_stamp = dateStamp; | ||
if (!obj.create()) { | ||
return EmConceptHistory(); | ||
} | ||
return EmConceptHistory(obj); | ||
} | ||
|
||
EmConceptHistory EmConceptHistory::create(const QVariantMap& values) | ||
{ | ||
EmConceptHistory model; | ||
model.setProperties(values); | ||
if (!model.d->create()) { | ||
model.d->clear(); | ||
} | ||
return model; | ||
} | ||
|
||
EmConceptHistory EmConceptHistory::get(const QString& id) | ||
{ | ||
TMongoODMapper<EmConceptHistoryObject> mapper; | ||
return EmConceptHistory(mapper.findByObjectId(id)); | ||
} | ||
|
||
QList<EmConceptHistory> EmConceptHistory::get_price(const QStringList& codes, double start, double end) | ||
{ | ||
TMongoODMapper<EmConceptHistoryObject> mapper; | ||
// mapper.setSortOrder(EmConceptHistoryObject::Date, Tf::DescendingOrder); | ||
TCriteria cri; | ||
// QDateTime start_ = QDateTime::fromString(start, Qt::ISODate); | ||
cri.add(EmConceptHistoryObject::MktCode, TMongo::In, | ||
codes); // AND add to the end operator | ||
|
||
cri.add(EmConceptHistoryObject::DateStamp, TMongo::GreaterThan, | ||
start); // AND add to the end operator | ||
|
||
// QDateTime end_ = QDateTime::fromString(end, Qt::ISODate); | ||
cri.add(EmConceptHistoryObject::DateStamp, TMongo::LessEqual, | ||
end); // AND add to the end operator | ||
return tfGetModelListByMongoCriteria<EmConceptHistory, EmConceptHistoryObject>(cri); | ||
} | ||
|
||
int EmConceptHistory::count() | ||
{ | ||
TMongoODMapper<EmConceptHistoryObject> mapper; | ||
return mapper.findCount(); | ||
} | ||
|
||
QList<EmConceptHistory> EmConceptHistory::getAll() | ||
{ | ||
return tfGetModelListByMongoCriteria<EmConceptHistory, EmConceptHistoryObject>(TCriteria()); | ||
} | ||
|
||
QJsonArray EmConceptHistory::getAllJson() | ||
{ | ||
QJsonArray array; | ||
TMongoODMapper<EmConceptHistoryObject> mapper; | ||
|
||
if (mapper.find()) { | ||
while (mapper.next()) { | ||
array.append(QJsonValue(QJsonObject::fromVariantMap(EmConceptHistory(mapper.value()).toVariantMap()))); | ||
} | ||
} | ||
return array; | ||
} | ||
|
||
TModelObject* EmConceptHistory::modelData() { return d.data(); } | ||
|
||
const TModelObject* EmConceptHistory::modelData() const { return d.data(); } | ||
|
||
QDataStream& operator<<(QDataStream& ds, const EmConceptHistory& model) | ||
{ | ||
auto varmap = model.toVariantMap(); | ||
ds << varmap; | ||
return ds; | ||
} | ||
|
||
QDataStream& operator>>(QDataStream& ds, EmConceptHistory& model) | ||
{ | ||
QVariantMap varmap; | ||
ds >> varmap; | ||
model.setProperties(varmap); | ||
return ds; | ||
} | ||
|
||
// Don't remove below this line | ||
T_REGISTER_STREAM_OPERATORS(EmConceptHistory) |
Oops, something went wrong.