yakra / DataProcessing

Data Processing Scripts and Programs for Travel Mapping Project
0 stars 0 forks source link

format waypoint colocation stats in columns #131

Open yakra opened 4 years ago

yakra commented 4 years ago
#include <sys/ioctl.h>
#include <unistd.h>

// ...

        cout << et.et() << "Computing waypoint colocation stats, reporting all with 8 or more colocations:\n" << endl;

// ...

            {   printf("(%.15g, %.15g) is occupied by %i waypoints:\n", w->lat, w->lng, c);
                // find longest root + label with whitespace
                size_t maxlen = 0;
                for (Waypoint* p : *w->colocated)
                    if (maxlen < p->route->root.size() + p->label.size() + 4)
                    maxlen = p->route->root.size() + p->label.size() + 4;
                // obtain terminal width
                winsize ts;
                ioctl(STDIN_FILENO, TIOCGWINSZ, &ts);
                // print points
                if (ts.ws_col >= maxlen)
                     {  size_t cols = ts.ws_col / maxlen;
                    size_t col = 0;
                    for (Waypoint* p : *w->colocated)
                    {   cout << p->route->root << ' ' << p->label << "   ";
                        col++;
                        for (size_t a = p->route->root.size() + p->label.size() + 4; a < maxlen; a++) cout << ' ';
                        if (col == cols)
                        {   cout << endl;
                            col = 0;
                        }
                    }
                    if (col) cout << endl;
                    cout << endl;
                     }
                else {  list<Waypoint*>::iterator p = w->colocated->begin();
                    cout << "['" << (*p)->route->root << ' ' << (*p)->label << '\'';
                    for (p++; p != w->colocated->end(); p++)
                        cout << ", '" << (*p)->route->root << ' ' << (*p)->label << '\'';
                    cout << "]\n\n";//*/
                     }
            }

2 lines near the end of that last bit stay the same other than indentation.

Python equivalent: get_terminal_size() works in the python3 terminal, but not when running siteupdate.py itself. I dunno man. Low priority.