Skip to content

Commit 1275829

Browse files
committed
save next and previous annotation to database
1 parent 48bfce2 commit 1275829

File tree

2 files changed

+23
-16
lines changed

2 files changed

+23
-16
lines changed

source/annotatorlib/source/Loader/MySQLLoader.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -46,26 +46,26 @@ void MySQLLoader::loadAttributes(Poco::Data::Session &sqlSession,
4646

4747
void MySQLLoader::loadAnnotations(Poco::Data::Session &sqlSession,
4848
Session *session) {
49-
typedef Poco::Tuple<std::string, std::string, std::string, std::string, float,
49+
typedef Poco::Tuple<std::string, std::string, std::string, std::string, std::string, float,
5050
float, float, float, std::string>
5151
AnnotationTuple;
5252
std::vector<AnnotationTuple> annotations;
5353

5454
Poco::Data::Statement statement(sqlSession);
55-
statement << "SELECT `id`,`next`,`object`, `frame`, `x`, `y`, `width`, "
55+
statement << "SELECT `id`,`next`, `previous`,`object`, `frame`, `x`, `y`, `width`, "
5656
"`height`, `type` FROM `annotations`",
5757
into(annotations);
5858
statement.execute();
5959

6060
for (AnnotationTuple at : annotations) {
61-
unsigned long object_id = std::stol(at.get<2>());
62-
unsigned long frame_id = std::stol(at.get<3>());
63-
64-
float x = at.get<4>();
65-
float y = at.get<5>();
66-
float width = at.get<6>();
67-
float height = at.get<7>();
68-
AnnotationType type = AnnotationTypeFromString(at.get<8>());
61+
unsigned long object_id = std::stol(at.get<3>());
62+
unsigned long frame_id = std::stol(at.get<4>());
63+
64+
float x = at.get<5>();
65+
float y = at.get<6>();
66+
float width = at.get<7>();
67+
float height = at.get<8>();
68+
AnnotationType type = AnnotationTypeFromString(at.get<9>());
6969

7070
shared_ptr<Object> o = session->getObject(object_id);
7171
shared_ptr<Frame> f = session->getFrame(frame_id);

source/annotatorlib/source/Storage/MySQLStorage.cpp

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ bool MySQLStorage::addAnnotation(shared_ptr<Annotation> annotation,
3333
struct Annotation {
3434
std::string id;
3535
std::string next;
36+
std::string previous;
3637
std::string object;
3738
std::string frame;
3839
float x;
@@ -44,23 +45,25 @@ bool MySQLStorage::addAnnotation(shared_ptr<Annotation> annotation,
4445
Annotation a_ = {
4546
std::to_string(annotation->getId()),
4647
"0",
48+
"0",
4749
std::to_string(annotation->getObject()->getId()),
4850
"0",
4951
annotation->getX(),
5052
annotation->getY(),
5153
annotation->getWidth(),
5254
annotation->getHeight(),
5355
AnnotatorLib::AnnotationTypeToString(annotation->getType())};
54-
if (annotation->getNext()) a_.next = std::to_string(annotation->getId());
56+
if (annotation->getNext()) a_.next = std::to_string(annotation->getNext()->getId());
57+
if (annotation->getPrevious()) a_.previous = std::to_string(annotation->getPrevious()->getId());
5558
if (annotation->getFrame())
5659
a_.frame = std::to_string(annotation->getFrame()->getId());
5760

5861
Poco::Data::Statement statement = getStatement();
5962

6063
try {
61-
statement << "INSERT IGNORE INTO `annotations` VALUES(?, ?, ?, ?, ?, ?, "
64+
statement << "INSERT IGNORE INTO `annotations` VALUES(?, ?, ?, ?, ?, ?, ?, "
6265
"?, ?, ?);",
63-
use(a_.id), use(a_.next), use(a_.object), use(a_.frame), use(a_.x),
66+
use(a_.id), use(a_.next), use(a_.previous), use(a_.object), use(a_.frame), use(a_.x),
6467
use(a_.y), use(a_.width), use(a_.height), use(a_.type);
6568
statement.execute();
6669
} catch (Poco::Exception &e) {
@@ -91,6 +94,7 @@ void MySQLStorage::updateAnnotation(shared_ptr<Annotation> annotation) {
9194
struct Annotation {
9295
std::string id;
9396
std::string next;
97+
std::string previous;
9498
std::string object;
9599
std::string frame;
96100
float x;
@@ -102,24 +106,26 @@ void MySQLStorage::updateAnnotation(shared_ptr<Annotation> annotation) {
102106
Annotation a_ = {
103107
std::to_string(annotation->getId()),
104108
"0",
109+
"0",
105110
std::to_string(annotation->getObject()->getId()),
106111
"0",
107112
annotation->getX(),
108113
annotation->getY(),
109114
annotation->getWidth(),
110115
annotation->getHeight(),
111116
AnnotatorLib::AnnotationTypeToString(annotation->getType())};
112-
if (annotation->getNext()) a_.next = std::to_string(annotation->getId());
117+
if (annotation->getNext()) a_.next = std::to_string(annotation->getNext()->getId());
118+
if (annotation->getPrevious()) a_.previous = std::to_string(annotation->getPrevious()->getId());
113119
if (annotation->getFrame())
114120
a_.frame = std::to_string(annotation->getFrame()->getId());
115121

116122
Poco::Data::Statement statement = getStatement();
117123

118124
try {
119125
statement
120-
<< "UPDATE `annotations` SET `id`=?, `next`=?, `object`=?, `frame`=?,"
126+
<< "UPDATE `annotations` SET `id`=?, `next`=?, `previous`=?, `object`=?, `frame`=?,"
121127
"`x`=?, `y`=?, `width`=?, `height`=?, `type`=? WHERE `id`=?;",
122-
use(a_.id), use(a_.next), use(a_.object), use(a_.frame), use(a_.x),
128+
use(a_.id), use(a_.next), use(a_.previous), use(a_.object), use(a_.frame), use(a_.x),
123129
use(a_.y), use(a_.width), use(a_.height), use(a_.type), use(a_.id);
124130
statement.execute();
125131
} catch (Poco::Exception &e) {
@@ -285,6 +291,7 @@ void MySQLStorage::createTables() {
285291
statement << "CREATE TABLE IF NOT EXISTS `annotations` ( \
286292
`id` char(16) NOT NULL, \
287293
`next` char(16) NOT NULL, \
294+
`previous` char(16) NOT NULL, \
288295
`object` char(16) NOT NULL, \
289296
`frame` char(16) NOT NULL, \
290297
`x` float NOT NULL default 0, \

0 commit comments

Comments
 (0)