@@ -192,9 +192,6 @@ def line(self, cursor):
192
192
self .offset = newoffset
193
193
else :
194
194
xdict = apply_dbtypes ( xlog_dict (line ) )
195
- if xdict .get ('time' ):
196
- xdict ['time' ] = datetime .to_sql (xdict ['time' ])
197
-
198
195
xline = Xlogline ( self , self .filename , self .offset ,
199
196
xdict .get ('end' ) or xdict .get ('time' ),
200
197
xdict , self .proc_op )
@@ -291,6 +288,28 @@ def xlog_set_killer_group(d):
291
288
292
289
d ['kgroup' ] = killer
293
290
291
+ def xlog_milestone_fixup (d ):
292
+ for field in [x for x in ['lv' , 'uid' ] if d .has_key (x )]:
293
+ del d [field ]
294
+ verb = d ['type' ]
295
+ milestone = d ['milestone' ]
296
+ noun = None
297
+ if verb == 'uniq' :
298
+ match = R_MILE_UNIQ .findall (milestone )
299
+ if match [0 ][0 ] == 'banished' :
300
+ verb = 'uniq.ban'
301
+ noun = match [0 ][1 ]
302
+ if verb == 'ghost' :
303
+ match = R_MILE_GHOST .findall (milestone )
304
+ if match [0 ][0 ] == 'banished' :
305
+ verb = 'ghost.ban'
306
+ noun = match [0 ][1 ]
307
+ if verb == 'rune' :
308
+ noun = R_RUNE .findall (milestone )[0 ]
309
+ noun = noun or milestone
310
+ d ['verb' ] = verb
311
+ d ['noun' ] = noun
312
+
294
313
def xlog_dict (logline ):
295
314
d = parse_logline (logline .strip ())
296
315
# Fake a raceabbr field.
@@ -305,6 +324,8 @@ def xlog_dict(logline):
305
324
d ['nrune' ] = d .get ('nrune' ) or d .get ('urune' )
306
325
d ['urune' ] = d .get ('urune' ) or d .get ('nrune' )
307
326
327
+ if d .has_key ('milestone' ):
328
+ xlog_milestone_fixup (d )
308
329
xlog_set_killer_group (d )
309
330
310
331
return d
@@ -332,7 +353,7 @@ def xlog_dict(logline):
332
353
[ 'mhp' , 'maxhp' ],
333
354
[ 'mmhp' , 'maxmaxhp' ],
334
355
[ 'str' , 'strength' ],
335
- [ 'int' , 'intellegence ' ],
356
+ [ 'int' , 'intelligence ' ],
336
357
[ 'dex' , 'dexterity' ],
337
358
[ 'god' , 'god' ],
338
359
[ 'start' , 'start_time' ],
@@ -350,13 +371,52 @@ def xlog_dict(logline):
350
371
[ 'vmsg' , 'verb_msg' ],
351
372
[ 'kaux' , 'kaux' ],
352
373
[ 'nrune' , 'nrune' ],
353
- [ 'urune' , 'runes' ] ]
374
+ [ 'urune' , 'runes' ],
375
+ ]
376
+
377
+ MILE_DB_MAPPINGS = [
378
+ [ 'v' , 'version' ],
379
+ [ 'lv' , 'lv' ],
380
+ [ 'name' , 'player' ],
381
+ [ 'uid' , 'uid' ],
382
+ [ 'race' , 'race' ],
383
+ [ 'raceabbr' , 'raceabbr' ],
384
+ [ 'cls' , 'class' ],
385
+ [ 'char' , 'charabbrev' ],
386
+ [ 'xl' , 'xl' ],
387
+ [ 'sk' , 'skill' ],
388
+ [ 'sklev' , 'sk_lev' ],
389
+ [ 'title' , 'title' ],
390
+ [ 'place' , 'place' ],
391
+ [ 'br' , 'branch' ],
392
+ [ 'lvl' , 'lvl' ],
393
+ [ 'ltyp' , 'ltyp' ],
394
+ [ 'hp' , 'hp' ],
395
+ [ 'mhp' , 'maxhp' ],
396
+ [ 'mmhp' , 'maxmaxhp' ],
397
+ [ 'str' , 'strength' ],
398
+ [ 'int' , 'intelligence' ],
399
+ [ 'dex' , 'dexterity' ],
400
+ [ 'god' , 'god' ],
401
+ [ 'start' , 'start_time' ],
402
+ [ 'dur' , 'duration' ],
403
+ [ 'turn' , 'turn' ],
404
+ [ 'dam' , 'damage' ],
405
+ [ 'piety' , 'piety' ],
406
+ [ 'nrune' , 'nrune' ],
407
+ [ 'urune' , 'runes' ],
408
+ [ 'time' , 'milestone_time' ],
409
+ ]
354
410
355
411
LOGLINE_TO_DBFIELD = dict (LOG_DB_MAPPINGS )
412
+ COMBINED_LOG_TO_DB = dict (LOG_DB_MAPPINGS + MILE_DB_MAPPINGS )
413
+
356
414
R_MONTH_FIX = re .compile (r'^(\d{4})(\d{2})(.*)' )
357
415
R_GHOST_NAME = re .compile (r"^(.*)'s? ghost" )
358
416
R_MILESTONE_GHOST_NAME = re .compile (r"the ghost of (.*) the " )
359
417
R_KILL_UNIQUE = re .compile (r'^killed (.*)\.$' )
418
+ R_MILE_UNIQ = re .compile (r'^\w+ (.*)\.$' )
419
+ R_MILE_GHOST = re .compile (r'^\w+ the ghost of (\S+)' )
360
420
R_RUNE = re .compile (r"found an? (.*) rune" )
361
421
R_HYDRA = re .compile (r'^an? (\w+)-headed hydra' )
362
422
@@ -458,6 +518,7 @@ def count(self, cursor, msg=None, exc=Exception):
458
518
'piety' :sql_int ,
459
519
'penitence' :sql_int ,
460
520
'end_time' :datetime ,
521
+ 'milestone_time' :datetime ,
461
522
'terse_msg' :varchar ,
462
523
'verb_msg' :varchar ,
463
524
'nrune' :sql_int ,
@@ -546,33 +607,40 @@ def apply_dbtypes(game):
546
607
(i.e. not in dbfield_to_sqltype) are ignored."""
547
608
new_hash = { }
548
609
for key , value in game .items ():
549
- if LOGLINE_TO_DBFIELD .has_key (key ):
550
- new_hash [key ] = dbfield_to_sqltype [LOGLINE_TO_DBFIELD [key ]].to_sql (value )
610
+ if (COMBINED_LOG_TO_DB .has_key (key ) and
611
+ dbfield_to_sqltype .has_key (COMBINED_LOG_TO_DB [key ])):
612
+ new_hash [key ] = dbfield_to_sqltype [COMBINED_LOG_TO_DB [key ]].to_sql (value )
551
613
else :
552
614
new_hash [key ] = value
553
615
return new_hash
554
616
555
- def make_games_insert_query (dbfields , filename , offset ):
556
- fields = ["source_file" , "source_file_offset" ]
557
- values = [filename , offset ]
558
-
559
- for logkey , sqlkey in LOG_DB_MAPPINGS :
560
- if dbfields .has_key (logkey ):
617
+ def make_xlog_db_query (db_mappings , xdict , filename , offset , table ):
618
+ fields = ['source_file' ]
619
+ values = [filename ]
620
+ if offset is not None and offset != False :
621
+ fields .append ('source_file_offset' )
622
+ values .append (offset )
623
+ for logkey , sqlkey in db_mappings :
624
+ if xdict .has_key (logkey ):
561
625
fields .append (sqlkey )
562
- values .append (dbfields [logkey ])
563
-
564
- return Query ('INSERT INTO games (%s) VALUES (%s);' %
565
- ("," .join (fields ), "," .join ([ "%s" for v in values ])),
626
+ values .append (xdict [logkey ])
627
+ return Query ('INSERT INTO %s (%s) VALUES (%s);' %
628
+ (table , "," .join (fields ), "," .join ([ "%s" for v in values ])),
566
629
* values )
567
630
568
- def insert_logline (cursor , logdict , filename , offset ):
569
- query = make_games_insert_query (logdict , filename , offset )
631
+ def insert_xlog_db (cursor , xdict , filename , offset ):
632
+ milestone = xdict .has_key ('milestone' )
633
+ db_mappings = milestone and MILE_DB_MAPPINGS or LOG_DB_MAPPINGS
634
+ thingname = milestone and 'milestone' or 'logline'
635
+ table = milestone and 'milestones' or 'games'
636
+ save_offset = not milestone
637
+ query = make_xlog_db_query (db_mappings , xdict , filename ,
638
+ save_offset and offset , table )
570
639
try :
571
640
query .execute (cursor )
572
641
except Exception , e :
573
- error ("Error inserting logline %s (query: %s [%s]): %s"
574
- % (logdict , query .query , query .values , e ))
575
- raise
642
+ error ("Error inserting %s %s (query: %s [%s]): %s"
643
+ % (thingname , milestone , query .query , query .values , e ))
576
644
577
645
def dbfile_offset (cursor , table , filename ):
578
646
"""Given a db cursor and filename, returns the offset of the last
@@ -651,7 +719,7 @@ def process_log(cursor, filename, offset, d):
651
719
652
720
cursor .execute ('BEGIN;' )
653
721
try :
654
- insert_logline (cursor , d , filename , offset )
722
+ insert_xlog_db (cursor , d , filename , offset )
655
723
if ghost_kill :
656
724
record_ghost_kill (cursor , d )
657
725
@@ -752,6 +820,7 @@ def add_milestone_record(c, filename, offset, d):
752
820
c .execute ('BEGIN;' )
753
821
try :
754
822
update_milestone_bookmark (c , filename , offset )
823
+ insert_xlog_db (c , d , filename , offset )
755
824
handler = MILESTONE_HANDLERS .get (d ['type' ])
756
825
if handler :
757
826
handler (c , d )
0 commit comments