sportdb-formats 1.0.2 → 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Manifest.txt +4 -0
- data/Rakefile +2 -2
- data/lib/sportdb/formats.rb +17 -5
- data/lib/sportdb/formats/datafile_package.rb +10 -7
- data/lib/sportdb/formats/match/match_parser_csv.rb +314 -0
- data/lib/sportdb/formats/package.rb +137 -7
- data/lib/sportdb/formats/score/score_formats.rb +41 -1
- data/lib/sportdb/formats/team/club_reader_props.rb +3 -3
- data/lib/sportdb/formats/version.rb +3 -1
- data/test/helper.rb +1 -1
- data/test/test_club_reader_props.rb +2 -2
- data/test/test_csv_match_parser.rb +114 -0
- data/test/test_csv_match_parser_utils.rb +20 -0
- data/test/test_csv_reader.rb +5 -5
- data/test/test_datafile.rb +0 -32
- data/test/test_datafile_package.rb +46 -0
- data/test/test_package.rb +60 -28
- data/test/test_package_match.rb +27 -3
- data/test/test_scores.rb +58 -49
- metadata +8 -4
| @@ -93,12 +93,51 @@ module ScoreFormats | |
| 93 93 | 
             
                         (?=[ \]]|$)/xi    ## todo/check:  remove loakahead assertion here - why require space?
         | 
| 94 94 | 
             
                                           ## note: \b works only after non-alphanum e.g. )
         | 
| 95 95 |  | 
| 96 | 
            +
             | 
| 96 97 | 
             
                #####
         | 
| 97 98 | 
             
                #  deutsch / german helpers (penalty, extra time, ...)
         | 
| 98 99 | 
             
                ## todo add more marker e.g. im Elf. or such!!!
         | 
| 99 100 | 
             
                P_DE  =  '(?: ie | i\.e\.? )'     # e.g. iE, i.E., i.E etc.
         | 
| 100 101 | 
             
                ET_DE =  '(?: nv | n\.v\.? )'     # e.g. nV, n.V., n.V etc.
         | 
| 101 102 |  | 
| 103 | 
            +
             | 
| 104 | 
            +
                ## support alternate all-in-one score e.g.
         | 
| 105 | 
            +
                ##     i.E. 2:4, n.V. 3:3 (1:1, 1:1)  or
         | 
| 106 | 
            +
                ##               n.V. 3:2 (2:2, 1:2)
         | 
| 107 | 
            +
                DE__P_ET_FT_HT__RE = /\b
         | 
| 108 | 
            +
                                 (?:
         | 
| 109 | 
            +
                                 #{P_DE}
         | 
| 110 | 
            +
                                  [ ]*
         | 
| 111 | 
            +
                                 (?<score1p>\d{1,2})
         | 
| 112 | 
            +
                                  [ ]* : [ ]*
         | 
| 113 | 
            +
                                 (?<score2p>\d{1,2})
         | 
| 114 | 
            +
                                  [ ]* (?:, [ ]*)?
         | 
| 115 | 
            +
                                 )?   # note: make penalty (P) score optional for now
         | 
| 116 | 
            +
                                  #{ET_DE}
         | 
| 117 | 
            +
                                  [ ]*
         | 
| 118 | 
            +
                                 (?<score1et>\d{1,2})
         | 
| 119 | 
            +
                                  [ ]* : [ ]*
         | 
| 120 | 
            +
                                 (?<score2et>\d{1,2})
         | 
| 121 | 
            +
                                  [ ]*
         | 
| 122 | 
            +
                                \(
         | 
| 123 | 
            +
                             [ ]*
         | 
| 124 | 
            +
                         (?<score1>\d{1,2})
         | 
| 125 | 
            +
                              [ ]* : [ ]*
         | 
| 126 | 
            +
                         (?<score2>\d{1,2})
         | 
| 127 | 
            +
                              [ ]*
         | 
| 128 | 
            +
                           (?:
         | 
| 129 | 
            +
                               , [ ]*
         | 
| 130 | 
            +
                               (?:
         | 
| 131 | 
            +
                                (?<score1i>\d{1,2})
         | 
| 132 | 
            +
                                  [ ]* : [ ]*
         | 
| 133 | 
            +
                                (?<score2i>\d{1,2})
         | 
| 134 | 
            +
                                  [ ]*
         | 
| 135 | 
            +
                               )?
         | 
| 136 | 
            +
                           )?    # note: make half time (HT) score optional for now
         | 
| 137 | 
            +
                         \)
         | 
| 138 | 
            +
                        (?=[ \]]|$)
         | 
| 139 | 
            +
                          /xi
         | 
| 140 | 
            +
             | 
| 102 141 | 
             
                ## support all-in-one "literal form e.g.
         | 
| 103 142 | 
             
                #  2:2 (1:1, 1:0) n.V. 5:1 i.E.   or
         | 
| 104 143 | 
             
                #  2-2 (1-1, 1-0) n.V. 5-1 i.E.
         | 
| @@ -168,7 +207,8 @@ FORMATS_EN = [ | |
| 168 207 | 
             
            ]
         | 
| 169 208 |  | 
| 170 209 | 
             
            FORMATS_DE = [
         | 
| 171 | 
            -
              [ DE__ET_FT_HT_P__RE, '[SCORE.DE__ET_(FT_HT?)_P?]' ], # e.g. | 
| 210 | 
            +
              [ DE__ET_FT_HT_P__RE, '[SCORE.DE__ET_(FT_HT?)_P?]' ], # e.g. 2:2 (1:1, 1:0) n.V. 5:1 i.E.
         | 
| 211 | 
            +
              [ DE__P_ET_FT_HT__RE, '[SCORE.DE__P?_ET_(FT_HT?)]' ], # e.g. i.E. 2:4, n.V. 3:3 (1:1, 1:1)
         | 
| 172 212 | 
             
              [ DE__FT_HT__RE,      '[SCORE.DE__FT_(HT)?]'       ], # e.g. 1:1 (1:0)
         | 
| 173 213 | 
             
            ]
         | 
| 174 214 |  | 
| @@ -27,7 +27,7 @@ class ClubPropsReader | |
| 27 27 | 
             
              def parse
         | 
| 28 28 | 
             
                recs = parse_csv( @txt )
         | 
| 29 29 | 
             
                recs.each do |rec|
         | 
| 30 | 
            -
                  name = rec[ | 
| 30 | 
            +
                  name = rec['Name']
         | 
| 31 31 | 
             
                  if name.nil?
         | 
| 32 32 | 
             
                    puts "** !!! ERROR !!! Name column required / missing / NOT found in row:"
         | 
| 33 33 | 
             
                    pp rec
         | 
| @@ -62,8 +62,8 @@ class ClubPropsReader | |
| 62 62 | 
             
                    ## todo/fix:   only updated "on-demand" from in-memory struct/records!!!!
         | 
| 63 63 |  | 
| 64 64 | 
             
                    ##  update attributes
         | 
| 65 | 
            -
                    club_rec.key  = rec[ | 
| 66 | 
            -
                    club_rec.code = rec[ | 
| 65 | 
            +
                    club_rec.key  = rec['Key']      if rec['Key']
         | 
| 66 | 
            +
                    club_rec.code = rec['Code']     if rec['Code']
         | 
| 67 67 | 
             
                    ## todo/fix: add (some) more props e.g. address, web, etc.
         | 
| 68 68 | 
             
                  end
         | 
| 69 69 | 
             
                end
         | 
| @@ -2,11 +2,12 @@ | |
| 2 2 |  | 
| 3 3 |  | 
| 4 4 | 
             
            module SportDb
         | 
| 5 | 
            +
              module Module
         | 
| 5 6 | 
             
            module Formats
         | 
| 6 7 |  | 
| 7 8 | 
             
              MAJOR = 1    ## todo: namespace inside version or something - why? why not??
         | 
| 8 9 | 
             
              MINOR = 0
         | 
| 9 | 
            -
              PATCH =  | 
| 10 | 
            +
              PATCH = 3
         | 
| 10 11 | 
             
              VERSION = [MAJOR,MINOR,PATCH].join('.')
         | 
| 11 12 |  | 
| 12 13 | 
             
              def self.version
         | 
| @@ -22,4 +23,5 @@ module Formats | |
| 22 23 | 
             
              end
         | 
| 23 24 |  | 
| 24 25 | 
             
            end # module Formats
         | 
| 26 | 
            +
            end # module Module
         | 
| 25 27 | 
             
            end # module SportDb
         | 
    
        data/test/helper.rb
    CHANGED
    
    | @@ -147,7 +147,7 @@ def parse_json( str ) | |
| 147 147 | 
             
            end
         | 
| 148 148 |  | 
| 149 149 | 
             
            def read_test( path )
         | 
| 150 | 
            -
              blocks = read_blocks( " | 
| 150 | 
            +
              blocks = read_blocks( "#{SportDb::Test.data_dir}/football.txt/#{path}" )
         | 
| 151 151 |  | 
| 152 152 | 
             
              if blocks.size == 2
         | 
| 153 153 | 
             
                [blocks[0], parse_json( blocks[1] )]
         | 
| @@ -29,8 +29,8 @@ TXT | |
| 29 29 | 
             
                recs = parse_csv( ENG_CLUBS_PROPS_TXT )
         | 
| 30 30 | 
             
                pp recs
         | 
| 31 31 |  | 
| 32 | 
            -
                assert_equal [{  | 
| 33 | 
            -
                              {  | 
| 32 | 
            +
                assert_equal [{ 'Key' => 'chelsea', 'Name' => 'Chelsea FC', 'Code' => 'CHE' },
         | 
| 33 | 
            +
                              { 'Key' => 'arsenal', 'Name' => 'Arsenal FC', 'Code' => 'ARS' }], recs[0..1]
         | 
| 34 34 | 
             
              end
         | 
| 35 35 |  | 
| 36 36 | 
             
              CLUBS = SportDb::Import.catalog.clubs
         | 
| @@ -0,0 +1,114 @@ | |
| 1 | 
            +
            # encoding: utf-8
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            ###
         | 
| 4 | 
            +
            #  to run use
         | 
| 5 | 
            +
            #     ruby -I ./lib -I ./test test/test_csv_match_parser.rb
         | 
| 6 | 
            +
             | 
| 7 | 
            +
             | 
| 8 | 
            +
            require 'helper'
         | 
| 9 | 
            +
             | 
| 10 | 
            +
             | 
| 11 | 
            +
            class TestCsvMatchParser < MiniTest::Test
         | 
| 12 | 
            +
             | 
| 13 | 
            +
            ##
         | 
| 14 | 
            +
            # Div,Date,HomeTeam,AwayTeam,FTHG,FTAG,FTR,HTHG,HTAG,HTR,
         | 
| 15 | 
            +
            #   Referee,HS,AS,HST,AST,HF,AF,HC,AC,HY,AY,HR,AR,
         | 
| 16 | 
            +
            #    B365H,B365D,B365A,BWH,BWD,BWA,IWH,IWD,IWA,LBH,LBD,LBA,PSH,PSD,PSA,
         | 
| 17 | 
            +
            #    WHH,WHD,WHA,VCH,VCD,VCA,
         | 
| 18 | 
            +
            #    Bb1X2,BbMxH,BbAvH,BbMxD,BbAvD,BbMxA,BbAvA,BbOU,BbMx>2.5,BbAv>2.5,BbMx<2.5,BbAv<2.5,
         | 
| 19 | 
            +
            #    BbAH,BbAHh,BbMxAHH,BbAvAHH,BbMxAHA,BbAvAHA,PSCH,PSCD,PSCA
         | 
| 20 | 
            +
              def test_eng_filters
         | 
| 21 | 
            +
                path = "#{SportDb::Test.data_dir}/england/2017-18/E0.csv"
         | 
| 22 | 
            +
             | 
| 23 | 
            +
                matches = SportDb::CsvMatchParser.read( path,
         | 
| 24 | 
            +
                                                        filters: { 'HomeTeam' => 'Arsenal' } )
         | 
| 25 | 
            +
             | 
| 26 | 
            +
                pp path
         | 
| 27 | 
            +
                pp matches[0..2]
         | 
| 28 | 
            +
             | 
| 29 | 
            +
                m=matches[0]
         | 
| 30 | 
            +
                assert_equal '2017-08-11', m.date
         | 
| 31 | 
            +
                assert_equal 4, m.score1
         | 
| 32 | 
            +
                assert_equal 3, m.score2
         | 
| 33 | 
            +
                assert_equal 2, m.score1i
         | 
| 34 | 
            +
                assert_equal 2, m.score2i
         | 
| 35 | 
            +
                assert_equal 'Arsenal',    m.team1
         | 
| 36 | 
            +
                assert_equal 'Leicester',  m.team2
         | 
| 37 | 
            +
             | 
| 38 | 
            +
                m=matches[1]
         | 
| 39 | 
            +
                assert_equal '2017-09-09', m.date
         | 
| 40 | 
            +
                assert_equal 3, m.score1
         | 
| 41 | 
            +
                assert_equal 0, m.score2
         | 
| 42 | 
            +
                assert_equal 2, m.score1i
         | 
| 43 | 
            +
                assert_equal 0, m.score2i
         | 
| 44 | 
            +
                assert_equal 'Arsenal',     m.team1
         | 
| 45 | 
            +
                assert_equal 'Bournemouth', m.team2
         | 
| 46 | 
            +
              end
         | 
| 47 | 
            +
             | 
| 48 | 
            +
             | 
| 49 | 
            +
              def test_eng_headers
         | 
| 50 | 
            +
                path = "#{SportDb::Test.data_dir}/england/2017-18/E0.csv"
         | 
| 51 | 
            +
             | 
| 52 | 
            +
                headers = { team1:  'HomeTeam',
         | 
| 53 | 
            +
                            team2:  'AwayTeam',
         | 
| 54 | 
            +
                            date:   'Date',
         | 
| 55 | 
            +
                            score1: 'FTHG',
         | 
| 56 | 
            +
                            score2: 'FTAG' }
         | 
| 57 | 
            +
             | 
| 58 | 
            +
                matches = SportDb::CsvMatchParser.read( path, headers: headers )
         | 
| 59 | 
            +
             | 
| 60 | 
            +
                pp path
         | 
| 61 | 
            +
                pp matches[0..2]
         | 
| 62 | 
            +
             | 
| 63 | 
            +
                m=matches[0]
         | 
| 64 | 
            +
                assert_equal '2017-08-11', m.date
         | 
| 65 | 
            +
                assert_equal 4, m.score1
         | 
| 66 | 
            +
                assert_equal 3, m.score2
         | 
| 67 | 
            +
                assert_nil   m.score1i      ## todo/fix: missing half time (ht) score !!!!
         | 
| 68 | 
            +
                assert_nil   m.score2i      ## todo/fix: missing half time (ht) score !!!!
         | 
| 69 | 
            +
                assert_equal 'Arsenal',   m.team1
         | 
| 70 | 
            +
                assert_equal 'Leicester', m.team2
         | 
| 71 | 
            +
             | 
| 72 | 
            +
                m=matches[1]
         | 
| 73 | 
            +
                assert_equal '2017-08-12', m.date
         | 
| 74 | 
            +
                assert_equal 0, m.score1
         | 
| 75 | 
            +
                assert_equal 2, m.score2
         | 
| 76 | 
            +
                assert_nil   m.score1i      ## todo/fix: missing half time (ht) score !!!!
         | 
| 77 | 
            +
                assert_nil   m.score2i      ## todo/fix: missing half time (ht) score !!!!
         | 
| 78 | 
            +
                assert_equal 'Brighton', m.team1
         | 
| 79 | 
            +
                assert_equal 'Man City', m.team2
         | 
| 80 | 
            +
              end
         | 
| 81 | 
            +
             | 
| 82 | 
            +
             | 
| 83 | 
            +
            ###
         | 
| 84 | 
            +
            # Country,League,Season,Date,Time,Home,Away,HG,AG,
         | 
| 85 | 
            +
            #  Res,PH,PD,PA,MaxH,MaxD,MaxA,AvgH,AvgD,AvgA
         | 
| 86 | 
            +
              def test_at
         | 
| 87 | 
            +
                path = "#{SportDb::Test.data_dir}/austria/AUT.csv"
         | 
| 88 | 
            +
             | 
| 89 | 
            +
                matches = SportDb::CsvMatchParser.read( path, filters: { 'Season' => '2017/2018' } )
         | 
| 90 | 
            +
             | 
| 91 | 
            +
                pp matches[0..2]
         | 
| 92 | 
            +
                pp path
         | 
| 93 | 
            +
             | 
| 94 | 
            +
                m=matches[0]
         | 
| 95 | 
            +
                assert_equal '2017-07-22', m.date
         | 
| 96 | 
            +
                assert_equal 2, m.score1
         | 
| 97 | 
            +
                assert_equal 2, m.score2
         | 
| 98 | 
            +
                assert_nil      m.score1i  ## todo/fix: missing half time (ht) score !!!!
         | 
| 99 | 
            +
                assert_nil      m.score2i  ## todo/fix: missing half time (ht) score !!!!
         | 
| 100 | 
            +
                assert_equal 'Rapid Vienna', m.team1
         | 
| 101 | 
            +
                assert_equal 'Mattersburg',  m.team2
         | 
| 102 | 
            +
             | 
| 103 | 
            +
                m=matches[1]
         | 
| 104 | 
            +
                assert_equal '2017-07-22', m.date
         | 
| 105 | 
            +
                assert_equal 0, m.score1
         | 
| 106 | 
            +
                assert_equal 2, m.score2
         | 
| 107 | 
            +
                assert_nil   m.score1i    ## todo/fix: missing half time (ht) score !!!!
         | 
| 108 | 
            +
                assert_nil   m.score2i    ## todo/fix: missing half time (ht) score !!!!
         | 
| 109 | 
            +
                assert_equal 'AC Wolfsberger', m.team1
         | 
| 110 | 
            +
                assert_equal 'Salzburg',       m.team2
         | 
| 111 | 
            +
              end
         | 
| 112 | 
            +
             | 
| 113 | 
            +
             | 
| 114 | 
            +
            end # class TestCsvMatchParser
         | 
| @@ -0,0 +1,20 @@ | |
| 1 | 
            +
            # encoding: utf-8
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            ###
         | 
| 4 | 
            +
            #  to run use
         | 
| 5 | 
            +
            #     ruby -I ./lib -I ./test test/test_csv_match_parser_utils.rb
         | 
| 6 | 
            +
             | 
| 7 | 
            +
             | 
| 8 | 
            +
            require 'helper'
         | 
| 9 | 
            +
             | 
| 10 | 
            +
            class TestCsvMatchParserUtils < MiniTest::Test
         | 
| 11 | 
            +
             | 
| 12 | 
            +
              def test_find_seasons
         | 
| 13 | 
            +
                 pp = SportDb::CsvMatchParser.find_seasons( "#{SportDb::Test.data_dir}/dl/AUT.csv" )  ## defaults to col: 'Season', col_sep: ','
         | 
| 14 | 
            +
                 pp = SportDb::CsvMatchParser.find_seasons( "#{SportDb::Test.data_dir}/dl/Bundesliga_1963_2014.csv", col: 'Saison', sep: ';'  )
         | 
| 15 | 
            +
                 assert true
         | 
| 16 | 
            +
              end
         | 
| 17 | 
            +
             | 
| 18 | 
            +
            end # class TestCsvMatchParserUtils
         | 
| 19 | 
            +
             | 
| 20 | 
            +
             | 
    
        data/test/test_csv_reader.rb
    CHANGED
    
    | @@ -13,7 +13,7 @@ class TestCsvReader < MiniTest::Test | |
| 13 13 | 
             
                recs = parse_csv( <<TXT )
         | 
| 14 14 | 
             
            ### World Countries
         | 
| 15 15 |  | 
| 16 | 
            -
             | 
| 16 | 
            +
            Key, Code, Name
         | 
| 17 17 | 
             
            af,  AFG,  Afghanistan
         | 
| 18 18 | 
             
            al,  ALB,  Albania
         | 
| 19 19 | 
             
            dz,  ALG,  Algeria
         | 
| @@ -21,10 +21,10 @@ as,  ASA,  American Samoa (US) | |
| 21 21 | 
             
            TXT
         | 
| 22 22 |  | 
| 23 23 | 
             
               pp recs
         | 
| 24 | 
            -
               assert_equal  [{  | 
| 25 | 
            -
                              {  | 
| 26 | 
            -
                              {  | 
| 27 | 
            -
                              {  | 
| 24 | 
            +
               assert_equal  [{ 'Key' => 'af', 'Code' => 'AFG', 'Name' => 'Afghanistan'},
         | 
| 25 | 
            +
                              { 'Key' => 'al', 'Code' => 'ALB', 'Name' => 'Albania'},
         | 
| 26 | 
            +
                              { 'Key' => 'dz', 'Code' => 'ALG', 'Name' => 'Algeria'},
         | 
| 27 | 
            +
                              { 'Key' => 'as', 'Code' => 'ASA', 'Name' => 'American Samoa (US)'},
         | 
| 28 28 | 
             
                             ], recs[0..3]
         | 
| 29 29 | 
             
              end
         | 
| 30 30 |  | 
    
        data/test/test_datafile.rb
    CHANGED
    
    | @@ -27,36 +27,4 @@ class TestDatafile < MiniTest::Test | |
| 27 27 | 
             
                assert Datafile::Package.match_exclude?( '/.build/leagues.txt' )
         | 
| 28 28 | 
             
                assert Datafile::Package.match_exclude?( '/.git/leagues.txt' )
         | 
| 29 29 | 
             
              end
         | 
| 30 | 
            -
             | 
| 31 | 
            -
             | 
| 32 | 
            -
              CLUBS_DIR   = '../../../openfootball/clubs'    ## source repo directory path
         | 
| 33 | 
            -
              LEAGUES_DIR = '../../../openfootball/leagues'
         | 
| 34 | 
            -
             | 
| 35 | 
            -
              def test_bundle
         | 
| 36 | 
            -
                datafiles = SportDb::Package.find_clubs( CLUBS_DIR )
         | 
| 37 | 
            -
                pp datafiles
         | 
| 38 | 
            -
             | 
| 39 | 
            -
                ## todo/fix: turn into Datafile::Bundle.new  and Bundle#write/save -why? why not?
         | 
| 40 | 
            -
                bundle = Datafile::Bundle.new( './tmp/clubs.txt' )
         | 
| 41 | 
            -
                bundle.write <<TXT
         | 
| 42 | 
            -
            ##########################################
         | 
| 43 | 
            -
            # auto-generated all-in-one single datafile clubs.txt bundle
         | 
| 44 | 
            -
            #    on #{Time.now} from #{datafiles.size} datafile(s)
         | 
| 45 | 
            -
            TXT
         | 
| 46 | 
            -
                bundle.write datafiles
         | 
| 47 | 
            -
                bundle.close
         | 
| 48 | 
            -
              end
         | 
| 49 | 
            -
             | 
| 50 | 
            -
              def test_bundle_old
         | 
| 51 | 
            -
                datafiles = SportDb::Package.find_leagues( LEAGUES_DIR )
         | 
| 52 | 
            -
                pp datafiles
         | 
| 53 | 
            -
             | 
| 54 | 
            -
                Datafile.write_bundle( './tmp/leagues.txt',
         | 
| 55 | 
            -
                                       datafiles: datafiles,
         | 
| 56 | 
            -
                                       header: <<TXT )
         | 
| 57 | 
            -
            ##########################################
         | 
| 58 | 
            -
            # auto-generated all-in-one single datafile leagues.txt bundle
         | 
| 59 | 
            -
            #    on #{Time.now} from #{datafiles.size} datafile(s)
         | 
| 60 | 
            -
            TXT
         | 
| 61 | 
            -
              end
         | 
| 62 30 | 
             
            end   # class TestDatafile
         | 
| @@ -0,0 +1,46 @@ | |
| 1 | 
            +
            # encoding: utf-8
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            ###
         | 
| 4 | 
            +
            #  to run use
         | 
| 5 | 
            +
            #     ruby -I ./lib -I ./test test/test_datafile_package.rb
         | 
| 6 | 
            +
             | 
| 7 | 
            +
             | 
| 8 | 
            +
            require 'helper'
         | 
| 9 | 
            +
             | 
| 10 | 
            +
             | 
| 11 | 
            +
            class TestDatafilePackage < MiniTest::Test
         | 
| 12 | 
            +
             | 
| 13 | 
            +
              def test_read
         | 
| 14 | 
            +
                [Datafile::DirPackage.new( '../../../openfootball/england' ),
         | 
| 15 | 
            +
                 Datafile::ZipPackage.new( 'tmp/england-master.zip' )
         | 
| 16 | 
            +
                ].each do |eng|
         | 
| 17 | 
            +
                   assert eng.find( '2015-16/.conf.txt' ).read.start_with?( '= English Premier League 2015/16' )
         | 
| 18 | 
            +
                   assert eng.find( '2017-18/.conf.txt' ).read.start_with?( '= English Premier League 2017/18' )
         | 
| 19 | 
            +
                   assert eng.find( '2015-16/1-premierleague-i.txt' ).read.start_with?( '= English Premier League 2015/16' )
         | 
| 20 | 
            +
                end
         | 
| 21 | 
            +
             | 
| 22 | 
            +
                [Datafile::DirPackage.new( '../../../openfootball/austria' ),
         | 
| 23 | 
            +
                 Datafile::ZipPackage.new( 'tmp/austria-master.zip' )
         | 
| 24 | 
            +
                ].each do |at|
         | 
| 25 | 
            +
                   assert at.find( '2018-19/.conf.txt' ).read.start_with?( '= Österr. Bundesliga 2018/19' )
         | 
| 26 | 
            +
                end
         | 
| 27 | 
            +
             | 
| 28 | 
            +
                puts "DirPackage:"
         | 
| 29 | 
            +
                pack = Datafile::DirPackage.new( '../../../openfootball/austria' )
         | 
| 30 | 
            +
                puts pack.name
         | 
| 31 | 
            +
                puts "  entries:"
         | 
| 32 | 
            +
                pack.each( pattern: /\.txt$/ ) do |entry|
         | 
| 33 | 
            +
                  puts entry.name
         | 
| 34 | 
            +
                end
         | 
| 35 | 
            +
             | 
| 36 | 
            +
                puts "ZipPackage:"
         | 
| 37 | 
            +
                pack = Datafile::ZipPackage.new( 'tmp/austria-master.zip' )
         | 
| 38 | 
            +
                puts pack.name
         | 
| 39 | 
            +
                puts "  entries:"
         | 
| 40 | 
            +
                pack.each( pattern: /\.txt$/ ) do |entry|
         | 
| 41 | 
            +
                  puts entry.name
         | 
| 42 | 
            +
                end
         | 
| 43 | 
            +
             | 
| 44 | 
            +
              end  # method test_read
         | 
| 45 | 
            +
             | 
| 46 | 
            +
            end  # class TestDatafilePackage
         | 
    
        data/test/test_package.rb
    CHANGED
    
    | @@ -7,40 +7,72 @@ | |
| 7 7 |  | 
| 8 8 | 
             
            require 'helper'
         | 
| 9 9 |  | 
| 10 | 
            -
             | 
| 11 10 | 
             
            class TestPackage < MiniTest::Test
         | 
| 12 11 |  | 
| 13 | 
            -
               | 
| 14 | 
            -
             | 
| 15 | 
            -
                 Datafile::ZipPackage.new( 'tmp/england-master.zip' )
         | 
| 16 | 
            -
                ].each do |eng|
         | 
| 17 | 
            -
                   assert eng.find( '2015-16/.conf.txt' ).read.start_with?( '= English Premier League 2015/16' )
         | 
| 18 | 
            -
                   assert eng.find( '2017-18/.conf.txt' ).read.start_with?( '= English Premier League 2017/18' )
         | 
| 19 | 
            -
                   assert eng.find( '2015-16/1-premierleague-i.txt' ).read.start_with?( '= English Premier League 2015/16' )
         | 
| 20 | 
            -
                end
         | 
| 12 | 
            +
              AUSTRIA_DIR     = '../../../openfootball/austria'
         | 
| 13 | 
            +
              AUSTRIA_CSV_DIR = '../../../footballcsv/austria'
         | 
| 21 14 |  | 
| 22 | 
            -
             | 
| 23 | 
            -
             | 
| 24 | 
            -
             | 
| 25 | 
            -
             | 
| 26 | 
            -
             | 
| 15 | 
            +
              ENGLAND_DIR     = '../../../openfootball/england'
         | 
| 16 | 
            +
              ENGLAND_CSV_DIR = '../../../footballcsv/england'
         | 
| 17 | 
            +
             | 
| 18 | 
            +
             | 
| 19 | 
            +
              def test_match_by
         | 
| 27 20 |  | 
| 28 | 
            -
                 | 
| 29 | 
            -
             | 
| 30 | 
            -
             | 
| 31 | 
            -
                 | 
| 32 | 
            -
             | 
| 33 | 
            -
                  puts  | 
| 21 | 
            +
                [ AUSTRIA_CSV_DIR,
         | 
| 22 | 
            +
                  ENGLAND_CSV_DIR,
         | 
| 23 | 
            +
                  "#{SportDb::Test.data_dir}/packages/test-levels",
         | 
| 24 | 
            +
                ].each do |path|
         | 
| 25 | 
            +
                  puts
         | 
| 26 | 
            +
                  puts "match (csv) in #{path}:"
         | 
| 27 | 
            +
                  pack = SportDb::Package.new( path )
         | 
| 28 | 
            +
                  pp pack.match_by_season_dir( format: 'csv' )
         | 
| 29 | 
            +
                  puts "---"
         | 
| 30 | 
            +
                  pp pack.match_by_season( format: 'csv' )
         | 
| 34 31 | 
             
                end
         | 
| 35 32 |  | 
| 36 | 
            -
                 | 
| 37 | 
            -
             | 
| 38 | 
            -
             | 
| 39 | 
            -
                 | 
| 40 | 
            -
             | 
| 41 | 
            -
                  puts  | 
| 33 | 
            +
                [ AUSTRIA_DIR,
         | 
| 34 | 
            +
                  ENGLAND_DIR,
         | 
| 35 | 
            +
                  "#{SportDb::Test.data_dir}/packages/test-levels",
         | 
| 36 | 
            +
                ].each do |path|
         | 
| 37 | 
            +
                  puts
         | 
| 38 | 
            +
                  puts "match (txt) in #{path}:"
         | 
| 39 | 
            +
                  pack = SportDb::Package.new( path )
         | 
| 40 | 
            +
                  pp pack.match_by_season_dir
         | 
| 41 | 
            +
                  puts "---"
         | 
| 42 | 
            +
                  pp pack.match_by_season( start: '2000' )   ## note: try with start season filter!!
         | 
| 42 43 | 
             
                end
         | 
| 44 | 
            +
              end
         | 
| 45 | 
            +
             | 
| 46 | 
            +
             | 
| 47 | 
            +
              CLUBS_DIR   = '../../../openfootball/clubs'    ## source repo directory path
         | 
| 48 | 
            +
              LEAGUES_DIR = '../../../openfootball/leagues'
         | 
| 49 | 
            +
             | 
| 50 | 
            +
              def test_bundle
         | 
| 51 | 
            +
                datafiles = SportDb::Package.find_clubs( CLUBS_DIR )
         | 
| 52 | 
            +
                pp datafiles
         | 
| 53 | 
            +
             | 
| 54 | 
            +
                ## todo/fix: turn into Datafile::Bundle.new  and Bundle#write/save -why? why not?
         | 
| 55 | 
            +
                bundle = Datafile::Bundle.new( './tmp/clubs.txt' )
         | 
| 56 | 
            +
                bundle.write <<TXT
         | 
| 57 | 
            +
            ##########################################
         | 
| 58 | 
            +
            # auto-generated all-in-one single datafile clubs.txt bundle
         | 
| 59 | 
            +
            #    on #{Time.now} from #{datafiles.size} datafile(s)
         | 
| 60 | 
            +
            TXT
         | 
| 61 | 
            +
                bundle.write datafiles
         | 
| 62 | 
            +
                bundle.close
         | 
| 63 | 
            +
              end
         | 
| 64 | 
            +
             | 
| 65 | 
            +
              def test_bundle_old
         | 
| 66 | 
            +
                datafiles = SportDb::Package.find_leagues( LEAGUES_DIR )
         | 
| 67 | 
            +
                pp datafiles
         | 
| 43 68 |  | 
| 44 | 
            -
             | 
| 69 | 
            +
                Datafile.write_bundle( './tmp/leagues.txt',
         | 
| 70 | 
            +
                                       datafiles: datafiles,
         | 
| 71 | 
            +
                                       header: <<TXT )
         | 
| 72 | 
            +
            ##########################################
         | 
| 73 | 
            +
            # auto-generated all-in-one single datafile leagues.txt bundle
         | 
| 74 | 
            +
            #    on #{Time.now} from #{datafiles.size} datafile(s)
         | 
| 75 | 
            +
            TXT
         | 
| 76 | 
            +
              end
         | 
| 45 77 |  | 
| 46 | 
            -
            end | 
| 78 | 
            +
            end # class TestPackage
         |