def extract(al,progress=True):
    seq=[]#
    for a in al:
        rd=parse(a['path'])
        if progress:
            print 'load '+a['path']+' succ'
        main_keys=['type','religion']
        wait_keys=['size','money']
        weight_keys=['literacy']
        #dd=defaultdict(lambda:{'size':0.0,'money':0.0})
        sum_dict={mk:{} for mk in main_keys}
        #sum_dict['sum']={wk:0.0 for wk in wait_keys}#sum是直接和,不分类
        record={'pop_number':len(rd['pop'].values()),'sum':sum_dict,'main_number':copy.deepcopy(sum_dict)}
        for pop in rd['pop'].values():
            for mk in main_keys:
                tk=pop[mk]
                if not(record['sum'][mk].has_key(tk)):
                    record['sum'][mk][tk]={k:0.0 for k in wait_keys+weight_keys}
                for wk in wait_keys:
                    record['sum'][mk][tk][wk]+=float(pop[wk])
                for wk in weight_keys:
                    record['sum'][mk][tk][wk]+=float(pop[wk])*float(pop['size'])
                    #record['sum'][mk][wk]+=float(pop[wk])
                record['main_number'][mk][tk]=record['main_number'][mk].get(tk,0)+1
        sur_l=record['sum']['type'].values()
        record['sum']['sum']={sk:sum([sd[sk] for sd in sur_l]) for sk in sur_l[0].keys()}
        record['date']=a['date']
        seq.append(record)
        if progress:
            print 'deal '+a['path']+' succ'
    return seq
def to_sql_all(al,cache_path='cache'):
    #接收路径词典列表,使用日期给cache编号
    for a in al:
        date,path=a['date'],a['path']
        year,month,day=date
        rd=parse(path)
        save_path=cache_path+'/'+year+'.db'
        to_sql(rd,connect_path=save_path)
        print 'clear',date
    print 'end'
def test(al):
    global money_seq,size_seq
    money_seq=[]
    size_seq=[]
    for a in al:
        rd=parse(a['path'])
        print 'load '+a['path']+' succ'
        money_t=0.0
        size_t=0.0
        for pop in rd['pop'].values():
            money_t+=float(pop['money'])
            size_t+=float(pop['size'])
        money_seq.append(money_t)
        size_seq.append(size_t)
예제 #4
0
def sample():
    return select2.get_building_price(select2.parse(path))
def sample(path="../SPA1901_09_28.v2"):
    return parse(path)
def test2():
    rd=parse('SPA1901_09_28.v2')
    to_sql(rd,connect_path='bignews.db')
    country_l=RD_list('bignews.db','country')
    country_d=RD_dict(country_l)
    country_d['ENG']