<jupyter_start><jupyter_text>Building Synthetic Agents!!! March 7 20201<jupyter_code>#BuildingInSimulationAndStats
import geopandas as gpd
import pandas as pd
import numpy as np
import pyproj

pyproj.datadir.set_data_dir('/Users/shai/anaconda3/envs/geo_env/share/proj')



BldInfo = pd.read_excel('BuildingInSimulationAndStats.xlsx')
BldInfo = BldInfo.iloc[:,1:]
pd.options.display.max_rows=150
pd.options.display.max_columns=150
#Low_discount,High_discount
BldInfo['Owner_Percent'].mean()
BldInfo
BldInfo['Before_app'].sum()
currentBLdg
currentBLdg['discount_percent'].mean()
def minMaxColumnsCreator(tuple_,DS):
    DS[tuple_[0]] = 1
    option = tuple_[-1]
    if (option == 'between'):
        min_ = currentBLdg[tuple_[1]].astype(int)
        max_ = currentBLdg[tuple_[2]].astype(int)
        DS[tuple_[0]] = DS[tuple_[0]].apply(lambda x: np.random.randint(min_,max_))
    else: #insert
        DS[tuple_[0]] = currentBLdg['Area_round_mode'].astype(int)
        
    return DS[tuple_[0]]
def percentColumnImplementation(tuple_,DS):
    DS[tuple_[0]] = 1
    option = tuple_[-1]
    posNumber = (currentBLdg[tuple_[1]]*currentBLdg['Before_app']).astype(int)
    posList  = DS['apIndex'].sample(n=posNumber).tolist()
    negList = DS[~DS['apIndex'].isin(posList)]['apIndex'].tolist()
    DS.loc[DS['apIndex'].isin(posList),tuple_[0]]=1
    DS.loc[DS['apIndex'].isin(negList),tuple_[0]]=0
    if (option=='discount'): #discount
        new100 = currentBLdg['Low_discount']+currentBLdg['High_discount']
        if new100>0:
            highP = currentBLdg['High_discount']/new100
            discountAppsCon = DS['apIndex'].isin(posList)
            highDiscountList = DS[discountAppsCon]['apIndex'].sample(frac=highP).tolist()
            lowDiscountList = DS[discountAppsCon][~DS[discountAppsCon]['apIndex'].isin(highDiscountList)]['apIndex'].tolist()
            DS.loc[DS['apIndex'].isin(highDiscountList),'DiscountType']='High'
            DS.loc[DS['apIndex'].isin(lowDiscountList),'DiscountType']='Low'
            DS.loc[DS['apIndex'].isin(negList),'DiscountType'] = 'Non'
    return DS
def syntehticAgentsFromBuilding(bld,numAp,currentBLdg):
    DS = pd.DataFrame({'Building ID':[bld]*numAp,'apIndex':range(1,numAp+1)})
    listData =[('YearsInBldg','min_living_till_2020','max_living_till_2020','between'),('avrgAge','Min_age_2020','Max_age_2020','between'),('AptArea','Area_round_mode','insert')]
    for tuple_ in listData:
        DS[tuple_[0]] = minMaxColumnsCreator(tuple_,DS.copy())
        
    listData2 = [('Owner','Owner_Percent','simple'),('Discount','discount_percent','DiscountType','Low_discount','High_discount','discount')]
    for tuple_ in listData2:
        DS = percentColumnImplementation(tuple_,DS.copy())

    return DS
    
for i in BldInfo.index:
    currentBLdg = BldInfo.loc[i]
    bldProj = currentBLdg['ProjNumber']
    numAp = currentBLdg['Before_app'].astype(int)
    listOfBuildings = currentBLdg['BeforeBldgs'].split(',')
    lenBuildings = len(listOfBuildings)
    numAp = currentBLdg['Before_app'].astype(int)
    totalAp = lenBuildings*numAp
    if i==0: #first run
        for bld in listOfBuildings:
            if bld == listOfBuildings[0]:
                     
                apDs = syntehticAgentsFromBuilding(bld,numAp,currentBLdg)
            else: 
                apDs = pd.concat([apDs,syntehticAgentsFromBuilding(bld,numAp,currentBLdg)])
    else:
        for bld in listOfBuildings:
            if bld == listOfBuildings[0]:
                currentBldg = syntehticAgentsFromBuilding(bld,numAp,currentBLdg)
            else:
                currentBldg = pd.concat([currentBldg,syntehticAgentsFromBuilding(bld,numAp,currentBLdg)])
        apDs = pd.concat([apDs,currentBldg]).reset_index(drop=True)
apDs['BldDoor'] =apDs['Building ID']+"-"+apDs['apIndex'].astype(str)
    
apDs.head(25)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.15376676986584106, 'fraction_numerical': 0.017285861713106296, 'mean_word_length': 4.332874828060523, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '288279', 'license': 'MIT', 'n_tokens_mistral': 1453, 'n_tokens_neox': 1355, 'n_words': 167, 'path': 'Data collection and engineering/BuildingSyntheticAgents.ipynb', 'repo_name': 'Shai2u/batyam_may2021', 'size': '3876'}