コード例 #1
0
ファイル: mid.py プロジェクト: lolaverkade/irdata
def load_midb(src):
    session = model.SESSION()
    reader = csv2.DictReader(src, encoding='latin1')
    reader.fieldnames = [utils.camel2under(x) for x in reader.fieldnames]
    cols = [c.name for c in model.MidB.__table__.columns]
    int_cols = [
        c.name for c in model.MidB.__table__.columns
        if isinstance(c.type, sa.types.Integer)
    ]
    cnt = collections.Counter()
    for row in reader:
        cnt[(row['disp_num'], row['ccode'])] += 1
        row['spell_num'] = cnt[(row['disp_num'], row['ccode'])]
        start_date = utils.daterng(*(_int(row[k])
                                     for k in ('st_year', 'st_mon', 'st_day')))
        row['st_date_min'], row['st_date_min'] = start_date
        end_date = utils.daterng(*(_int(row[k])
                                   for k in ('end_year', 'end_mon',
                                             'end_day')))
        row['end_date_min'], row['end_date_min'] = end_date
        ## set -9 to NULL
        for k in int_cols:
            row[k] = _int(row[k])
        session.add(model.MidB(**utils.subset(row, cols)))
    session.commit()
コード例 #2
0
 def _dates(row, n):
     if row['yr_beg%d' % n]:
         y = model.War3ParticDate()
         y.war_partic = row['war_partic']
         y.spell_no = n
         date_beg = utils.daterng(_int(row['yr_beg%d' % n]),
                                  _int(row['mon_beg%d' % n]),
                                  _int(row['day_beg%d' % n]))
         y.date_beg_min, y.date_beg_max = date_beg
         date_end = utils.daterng(_int(row['yr_end%d' % n]),
                                  _int(row['mon_end%d' % n]),
                                  _int(row['day_end%d' % n]))
         y.date_end_min, y.date_end_max = date_end
         session.add(y)
コード例 #3
0
ファイル: war3.py プロジェクト: jrnold/irdata
 def _dates(row, n):
     if row['yr_beg%d' % n]:
         y = model.War3ParticDate()
         y.war_partic = row['war_partic']
         y.spell_no = n
         date_beg = utils.daterng(_int(row['yr_beg%d' % n]),
                                  _int(row['mon_beg%d' % n]),
                                  _int(row['day_beg%d' % n]))
         y.date_beg_min, y.date_beg_max = date_beg
         date_end = utils.daterng(_int(row['yr_end%d' % n]),
                                  _int(row['mon_end%d' % n]),
                                  _int(row['day_end%d' % n]))
         y.date_end_min, y.date_end_max = date_end
         session.add(y)
コード例 #4
0
ファイル: mid.py プロジェクト: jrnold/irdata
def load_midi(src):
    session = model.SESSION()
    reader = csv2.DictReader(src, encoding='latin1')
    reader.fieldnames = [utils.camel2under(x) for x in reader.fieldnames]
    cols = [c.name for c in model.MidI.__table__.columns]
    int_cols = [c.name for c in model.MidI.__table__.columns
                if isinstance(c.type, sa.types.Integer)]
    for row in reader:
        start_date = utils.daterng(*(_int(row[k]) for k in
                                     ('st_year', 'st_mon', 'st_day')))
        row['st_date_min'], row['st_date_min'] = start_date
        end_date = utils.daterng(*(_int(row[k]) for k in
                                   ('end_year', 'end_mon', 'end_day')))
        row['end_date_min'], row['end_date_min'] = end_date
        ## set -9 to NULL
        for k in int_cols:
            row[k] = _int(row[k])
        session.add(model.MidI(**utils.subset(row, cols)))
    session.commit()
コード例 #5
0
ファイル: war4.py プロジェクト: lolaverkade/irdata
 def add_partic_dates(row, name, side):
     y = model.War4ParticDate()
     war_side = war_side_pkey(_int(row['war_num']), (side == "b") + 1)
     belligerent = belligerent_key(None, name)
     y.war_partic = war_partic_pkey(war_side, belligerent)
     y.partic_num = 1
     start_date = utils.daterng(_int(row['start_year']),
                                _int(row['start_month']),
                                _int(row['start_day']))
     y.start_date_min, y.start_date_max = start_date
     if row['end_year'] == "-7":
         y.end_date_min = y.end_date_max = model.War4.ONGOING_DATE
         y.ongoing = True
     else:
         end_date = utils.daterng(_int(row['end_year']),
                                  _int(row['end_month']),
                                  _int(row['end_day']))
         y.end_date_min, y.end_date_max = end_date
         y.ongoing = False
     session.add(y)
コード例 #6
0
ファイル: war4.py プロジェクト: jrnold/irdata
 def add_partic_dates(row, name, side):
     y = model.War4ParticDate()
     war_side = war_side_pkey(_int(row['war_num']),
                              (side == "b") + 1)
     belligerent = belligerent_key(None, name)
     y.war_partic = war_partic_pkey(war_side, belligerent)
     y.partic_num = 1
     start_date = utils.daterng(_int(row['start_year']),
                                _int(row['start_month']),
                                _int(row['start_day']))
     y.start_date_min, y.start_date_max = start_date
     if row['end_year'] == "-7":
         y.end_date_min = y.end_date_max = model.War4.ONGOING_DATE
         y.ongoing = True
     else:
         end_date = utils.daterng(_int(row['end_year']),
                                  _int(row['end_month']),
                                  _int(row['end_day']))
         y.end_date_min, y.end_date_max = end_date
         y.ongoing = False
     session.add(y)
コード例 #7
0
ファイル: war4.py プロジェクト: lolaverkade/irdata
 def add_partic_dates(row, n):
     if row['start_year%d' % n] != '-8':
         y = model.War4ParticDate()
         war_side = war_side_pkey(int(row['war_num']), int(row['side']))
         belligerent = belligerent_key(row['ccode'], row['state_name'])
         y.war_partic = war_partic_pkey(war_side, belligerent)
         y.partic_num = n
         start_date = utils.daterng(_int(row['start_year%d' % n]),
                                    _int(row['start_month%d' % n]),
                                    _int(row['start_day%d' % n]))
         y.start_date_min, y.start_date_max = start_date
         if row['end_year%d' % n] == "-7":
             y.end_date_min = y.end_date_max = model.War4.ONGOING_DATE
             y.ongoing = True
         else:
             end_date = utils.daterng(_int(row['end_year%d' % n]),
                                      _int(row['end_month%d' % n]),
                                      _int(row['end_day%d' % n]))
             y.end_date_min, y.end_date_max = end_date
             y.ongoing = False
         session.add(y)
コード例 #8
0
ファイル: war4.py プロジェクト: jrnold/irdata
 def add_partic_dates(row, n):
     if row['start_year%d' % n] != '-8':
         y = model.War4ParticDate()
         war_side = war_side_pkey(int(row['war_num']),
                                  int(row['side']))
         belligerent = belligerent_key(row['ccode'], row['state_name'])
         y.war_partic = war_partic_pkey(war_side, belligerent)
         y.partic_num = n
         start_date = utils.daterng(_int(row['start_year%d' % n]),
                                    _int(row['start_month%d' % n]),
                                    _int(row['start_day%d' % n]))
         y.start_date_min, y.start_date_max = start_date
         if row['end_year%d' % n] == "-7":
             y.end_date_min = y.end_date_max = model.War4.ONGOING_DATE
             y.ongoing = True
         else:
             end_date = utils.daterng(_int(row['end_year%d' % n]),
                                      _int(row['end_month%d' % n]),
                                      _int(row['end_day%d' % n]))
             y.end_date_min, y.end_date_max = end_date
             y.ongoing = False
         session.add(y)