summaryrefslogtreecommitdiff
path: root/src/tool/moneycount/main.cpp
blob: 2c3d56c3227d0ec6c866bfa406ffdd5e4810ec76 (plain) (blame)
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
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <fstream>
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>

#include "mmo.hpp"
#include "athena_text.hpp"
#include "inf.hpp"

#define ATHENA_FILE "save/athena.txt"
#define ACCREG_FILE "save/accreg.txt"

std::vector<int> values;

void countAthena()
{
    int total = 0;
    std::string input;
    std::ifstream fp(ATHENA_FILE);
    char *buffer = new char[65536];

    while (fp.good())
    {
        std::getline(fp,input);
        mmo_charstatus *thisChar = new struct mmo_charstatus;

        strcpy(buffer,input.c_str());

        if (mmo_char_fromstr(buffer, thisChar))
        {
            total++;
            values.push_back(thisChar->zeny);
        }

        delete thisChar;
    }


    std::cout << "Parsed a total of " << total << " lines in " << ATHENA_FILE << std::endl << std::endl;

    delete [] buffer;
    fp.close();
}

void countAccReg()
{
     int total = 0;
     std::ifstream fp(ACCREG_FILE);
     char *buffer = new char[65536];
     while (fp.good())
     {
         std::string line;
         std::getline(fp, line);
         struct accreg *reg = new struct accreg;

         strcpy(buffer, line.c_str());

         if (accreg_fromstr(buffer, reg))
         {
            total++;
            for (int i = 0; i < reg->reg_num; i++)
            {
                if (strcmp(reg->reg[i].str,"#BankAccount") == 0)
                {
                    values.push_back(reg->reg[i].value);
                }
            }
         }

         delete reg;
     }

     std::cout << "Parsed a total of " << total << " lines in " << ACCREG_FILE << std::endl << std::endl;

     delete [] buffer;
     fp.close();
}

stlplus::inf stdDevTotal(0);
stlplus::inf sum(0);
stlplus::inf mean(0);

bool lessthan (int i,int j) { return (i<j); }
void findstddev(int i) { stdDevTotal += stlplus::inf((stlplus::inf(i) - mean) * (stlplus::inf(i) - mean)); }
void findSum(int i) { sum += stlplus::inf(i); }

stlplus::inf infsqrt(stlplus::inf &x)
{
    stlplus::inf old(x);
    stlplus::inf newv(x / stlplus::inf(2));
    while (old - newv > stlplus::inf(1))
    {
        old = newv;
        newv = old - (old * old - x) / (stlplus::inf(2) * old);
    }
    return newv;
}


void showStats()
{
    // Reset globals
    sum = 0;
    mean = 0;
    stdDevTotal = 0;

    std::sort(values.begin(), values.end(), lessthan);
    std::for_each(values.begin(), values.end(), findSum);

    stlplus::inf total(sum);
    stlplus::inf count(values.size());
    stlplus::inf mean(total / count);

    std::for_each(values.begin(), values.end(), findstddev);

    int a4th = stlplus::inf(count / stlplus::inf(4)).to_int();
    int a10th = stlplus::inf(count / stlplus::inf(10)).to_int();

    int lower = values[0],

        t1 = values[a10th * 1],
        t2 = values[a10th * 2],

        q1 = values[a4th * 1],

        t3 = values[a10th * 3],
        t4 = values[a10th * 4],

        median = values[a4th * 2],

        t6 = values[a10th * 6],
        t7 = values[a10th * 7],

        q3 = values[a4th * 3],

        t8 = values[a10th * 8],
        t9 = values[a10th * 9],

        upper = values[count.to_int() - 1];

    stlplus::inf variance(stdDevTotal / count);

    std::cout << "Sum = " << total
              << "\nCount = " << count
              << "\nMean = " << mean
              << "\nSimple Variance = " << variance
              << "\nStandard Deviation = " << infsqrt(variance)
              << "\nLower bound = " << lower
              << "\n10th Percentile = " << t1
              << "\n20th Percentile  = " << t2
              << "\nQ1 = " << q1
              << "\n30th Percentile = " << t3
              << "\n40th Percentile = " << t4
              << "\nMedian = " << median
              << "\n60th Percentile = " << t6
              << "\n70th Percentile = " << t7
              << "\nQ3 = " << q3
              << "\n80th Percentile = " << t8
              << "\n90th Percentile = " << t9
              << "\nUpper bound = " << upper << std::endl << std::endl;
}

int main()
{
    countAthena();
    std::cout << "The stats for player held money is:" << std::endl;
    showStats();
    values.clear();

    countAccReg();
    std::cout << "The stats for bank held money is:" << std::endl;
    showStats();

    return 0;
}