Git Product home page Git Product logo

bprinter's People

Contributors

dattanchu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

bprinter's Issues

Row cells not lining up

This is a great library, thank you. I am having a problem where the rows do not add up to the column header. Here is my code:

#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <chrono>
#include <cstdio>
#include <thread>
#include "nlohmann/json.hpp"
#include "bprinter/table_printer.h"

#if defined(USE_BOOST_KARMA)
#include <boost/spirit/include/karma.hpp>
namespace karma = boost::spirit::karma;
#endif

using bprinter::TablePrinter;

// #include <BitcarbonConstants.hpp>

using namespace std;
using json = nlohmann::json;

std::string exec(const char* cmd) {
  std::array<char, 128> buffer;
  std::string result;
  std::shared_ptr<FILE> pipe(popen(cmd, "r"), pclose);
  if (!pipe) throw std::runtime_error("popen() failed!");
  while (!feof(pipe.get())) {
      if (fgets(buffer.data(), 128, pipe.get()) != nullptr)
          result += buffer.data();
  }
  return result;
}

int main () {

  const std::string CLEOS_OPTS = "";//"-u http://dev.cryptolions.io:38888";
  const std::string ACCT_NAME = "eva";

  double duration;
  auto start = std::chrono::system_clock::now();
  srand (time(NULL));

  string command = "cleos " + CLEOS_OPTS + " get table -l 1000 " + ACCT_NAME
                            + " " + ACCT_NAME + " rides";
  cout << command << endl;

  string result = exec (command.c_str());
  json j = json::parse(result);

  json row = j["rows"];
  TablePrinter tp(&std::cout);
  tp.AddColumn("RideId", 6);
  tp.AddColumn("Driver", 10);
  tp.AddColumn("Rider", 10);
  tp.AddColumn("Dist Chg", 10);
  tp.AddColumn("Time Chg", 10);
  tp.AddColumn("Tip", 10);
  tp.AddColumn("Comm", 10);
  tp.AddColumn("World", 10);
  tp.AddColumn("Total", 10);

  tp.PrintHeader();

  int counter = 0;
  for (auto el : row) {
    // string rideId = ;
    // string driver = el["driver"];
    // string rider = el["rider"];
    
    tp   << el["rideId"]        << el["driver"]  << el["rider"] << el["dist_charge"]
         << el["time_charge"]   << el["tip_charge"]    
         << el["comm_charge"]   << el["world_charge"]  
         << el["total_charge"];
    counter++;
  }
  tp.PrintFooter();

  auto end = std::chrono::system_clock::now();
  std::chrono::duration<double> elapsed_seconds = end-start;

  //duration = ( clock() - start ) / (double) CLOCKS_PER_SEC;
  cout << "Receipts: " << counter;
  cout << "::: Elapsed time: " << elapsed_seconds.count() << "s" << endl;
  cout << "; RPS: " << counter / elapsed_seconds.count() << "\n";

  return 0;

}

And here is the output. The header is perfect but the rows below do not match up. Any ideas?
thank you

+----------------------------------------------------------------------------------------------+
|RideId|    Driver|     Rider|  Dist Chg|  Time Chg|       Tip|      Comm|     World|     Total|
+----------------------------------------------------------------------------------------------+
|0|"driver1"|"rider2"|25500|0|28055|1275|1275|5|
|1|"driver3"|"rider1"|21964|2650|34128|4507|4507|500|
|2|"driver1"|"rider1"|25500|0|28055|1275|1275|5|
|3|"driver2"|"rider1"|58392|0|18356|12750|12750|0|
|4|"driver1"|"rider2"|25500|0|28055|1275|1275|5|
|5|"driver2"|"rider1"|25500|53|28112|1277|1277|5|
|6|"driver2"|"rider1"|25500|53|28112|1277|1277|5|
|7|"driver2"|"rider1"|25500|213|28288|1285|1285|5|
|8|"driver2"|"rider1"|25500|160|28231|1283|1283|5|
|9|"driver2"|"rider1"|25500|106|28171|1280|1280|5|
+----------------------------------------------------------------------------------------------+
Receipts: 10::: Elapsed time: 0.0357193s
; RPS: 279.961

Remove Entry

Hi

Can you add functionality to remove entries from the table during runtime?
This would make it easier to use it event-based aka adding new entries when data arrives end removing entries from the table when they are not needed anymore

Get errors with running example.

/tmp/ccuGj3Z9.o: In function main': kw.cpp:(.text+0x5d): undefined reference to bprinter::TablePrinter::TablePrinter(std::ostream*, std::__cxx11::basic_string<char, std::char_traits, std::allocator > const&)'
kw.cpp:(.text+0xc2): undefined reference to bprinter::TablePrinter::AddColumn(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int)' kw.cpp:(.text+0x127): undefined reference to bprinter::TablePrinter::AddColumn(std::__cxx11::basic_string<char, std::char_traits, std::allocator > const&, int)'
kw.cpp:(.text+0x18c): undefined reference to bprinter::TablePrinter::AddColumn(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int)' kw.cpp:(.text+0x1f1): undefined reference to bprinter::TablePrinter::AddColumn(std::__cxx11::basic_string<char, std::char_traits, std::allocator > const&, int)'
kw.cpp:(.text+0x21b): undefined reference to bprinter::TablePrinter::PrintHeader()' kw.cpp:(.text+0x26b): undefined reference to bprinter::TablePrinter::operator<<(double)'
kw.cpp:(.text+0x2bb): undefined reference to bprinter::TablePrinter::operator<<(double)' kw.cpp:(.text+0x347): undefined reference to bprinter::TablePrinter::operator<<(double)'
kw.cpp:(.text+0x397): undefined reference to bprinter::TablePrinter::operator<<(double)' kw.cpp:(.text+0x45f): undefined reference to bprinter::TablePrinter::operator<<(double)'
/tmp/ccuGj3Z9.o:kw.cpp:(.text+0x50f): more undefined references to bprinter::TablePrinter::operator<<(double)' follow /tmp/ccuGj3Z9.o: In function main':
kw.cpp:(.text+0x51b): undefined reference to bprinter::TablePrinter::PrintFooter()' kw.cpp:(.text+0x527): undefined reference to bprinter::TablePrinter::~TablePrinter()'
kw.cpp:(.text+0x624): undefined reference to bprinter::TablePrinter::~TablePrinter()' /tmp/ccuGj3Z9.o: In function bprinter::TablePrinter& bprinter::TablePrinter::operator<< <char const*>(char const*)':
kw.cpp:(.text.ZN8bprinter12TablePrinterlsIPKcEERS0_T[ZN8bprinter12TablePrinterlsIPKcEERS0_T]+0xc3): undefined reference to bprinter::TablePrinter::get_num_columns() const' /tmp/ccuGj3Z9.o: In function bprinter::TablePrinter& bprinter::TablePrinter::operator<< (int)':
kw.cpp:(.text.ZN8bprinter12TablePrinterlsIiEERS0_T[ZN8bprinter12TablePrinterlsIiEERS0_T]+0xc0): undefined reference to `bprinter::TablePrinter::get_num_columns() const'
collect2: error: ld returned 1 exit status
kw.txt

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.