]> gitweb.michael.orlitzky.com - dead/htsn-import.git/blob - doc/man1/htsn-import.1
Add GameInfo support for cbaskpreviewxml.dtd.
[dead/htsn-import.git] / doc / man1 / htsn-import.1
1 .TH htsn-import 1
2
3 .SH NAME
4 htsn-import \- Import XML files from The Sports Network into an RDBMS.
5
6 .SH SYNOPSIS
7
8 \fBhtsn-import\fR [OPTIONS] [FILES]
9
10 .SH DESCRIPTION
11 .P
12 The Sports Network <http://www.sportsnetwork.com/> offers an XML feed
13 containing various sports news and statistics. Our sister program
14 \fBhtsn\fR is capable of retrieving the feed and saving the individual
15 XML documents contained therein. But what to do with them?
16 .P
17 The purpose of \fBhtsn-import\fR is to take these XML documents and
18 get them into something we can use, a relational database management
19 system (RDBMS), otherwise known as a SQL database. The structure of
20 relational database, is, well, relational, and the feed XML is not. So
21 there is some work to do before the data can be imported into the
22 database.
23 .P
24 First, we must parse the XML. Each supported document type (see below)
25 has a full pickle/unpickle implementation (\(dqpickle\(dq is simply a
26 synonym for serialize here). That means that we parse the entire
27 document into a data structure, and if we pickle (serialize) that data
28 structure, we get the exact same XML document tha we started with.
29 .P
30 This is important for two reasons. First, it serves as a second level
31 of validation. The first validation is performed by the XML parser,
32 but if that succeeds and unpicking fails, we know that something is
33 fishy. Second, we don't ever want to be surprised by some new element
34 or attribute showing up in the XML. The fact that we can unpickle the
35 whole thing now means that we won't be surprised in the future.
36 .P
37 The aforementioned feature is especially important because we
38 automatically migrate the database schema every time we import a
39 document. If you attempt to import a \(dqnewsxml.dtd\(dq document, all
40 database objects relating to the news will be created if they do not
41 exist. We don't want the schema to change out from under us without
42 warning, so it's important that no XML be parsed that would result in
43 a different schema than we had previously. Since we can
44 pickle/unpickle everything already, this should be impossible.
45
46 .SH SUPPORTED DOCUMENT TYPES
47 .P
48 The XML document types obtained from the feed are uniquely identified
49 by their DTDs. We currently support documents with the following DTDs:
50 .IP \[bu] 2
51 Auto_Racing_Schedule_XML.dtd
52 .IP \[bu] 2
53 CBASK_Lineup_XML.dtd (GameInfo)
54 .IP \[bu] 2
55 cbaskpreviewxml.dtd (GameInfo)
56 .IP \[bu]
57 Heartbeat.dtd
58 .IP \[bu]
59 Injuries_Detail_XML.dtd
60 .IP \[bu]
61 injuriesxml.dtd
62 .IP \[bu]
63 MLB_Gaming_Matchup_XML.dtd (GameInfo)
64 .IP \[bu]
65 MLB_Lineup_XML.dtd (GameInfo)
66 .IP \[bu]
67 MLB_Matchup_XML.dtd (GameInfo)
68 .IP \[bu]
69 MLS_Preview_XML.dtd (GameInfo)
70 .IP \[bu]
71 mlbpreviewxml.dtd (GameInfo)
72 .IP \[bu]
73 NBA_Gaming_Matchup_XML.dtd (GameInfo)
74 .IP \[bu]
75 NBA_Playoff_Matchup_XML.dtd (GameInfo)
76 .IP \[bu]
77 NBALineupXML.dtd (GameInfo)
78 .IP \[bu]
79 nbapreviewxml.dtd (GameInfo)
80 .IP \[bu]
81 newsxml.dtd
82 .IP \[bu]
83 nhlpreviewxml.dtd (GameInfo)
84 .IP \[bu]
85 Odds_XML.dtd
86 .IP \[bu]
87 recapxml.dtd (GameInfo)
88 .IP \[bu]
89 scoresxml.dtd
90 .IP \[bu]
91 weatherxml.dtd
92 .P
93 The GameInfo and SportsInfo types do not have their own top-level
94 tables in the database. Instead, their raw XML is stored in either the
95 \(dqgame_info\(dq or \(dqsports_info\(dq table respectively.
96
97 .SH DATABASE SCHEMA
98 .P
99 At the top level (with two notable exceptions), we have one table for
100 each of the XML document types that we import. For example, the
101 documents corresponding to \fInewsxml.dtd\fR will have a table called
102 \(dqnews\(dq. All top-level tables contain two important fields,
103 \(dqxml_file_id\(dq and \(dqtime_stamp\(dq. The former is unique and
104 prevents us from inserting the same data twice. The time stamp on the
105 other hand lets us know when the data is old and can be removed. The
106 database schema make it possible to delete only the outdated top-level
107 records; all transient children should be removed by triggers.
108 .P
109 These top-level tables will often have children. For example, each
110 news item has zero or more locations associated with it. The child
111 table will be named <parent>_<children>, which in this case
112 corresponds to \(dqnews_locations\(dq.
113 .P
114 To relate the two, a third table may exist with name
115 <parent>__<child>. Note the two underscores. This prevents ambiguity
116 when the child table itself contains underscores. The table joining
117 \(dqnews\(dq with \(dqnews_locations\(dq is thus called
118 \(dqnews__news_locations\(dq. This is necessary when the child table
119 has a unique constraint; we don't want to blindly insert duplicate
120 records keyed to the parent. Instead we'd like to use the third table
121 to map an existing child to the new parent.
122 .P
123 Where it makes sense, children are kept unique to prevent pointless
124 duplication. This slows down inserts, and speeds up reads (which are
125 much more frequent). There is a tradeoff to be made, however. For a
126 table with a small, fixed upper bound on the number of rows (like
127 \(dqodds_casinos\(dq), there is great benefit to de-duplication. The
128 total number of rows stays small, so inserts are still quick, and many
129 duplicate rows are eliminated.
130 .P
131 But, with a table like \(dqodds_games\(dq, the number of games grows
132 quickly and without bound. It is therefore more beneficial to be able
133 to delete the old games (through an ON DELETE CASCADE, tied to
134 \(dqodds\(dq) than it is to eliminate duplication. A table like
135 \(dqnews_locations\(dq is somewhere in-between. It is hoped that the
136 unique constraint in the top-level table's \(dqxml_file_id\(dq will
137 prevent duplication in this case anyway.
138 .P
139 The aforementioned exceptions are the \(dqgame_info\(dq and
140 \(dqsports_info\(dq tables. These tables contain the raw XML for a
141 number of DTDs that are not handled individually. This is partially
142 for backwards-compatibility with a legacy implementation, but is
143 mostly a stopgap due to a lack of resources at the moment. These two
144 tables (game_info and sports_info) still possess timestamps that allow
145 us to prune old data.
146 .P
147 UML diagrams of the resulting database schema for each XML document
148 type are provided with the \fBhtsn-import\fR documentation.
149
150 .SH XML Schema Oddities
151 .P
152 There are a number of problems with the XML on the wire. Even if we
153 construct the DTDs ourselves, the results are sometimes
154 inconsistent. Here we document a few of them.
155
156 .IP \[bu] 2
157 Odds_XML.dtd
158
159 The <Notes> elements here are supposed to be associated with a set of
160 <Game> elements, but since the pair
161 (<Notes>...</Notes><Game>...</Game>) can appear zero or more times,
162 this leads to ambiguity in parsing. We therefore ignore the notes
163 entirely (although a hack is employed to facilitate parsing).
164
165 .IP \[bu]
166 weatherxml.dtd
167
168 There appear to be two types of weather documents; the first has
169 <listing> contained within <forecast> and the second has <forecast>
170 contained within <listing>. While it would be possible to parse both,
171 it would greatly complicate things. The first form is more common, so
172 that's all we support for now.
173
174 .SH OPTIONS
175
176 .IP \fB\-\-backend\fR,\ \fB\-b\fR
177 The RDBMS backend to use. Valid choices are \fISqlite\fR and
178 \fIPostgres\fR. Capitalization is important, sorry.
179
180 Default: Sqlite
181
182 .IP \fB\-\-connection-string\fR,\ \fB\-c\fR
183 The connection string used for connecting to the database backend
184 given by the \fB\-\-backend\fR option. The default is appropriate for
185 the \fISqlite\fR backend.
186
187 Default: \(dq:memory:\(dq
188
189 .IP \fB\-\-log-file\fR
190 If you specify a file here, logs will be written to it (possibly in
191 addition to syslog). Can be either a relative or absolute path. It
192 will not be auto-rotated; use something like logrotate for that.
193
194 Default: none
195
196 .IP \fB\-\-log-level\fR
197 How verbose should the logs be? We log notifications at four levels:
198 DEBUG, INFO, WARN, and ERROR. Specify the \(dqmost boring\(dq level of
199 notifications you would like to receive (in all-caps); more
200 interesting notifications will be logged as well. The debug output is
201 extremely verbose and will not be written to syslog even if you try.
202
203 Default: INFO
204
205 .IP \fB\-\-remove\fR,\ \fB\-r\fR
206 Remove successfully processed files. If you enable this, you can see
207 at a glance which XML files are not being processed, because they're
208 all that should be left.
209
210 Default: disabled
211
212 .IP \fB\-\-syslog\fR,\ \fB\-s\fR
213 Enable logging to syslog. On Windows this will attempt to communicate
214 (over UDP) with a syslog daemon on localhost, which will most likely
215 not work.
216
217 Default: disabled
218
219 .SH CONFIGURATION FILE
220 .P
221 Any of the command-line options mentioned above can be specified in a
222 configuration file instead. We first look for \(dqhtsn-importrc\(dq in
223 the system configuration directory. We then look for a file named
224 \(dq.htsn-importrc\(dq in the user's home directory. The latter will
225 override the former.
226 .P
227 The user's home directory is simply $HOME on Unix; on Windows it's
228 wherever %APPDATA% points. The system configuration directory is
229 determined by Cabal; the \(dqsysconfdir\(dq parameter during the
230 \(dqconfigure\(dq step is used.
231 .P
232 The file's syntax is given by examples in the htsn-importrc.example file
233 (included with \fBhtsn-import\fR).
234 .P
235 Options specified on the command-line override those in either
236 configuration file.
237
238 .SH EXAMPLES
239 .IP \[bu] 2
240 Import newsxml.xml into a preexisting sqlite database named \(dqfoo.sqlite3\(dq:
241
242 .nf
243 .I $ htsn-import --connection-string='foo.sqlite3' \\\\
244 .I " test/xml/newsxml.xml"
245 Successfully imported test/xml/newsxml.xml.
246 Imported 1 document(s) total.
247 .fi
248 .IP \[bu]
249 Repeat the previous example, but delete newsxml.xml afterwards:
250
251 .nf
252 .I $ htsn-import --connection-string='foo.sqlite3' \\\\
253 .I " --remove test/xml/newsxml.xml"
254 Successfully imported test/xml/newsxml.xml.
255 Imported 1 document(s) total.
256 Removed processed file test/xml/newsxml.xml.
257 .fi
258 .IP \[bu]
259 Use a Postgres database instead of the default Sqlite. This assumes
260 that you have a database named \(dqhtsn\(dq accessible to user
261 \(dqpostgres\(dq locally:
262
263 .nf
264 .I $ htsn-import --connection-string='dbname=htsn user=postgres' \\\\
265 .I " --backend=Postgres test/xml/newsxml.xml"
266 Successfully imported test/xml/newsxml.xml.
267 Imported 1 document(s) total.
268 .fi
269
270 .SH BUGS
271
272 .P
273 Send bugs to michael@orlitzky.com.