def generateReligions(self, locality): Catholic = rel.Catholicism() Protestant = rel.Protestantism() localCatholic = bu.Business([], "Catholic", locality, 10000000) localProtestant = bu.Business([], "Protestant", locality, 100000000) Catholic.addBusiness(localCatholic) Protestant.addBusiness(localProtestant) religionList = [Catholic, Protestant] return religionList
def importBusinesses(businessDict): businessDataset = open( "/globalscratch/plingras/matt/original/yelp_academic_dataset_business.json", "r") for line in businessDataset: currBusiness = business.Business(line) businessDict[currBusiness.data["business_id"]] = currBusiness return businessDict
def test_kmeansBase(self): data = [ business.Business(10, [0, 0, 0]), business.Business(20, [1, 1, 1]), business.Business(30, [2, 2, 2]), business.Business(411, [10, 10, 10]), business.Business(511, [11, 11, 11]), business.Business(611, [12, 12, 12]), business.Business(7123, [110, 110, 110]), business.Business(8123, [111, 111, 111]), business.Business(9123, [112, 112, 112]) ] expected = [ [0, 1, 2], [3, 4, 5], [6, 7, 8] ] manhattan = lambda a, b: distance.manhattan([a], [b]) kMeans = clustering.KMeans(3, featureDistanceMap.FeatureDistanceMap([manhattan, manhattan, manhattan])) self.assertEqual(sorted(kMeans.cluster(data)), sorted(expected))
def newBusiness(self, boss, busiName=None, capital=1000000): newBus = None if busiName is None: busiName = boss.lastname + " " + random.choice(d.busiNameList) if boss.capital >= capital: boss.capital -= capital newBus = bu.Business([boss], busiName, boss.locality, capital) boss.businesses.append(newBus) startupHQ = boss.getHome() OwnerJob = jobs.Owner(newBus, startupHQ) self.model.hirer.jobApplication(boss, OwnerJob) if boss != self.model.char: i_build = self.model.startupAI.whatToBuild(boss) self.model.builder.buildChain(boss.businesses[0], i_build) return newBus
def extractFeatures(rawBusiness, attributeMap, categoryMap, topWordMap, keyWordMap, openHoursMap): featureVector = [] numericColumns = [ COLUMN_STARS, COLUMN_TOTAL_REVIEW_COUNT, COLUMN_AVAILABLE_REVIEW_COUNT, COLUMN_MEAN_REVIEW_LEN, COLUMN_MEAN_WORD_LEN, COLUMN_NUM_WORDS, COLUMN_MEAN_WORD_COUNT, COLUMN_TOTAL_HOURS ] for column in numericColumns: featureVector.append(rawBusiness[column]) attributes = [attributeMap[ele] for ele in splitWithEmpty(rawBusiness[COLUMN_ATTRIBUTES])] featureVector.append(attributes) categories = [categoryMap[ele] for ele in splitWithEmpty(rawBusiness[COLUMN_CATEGORIES])] featureVector.append(categories) topWords = [topWordMap[ele] for ele in splitWithEmpty(rawBusiness[COLUMN_TOP_WORDS])] featureVector.append(topWords) keyWords = [keyWordMap[ele] for ele in splitWithEmpty(rawBusiness[COLUMN_KEY_WORDS])] featureVector.append(keyWords) openHours = [openHoursMap[ele] for ele in splitWithEmpty(rawBusiness[COLUMN_OPEN_HOURS])] featureVector.append(openHours) otherInfo = { "yelpId": rawBusiness[COLUMN_YELP_ID], "name": rawBusiness[COLUMN_NAME] } return business.Business(rawBusiness[COLUMN_ID], featureVector, otherInfo)
import sys #main #world generator worldGen = gen.generator() BraveNewWorld = worldGen.generateWorld(30, 3, 3) BraveNewWorld.printMap() Jonestown = d.getLocality()[0] #people, unit, business test JohnDoe = d.peopleList[0] JaneDoe = d.peopleList[1] SusanSmith = d.peopleList[2] MillersMill = b.Business("Miller's Mill", 30) TheMill = u.Mill("The old mill", Jonestown, (1, 1), MillersMill) MillersWarehouse = u.Warehouse("Miller's Warehouse", Jonestown, (7, 3), MillersMill) Bakery = u.Market("Ye Olde Bakery", Jonestown, (7, 1), MillersMill) Deli = u.Market("Ye Delicious Deli", Jonestown, (1, 3), MillersMill) MillingJob = j.Miller(10, MillersMill, TheMill) Transporter = j.Carrier(1, MillersMill, MillersWarehouse) ManagerJob = j.Manager(1, MillersMill, MillersWarehouse) BraveNewWorld.printMap() Jonestown.printMap() #jobs test
#world generator worldGen = gen.generator() BraveNewWorld = worldGen.generateWorld(30000, 10, 10) Jonestown = d.getLocality()[0] Jonestown.week.machine.set_state('Friday') #people, unit, business test JohnDoe = d.peopleList[0] JaneDoe = d.peopleList[1] JimSmith = d.peopleList[2] SusanSmith = d.peopleList[3] JoeJohnson = d.peopleList[4] SallyJohnson = d.peopleList[5] MillersMill = b.Business("Miller's Mill", Jonestown, 1000000) TheMill = u.Mill("The old mill", Jonestown, (1,1), MillersMill) MillersWarehouse = u.Warehouse("Miller's Warehouse", Jonestown, (7,3), MillersMill) Bakery = u.Bakery("Ye Olde Bakery", Jonestown, (7,1), MillersMill) WheatFarm = u.Farm("Johnson's Wheat Farm", Jonestown, (5,1), MillersMill) BraveNewWorld.printMap() Jonestown.printMap() #jobs test MillingJob = j.Miller(9000, MillersMill, TheMill, 400) Transporter = j.Carrier(1, MillersMill, MillersWarehouse, 400) ManagerJob = j.Manager(MillersMill, Bakery, 400) BakerJob = j.Baker(9000, MillersMill, Bakery, 400) FarmerJob = j.Farmer(9000,MillersMill, WheatFarm, 400)
import business my_store = business.Business("Vinyl Store") my_store.build_customers("customers.txt") my_store.build_inventory("albums.txt") my_store.process_commands("commands.txt")
big = max(i, j) self._distances[self._calcIndex(small, big)] = val def get(self, i, j): if (i == j): return 0 small = min(i, j) big = max(i, j) return self._distances[self._calcIndex(small, big)] if __name__ == '__main__': data = [ business.Business(1, [0, 0, 0]), business.Business(2, [1, 1, 1]), business.Business(3, [2, 2, 2]), business.Business(4, [10, 10, 10]), business.Business(5, [11, 11, 11]), business.Business(6, [12, 12, 12]), business.Business(7, [110, 110, 110]), business.Business(8, [111, 111, 111]), business.Business(9, [112, 112, 112]) ] manhattan = lambda a, b: distance.manhattan([a], [b]) kMeans = KMeans(3, featureDistanceMap.FeatureDistanceMap([manhattan, manhattan, manhattan])) clusters = kMeans.cluster(data)