Simplified some debug code
This commit is contained in:
parent
f76b271d24
commit
45451125e3
1 changed files with 16 additions and 33 deletions
|
|
@ -120,12 +120,16 @@ commodity_t::history_t::find_price(const optional<datetime_t>& moment,
|
||||||
price_point_t point;
|
price_point_t point;
|
||||||
bool found = false;
|
bool found = false;
|
||||||
|
|
||||||
|
#if defined(DEBUG_ON)
|
||||||
#define DEBUG_INDENT(cat, indent) \
|
#define DEBUG_INDENT(cat, indent) \
|
||||||
do { \
|
do { \
|
||||||
if (SHOW_DEBUG(cat)) \
|
if (SHOW_DEBUG(cat)) \
|
||||||
for (int i = 0; i < indent; i++) \
|
for (int i = 0; i < indent; i++) \
|
||||||
ledger::_log_buffer << " "; \
|
ledger::_log_buffer << " "; \
|
||||||
} while (false)
|
} while (false)
|
||||||
|
#else
|
||||||
|
#define DEBUG_INDENT(cat, indent)
|
||||||
|
#endif
|
||||||
|
|
||||||
#if defined(DEBUG_ON)
|
#if defined(DEBUG_ON)
|
||||||
DEBUG_INDENT("commodity.prices.find", indent);
|
DEBUG_INDENT("commodity.prices.find", indent);
|
||||||
|
|
@ -141,10 +145,8 @@ commodity_t::history_t::find_price(const optional<datetime_t>& moment,
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (prices.size() == 0) {
|
if (prices.size() == 0) {
|
||||||
#if defined(DEBUG_ON)
|
|
||||||
DEBUG_INDENT("commodity.prices.find", indent);
|
DEBUG_INDENT("commodity.prices.find", indent);
|
||||||
DEBUG("commodity.prices.find", " there are no prices in this history");
|
DEBUG("commodity.prices.find", " there are no prices in this history");
|
||||||
#endif
|
|
||||||
return none;
|
return none;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -153,10 +155,9 @@ commodity_t::history_t::find_price(const optional<datetime_t>& moment,
|
||||||
point.when = (*r).first;
|
point.when = (*r).first;
|
||||||
point.price = (*r).second;
|
point.price = (*r).second;
|
||||||
found = true;
|
found = true;
|
||||||
#if defined(DEBUG_ON)
|
|
||||||
DEBUG_INDENT("commodity.prices.find", indent);
|
DEBUG_INDENT("commodity.prices.find", indent);
|
||||||
DEBUG("commodity.prices.find", " using most recent price");
|
DEBUG("commodity.prices.find", " using most recent price");
|
||||||
#endif
|
|
||||||
} else {
|
} else {
|
||||||
history_map::const_iterator i = prices.lower_bound(*moment);
|
history_map::const_iterator i = prices.lower_bound(*moment);
|
||||||
if (i == prices.end()) {
|
if (i == prices.end()) {
|
||||||
|
|
@ -164,10 +165,9 @@ commodity_t::history_t::find_price(const optional<datetime_t>& moment,
|
||||||
point.when = (*r).first;
|
point.when = (*r).first;
|
||||||
point.price = (*r).second;
|
point.price = (*r).second;
|
||||||
found = true;
|
found = true;
|
||||||
#if defined(DEBUG_ON)
|
|
||||||
DEBUG_INDENT("commodity.prices.find", indent);
|
DEBUG_INDENT("commodity.prices.find", indent);
|
||||||
DEBUG("commodity.prices.find", " using last price");
|
DEBUG("commodity.prices.find", " using last price");
|
||||||
#endif
|
|
||||||
} else {
|
} else {
|
||||||
point.when = (*i).first;
|
point.when = (*i).first;
|
||||||
if (*moment < point.when) {
|
if (*moment < point.when) {
|
||||||
|
|
@ -181,40 +181,31 @@ commodity_t::history_t::find_price(const optional<datetime_t>& moment,
|
||||||
point.price = (*i).second;
|
point.price = (*i).second;
|
||||||
found = true;
|
found = true;
|
||||||
}
|
}
|
||||||
#if defined(DEBUG_ON)
|
|
||||||
DEBUG_INDENT("commodity.prices.find", indent);
|
DEBUG_INDENT("commodity.prices.find", indent);
|
||||||
DEBUG("commodity.prices.find", " using found price");
|
DEBUG("commodity.prices.find", " using found price");
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (! found) {
|
if (! found) {
|
||||||
#if defined(DEBUG_ON)
|
|
||||||
DEBUG_INDENT("commodity.prices.find", indent);
|
DEBUG_INDENT("commodity.prices.find", indent);
|
||||||
DEBUG("commodity.prices.find", " could not find a price");
|
DEBUG("commodity.prices.find", " could not find a price");
|
||||||
#endif
|
|
||||||
return none;
|
return none;
|
||||||
}
|
}
|
||||||
else if (moment && point.when > *moment) {
|
else if (moment && point.when > *moment) {
|
||||||
#if defined(DEBUG_ON)
|
|
||||||
DEBUG_INDENT("commodity.prices.find", indent);
|
DEBUG_INDENT("commodity.prices.find", indent);
|
||||||
DEBUG("commodity.prices.find", " price is too young ");
|
DEBUG("commodity.prices.find", " price is too young ");
|
||||||
#endif
|
|
||||||
return none;
|
return none;
|
||||||
}
|
}
|
||||||
else if (oldest && point.when < *oldest) {
|
else if (oldest && point.when < *oldest) {
|
||||||
#if defined(DEBUG_ON)
|
|
||||||
DEBUG_INDENT("commodity.prices.find", indent);
|
DEBUG_INDENT("commodity.prices.find", indent);
|
||||||
DEBUG("commodity.prices.find", " price is too old ");
|
DEBUG("commodity.prices.find", " price is too old ");
|
||||||
#endif
|
|
||||||
return none;
|
return none;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
#if defined(DEBUG_ON)
|
|
||||||
DEBUG_INDENT("commodity.prices.find", indent);
|
DEBUG_INDENT("commodity.prices.find", indent);
|
||||||
DEBUG("commodity.prices.find",
|
DEBUG("commodity.prices.find",
|
||||||
" returning price: " << point.when << ", " << point.price);
|
" returning price: " << point.when << ", " << point.price);
|
||||||
#endif
|
|
||||||
return point;
|
return point;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -232,7 +223,13 @@ commodity_t::varied_history_t::find_price(const commodity_t& source,
|
||||||
optional<price_point_t> point;
|
optional<price_point_t> point;
|
||||||
optional<datetime_t> limit = oldest;
|
optional<datetime_t> limit = oldest;
|
||||||
|
|
||||||
assert(! commodity || source != *commodity);
|
#if defined(VERIFY_ON)
|
||||||
|
if (commodity) {
|
||||||
|
VERIFY(source != *commodity);
|
||||||
|
VERIFY(! commodity->has_annotation());
|
||||||
|
VERIFY(source.referent() != commodity->referent());
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#if defined(DEBUG_ON)
|
#if defined(DEBUG_ON)
|
||||||
DEBUG_INDENT("commodity.prices.find", indent);
|
DEBUG_INDENT("commodity.prices.find", indent);
|
||||||
|
|
@ -267,11 +264,9 @@ commodity_t::varied_history_t::find_price(const commodity_t& source,
|
||||||
if (comm == source)
|
if (comm == source)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
#if defined(DEBUG_ON)
|
|
||||||
DEBUG_INDENT("commodity.prices.find", indent + 1);
|
DEBUG_INDENT("commodity.prices.find", indent + 1);
|
||||||
DEBUG("commodity.prices.find",
|
DEBUG("commodity.prices.find",
|
||||||
" searching for price via commodity '" << comm << "'");
|
" searching for price via commodity '" << comm << "'");
|
||||||
#endif
|
|
||||||
|
|
||||||
point = hist.second.find_price(moment, limit
|
point = hist.second.find_price(moment, limit
|
||||||
#if defined(DEBUG_ON)
|
#if defined(DEBUG_ON)
|
||||||
|
|
@ -284,10 +279,8 @@ commodity_t::varied_history_t::find_price(const commodity_t& source,
|
||||||
optional<price_point_t> xlat;
|
optional<price_point_t> xlat;
|
||||||
|
|
||||||
if (commodity && comm != *commodity) {
|
if (commodity && comm != *commodity) {
|
||||||
#if defined(DEBUG_ON)
|
|
||||||
DEBUG_INDENT("commodity.prices.find", indent + 1);
|
DEBUG_INDENT("commodity.prices.find", indent + 1);
|
||||||
DEBUG("commodity.prices.find", " looking for translation price");
|
DEBUG("commodity.prices.find", " looking for translation price");
|
||||||
#endif
|
|
||||||
|
|
||||||
xlat = comm.find_price(commodity, moment, limit
|
xlat = comm.find_price(commodity, moment, limit
|
||||||
#if defined(DEBUG_ON)
|
#if defined(DEBUG_ON)
|
||||||
|
|
@ -295,57 +288,47 @@ commodity_t::varied_history_t::find_price(const commodity_t& source,
|
||||||
#endif
|
#endif
|
||||||
);
|
);
|
||||||
if (xlat) {
|
if (xlat) {
|
||||||
#if defined(DEBUG_ON)
|
|
||||||
DEBUG_INDENT("commodity.prices.find", indent + 1);
|
DEBUG_INDENT("commodity.prices.find", indent + 1);
|
||||||
DEBUG("commodity.prices.find", " found translated price "
|
DEBUG("commodity.prices.find", " found translated price "
|
||||||
<< xlat->price << " from " << xlat->when);
|
<< xlat->price << " from " << xlat->when);
|
||||||
#endif
|
|
||||||
|
|
||||||
point->price = xlat->price * point->price;
|
point->price = xlat->price * point->price;
|
||||||
if (xlat->when < point->when) {
|
if (xlat->when < point->when) {
|
||||||
point->when = xlat->when;
|
point->when = xlat->when;
|
||||||
#if defined(DEBUG_ON)
|
|
||||||
DEBUG_INDENT("commodity.prices.find", indent + 1);
|
DEBUG_INDENT("commodity.prices.find", indent + 1);
|
||||||
DEBUG("commodity.prices.find",
|
DEBUG("commodity.prices.find",
|
||||||
" adjusting date of result back to " << point->when);
|
" adjusting date of result back to " << point->when);
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
#if defined(DEBUG_ON)
|
|
||||||
DEBUG_INDENT("commodity.prices.find", indent + 1);
|
DEBUG_INDENT("commodity.prices.find", indent + 1);
|
||||||
DEBUG("commodity.prices.find", " saw no translated price there");
|
DEBUG("commodity.prices.find", " saw no translated price there");
|
||||||
#endif
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
assert(! commodity || point->price.commodity() == *commodity);
|
assert(! commodity || point->price.commodity() == *commodity);
|
||||||
#if defined(DEBUG_ON)
|
|
||||||
DEBUG_INDENT("commodity.prices.find", indent + 1);
|
DEBUG_INDENT("commodity.prices.find", indent + 1);
|
||||||
DEBUG("commodity.prices.find",
|
DEBUG("commodity.prices.find",
|
||||||
" saw a price there: " << point->price << " from " << point->when);
|
" saw a price there: " << point->price << " from " << point->when);
|
||||||
#endif
|
|
||||||
if (! limit || point->when > *limit) {
|
if (! limit || point->when > *limit) {
|
||||||
limit = point->when;
|
limit = point->when;
|
||||||
best = *point;
|
best = *point;
|
||||||
found = true;
|
found = true;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
#if defined(DEBUG_ON)
|
|
||||||
DEBUG_INDENT("commodity.prices.find", indent + 1);
|
DEBUG_INDENT("commodity.prices.find", indent + 1);
|
||||||
DEBUG("commodity.prices.find", " saw no price there");
|
DEBUG("commodity.prices.find", " saw no price there");
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (found) {
|
if (found) {
|
||||||
#if defined(DEBUG_ON)
|
|
||||||
DEBUG_INDENT("commodity.prices.find", indent);
|
DEBUG_INDENT("commodity.prices.find", indent);
|
||||||
DEBUG("commodity.prices.find",
|
DEBUG("commodity.prices.find",
|
||||||
" found price " << best.price << " from " << best.when);
|
" found price " << best.price << " from " << best.when);
|
||||||
DEBUG("commodity.download",
|
DEBUG("commodity.download",
|
||||||
"found price " << best.price << " from " << best.when);
|
"found price " << best.price << " from " << best.when);
|
||||||
#endif
|
|
||||||
return best;
|
return best;
|
||||||
}
|
}
|
||||||
return none;
|
return none;
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue