|
33 | 33 | #include "jconf.h"
|
34 | 34 | #include "console.h"
|
35 | 35 | #include "donate-level.h"
|
| 36 | +#include "webdesign.h" |
36 | 37 |
|
37 | 38 | #ifdef _WIN32
|
38 | 39 | #define strncasecmp _strnicmp
|
@@ -478,13 +479,11 @@ void executor::ex_main()
|
478 | 479 |
|
479 | 480 | inline const char* hps_format(double h, char* buf, size_t l)
|
480 | 481 | {
|
481 |
| - if(std::isnormal(h)) |
| 482 | + if(std::isnormal(h) || h == 0.0) |
482 | 483 | {
|
483 | 484 | snprintf(buf, l, " %03.1f", h);
|
484 | 485 | return buf;
|
485 | 486 | }
|
486 |
| - else if(h == 0.0) //Zero is not normal but we want it |
487 |
| - return " 0.0"; |
488 | 487 | else
|
489 | 488 | return " (na)";
|
490 | 489 | }
|
@@ -695,22 +694,154 @@ void executor::print_report(ex_event_name ev)
|
695 | 694 | printer::inst()->print_str(out.c_str());
|
696 | 695 | }
|
697 | 696 |
|
| 697 | +void executor::http_hashrate_report(std::string& out) |
| 698 | +{ |
| 699 | + char num_a[32], num_b[32], num_c[32], num_d[32]; |
| 700 | + char buffer[4096]; |
| 701 | + size_t nthd = pvThreads->size(); |
| 702 | + |
| 703 | + out.reserve(4096); |
| 704 | + |
| 705 | + snprintf(buffer, sizeof(buffer), sHtmlCommonHeader, "Hashrate Report", "Hashrate Report"); |
| 706 | + out.append(buffer); |
| 707 | + |
| 708 | + snprintf(buffer, sizeof(buffer), sHtmlHashrateBodyHigh, (unsigned int)nthd + 3); |
| 709 | + out.append(buffer); |
| 710 | + |
| 711 | + double fTotal[3] = { 0.0, 0.0, 0.0}; |
| 712 | + for(size_t i=0; i < nthd; i++) |
| 713 | + { |
| 714 | + double fHps[3]; |
| 715 | + |
| 716 | + fHps[0] = telem->calc_telemetry_data(2500, i); |
| 717 | + fHps[1] = telem->calc_telemetry_data(60000, i); |
| 718 | + fHps[2] = telem->calc_telemetry_data(900000, i); |
| 719 | + |
| 720 | + num_a[0] = num_b[0] = num_c[0] ='\0'; |
| 721 | + hps_format(fHps[0], num_a, sizeof(num_a)); |
| 722 | + hps_format(fHps[1], num_b, sizeof(num_b)); |
| 723 | + hps_format(fHps[2], num_c, sizeof(num_c)); |
| 724 | + |
| 725 | + fTotal[0] += fHps[0]; |
| 726 | + fTotal[1] += fHps[1]; |
| 727 | + fTotal[2] += fHps[2]; |
| 728 | + |
| 729 | + snprintf(buffer, sizeof(buffer), sHtmlHashrateTableRow, (unsigned int)i, num_a, num_b, num_c); |
| 730 | + out.append(buffer); |
| 731 | + } |
| 732 | + |
| 733 | + num_a[0] = num_b[0] = num_c[0] = num_d[0] ='\0'; |
| 734 | + hps_format(fTotal[0], num_a, sizeof(num_a)); |
| 735 | + hps_format(fTotal[1], num_b, sizeof(num_b)); |
| 736 | + hps_format(fTotal[2], num_c, sizeof(num_c)); |
| 737 | + hps_format(fHighestHps, num_d, sizeof(num_d)); |
| 738 | + |
| 739 | + snprintf(buffer, sizeof(buffer), sHtmlHashrateBodyLow, num_a, num_b, num_c, num_d); |
| 740 | + out.append(buffer); |
| 741 | +} |
| 742 | + |
| 743 | +void executor::http_result_report(std::string& out) |
| 744 | +{ |
| 745 | + char date[128]; |
| 746 | + char buffer[4096]; |
| 747 | + |
| 748 | + out.reserve(4096); |
| 749 | + |
| 750 | + snprintf(buffer, sizeof(buffer), sHtmlCommonHeader, "Result Report", "Result Report"); |
| 751 | + out.append(buffer); |
| 752 | + |
| 753 | + size_t iGoodRes = vMineResults[0].count, iTotalRes = iGoodRes; |
| 754 | + size_t ln = vMineResults.size(); |
| 755 | + |
| 756 | + for(size_t i=1; i < ln; i++) |
| 757 | + iTotalRes += vMineResults[i].count; |
| 758 | + |
| 759 | + double fGoodResPrc = 0.0; |
| 760 | + if(iTotalRes > 0) |
| 761 | + fGoodResPrc = 100.0 * iGoodRes / iTotalRes; |
| 762 | + |
| 763 | + double fAvgResTime = 0.0; |
| 764 | + if(iPoolCallTimes.size() > 0) |
| 765 | + { |
| 766 | + using namespace std::chrono; |
| 767 | + fAvgResTime = ((double)duration_cast<seconds>(system_clock::now() - tPoolConnTime).count()) |
| 768 | + / iPoolCallTimes.size(); |
| 769 | + } |
| 770 | + |
| 771 | + snprintf(buffer, sizeof(buffer), sHtmlResultBodyHigh, |
| 772 | + iPoolDiff, iGoodRes, iTotalRes, fGoodResPrc, fAvgResTime, iPoolHashes, |
| 773 | + int_port(iTopDiff[0]), int_port(iTopDiff[1]), int_port(iTopDiff[2]), int_port(iTopDiff[3]), |
| 774 | + int_port(iTopDiff[4]), int_port(iTopDiff[5]), int_port(iTopDiff[6]), int_port(iTopDiff[7]), |
| 775 | + int_port(iTopDiff[8]), int_port(iTopDiff[9])); |
| 776 | + |
| 777 | + out.append(buffer); |
| 778 | + |
| 779 | + for(size_t i=1; i < vMineResults.size(); i++) |
| 780 | + { |
| 781 | + snprintf(buffer, sizeof(buffer), sHtmlResultTableRow, vMineResults[i].msg.c_str(), |
| 782 | + int_port(vMineResults[i].count), time_format(date, sizeof(date), vMineResults[i].time)); |
| 783 | + out.append(buffer); |
| 784 | + } |
| 785 | + |
| 786 | + out.append(sHtmlResultBodyLow); |
| 787 | +} |
| 788 | + |
| 789 | +void executor::http_connection_report(std::string& out) |
| 790 | +{ |
| 791 | + char date[128]; |
| 792 | + char buffer[4096]; |
| 793 | + |
| 794 | + out.reserve(4096); |
| 795 | + |
| 796 | + snprintf(buffer, sizeof(buffer), sHtmlCommonHeader, "Connection Report", "Connection Report"); |
| 797 | + out.append(buffer); |
| 798 | + |
| 799 | + jpsock* pool = pick_pool_by_id(dev_pool_id + 1); |
| 800 | + const char* cdate = "not connected"; |
| 801 | + if (pool->is_running() && pool->is_logged_in()) |
| 802 | + cdate = time_format(date, sizeof(date), tPoolConnTime); |
| 803 | + |
| 804 | + size_t n_calls = iPoolCallTimes.size(); |
| 805 | + unsigned int ping_time = 0; |
| 806 | + if (n_calls > 1) |
| 807 | + { |
| 808 | + //Not-really-but-good-enough median |
| 809 | + std::nth_element(iPoolCallTimes.begin(), iPoolCallTimes.begin() + n_calls/2, iPoolCallTimes.end()); |
| 810 | + ping_time = iPoolCallTimes[n_calls/2]; |
| 811 | + } |
| 812 | + |
| 813 | + snprintf(buffer, sizeof(buffer), sHtmlConnectionBodyHigh, |
| 814 | + jconf::inst()->GetPoolAddress(), |
| 815 | + cdate, ping_time); |
| 816 | + out.append(buffer); |
| 817 | + |
| 818 | + |
| 819 | + for(size_t i=0; i < vSocketLog.size(); i++) |
| 820 | + { |
| 821 | + snprintf(buffer, sizeof(buffer), sHtmlConnectionTableRow, |
| 822 | + time_format(date, sizeof(date), vSocketLog[i].time), vSocketLog[i].msg.c_str()); |
| 823 | + out.append(buffer); |
| 824 | + } |
| 825 | + |
| 826 | + out.append(sHtmlConnectionBodyLow); |
| 827 | +} |
| 828 | + |
698 | 829 | void executor::http_report(ex_event_name ev)
|
699 | 830 | {
|
700 | 831 | assert(pHttpString != nullptr);
|
701 | 832 |
|
702 | 833 | switch(ev)
|
703 | 834 | {
|
704 | 835 | case EV_HTML_HASHRATE:
|
705 |
| - hashrate_report(*pHttpString); |
| 836 | + http_hashrate_report(*pHttpString); |
706 | 837 | break;
|
707 | 838 |
|
708 | 839 | case EV_HTML_RESULTS:
|
709 |
| - result_report(*pHttpString); |
| 840 | + http_result_report(*pHttpString); |
710 | 841 | break;
|
711 | 842 |
|
712 | 843 | case EV_HTML_CONNSTAT:
|
713 |
| - connection_report(*pHttpString); |
| 844 | + http_connection_report(*pHttpString); |
714 | 845 | break;
|
715 | 846 | default:
|
716 | 847 | assert(false);
|
|
0 commit comments