-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstatistics.cpp
More file actions
194 lines (162 loc) · 8.33 KB
/
statistics.cpp
File metadata and controls
194 lines (162 loc) · 8.33 KB
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
//
// statistics.cpp
// Test Product
//
// Created by David Brown on 10/06/2017.
// Copyright © 2017 David Brown. All rights reserved.
//
#include <iomanip>
#include <iostream>
#include <fstream>
#include "statistics.hpp"
Statistics *Statistics::_instance = nullptr;
Statistics *Statistics::Instance()
{
if (_instance == nullptr) {
_instance = new Statistics();
}
return _instance;
}
Statistics::Statistics()
{
reg = Register::Instance();
current = new Fields;
}
// This is called BEFORE the next period is triggered. It dumps current stats
// and creates a new record for the next period, entering BFwd amounts from
// the CFwd amounts from the previous period where appropriate.
void Statistics::next(int period)
{
Government *gov = Government::Instance();
stats.push_back(current);
Fields *previous = stats.back();
current = new Fields;
// Gov
previous->gov.cfwd = gov->getBalance();
previous->gov.exp = gov->getExpenditure();
previous->gov.ben = gov->getBenefitsPaid();
previous->gov.rec = gov->getReceipts();
previous->gov.num_firms = reg->getNumFirms();
previous->gov.num_emps = reg->getNumEmployed();
previous->gov.num_unemps = reg->getNumUnemployed();
previous->gov.num_gov_emps = gov->getNumEmployees();
previous->gov.hires = reg->getNumHired();
previous->gov.fires = reg->getNumFired();
//
current->gov.num_emps = reg->getNumEmployed();
current->gov.bfwd = previous->gov.cfwd;
// Prod
previous->prod.cfwd = reg->getProdBal();
previous->prod.grant = reg->getGrantsRecd();
previous->prod.dedns = reg->getDednsPaid();
previous->prod.wages = reg->getWagesPaid();
previous->prod.bonuses = reg->getBonusesPaid();
previous->prod.sales = reg->getSalesReceipts();
previous->prod.sales_tax = reg->getSalesTaxPaid();
//
current->prod.bfwd = previous->prod.cfwd;
// Dom
previous->emp.close = reg->getWorkersBal();
previous->emp.wages = reg->getWagesRecd();
previous->emp.benefits = reg->getBenefitsRecd();
previous->emp.inc_tax = reg->getIncTaxPaid();
previous->emp.purch = reg->getPurchasesMade();
// *
current->emp.start = previous->emp.close;
}
#include <stdio.h>
#include <unistd.h>
#include <string.h>
void Statistics::report()
{
// Kludge to get the directory containing the output file
char the_path[256];
getcwd(the_path, 255);
std::ofstream myfile;
std::string fname(Settings::fname + ".csv");
myfile.open(fname);
if (myfile.is_open()) {
std::cout << "\nOutput file is " << fname << std::endl;
myfile << "\"Period\",\"Gov Bal\",\"Prod Bal\",\"Dom Bal\",\"Gov Exp\",\"Benefits Paid\",\"Bonuses Paid\",\"Gov Recpts\",\"Hires\",\"Fires\",\"Num Firms\",\"Employed\",\"Unemployed\",\"Gov Emps\",\"Inc Tax\",\"Sales Tax\",\"Dedns\",\"Wages+Bonus\",\"Benefits Recd\",\"Consumption\"\n";
} else {
std::cout << "Cannot open output file\n";
}
std::cout << "\nLOG\n";
int period = 0;
for (auto it : stats) {
if (myfile.is_open()) {
myfile << period
<< "," << it->gov.cfwd
<< "," << it->prod.cfwd
<< "," << it->emp.close
<< "," << it->gov.exp
<< "," << it->gov.ben
<< "," << it->prod.bonuses
<< "," << it->gov.rec
<< "," << it->gov.hires
<< "," << it->gov.fires
<< "," << it->gov.num_firms
<< "," << it->gov.num_emps
<< "," << it->gov.num_unemps
<< "," << it->gov.num_gov_emps
<< "," << it->emp.inc_tax
<< "," << it->prod.sales_tax
<< "," << it->prod.dedns
<< "," << it->emp.wages
<< "," << it->emp.benefits
<< "," << it->emp.purch
<< "\n";
// TO DO: Add new hires, rehires and fires...
}
std::cout << "\nPeriod " << ++period << "\n---------\n";
std::cout << "\nGovernment\n"
<< "\n\t" << std::setw(21) << "Expenditure: " << std::setw(9) << it->gov.exp
<< "\n\t" << std::setw(21) << "Benefits Paid: " << std::setw(9) << it->gov.ben << " +"
<< "\n\t" << std::setw(21) << "Receipts: " << std::setw(9) << it->gov.rec << " -"
<< "\n\t" << std::setw(21) << " " << std::setw(9) << "---------"
<< "\n\t" << std::setw(21) << "Deficit: " << std::setw(9) << (it->gov.exp + it->gov.ben - it->gov.rec) << "\n"
<< "\n\t" << std::setw(21) << "Sector balance: " << std::setw(9) << it->gov.cfwd
<< "\n";
std::cout << "\nFirms\n"
<< "\n\t" << std::setw(21) << "Number of firms: " << std::setw(9) << it->gov.num_firms
<< "\n\t" << std::setw(21) << "Number of employees: " << std::setw(9) << it->gov.num_emps
<< "\n\t" << std::setw(21) << "Hired this week: " << std::setw(9) << it->gov.hires
<< "\n\t" << std::setw(21) << "Fired this week: " << std::setw(9) << it->gov.fires << "\n"
<< "\n\t" << std::setw(21) << "Starting balance: " << std::setw(9) << it->prod.bfwd
<< "\n\t" << std::setw(21) << "Government grant: " << std::setw(9) << it->prod.grant << " +"
<< "\n\t" << std::setw(21) << "Wages paid: " << std::setw(9) << it->prod.wages << " -"
<< "\n\t" << std::setw(21) << "Bonuses paid: " << std::setw(9) << it->prod.bonuses << " -"
<< "\n\t" << std::setw(21) << "Dedns paid: " << std::setw(9) << it->prod.dedns << " -"
<< "\n\t" << std::setw(21) << "Sales: " << std::setw(9) << it->prod.sales << " +"
<< "\n\t" << std::setw(21) << "Sales tax paid: " << std::setw(9) << it->prod.sales_tax << " -"
<< "\n\t" << std::setw(21) << "Closing balance: " << std::setw(9) << it->prod.cfwd << " -"
<< "\n\t" << std::setw(21) << " " << std::setw(9) << "---------"
<< "\n\t" << std::setw(21) << " " << std::setw(9) << (it->prod.bfwd + it->prod.grant - it->prod.wages - it->prod.bonuses - it->prod.dedns + it->prod.sales - it->prod.sales_tax - it->prod.cfwd) << "\n";
std::cout << "\nWorkers\n";
std::cout << "\n\t" << std::setw(21) << "Starting balance: " << std::setw(9) << it->emp.start
<< "\n\t" << std::setw(21) << "Wages recd: " << std::setw(9) << it->emp.wages << " +"
<< "\n\t" << std::setw(21) << "Income tax paid: " << std::setw(9) << it->emp.inc_tax << " -"
<< "\n\t" << std::setw(21) << "Benefits Recd: " << std::setw(9) << it->emp.benefits << " +"
<< "\n\t" << std::setw(21) << "Purchases: " << std::setw(9) << it->emp.purch << " -"
<< "\n\t" << std::setw(21) << "Closing balance: " << std::setw(9) << it->emp.close << " -"
<< "\n\t" << std::setw(21) << " " << std::setw(9) << "========="
<< "\n\t" << std::setw(21) << " " << std::setw(9) << (it->emp.start + it->emp.wages + it->emp.benefits - it->emp.inc_tax - it->emp.purch - it->emp.close)
<< "\n\t" << std::setw(21) << " " << std::setw(9) << "---------"
<< "\n";
int recon = it->gov.cfwd + it->prod.cfwd + it->emp.close;
std::cout << "\nSectors\n"
<< "\n\t" << std::setw(21) << "Government: " << std::setw(9) << it->gov.cfwd
<< "\n\t" << std::setw(21) << "Firms: " << std::setw(9) << it->prod.cfwd
<< "\n\t" << std::setw(21) << "Workers: " << std::setw(9) << it->emp.close
<< "\n\t" << std::setw(21) << " " << std::setw(9) << "---------"
<< "\n\t" << std::setw(21) << " " << std::setw(9) << recon
<< "\n\t" << std::setw(21) << " " << std::setw(9) << "---------"
<< "\n";
if (recon != 0) {
std::cout << "*** Reconciliation fails ***\n";
}
}
if (myfile.is_open()) {
myfile.close();
}
}