Commit 3b90b9cb authored by Jason Rhinelander's avatar Jason Rhinelander

Simulation data: make book numbers per capita

books_written, books_bought, books_pirated, and books_public are all not
particular useful as total numbers because, ceteris paribus, a larger
simulation will have larger values of all of them.

This changes them all to per-capita values (the first changes to a
per-100-readers value, the rest to per-reader averages).
parent 2720ff75
......@@ -19,8 +19,7 @@ namespace creativity { namespace data {
double book_market_periods(const Storage &cs, eris_time_t from, eris_time_t to) {
if (from > to) throw std::logic_error("from > to");
unsigned long total = 0;
unsigned int count = 0;
uint_fast32_t total = 0, count = 0;
auto csto = cs[to];
for (auto &bp : csto->books) {
auto &b = bp.second;
......@@ -36,7 +35,7 @@ double book_market_periods(const Storage &cs, eris_time_t from, eris_time_t to)
double book_p0(const Storage &cs, eris_time_t from, eris_time_t to) {
if (from > to) throw std::logic_error("from > to");
double p_total = 0;
unsigned int count = 0;
uint_fast32_t count = 0;
for (eris_time_t t = std::max<eris_time_t>(1, from); t <= to; t++) {
auto cst = cs[t];
for (auto &bp : cst->books) {
......@@ -292,62 +291,71 @@ DIST_FNS(book_author_effort)
double books_written(const Storage &cs, eris_time_t from, eris_time_t to) {
if (from > to) throw std::logic_error("from > to");
unsigned int count = 0;
double count = 0;
for (eris_time_t t = from; t <= to; t++) {
auto cst = cs[t];
uint_fast32_t period_count = 0;
for (auto &bp : cst->books) {
auto &b = bp.second;
if (b.created == t) {
count++;
period_count++;
}
}
count += period_count / (double) cst->readers.size();
}
return count / (double) (to-from+1);
return count / (to-from+1) * 100.0;
}
double books_bought(const Storage &cs, eris_time_t from, eris_time_t to) {
if (from > to) throw std::logic_error("from > to");
unsigned long count = 0;
double count = 0;
for (eris_time_t t = from; t <= to; t++) {
auto cst = cs[t];
uint_fast32_t period_count = 0;
for (auto &bp : cst->books) {
auto &b = bp.second;
if (b.market_private)
count += b.sales;
period_count += b.sales;
}
count += period_count / (double) cst->readers.size();
}
return count / (double) (to-from+1);
return count / (to-from+1);
}
double books_pirated(const Storage &cs, eris_time_t from, eris_time_t to) {
if (from > to) throw std::logic_error("from > to");
unsigned long count = 0;
double count = 0;
for (eris_time_t t = from; t <= to; t++) {
auto cst = cs[t];
uint_fast32_t period_count = 0;
for (auto &bp : cst->books) {
auto &b = bp.second;
count += b.pirated;
period_count += b.pirated;
}
count += period_count / (double) cst->readers.size();
}
return count / (double) (to-from+1);
return count / (to-from+1);
}
double books_public_copies(const Storage &cs, eris_time_t from, eris_time_t to) {
if (from > to) throw std::logic_error("from > to");
unsigned long count = 0;
double count = 0;
for (eris_time_t t = from; t <= to; t++) {
auto cst = cs[t];
uint_fast32_t period_count = 0;
for (auto &bp : cst->books) {
auto &b = bp.second;
if (b.market_public())
count += b.sales;
period_count += b.sales;
}
count += period_count / (double) cst->readers.size();
}
return count / (double) (to-from+1);
......
......@@ -182,20 +182,21 @@ DIST_FNS(net_u)
#undef DIST_FNS
/** Average number of books written per period.
/** Average number of books written per 100 agents per period.
*/
double books_written(const state::Storage &cs, eris::eris_time_t from, eris::eris_time_t to);
/** Average number of books purchased per period (aggregate, not per-reader)
/** Average number of books purchased per reader per period
*/
double books_bought(const state::Storage &cs, eris::eris_time_t from, eris::eris_time_t to);
/** Average number of books pirated per period (aggreate, not per-reader). Note that pirated copies
* of books that left the market before `from` are still included.
/** Average number of books pirated per reader per period. Note that pirated copies of books that
* left the market before `from` are still included, i.e. this counts all piracy activity in the
* given period, not just piracy activity for books written in the given period.
*/
double books_pirated(const state::Storage &cs, eris::eris_time_t from, eris::eris_time_t to);
/** Average number of books obtained from the public provider.
/** Average number of books obtained from the public provider per reader per period.
*/
double books_public_copies(const state::Storage &cs, eris::eris_time_t from, eris::eris_time_t to);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment