diff options
author | San Jacobs | 2022-07-28 04:19:14 +0200 |
---|---|---|
committer | San Jacobs | 2022-07-28 04:19:14 +0200 |
commit | 6d9d1ef96d4188ad6e5b201b39c31d742c99d147 (patch) | |
tree | 35f90d406e1b20c584ace1c4b5bad02bc26897d3 /src | |
parent | 799db65d26bbee7ea3c368ef9ea9c7f533cf92a7 (diff) | |
download | satscalc-6d9d1ef96d4188ad6e5b201b39c31d742c99d147.tar.gz satscalc-6d9d1ef96d4188ad6e5b201b39c31d742c99d147.tar.bz2 satscalc-6d9d1ef96d4188ad6e5b201b39c31d742c99d147.zip |
Wrote new menusystem and final calculation section
Alpha release soon!!
Diffstat (limited to 'src')
-rwxr-xr-x | src/main.cpp | 103 | ||||
-rwxr-xr-x | src/time.cpp | 23 |
2 files changed, 102 insertions, 24 deletions
diff --git a/src/main.cpp b/src/main.cpp index cc9cd43..9324ae5 100755 --- a/src/main.cpp +++ b/src/main.cpp @@ -36,20 +36,23 @@ int main(int argc, char* argv[]) std::cout << "-----\nStep 0: Setting the dayrate\n\n"; - //int dayrate_input; - //std::cout << "What is your dayrate? "; - //std::cin >> dayrate_input; - const int dayrate = 3338; - std::cout << "Dayrate: " << dayrate << "\n"; + int dayrate_input; + std::cout << "Dayrate: "; + std::cin >> dayrate_input; + std::cin.ignore(); + const int dayrate = dayrate_input; + const double hourly_rate = dayrate/7.5; std::cout << "Hourly rate: " << hourly_rate << "\n\n"; std::cout << "-----\nStep 1: Adding the days\n\n"; - std::cout << "How many days do you want to submit?" << std::endl; + std::cout << "How many days do you want to enter? "; int number_of_days; - // std::cin >> number_of_days; - number_of_days = 1; // Just here for debugging + std::cin >> number_of_days; + std::cin.ignore(); + //number_of_days = 1; // Just here for debugging + delta default_daylength{0, 8, 0}; std::vector<workday> workdays; moment previous_wrap{0, 16, 20, 11, 1000}; // Set to a long time ago @@ -62,14 +65,63 @@ int main(int argc, char* argv[]) // not std::cin, because it openly allows for invalid input std::cout << "\n - DAY " << day+1 << "-\nCalltime:\n"; moment calltime = timeinput(); - std::cout << "\nWraptime:\n"; - moment wraptime = timeinput(calltime); - std::cout << "\nPlanned wraptime:\n"; - moment planned_wraptime = timeinput(calltime); - std::cout << "\nLunch start:\n"; - moment lunch_start = timeinput(calltime); - std::cout << "\nLunch end:\n"; - moment lunch_end = timeinput(calltime); + + moment wraptime = calltime+default_daylength; + moment planned_wraptime = wraptime; + // TODO: Maybe lunch should be 0000-00-00 00:00 if day is short. + moment lunch_start = calltime+(delta){0,4,0}; + moment lunch_end = lunch_start+(delta){30,0,0}; + + std::cout << "\n------------- DAY " << day+1 << " -------------\n"; + while(1) { + std::cout << "[1] Calltime: " << timeprint(calltime) << "\n"; + std::cout << "[2] Wraptime: " << timeprint(wraptime) << "\n"; + std::cout << "[3] Planned wrap: " << timeprint(planned_wraptime) << "\n"; + std::cout << "[4] Lunch: " << timeprint((timeblock){lunch_start, lunch_end}) << "\n" << std::endl; + // TODO: Add second lunch option + + std::cout << "Write the number for what you want to change, or 0, to go to the next day." << std::endl; + + int input_number = 8; + std::cin >> input_number; + std::cin.ignore(); + + switch (input_number) { + case 0: + goto done; + case 1: + std::cout << "Changing calltime.\n"; + calltime = timeinput(); + break; + case 2: + std::cout << "Changing actual wraptime.\n"; + wraptime = timeinput(calltime); + break; + case 3: + std::cout << "Changing planned wraptime.\n"; + planned_wraptime = timeinput(calltime); + break; + case 4: + std::cout << "Changing lunch-time.\n"; + std::cout << "Lunch start:\n"; + lunch_start = timeinput(calltime); + std::cout << "Lunch end:\n"; + lunch_end = timeinput(calltime); + break; + default: + std::cout << "ERROR: That's not a valid number, ya doofus. 1, 2, 3, 4 or 0 only." << std::endl; + } + } +done: + + //std::cout << "\nWraptime:\n"; + //moment wraptime = timeinput(calltime); + //std::cout << "\nPlanned wraptime:\n"; + //moment planned_wraptime = timeinput(calltime); + //std::cout << "\nLunch start:\n"; + //moment lunch_start = timeinput(calltime); + //std::cout << "\nLunch end:\n"; + //moment lunch_end = timeinput(calltime); workdays.push_back({previous_wrap, calltime, @@ -92,6 +144,25 @@ int main(int argc, char* argv[]) previous_wrap = wraptime; } + double total_sum = 0; + for(int ii=0; ii < number_of_days; ii++) { + workday& each_day = workdays[ii]; + double day_price = 0; + std::cout << "\n ----- Day " << ii+1 << " ----- " << "\n"; + + for(int jj=0; jj < each_day.total_timeblocks; jj++) { + timeblock& each_block = each_day.blocks[jj]; + double block_price = each_block.hourcount() * hourly_rate * each_block.valuefactor; + std::cout << "Price of block " << jj << ": " << block_price << "\n"; + day_price += block_price; + } + std::cout << "Price of day " << ii+1 << ": " << day_price << "\n"; + total_sum += day_price; + } + + std::cout << "\nSUM: " << total_sum << std::endl; + + return 0; } } diff --git a/src/time.cpp b/src/time.cpp index c03251f..7a9f5f5 100755 --- a/src/time.cpp +++ b/src/time.cpp @@ -159,18 +159,20 @@ workday::workday(const moment& previous_wrap, int j = 0; for(int i = 0; i<10; i++) { const moment* each_moment = &splitpoints[i]; - std::cout << "Splitting: " << timeprint(*each_moment) << "\t\tJ: " << j << "\t\tI: " << i << std::endl; + //std::cout << "Splitting: " << timeprint(*each_moment) << "\t\tJ: " << j << "\t\tI: " << i << std::endl; if(*each_moment > call && *each_moment < wrap) { blocks[j++] = timesplit(initial_block, *each_moment); } } - std::cout << "Splitting finished." << std::endl; + //std::cout << "Splitting finished." << std::endl; + + // TODO: Clean away all timeblocks that are 0 in length blocks[j++] = initial_block; total_timeblocks = j; - std::cout << "Splitting completely finished." << std::endl; + //std::cout << "Splitting completely finished." << std::endl; // THE VALUE-FACTOR CALCULATION PART @@ -181,7 +183,7 @@ workday::workday(const moment& previous_wrap, for(int ii=0; ii < total_timeblocks; ii++){ timeblock& each_block = blocks[ii]; - std::cout << "pricing: " << timeprint(each_block) << std::endl; + //std::cout << "pricing: " << timeprint(each_block) << std::endl; if(each_block.end <= splitpoints[0]) each_block.upvalue(3); // +200% for sleep-breach if(each_block.start.hours >= 22) each_block.upvalue(2); // Work between 22:00 @@ -203,7 +205,7 @@ void workday::lunch(const moment& lunch_start, const moment& lunch_end) { } for(int ii=0; ii < total_timeblocks; ii++){ timeblock& each_block = blocks[ii]; - timeblock& next_block = blocks[ii+1]; + timeblock& next_block = blocks[ii+1]; // FIXME: On final loop, next_block will be garbage data if(each_block.start < lunch_start && each_block.end > lunch_end){ // If lunch simply occurs within a timeblock @@ -217,26 +219,31 @@ void workday::lunch(const moment& lunch_start, const moment& lunch_end) { total_timeblocks++; // Re-insert second half of split section into ii+1 blocks[ii] = first_half; + return; - } else if(each_block.start < lunch_start && lunch_start < each_block.end && + } else if(ii!=total_timeblocks-1 && each_block.start < lunch_start && lunch_start < each_block.end && next_block.start < lunch_end && lunch_end < next_block.end) { + // If we're not on the final block AND // If lunch occurs between two timeblocks each_block.end = lunch_start; next_block.start = lunch_end; + return; } else if(each_block.start == lunch_start) { // If lunch starts at the beginning of a timeblock each_block.start = lunch_end; + return; } else if(each_block.end == lunch_end) { // If lunch ends at the end of a timeblock each_block.start = lunch_end; + return; } // FIXME: If lunch spans across more than 1 border between timeblocks, bad stuff will happen. // Maybe there is a more principled way of solving this, that doesn't require writing code // for a bunch of edge-cases. If not, write the code. - return; } + return; } @@ -400,7 +407,7 @@ int days_in(int month, int year) { // TODO: Add checks for correct formatting, and ask for new input if wrong moment timeinput(moment input_moment) { char input_string[6]; - std::cout << "HH MM (24-hour format, use space)\n"; + std::cout << "HH MM (24-hour format, use space)" << std::endl; std::cin.getline(input_string, 6); // This uglyness is just how you use strtok() to split a string, apparently |