def test_modules_are_singletons(): import alpha import beta import data assert 2 == len(data.get_items()) assert 'alpha' in data.get_items() assert 'beta' in data.get_items()
def preprocess_for_display(dat): from data import get_items print("Preprocessing data for display") items = get_items() items_index = {i['id']: i for i in items} for item_id, value in dat.iteritems(): items_index[item_id]['winrate'] = value bad_items = [] for item_id, it in items_index.items(): if 'recipe' in it['name']: bad_items.append(item_id) if 'river' in it['name']: bad_items.append(item_id) for item_id in bad_items: del items_index[item_id] df = pd.DataFrame(items_index) df = df.transpose() df['cost'] = df['cost'].apply(pd.to_numeric) print(df) return df
def build_data(): from data import get_matches, get_items slots = [ 'item_0', 'item_1', 'item_2', 'item_3', 'item_4', 'item_5', 'backpack_0', 'backpack_1', 'backpack_2' ] items = get_items() matches = get_matches() item_ids = [i['id'] for i in items] win = pd.Series(0, index=item_ids) loss = pd.Series(0, index=item_ids) for match in tqdm(matches, desc="Processing Matches"): for i, pl in enumerate(match['players']): hero_is_radiant = i < 5 for slot in slots: item = pl[slot] if item != 0: if match['radiant_win'] != hero_is_radiant: # logical xor loss[item] += 1 else: win[item] += 1 return win, loss
def generate_images(): data = dataset() shops = get_shops(data) items = get_items(data) applied_image_item = map(lambda x: partial(image_item, x), shops) mapnp(lambda f: pmap(f, items), applied_image_item)
def preprocess_for_display(df): print("Preprocessing data for display") items = get_items() heroes = get_heroes() # sort items by cost sorted_items = [i['id'] for i in sorted(items, key=lambda i: i['cost'])] df = df.reindex(sorted_items) def process_hero(name): return name.replace('npc_dota_hero', '').replace('_', ' ') def process_item(name): return name.replace('item_', '').replace('_', ' ') # Fill in column names heromap = {h['id']: process_hero(h['name']) for h in heroes} itemmap = {i['id']: process_item(i['name']) for i in items} df = df.rename(columns=heromap, index=itemmap) # delete things we dont want to show bad_items = [] for r in itemmap.values(): if 'recipe' in r: bad_items.append(r) if 'river' in r: bad_items.append(r) df = df.drop(bad_items) df = df.transpose() # Looks nicer this way return df
def build_data(): slots = [ 'item_0', 'item_1', 'item_2', 'item_3', 'item_4', 'item_5', 'backpack_0', 'backpack_1', 'backpack_2' ] items = get_items() heroes = get_heroes() matches = get_matches() item_ids = [i['id'] for i in items] hero_ids = [h['id'] for h in heroes] buy = pd.DataFrame(0, index=item_ids, columns=hero_ids) win = pd.DataFrame(0, index=item_ids, columns=hero_ids) loss = pd.DataFrame(0, index=item_ids, columns=hero_ids) i_ser = pd.Series(0, index=item_ids) h_ser = pd.Series(0, index=hero_ids) for match in tqdm(matches, desc="Processing Matches"): for i, pl in enumerate(match['players']): hero = pl['hero_id'] hero_is_radiant = i < 5 h_ser[hero] += 1 for slot in slots: item = pl[slot] if item != 0: # old_val = buy.get_value(item, hero) # new_val = old_val + 1 # buy.set_value(item, hero, new_val) buy.ix[item, hero] += 1 i_ser[item] += 1 if match['radiant_win'] != hero_is_radiant: # logical xor loss.ix[item, hero] += 1 else: win.ix[item, hero] += 1 # Next we process the data into percentages instead of raw values print("Calculating percentages") buy_i = buy.divide(i_ser, axis='index') buy_h = buy.divide(h_ser, axis='columns') buy = buy_i.multiply(buy_h) return buy, win, loss
def apriori(data, min_sup=None): items = get_items(data) res = {} if min_sup is None: min_sup = 1 / len(items) print('Apriori with min support {:.3f}'.format(min_sup)) k = 1 print('Analyze L{} item set'.format(k), end='... ', file=stderr) cursets = get_L1(data, items, min_sup) l1_num = len(cursets) print('finished with {} item sets'.format(len(cursets)), file=stderr) while len(cursets) != 0: res.update(cursets) k += 1 print('Analyze L{} item set'.format(k), end='... ', file=stderr) cursets = get_Lk(data, items, cursets, min_sup) print('finished with {} item sets'.format(len(cursets)), file=stderr) print('Find {} frequent sets'.format(len(res) - l1_num)) res = {k: v['count'] for k, v in res.items()} return res
def report_items(): """库存信息报表""" for (k, v) in data.get_items(): sku_name = data.get_products()[k] loc_name = data.get_locations()[v] print('{0:8} {1}: {2:8} {3}'.format(k, sku_name, v, loc_name))
import os,sys from Tkinter import * import tkMessageBox import ttk import datetime import data FILEPATH=os.path.join(os.path.split(sys.argv[0])[0],'data') PRODUCTNAME=os.path.join(FILEPATH,'productname.txt') GET_PRODUCTNAME=data.get_items(PRODUCTNAME) class ProductManagement(object): def __init__(self,master,info='Product Management'): self.ma=master Label(self.ma,text="Product Name:").grid(row=0,column=0,sticky=W) self.productlist=[i for i in GET_PRODUCTNAME] self.product=ttk.Combobox(self.ma) self.product['values']=tuple(self.productlist) self.product['width']=25 self.product.grid(row=0,column=1,sticky=W) self.add=Button(self.ma,text='ADD',command=self.product_add) self.add.grid(row=1,column=0,sticky=W) self.delete=Button(self.ma,text="DELETE",command=self.product_del) self.delete.grid(row=1,column=1,sticky=W) def product_add(self): p=self.product.get()
#coding:utf-8 import os,sys import data FILEPATH=os.path.join(os.path.split(sys.argv[0])[0],'data') TSHIRT=['issue_status','issue_from','issue_to','issue_date','issue_type','issue_size','issue_qty','issue_color','issue_sex','issue_sleeve','issue_pocket','remarks','create_by','create_date'] COLOR=os.path.join(FILEPATH,'color.txt') SIZE=os.path.join(FILEPATH,'size.txt') GET_ITEMS=data.get_data('tshirt',TSHIRT) GET_COLOR=data.get_items(COLOR) GET_SIZE=data.get_items(SIZE)
def import_items(): global items items = [] items_data = data.get_items() for i in items_data: items.append(Item(i))
import os,sys from Tkinter import * import tkMessageBox import ttk import datetime import data FILEPATH=os.path.join(os.path.split(sys.argv[0])[0],'data') STATUSNAME=os.path.join(FILEPATH,'status.txt') GET_STATUSNAME=data.get_items(STATUSNAME) class ProductManagement(object): def __init__(self,master,info='Status Management'): self.ma=master Label(self.ma,text="Status Name:").grid(row=0,column=0,sticky=W) self.productlist=[i for i in GET_STATUSNAME] self.product=ttk.Combobox(self.ma) self.product['values']=tuple(self.productlist) self.product['width']=25 self.product.grid(row=0,column=1,sticky=W) self.add=Button(self.ma,text='ADD',command=self.product_add) self.add.grid(row=1,column=0,sticky=W) self.delete=Button(self.ma,text="DELETE",command=self.product_del) self.delete.grid(row=1,column=1,sticky=W) def product_add(self): p=self.product.get()
#-*-coding=utf-8-*- import os,sys from Tkinter import * import tkMessageBox import ttk import datetime import data FILEPATH=os.path.join(os.path.split(sys.argv[0])[0],'data') STATUS=os.path.join(FILEPATH,'status.txt') PRODUCTNAME=os.path.join(FILEPATH,'productname.txt') GET_ITEMS=data.get_data() GET_STATUS=data.get_items(STATUS) GET_PRODUCTNAME=data.get_items(PRODUCTNAME) GET_NAMES=data.get_name_list() localkinds=['OFFICE','STORE'] class ReportCenter(object): def __init__(self,master,info='Report Management'): self.ma=master self.topline=Frame(self.ma) #========name list========= frame1=Frame(self.topline,bd=1) Label(frame1,text='Employee Name').grid(row=0,column=0,sticky=W) self.getnamelist=[i[1]+' '+i[0] for i in GET_NAMES] self.namelist=ttk.Combobox(frame1) self.namelist['values']=tuple(self.getnamelist) self.namelist['width']=25
#coding:utf-8 import os,sys import data FILEPATH=os.path.join(os.path.split(sys.argv[0])[0],'data') DATAFILE=os.path.join(FILEPATH,'system.db') STATUS=os.path.join(FILEPATH,'status.txt') TYPE=os.path.join(FILEPATH,'type.txt') USER=os.path.join(FILEPATH,'user.txt') GET_STATUS=data.get_items(STATUS) GET_TYPE=data.get_items(TYPE) GET_USER=data.get_items(USER) GET_NAMES=data.get_name_list()