Exemple #1
0
def translate(items, p, lines):
    keys = {
        'confirmedCount': 'numb_confirmed',
        'suspectedCount': 'numb_suspected',
        'curedCount': 'numb_ok',
        'deadCount': 'numb_die',
        'comment': 'comment'
    }

    for item in items:
        line = dict((keys[k], item[k]) for k in item if k in keys)
        line['data_date'] = TS2S(item['updateTime'] / 1000.0)
        line['region_code'], line['region_name'] = p['code'], p['name']
        line['sum_type'], line['region_level'], line[
            'region_parent'] = 1, 1, 86
        lines.append(line)

        if item.get('cities', None):
            for ct in item['cities']:
                cline = dict((keys[k], ct.get(k, "")) for k in ct if k in keys)
                cline['sum_type'], cline['region_level'] = 1, 2
                cline['region_name'], cline['region_parent'] = ct[
                    'cityName'], p['code']
                cline['data_date'] = line['data_date']
                cline['region_code'] = ct.get('locationId', 0)
                '''行政编码和级别判断'''
                if cline['region_code'] not in REGIONS[p['code']]['children']:
                    cline['region_code'] = check_city(ct['cityName'],
                                                      p['code'])
                    if not cline['region_code']: cline['region_level'] = 3

                lines.append(cline)
        '''End If'''
    '''End For'''
Exemple #2
0
def add_city_code():
    db = Database()
    sql = "select id, region_name, region_parent FROM patients WHERE region_level=2 and region_code=0"
    comands = []
    for (id_, name, parent) in db.select(sql):
        code = check_city(name, parent)
        if not code:
            print(parent, name, code)
            continue
        sql = "update patients set region_code=%s where id=%s"
        comands.append([sql, (code, id_)])
    db.Transaction(comands)
 def find_name(name):
     if name in Position.Cache: return Position.Cache[name]
     for p in REGIONS:
         code = check_city(name, p)
         '''
                                     以下语句速度更快些,但对于特殊别名无法识别
             if name in REGIONS[p]['name_code']: 
                 code = REGIONS[p]['name_code'][name]
         '''
         if code:
             Position.Cache[name] = info = Info(name, code,
                                                REGIONS[p]['name'], p)
             return info
     '''End For'''
     Position.Cache[name] = None
     return None
 def recognise_name(self, parent):
     if parent.get('province', '') in PROVINCE:
         p_name = parent['province']
         p_code = PROVINCE[p_name]
         '''省市级同名'''
         if parent['name'] == p_name:
             return Info(p_name, p_code, p_name, p_code)
         code = check_city(parent['name'], p_code)
         return Info(parent['name'], code, p_name, p_code)
     else:
         '''无province字段情况'''
         if parent['name'] in PROVINCE:
             p_name = parent['name']
             p_code = PROVINCE[p_name]
             return Info(parent['name'], p_code, p_name, p_code)
         info = Position.find_name(parent['name'])
         return info
Exemple #5
0
def detection_data_citys():
    db = Database()
    unknowns = {}    
    sql = '''SELECT region_parent, region_name FROM patients WHERE region_level=2 
        group by region_parent, region_name'''
    for (parent, name) in db.select(sql):
        if parent not in REGIONS:
            L.error("Not in Region Source: {}".format(parent))
            continue
        if check_city(name, parent): continue
        
        if parent not in unknowns: unknowns[parent] = set()
        unknowns[parent].add(name)

    for p in unknowns:
        print('----------------------')
        print([v['name'] for v in REGIONS[p]['children'].values()])
        print(list(unknowns[p]))