zugzwang 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7c824df5a3a56edd454328beac8fdd7541bb5384587a60575502ba67f0536e61
4
- data.tar.gz: 78bd8e37e7051981fc78d067e23029015606294fea0548a78859c925e2ef031c
3
+ metadata.gz: c94a00ce313f8e6c8d11fbc4976ffd5d75d0d1ca2909bda1354c183fe0c4b448
4
+ data.tar.gz: cc8a44622f7a9005c9c8f9f80074fbb098c83566a0ad5f54a362b9cbf4c59661
5
5
  SHA512:
6
- metadata.gz: 85a6871c5966e70a240028ac7b724d84a30fe8c432fe66f1db89dc92428c07514b58041b67df963d5344c30428c0fc30ce7deb723e2c320d9c8e991fcf339e63
7
- data.tar.gz: c48fa8aad9589065c587d9a80fae3ceb925129008904ae6507eb494e0bdb99e30f9935d47e0af16394a540c2068bad133044bf3ecee14df21e09ca4bdf59a329
6
+ metadata.gz: 400589fa148bff4060ae59f48a2f8d9e320a7afab5c5f261f6de703d57410cfe4084a78eaf8bf8562f31e67d515de59b2da0db6efe9583dea355f75a35277c52
7
+ data.tar.gz: a3926859051035f82a12c2c9770710a9be0b6a2342d8e570dbf1d9d57c6f467c02f918c3d780c81c0f851bd13b2922d5d1bafc9fa778fb893a18fb454cfb79e7
data/README.md CHANGED
@@ -13,6 +13,8 @@ PGN (**P**ost-**G**ame **N**otation) files are plain-text files that provide rec
13
13
 
14
14
  The extensive [game database provided by Lichess](https://database.lichess.org/) (over 368 million games as of July 2018) uses the following format for each game of within their PGN files.
15
15
 
16
+ This format is essentially the same as standard PGN formats, but with a few differences. Particularly with the game record and some of the metadata fields.
17
+
16
18
  ```
17
19
  [Event "Rated Bullet tournament https://lichess.org/tournament/yc1WW2Ox"]
18
20
  [Site "https://lichess.org/PpwPOZMq"]
@@ -65,11 +67,13 @@ In the example game above, the metadata section is the part that looks like:
65
67
 
66
68
  This is the section that the CLI is concerned with, and will produce a database record with the fields consisting of the metadata for each game.
67
69
 
68
- #### PGN
70
+ #### Game record
71
+
72
+ This section contains the actual record of the chess game, the moves are given in <a href="https://en.wikipedia.org/wiki/Algebraic_notation_(chess)">Algebraic Chess Notation</a>, along with the time on the clock for each move.
69
73
 
70
- This section contains the actual record of the chess game, the moves are given in <a href="https://en.wikipedia.org/wiki/Algebraic_notation_(chess)">Algebraic Chess Notation</a>.
74
+ Additionally, some games may include Stockfish evaluation for each move.
71
75
 
72
- In the example game above, the PGN section is the part that looks like:
76
+ In the example game above, the game record is the part that looks like:
73
77
 
74
78
  ```
75
79
  1. e4 { [%eval 0.17] [%clk 0:00:30] } 1... c5 { [%eval 0.19] [%clk 0:00:30] }
@@ -82,6 +86,16 @@ In the example game above, the PGN section is the part that looks like:
82
86
 
83
87
  Since this CLI is not concerned with individual moves or position analysis, this data is discarded during the parsing process.
84
88
 
89
+ ## Field format changes
90
+
91
+ To fit with SQL data-type format specifications (and in order to optimize querying), the following PGN metadata fields have had their formats changed within the generated database file:
92
+
93
+ | Field | Format in PGN file | New format in database |
94
+ | ----------------- | ------------------------ | ------------------------------------------------ |
95
+ | `UTCDate` | `YYYY.MM.DD` | `YYYY-MM-DD` |
96
+ | `WhiteRatingDiff` | `+11` or `-11` (example) | `11` or `-11` (Integer without `+` for positive) |
97
+ | `BlackRatingDiff` | `+5` or `-5` (example) | `5` or `-5` (Integer without `+` for positive) |
98
+
85
99
  ## Installation
86
100
 
87
101
  To install the CLI:
data/lib/zugzwang.rb CHANGED
@@ -4,23 +4,23 @@ require "zugzwang/cli"
4
4
 
5
5
  module Zugzwang
6
6
  FIELDS = {
7
- Event: {type: :string},
8
- Site: {type: :string, size: 50},
9
- White: {type: :string, size: 30},
10
- Black: {type: :string, size: 30},
11
- Result: {type: :string, size: 10},
12
- UTCDate: {type: :date, size: 15},
13
- UTCTime: {type: :time, size: 8},
14
- WhiteElo: {type: :integer},
15
- BlackElo: {type: :integer},
16
- WhiteRatingDiff: {type: :string, size: 5},
17
- BlackRatingDiff: {type: :string, size: 5},
18
- WhiteTitle: {type: :string, size: 5},
19
- ECO: {type: :string, size: 3},
20
- Opening: {type: :string},
21
- TimeControl: {type: :string, size: 15},
22
- Termination: {type: :string, size: 20},
23
- Variant: {type: :string}
7
+ Event: {type: :string},
8
+ Site: {type: :string, size: 50},
9
+ White: {type: :string, size: 30},
10
+ Black: {type: :string, size: 30},
11
+ Result: {type: :string, size: 10},
12
+ UTCDate: {type: :date, size: 15},
13
+ UTCTime: {type: :time, size: 8},
14
+ WhiteElo: {type: :integer},
15
+ BlackElo: {type: :integer},
16
+ WhiteRatingDiff: {type: :integer},
17
+ BlackRatingDiff: {type: :integer},
18
+ WhiteTitle: {type: :string, size: 5},
19
+ ECO: {type: :string, size: 3},
20
+ Opening: {type: :string},
21
+ TimeControl: {type: :string, size: 15},
22
+ Termination: {type: :string, size: 20},
23
+ Variant: {type: :string}
24
24
  }
25
25
  EXTENSIONS = %i[sql sqlite sqlite3 db]
26
26
  end
@@ -1,4 +1,6 @@
1
1
  require 'ruby-progressbar'
2
+ require 'date'
3
+ require 'time'
2
4
 
3
5
  module Zugzwang
4
6
  module Create
@@ -43,7 +45,14 @@ module Zugzwang
43
45
  subbed = line.gsub(%r{[\r\n\[\]\"]},'')
44
46
  field, value = subbed.split(' ', 2)
45
47
  field = field.to_sym
46
- record[field.to_sym] = value if FIELDS.include?(field)
48
+ if FIELDS[field]
49
+ record[field] = case FIELDS[field][:type]
50
+ when :string then value
51
+ when :integer then value.to_i
52
+ when :date then Date.parse(value)
53
+ when :time then value
54
+ end
55
+ end
47
56
  prev = line
48
57
  progress_bar.increment
49
58
  end
@@ -1,3 +1,3 @@
1
1
  module Zugzwang
2
- VERSION = "0.1.3"
2
+ VERSION = "0.1.4"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zugzwang
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Edwin Onuonga