fifadat-convert 0.0.1 → 0.1.0
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/CHANGELOG.md +1 -0
- data/Manifest.txt +15 -11
- data/lib/fifadat/convert/convert-reports.rb +49 -67
- data/lib/fifadat/convert/convert.rb +67 -96
- data/lib/fifadat/convert/helper-date.rb +12 -0
- data/lib/fifadat/convert/helper-score.rb +104 -61
- data/lib/fifadat/convert/reader.rb +55 -0
- data/lib/fifadat/convert/tool.rb +1 -1
- data/lib/fifadat/convert/version.rb +2 -2
- data/lib/fifadat/convert.rb +54 -14
- data/lib/fifadat/{convert/goals.rb → models/goal.rb} +49 -18
- data/lib/fifadat/models/match.rb +218 -0
- data/lib/fifadat/models/match_report.rb +205 -0
- data/lib/fifadat/{convert/officials.rb → models/official.rb} +58 -20
- data/lib/fifadat/{convert/penalties.rb → models/penalty.rb} +50 -16
- data/lib/fifadat/models/player.rb +218 -0
- data/lib/fifadat/models/stadium.rb +98 -0
- data/lib/fifadat/models/stage.rb +99 -0
- data/lib/fifadat/{convert/substitutions.rb → models/substitution.rb} +84 -9
- data/lib/fifadat/models/team.rb +85 -0
- data/lib/fifadat/tables/players.rb +140 -0
- data/lib/fifadat/tables/stadiums.rb +71 -0
- data/lib/fifadat/tables/stages.rb +58 -0
- data/lib/fifadat/tables/teams.rb +57 -0
- metadata +17 -13
- data/lib/fifadat/convert/build_match.rb +0 -105
- data/lib/fifadat/convert/build_report.rb +0 -135
- data/lib/fifadat/convert/goals-calc_score.rb +0 -58
- data/lib/fifadat/convert/players.rb +0 -329
- data/lib/fifadat/convert/stadiums.rb +0 -99
- data/lib/fifadat/convert/stages.rb +0 -119
- data/lib/fifadat/convert/teams.rb +0 -91
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
=begin
|
|
4
|
-
[{"IdStage": "286472",
|
|
5
|
-
"Name": [{"Locale": "en-GB", "Description": "Final"}],
|
|
6
|
-
"IdSeason": "286466",
|
|
7
|
-
"SeasonName":
|
|
8
|
-
[{"Locale": "en-GB", "Description": "FIFA Club World Cup Morocco 2022™"}],
|
|
9
|
-
"IdCompetition": "107",
|
|
10
|
-
"StageLevel": null,
|
|
11
|
-
"StartDate": "2023-02-11T19:00:00Z",
|
|
12
|
-
"EndDate": "2023-02-11T19:00:00Z",
|
|
13
|
-
"Type": 0,
|
|
14
|
-
"SequenceOrder": 6,
|
|
15
|
-
"Properties": {"IdIFES": "286472"},
|
|
16
|
-
"IsUpdateable": null},
|
|
17
|
-
=end
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
def build_stage( h )
|
|
21
|
-
name = desc( h['Name'] )
|
|
22
|
-
seq = h['SequenceOrder']
|
|
23
|
-
level = h['StageLevel'] ## note - is optional
|
|
24
|
-
|
|
25
|
-
rec = {
|
|
26
|
-
## id: h['IdStage'], ## convert to number - why? why not?
|
|
27
|
-
seq: seq,
|
|
28
|
-
name: name,
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
if h['StartDate'] && h['EndDate']
|
|
33
|
-
## note - start/end dates are utc (NOT local)
|
|
34
|
-
start_date = parse_date_utc( h['StartDate'] ) ## expects ...:00Z format
|
|
35
|
-
end_date = parse_date_utc( h['EndDate'] ) ## expects ...:00Z format
|
|
36
|
-
|
|
37
|
-
## check if HH::MM is 00:00
|
|
38
|
-
## only use date for now; ignore time
|
|
39
|
-
## report warn(ing) if time present!!!
|
|
40
|
-
if start_date.hour != 0 || start_date.min != 0 ||
|
|
41
|
-
end_date.hour != 0 || end_date.min != 0
|
|
42
|
-
## issue warn start/end_date with HH:MM (NOT 00:00)
|
|
43
|
-
puts "!! warn: stage start/end_date with HH:MM (expected 00:00)"
|
|
44
|
-
pp h
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
rec[:start_date] = start_date.strftime('%Y-%m-%d')
|
|
48
|
-
rec[:end_date] = end_date.strftime('%Y-%m-%d')
|
|
49
|
-
else
|
|
50
|
-
## maybe add to log later - why? why not?
|
|
51
|
-
## puts "!! warn: stage witouout start/end_date"
|
|
52
|
-
## pp h
|
|
53
|
-
end
|
|
54
|
-
|
|
55
|
-
rec[:count] = 0
|
|
56
|
-
|
|
57
|
-
rec[:level] = level if level
|
|
58
|
-
|
|
59
|
-
rec
|
|
60
|
-
end
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
class Stages
|
|
65
|
-
|
|
66
|
-
def self.read( path )
|
|
67
|
-
data = read_json_v2( path )
|
|
68
|
-
obj = new
|
|
69
|
-
obj.add( data['Results'] )
|
|
70
|
-
obj
|
|
71
|
-
end
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
def initialize
|
|
75
|
-
@recs = {}
|
|
76
|
-
end
|
|
77
|
-
|
|
78
|
-
def add( recs ) ## rename to collect - why? why not?
|
|
79
|
-
recs.each { |h| _add( build_stage(h)) }
|
|
80
|
-
end
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
def _add( new_rec )
|
|
84
|
-
rec = @recs[ new_rec[:name] ]
|
|
85
|
-
if rec.nil?
|
|
86
|
-
@recs[ new_rec[:name]] = new_rec
|
|
87
|
-
else
|
|
88
|
-
raise ArgumentError, "duplicate stage entry: #{new_rec.pretty_inspect}"
|
|
89
|
-
end
|
|
90
|
-
end
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
## add match stats
|
|
94
|
-
def add_matches( matches )
|
|
95
|
-
matches.each do |m|
|
|
96
|
-
name = desc( m['StageName'] )
|
|
97
|
-
rec = find!( name )
|
|
98
|
-
rec[:count] += 1
|
|
99
|
-
end
|
|
100
|
-
end
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
def find!( name )
|
|
104
|
-
rec = @recs[ name ]
|
|
105
|
-
raise ArgumentError, "no stage w/ name >#{name}< found; sorry" if rec.nil?
|
|
106
|
-
rec
|
|
107
|
-
end
|
|
108
|
-
|
|
109
|
-
def as_json
|
|
110
|
-
## note - sort by seq
|
|
111
|
-
|
|
112
|
-
@recs.values.sort do |l,r|
|
|
113
|
-
l[:seq] <=> r[:seq]
|
|
114
|
-
end
|
|
115
|
-
end
|
|
116
|
-
|
|
117
|
-
def size() @recs.size; end
|
|
118
|
-
|
|
119
|
-
end # class Stages
|
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
def build_team( h )
|
|
4
|
-
|
|
5
|
-
if h
|
|
6
|
-
name = desc( h['TeamName'] )
|
|
7
|
-
|
|
8
|
-
## name = norm_team( name )
|
|
9
|
-
|
|
10
|
-
rec = {
|
|
11
|
-
id: h['IdTeam'],
|
|
12
|
-
name: name,
|
|
13
|
-
code: h['Abbreviation'],
|
|
14
|
-
country: h['IdCountry'], ## change to cc (country code) - why? why not?
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
rec
|
|
18
|
-
else ## assume nil - dummy record
|
|
19
|
-
rec = {
|
|
20
|
-
id: '<nil>',
|
|
21
|
-
name: '?',
|
|
22
|
-
code: '?', ## use nil - why? why not?
|
|
23
|
-
country: '?' ## use nil - why? why not?
|
|
24
|
-
}
|
|
25
|
-
rec
|
|
26
|
-
end
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
class Teams
|
|
33
|
-
def initialize
|
|
34
|
-
@recs = {}
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
def add_matches( matches )
|
|
38
|
-
## note - if team nil - will (auto-)add nil team (<nil>,?,?,?)
|
|
39
|
-
matches.each do |m|
|
|
40
|
-
_add( build_team( m['Home'] ) )
|
|
41
|
-
_add( build_team( m['Away'] ) )
|
|
42
|
-
end
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
=begin
|
|
47
|
-
!! ASSERT FAILED - team records NOT matching -
|
|
48
|
-
{:id=>"44129",
|
|
49
|
-
:name=>"Vasco da Gama",
|
|
50
|
-
:code=>"VDG",
|
|
51
|
-
:country=>"BRA",
|
|
52
|
-
:count=>7}
|
|
53
|
-
!=
|
|
54
|
-
{:id=>"44129",
|
|
55
|
-
:name=>"Vasco da Gama",
|
|
56
|
-
:code=>"VAS",
|
|
57
|
-
:country=>"BRA"}
|
|
58
|
-
=end
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
def _add( new_rec )
|
|
62
|
-
rec = @recs[ new_rec[:id] ]
|
|
63
|
-
if rec.nil?
|
|
64
|
-
rec = new_rec
|
|
65
|
-
rec[:count] = 1 ## add counter - why? why not?
|
|
66
|
-
@recs[ new_rec[:id]] = new_rec
|
|
67
|
-
else
|
|
68
|
-
rec[:count] += 1
|
|
69
|
-
|
|
70
|
-
## assert attributes equal - why? why not?
|
|
71
|
-
## note - ignore code for now
|
|
72
|
-
## new_rec[:code] == rec[:code] &&
|
|
73
|
-
assert( new_rec[:name] == rec[:name] &&
|
|
74
|
-
new_rec[:country] == rec[:country],
|
|
75
|
-
"team records NOT matching - #{rec.pretty_inspect} != #{new_rec.pretty_inspect}")
|
|
76
|
-
end
|
|
77
|
-
end
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
def as_json( id: false )
|
|
81
|
-
## note - always remove code for now
|
|
82
|
-
if id
|
|
83
|
-
@recs.values
|
|
84
|
-
else
|
|
85
|
-
@recs.values.map { |rec| rec.except( :id ) }
|
|
86
|
-
end
|
|
87
|
-
end
|
|
88
|
-
|
|
89
|
-
def size() @recs.size; end
|
|
90
|
-
|
|
91
|
-
end # class Teams
|