Add inner month statistics
This commit is contained in:
@@ -151,14 +151,17 @@ void StatsPanel::UpdateStats(int monthFrom, int yearFrom, int monthTo, int yearT
|
||||
{
|
||||
std::map<wxString, std::map<int, std::map<int, double> > > accountAmounts;
|
||||
std::map<wxString, double> categories;
|
||||
std::map<wxString, std::vector<double> > operations;
|
||||
std::map<wxString, std::vector<double> >::iterator accountIdIt2;
|
||||
std::map<wxString, double>::iterator categoriesIt;
|
||||
std::map<wxString, std::map<int, std::map<int, double> > >::iterator accountIdIt;
|
||||
std::map<int, std::map<int, double> >::iterator accountYearIt;
|
||||
double total;
|
||||
int size, i, a, b, percents, account;
|
||||
int size, i, a, b, percents, account, nbDays;
|
||||
double *amounts;
|
||||
wxString value;
|
||||
User* user = _kiss->GetUser();
|
||||
wxDateTime date;
|
||||
|
||||
if (_chart)
|
||||
{
|
||||
@@ -167,58 +170,100 @@ void StatsPanel::UpdateStats(int monthFrom, int yearFrom, int monthTo, int yearT
|
||||
delete _chart;
|
||||
}
|
||||
|
||||
_kiss->GetStats(monthFrom, yearFrom, monthTo, yearTo, &accountAmounts, &categories);
|
||||
|
||||
// first step: create plot
|
||||
_plot = new XYPlot();
|
||||
|
||||
// create dataset
|
||||
XYSimpleDataset *dataset = new XYSimpleDataset();
|
||||
|
||||
// Line on 0 all over the years
|
||||
size = ((yearTo - yearFrom) + 1) * 12;
|
||||
amounts = new double[size*2];
|
||||
for (a=0; a<(size/12); a++)
|
||||
if (monthFrom == monthTo && yearFrom == yearTo)
|
||||
{
|
||||
for(b=0; b<12; b++)
|
||||
{
|
||||
amounts[a*12*2+b*2+0] = a*12+b;
|
||||
amounts[a*12*2+b*2+1] = 0;
|
||||
}
|
||||
}
|
||||
nbDays = date.GetLastMonthDay((wxDateTime::Month)monthFrom, yearFrom).GetDay();
|
||||
|
||||
dataset->AddSerie((double *) amounts, size);
|
||||
delete[] amounts;
|
||||
|
||||
for (account = 0, i = 0, accountIdIt = accountAmounts.begin(); accountIdIt != accountAmounts.end();
|
||||
accountIdIt++, i++, account++)
|
||||
{
|
||||
if (!((wxCheckListBox*)_account)->IsChecked(account))
|
||||
{
|
||||
i-- ;
|
||||
continue;
|
||||
_kiss->GetMonthStats(monthFrom, yearFrom, nbDays, &operations, &categories);
|
||||
|
||||
// Line on 0 all over the years
|
||||
amounts = new double[nbDays*2];
|
||||
for (a=0; a<nbDays; a++)
|
||||
{
|
||||
amounts[a*2+0] = a;
|
||||
amounts[a*2+1] = 0;
|
||||
}
|
||||
|
||||
size = accountAmounts[accountIdIt->first].size();
|
||||
amounts = new double[size*12*2];
|
||||
size = 0;
|
||||
for(a = 0, accountYearIt = accountAmounts[accountIdIt->first].begin();
|
||||
accountYearIt != accountAmounts[accountIdIt->first].end();
|
||||
accountYearIt++, a++)
|
||||
dataset->AddSerie((double *) amounts, nbDays);
|
||||
delete[] amounts;
|
||||
|
||||
for (account = 0, i = 0, accountIdIt2 = operations.begin(); accountIdIt2 != operations.end();
|
||||
accountIdIt2++, i++, account++)
|
||||
{
|
||||
for(b = 0; b<12; b++)
|
||||
if (!((wxCheckListBox*)_account)->IsChecked(account))
|
||||
{
|
||||
i-- ;
|
||||
continue;
|
||||
}
|
||||
|
||||
amounts = new double[nbDays*2];
|
||||
size = 0;
|
||||
for (a=0; a<nbDays; a++)
|
||||
{
|
||||
if (!accountAmounts[accountIdIt->first][accountYearIt->first].count(b))
|
||||
continue;
|
||||
amounts[size*2+0] = a*12+b;
|
||||
amounts[size*2+1] = accountAmounts[accountIdIt->first][accountYearIt->first][b];
|
||||
size++;
|
||||
amounts[a*2+0] = a;
|
||||
amounts[a*2+1] = operations[accountIdIt2->first][a];
|
||||
}
|
||||
dataset->AddSerie((double *) amounts, nbDays);
|
||||
// set serie names to be displayed on legend
|
||||
dataset->SetSerieName(i+1, user->GetAccountName(accountIdIt2->first));
|
||||
delete[] amounts;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
_kiss->GetStats(monthFrom, yearFrom, monthTo, yearTo, &accountAmounts, &categories);
|
||||
|
||||
// Line on 0 all over the years
|
||||
size = ((yearTo - yearFrom) + 1) * 12;
|
||||
amounts = new double[size*2];
|
||||
for (a=0; a<(size/12); a++)
|
||||
{
|
||||
for(b=0; b<12; b++)
|
||||
{
|
||||
amounts[a*12*2+b*2+0] = a*12+b;
|
||||
amounts[a*12*2+b*2+1] = 0;
|
||||
}
|
||||
}
|
||||
dataset->AddSerie((double *) amounts, size);
|
||||
// set serie names to be displayed on legend
|
||||
dataset->SetSerieName(i+1, user->GetAccountName(accountIdIt->first));
|
||||
delete[] amounts;
|
||||
|
||||
dataset->AddSerie((double *) amounts, size);
|
||||
delete[] amounts;
|
||||
|
||||
for (account = 0, i = 0, accountIdIt = accountAmounts.begin(); accountIdIt != accountAmounts.end();
|
||||
accountIdIt++, i++, account++)
|
||||
{
|
||||
if (!((wxCheckListBox*)_account)->IsChecked(account))
|
||||
{
|
||||
i-- ;
|
||||
continue;
|
||||
}
|
||||
|
||||
size = accountAmounts[accountIdIt->first].size();
|
||||
amounts = new double[size*12*2];
|
||||
size = 0;
|
||||
for(a = 0, accountYearIt = accountAmounts[accountIdIt->first].begin();
|
||||
accountYearIt != accountAmounts[accountIdIt->first].end();
|
||||
accountYearIt++, a++)
|
||||
{
|
||||
for(b = 0; b<12; b++)
|
||||
{
|
||||
if (!accountAmounts[accountIdIt->first][accountYearIt->first].count(b))
|
||||
continue;
|
||||
amounts[size*2+0] = a*12+b;
|
||||
amounts[size*2+1] = accountAmounts[accountIdIt->first][accountYearIt->first][b];
|
||||
size++;
|
||||
}
|
||||
}
|
||||
dataset->AddSerie((double *) amounts, size);
|
||||
// set serie names to be displayed on legend
|
||||
dataset->SetSerieName(i+1, user->GetAccountName(accountIdIt->first));
|
||||
delete[] amounts;
|
||||
}
|
||||
}
|
||||
|
||||
// create line renderer and set it to dataset
|
||||
@@ -296,9 +341,8 @@ void StatsPanel::OnRangeChange(wxCommandEvent& event)
|
||||
_yearTo->GetStringSelection().ToLong(&yearTo);
|
||||
|
||||
if (yearTo > yearFrom ||
|
||||
(yearFrom == yearTo && monthFrom >= monthTo))
|
||||
(yearFrom == yearTo && monthFrom > monthTo))
|
||||
{
|
||||
std::cout << monthFrom << " " << monthTo << " " << _yearFrom->GetStringSelection().mb_str() << " " << yearFrom << " " << yearTo << "\n" ;
|
||||
wxMessageBox(_("Invalide date range"), _("KissCount"), wxICON_ERROR | wxOK);
|
||||
return;
|
||||
}
|
||||
|
Reference in New Issue
Block a user