Skip to content

Datachecks for field lengths #56

Closed

Description

@jteresco

A system should be put in place where all entries from TM data files that end up in DB fields are checked for length to avoid problems like TravelMapping/Web#195 .

A set of constants should be introduced to the site update program to make sure these values are consistent among all checks and when DB tables are created.

Activity

  1. self-assigned this
    on Jul 25, 2017
  2. jteresco commented on Jan 29, 2018

    @jteresco
    ContributorAuthor

    More evidence that this should happen: http://tm.teresco.org/forum/index.php?topic=2358.0

  3. jteresco commented on May 15, 2018

    @jteresco
    ContributorAuthor

    This is now more important, and should be combined with a truncation of entries that are too long, since MySQL 5.7 will not allow overlength fields to be added to a column. Increasing (possibly temporarily, possibly to be replaced with a TEXT field) the width of the description in the updates table.

  4. yakra commented on Nov 30, 2018

    @yakra
    Contributor

    This could be done during the Route constructor. el.add_error, and, yes, halt the siteupdate process. :)

  5. yakra commented on Jul 15, 2019

    @yakra
    Contributor

    Forgot about this one.
    I implemented at least part of it in C++:

    if (banner.size() > 6)
    { el.add_error("Banner >6 characters in " + system->systemname + ".csv line: [" + line + "], " + banner);
    return;
    }

  6. yakra commented on Jul 17, 2019

    @yakra
    Contributor

    MySQL 8 won't even insert the overlength values unto the tables, and the site update process halts.
    ERROR 1406 (22001) at line 1074: Data too long for column 'banner' at row 49532
    fraidfd is commented out on lab2 until the HighwayData side is resolved.

  7. yakra commented on Aug 27, 2019

    @yakra
    Contributor

    The above means these should be handled at the ErrorList level of the siteupdate program, rather than create a DatacheckEntry that would need a successful site update in order to be shown on siteupdate.php.

  8. yakra commented on Sep 6, 2019

    @yakra
    Contributor

    C++

    ABORTING due to 3 errors:
    1: Abbrev >3 characters in usafl.csv line: [usafl;FL;FL44;;Leesburg;;fl.fl044;], Leesburg
    2: Could not find Route matching root fl.fl044 in system usafl.
    3: No roots in usafl_con.csv line [usafl;FL44;;Leesburg;fl.fl044]
    Fri Sep  6 11:51:20 EDT 2019
    

    The 2nd and 3rd errors happen because the Route constructor aborts, and then the HighwaySystem ctor does if (!route_list.back().is_valid()) route_list.pop_back();

  9. 12 remaining items

  10. yakra commented on Apr 4, 2020

    @yakra
    Contributor

    Just queried the DB on lab2; turns out that Bourgogne-Franche-Comté Routes Départementales (Haute-Saône), at 60 characters, can in fact fit in the DB.

    Regardless of how the Python version behaves, this complicates the C++ version quite a bit, as the "error" it's reporting is a false positive.

    Fun fun. I think I'll take a break & spend my next couple days of quarantine getting reacquainted with my classic video game systems.

  11. yakra commented on Apr 4, 2020

    @yakra
    Contributor

    Just queried the DB on lab2; turns out that Bourgogne-Franche-Comté Routes Départementales (Haute-Saône), at 60 characters, can in fact fit in the DB.

    I'm guessing this changed some time between MySQL 5.7 & 8.0, along with the transition from 5.7 accepting & truncating overlength values, to 8.0 stopping with an error message...

    • TravelMapping-2020-03-24@21:13:20.sql worked fine on noreaster
    • lab2 barfed on it: ERROR 1406 (22001) at line 726: Data too long for column 'fullName' at row 362
      (the offending datum being Finland Seututiet (outlined - temp preview to fix active routes))

    I'm bummed that I didn't take a screenshot of travelmapping.net when things were messed up, but ISTR the ñ being displayed as a �, as in TravelMapping/Web#195. Here's how it appears on lab2:
    MEX57Cañ

    Seems the thing to do is plan for the most restrictive circumstances, that we're limited by byte counts rather than character counts.
    Pro: We don't have to get the C++ version to do character counts.
    Con: We do have to get the Python version to do byte counts.

    Edit: OK, it's pretty straightforward:

    >>> print(len('ñ'.encode('utf-8')))
    2
  12. yakra commented on Apr 4, 2020

    @yakra
    Contributor

    diffs

    • The old C++ version would stop processing a Route object if it encountered an overlength Banner or Abbrev. Fixed. Once I remove bel.n712pel, there are no diffs between the old and new logs/stats/graphs/nmp_merged.
    • siteupdate.py is running right now, 2nd pass just started. ToDo next.
    • And then, diff the new C++ & new Python output.

    • After that, on to changing all the new len('ñ') to len('ñ'.encode('utf-8')) checks.
  13. yakra commented on Apr 6, 2020

    @yakra
    Contributor

    OK, finally about ready to go on this.
    Considering all the small things to watch out for & fix that kept popping up, it'd be wise to break one of everything in HighwayData and make sure everything behaves as expected.

    Since the C++ version is all about speed, it writes the .sql file in the background during the graph generation process. Thus we have almost a complete file by the time we reach the ABORTING condition. All that's left are datacheckErrors, graphTypes & graphs. This is sometimes reported as taking 0.1s to write, so I just decided to finish it off before terminating. Not much harm in a junk .sql file hanging around, and it's there completely if you wanna do a post-mortem grep. And who knows, depending on the errors involved, it may even be possible to manually ingest it into a lab2 with no, or even a noreaster with minimal, ill effects.
    What matters is that the program terminates with an exit code of 1, so localupdate.sh knows to not continue.

    A final thought:
    How about checking for unrecognized colors in systems.csv? We could have a set of the "official TM" colors, and check each systems.csv datum for membership in this set, catching potential misspellings etc. Just that DBFieldLength is no longer the best class name for all our constants. Ideas on a better name? Thoughts?

  14. yakra commented on Apr 8, 2020

    @yakra
    Contributor
    • Break & test the following in C++:
      • region code in chopped routes .csv
      • country code in:
        • regions.csv
        • systems.csv
      • continent code in regions.csv
    • Keep dummy entries out of the DB
  15. jteresco commented on Apr 8, 2020

    @jteresco
    ContributorAuthor

    A thought on colors, probably overkill. We could go a bit further, having a colors.csv that defines names and RGB values for the "official" TM colors, introducing a new DB table to store them, the systems table would refer to those entries, and the front-end code would load up its set of colors from that new DB table.

  16. yakra commented on Apr 8, 2020

    @yakra
    Contributor

    I don't see a big need to specify RGB values, as we can already override them, albeit on a per-tier rather than per-color basis. I can happily agree to "probably overkill", and leave this feature out. It'll be good to get this enhancement out the door.

    Before the big stress test gets underway, while I'm in the CSV parsing routes I'm giving the C++ ones a much-needed cleanup, and tightening a couple other minor screws.
    After, there will be at least one merge conflict to resolve on my end.

  17. yakra commented on Apr 9, 2020

    @yakra
    Contributor

    There's a remote chance that the MALFORMED_LAT & MALFORMED_LON datachecks can produce overlength info values. I included checks for this, but the Python version is not 100% foolproof.
    Rather than spend time on a fix and then gunk up the commit history with obsolete code that will just be overwritten again in a few days, I think I'll scrap these changes (in both languages) & go no-build pending a cleanup per #299.

  18. yakra commented on Apr 10, 2020

    @yakra
    Contributor
    cd ~/TravelMapping/yakra/DataProcessing/siteupdate/cplusplus/
    
    g++ siteupdate.cpp -std=c++11 -pthread -o siteupdate_const 2>&1
    ./siteupdate_const -t 4 -l logs -n nmp_merged -c stats -g graphs -u /home/yakra/TravelMapping/UserData/list_files -w /home/yakra/TravelMapping/HighwayData | tee siteupdate_m1.log
    grep -n ABORTING siteupdate_m1.log; AbortLineCPP=$(grep -n ABORTING siteupdate_m1.log | cut -f1 -d:)
    tail -n +$AbortLineCPP siteupdate_m1.log | less
    
    cd ../python-teresco
    
    ./siteupdate.py -l logs -n nmp_merged -c stats -g graphs -u /home/yakra/TravelMapping/UserData/list_files -w /home/yakra/TravelMapping/HighwayData -t 1 | tee siteupdate_s1.log
    grep -n ABORTING siteupdate_s1.log; AbortLinePY=$(grep -n ABORTING siteupdate_s1.log | cut -f1 -d:)
    tail -n +$AbortLinePY siteupdate_s1.log | less
    
    cd ..
    
    diff <(tail -n +`expr $AbortLineCPP + 1` cplusplus/siteupdate_m1.log | sed 's~^[0-9]\+: ~~' | head -n 40) <(tail -n +`expr $AbortLinePY + 1` python-teresco/siteupdate_s1.log | sed 's~^[0-9]\+: ~~' | head -n 40)
  19. yakra commented on Apr 10, 2020

    @yakra
    Contributor
            # look up country and continent, add index into those arrays
            # in case they're needed for lookups later (not needed for DB)
            for i in range(len(countries)):
                country = countries[i][0]
                if country == fields[2]:
                    fields.append(i)
                    break
            if len(fields) != 6:
                el.add_error("Could not find country matching regions.csv line: " + line)
                continue
            for i in range(len(continents)):
                continent = continents[i][0]
                if continent == fields[3]:
                    fields.append(i)
                    break
            if len(fields) != 7:
                el.add_error("Could not find continent matching regions.csv line: " + line)
                continue

    I've retained the lookups for matching countries & continents. Any objections if I nix storing the indices as part of the fields array?

  20. yakra commented on Apr 11, 2020

    @yakra
    Contributor
    • vdiffs are slowly becoming sane
    • Combine where feasible (which is nowhere):
      • if len(line) == 0 or line.startswith('#'):
      • if (line.empty() || line[0] == '#')
    • Make sure all HighwayData breakages are as expected. I know I whiffed at least 4 of'em.
    • C++: Make rg_str part of the Route object; use it to load & process WPTs
      • Change validity check in HighwaySystem ctor accordingly
    • Check DIFFs again
    • Revert the Waypoint ctor changes
    • Maybe revert the list delimiter changes for the time being too
    • Merge & deal with conflicts
  21. jteresco commented on Apr 11, 2020

    @jteresco
    ContributorAuthor

    I've retained the lookups for matching countries & continents. Any objections if I nix storing the indices as part of the fields array?

    I am not sure why they were there in the first place, so I suppose no harm in getting rid of them.

  22. added a commit that references this issue on Apr 12, 2020
  23. yakra commented on Apr 13, 2020

    @yakra
    Contributor

    # in case they're needed for lookups later (not needed for DB)

    Sounds like a case of planning for the future, not fully knowing yet what's going to be done with the data.

    I did simillar when starting out the C++ version, looking up & storing a pointer the the continent & country std::pairs. Nothing much is done with them, but the only less RAM-intensive option would have been to include a C char array in the Region object. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions