<commit_before>//=======================================================================
// Copyright (c) 2013-2017 <NAME>.
// Distributed under the terms of the MIT License.
// (See accompanying file LICENSE or copy at
//  http://opensource.org/licenses/MIT)
//=======================================================================

#include <iostream>
#include <fstream>
#include <sstream>

#include "args.hpp"
#include "budget_exception.hpp"
#include "fortune.hpp"
#include "data.hpp"
#include "guid.hpp"
#include "config.hpp"
#include "utils.hpp"
#include "console.hpp"

using namespace budget;

namespace {

static data_handler<fortune> fortunes;

void list_fortunes(){
    std::vector<std::string> columns = {"ID", "Date", "Amount"};
    std::vector<std::vector<std::string>> contents;

    for(auto& fortune : fortunes.data){
        contents.push_back({to_string(fortune.id), to_string(fortune.check_date), to_string(fortune.amount)});
    }

    display_table(columns, contents);
}

} //end of anonymous namespace

void budget::status_fortunes(std::ostream& os, bool short_view){
    std::vector<std::string> short_columns = {"Date", "Amount", "Diff.", "Avg/Day", "Avg/Day Tot."};
    std::vector<std::string> long_columns = {"Date", "Amount", "Diff.", "Time", "Avg/Day", "Diff. Tot.", "Avg/Day Tot."};

    auto columns = short_view ? short_columns : long_columns;
    std::vector<std::vector<std::string>> contents;

    std::vector<budget::fortune> sorted_values = fortunes.data;

    std::sort(sorted_values.begin(), sorted_values.end(),
        [](const budget::fortune& a, const budget::fortune& b){ return a.check_date < b.check_date; });

    budget::money previous;
    budget::money first = sorted_values.front().amount;
    budget::date previous_date;
    budget::date first_date = sorted_values.front().check_date;

    for(std::size_t i = 0; i < sorted_values.size(); ++i){
        auto& fortune = sorted_values[i];

        bool display;
        if(!short_view){
            display = true;
        } else {
            const size_t displayed = 3;
            if(sorted_values.size() <= displayed){
                display = true;
            } else {
                display = i > sorted_values.size() - 1 - displayed;
            }
        }

        if (display) {
            if (i == 0) {
                if (short_view) {
                    contents.push_back({to_string(fortune.check_date), to_string(fortune.amount), "", "", ""});
                } else {
                    contents.push_back({to_string(fortune.check_date), to_string(fortune.amount), "", "", "", "", ""});
                }
            } else if (i == 1) {
                auto diff = fortune.amount - previous;
                auto d    = fortune.check_date - previous_date;
                auto avg  = diff / float(d);

                if (short_view) {
                    contents.push_back({to_string(fortune.check_date), to_string(fortune.amount),
                                        format_money(diff), to_string(avg), ""});
                } else {
                    contents.push_back({to_string(fortune.check_date), to_string(fortune.amount),
                                        format_money(diff), to_string(d), to_string(avg), "", ""});
                }
            } else {
                auto diff = fortune.amount - previous;
                auto d    = fortune.check_date - previous_date;
                auto avg  = diff / float(d);

                auto tot_diff = fortune.amount - first;
                auto tot_d    = fortune.check_date - first_date;
                auto tot_avg  = tot_diff / float(tot_d);

                if (short_view) {
                    contents.push_back({to_string(fortune.check_date), to_string(fortune.amount),
                                        format_money(diff), to_string(avg), to_string(tot_avg)});
                } else {
                    contents.push_back({to_string(fortune.check_date), to_string(fortune.amount),
                                        format_money(diff), to_string(d), to_string(avg), format_money(tot_diff), to_string(tot_avg)});
                }
            }<commit_msg>Fix invalid conversions<commit_after>//=======================================================================
// Copyright (c) 2013-2017 <NAME>.
// Distributed under the terms of the MIT License.
// (See accompanying file LICENSE or copy at
//  http://opensource.org/licenses/MIT)
//=======================================================================

#include <iostream>
#include <fstream>
#include <sstream>

#include "args.hpp"
#include "budget_exception.hpp"
#include "fortune.hpp"
#include "data.hpp"
#include "guid.hpp"
#include "config.hpp"
#include "utils.hpp"
#include "console.hpp"

using namespace budget;

namespace {

static data_handler<fortune> fortunes;

void list_fortunes(){
    std::vector<std::string> columns = {"ID", "Date", "Amount"};
    std::vector<std::vector<std::string>> contents;

    for(auto& fortune : fortunes.data){
        contents.push_back({to_string(fortune.id), to_string(fortune.check_date), to_string(fortune.amount)});
    }

    display_table(columns, contents);
}

} //end of anonymous namespace

void budget::status_fortunes(std::ostream& os, bool short_view){
    std::vector<std::string> short_columns = {"Date", "Amount", "Diff.", "Avg/Day", "Avg/Day Tot."};
    std::vector<std::string> long_columns = {"Date", "Amount", "Diff.", "Time", "Avg/Day", "Diff. Tot.", "Avg/Day Tot."};

    auto columns = short_view ? short_columns : long_columns;
    std::vector<std::vector<std::string>> contents;

    std::vector<budget::fortune> sorted_values = fortunes.data;

    std::sort(sorted_values.begin(), sorted_values.end(),
        [](const budget::fortune& a, const budget::fortune& b){ return a.check_date < b.check_date; });

    budget::money previous;
    budget::money first = sorted_values.front().amount;
    budget::date previous_date;
    budget::date first_date = sorted_values.front().check_date;

    for(std::size_t i = 0; i < sorted_values.size(); ++i){
        auto& fortune = sorted_values[i];

        bool display;
        if(!short_view){
            display = true;
        } else {
            const size_t displayed = 3;
            if(sorted_values.size() <= displayed){
                display = true;
            } else {
                display = i > sorted_values.size() - 1 - displayed;
            }
        }

        if (display) {
            if (i == 0) {
                if (short_view) {
                    contents.push_back({to_string(fortune.check_date), to_string(fortune.amount), "", "", ""});
                } else {
                    contents.push_back({to_string(fortune.check_date), to_string(fortune.amount), "", "", "", "", ""});
                }
            } else if (i == 1) {
                auto diff = fortune.amount - previous;
                auto d    = fortune.check_date - previous_date;
                auto avg  = diff / d;

                if (short_view) {
                    contents.push_back({to_string(fortune.check_date), to_string(fortune.amount),
                                        format_money(diff), to_string(avg), ""});
                } else {
                    contents.push_back({to_string(fortune.check_date), to_string(fortune.amount),
                                        format_money(diff), to_string(d), to_string(avg), "", ""});
                }
            } else {
                auto diff = fortune.amount - previous;
                auto d    = fortune.check_date - previous_date;
                auto avg  = diff / d;

                auto tot_diff = fortune.amount - first;
                auto tot_d    = fortune.check_date - first_date;
                auto tot_avg  = tot_diff / tot_d;

                if (short_view) {
                    contents.push_back({to_string(fortune.check_date), to_string(fortune.amount),
                                        format_money(diff), to_string(avg), to_string(tot_avg)});
                } else {
                    contents.push_back({to_string(fortune.check_date), to_string(fortune.amount),
                                        format_money(diff), to_string(d), to_string(avg), format_money(tot_diff), to_string(tot_avg)});
                }
            }
{'fraction_non_alphanumeric': 0.1687642334891526, 'fraction_numerical': 0.003116384993407647, 'mean_word_length': 2.2479564032697548, 'pattern_counts': {'":': 0, '<': 35, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7438113', 'n_tokens_mistral': 2454, 'n_tokens_neox': 2323, 'n_words': 472}