Advertisement
Guest User

FamilyTreeDW

a guest
Sep 23rd, 2011
294
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. FamilyTreeMember.cfc
  2. <!----------------------
  3. Description: FamilyTreeMember
  4. Author: Dan Wilson (dan@nodans.com)
  5. Date: 9/23/2011
  6. CHANGE LOG:
  7. ------------------------>
  8. <cfcomponent output="false">
  9.     <cfset variables.config.AttractiveScoreLow = 40 />
  10.     <cfset variables.config.AttractiveScoreHigh = 80 />
  11.     <cfset variables.config.EarliestRecords = createdate(1876, 4, 25) />
  12.     <cfset variables.config.FertilityLow = 30 />
  13.     <cfset variables.config.FertilityHigh = 70 />
  14.     <cfset variables.config.FirstNameArrayMale = ["Adan","Adolfo","Alejandro","Alfonso","Alfredo","Alonso","Alonzo","Alvaro","Andres","Armando","Belen","Bernar","Carlos","Carmelo","Cesar","Cortez","Cruz","Dario","Diego","Emilio","Enrique","Ernesto","Esteban","Estevan","Felipe","Fernando","Francisco","Gerardo","Gilberto","Gonzalo","Guillermo","Gustavo","Itzel"] />
  15.     <cfset variables.config.FirstNameArrayFemale = ["Alejandra","Alondra","Ana","Belinda","Brisa","Catalina","Elisa","Esmeralda","Esperanza","Estefani","Eduardo","Izabella","Jada","Jade","Isabel","Jaquinda","Jardena","Javiera","Jayda","Jayde","Jerusalen","Jesusa","Josefina","Josune","Joyceta","Juana","Juandalyn","Juliana","Julita","Justiniana"] />
  16.     <cfset variables.config.SurnameArray = ["Aguilar","Alcaraz","Alejandro","Almaraz","Almonte","Alva","Alvarado","Aparicio","Apodaca","Archuleta","Arella","Arenas","Barrios","Batista","Benavidez","Caballero","Calvillo","Canales","Carbajal","Cardenas","Carrasquillo","Casanova","Casares","Cavazos","Duenas","Duran","Echevarria","Fierro","Garica","Gurule","Jaquez","Llamas","Malave","Mendez","Montoya","Nieto","Orosco","Patino","Puente","Regalado","Roldan","Saldana","Sevilla","Teran","Vaca","Velez","Zambrano"] />
  17.     <cfset variables.config.MarriageAgeLow = 26 />
  18.     <cfset variables.config.MarriageAgeHigh = 42 />
  19.     <cfset variables.config.PossibleChildrenBaseline = 3 />
  20.     <cfset variables.familytree.patriarch = "" />
  21.     <cfset variables.familytree.results = [] />
  22.  
  23.     <cffunction name="init" access="public" returntype="FamilyTree">
  24.         <cfreturn this />
  25.     </cffunction>
  26.    
  27.     <!---   Date: 9/23/2011  Usage: I create the family tree and allow for economic conditions to affect the outcomes --->
  28.     <cffunction name="createFamilyTree" output="false" access="public" returntype="any" hint="I create the family tree and allow for economic conditions to affect the outcomes">
  29.         <cfargument name="EconomicConditions" type="numeric" required="true" hint="0-100 scale where 0 is horror and famine, and 100 is bounty and riches"/>
  30.         <cfset var multiplier = ( EconomicConditions - 50 )/100 />
  31.         <!--- Adjust our Family outlook based on Economic Conditions --->
  32.         <cfset variables.config.MarriageAgeLow = variables.config.MarriageAgeLow - variables.config.MarriageAgeLow * multiplier />
  33.         <cfset variables.config.MarriageAgeHigh = variables.config.MarriageAgeHigh + variables.config.MarriageAgeHigh * multiplier />
  34.         <cfset variables.config.FertilityLow = variables.config.FertilityLow - variables.config.FertilityLow * multiplier />
  35.         <cfset variables.config.FertilityHigh = variables.config.FertilityHigh + variables.config.FertilityHigh * multiplier />
  36.         <cfset variables.config.AttractiveScoreLow = variables.config.AttractiveScoreLow - variables.config.AttractiveScoreLow * multiplier />
  37.         <cfset variables.config.AttractiveScoreHigh = variables.config.AttractiveScoreHigh +  variables.config.AttractiveScoreHigh * multiplier />
  38.         <cfset variables.config.PossibleChildrenBaseline = variables.config.PossibleChildrenBaseline + variables.config.PossibleChildrenBaseline* multiplier />
  39.         <!--- Start Procreating --->
  40.         <cfset variables.familytree.patriarch = definePatriarchNode() />
  41.         <cfset makeGeneration( variables.familytree.patriarch, true ) />
  42.    </cffunction>
  43.    
  44.     <!---   Date: 9/23/2011  Usage: I display the family tree --->
  45.     <cffunction name="display" output="false" access="public" returntype="any" hint="I display the family tree">
  46.         <cfargument name="EconomicConditions" type="numeric" required="true" hint="0-100 scale where 0 is horror and famine, and 100 is bounty and riches"/>
  47.         <cfset createFamilyTree( arguments.EconomicConditions ) />
  48.         <cfreturn variables.familytree.patriarch.makeSnapshot() />
  49.     </cffunction>
  50.    
  51.     <!--- Don't Touch My Privates --->
  52.  
  53.     <cffunction name="definePatriarchNode" output="false" access="private" returntype="any" hint="I define the patriarchs">
  54.         <cfset var partiarchConfig = duplicate( getConfig() ) />
  55.         <cfset var patriarch = {
  56.             birthday=variables.config.EarliestRecords,
  57.             firstName=pickMaleName(),
  58.             lastName=pickSurname(),
  59.             isMale=1
  60.             } />       
  61.         <cfset var matriarch = {
  62.             birthday=variables.config.EarliestRecords,
  63.             firstName=pickFemaleName(),
  64.             lastName=pickSurname(),
  65.             isMale=0
  66.             } />       
  67.         <cfset patriarch = makePerson( argumentcollection:patriarch ) />       
  68.         <cfset matriarch = makePerson( argumentcollection:matriarch ) />
  69.         <cfreturn makeNode( patriarch, matriarch ) />
  70.     </cffunction>
  71.  
  72.     <cffunction name="getConfig" output="false" access="private" returntype="struct" hint="">
  73.         <cfreturn variables.config />
  74.     </cffunction>
  75.    
  76.     <cffunction name="makeGeneration" output="false" access="private" returntype="void" hint="I make the family tree">
  77.         <cfargument name="ParentNode" type="FamilyTreeNode" required="true"/>
  78.         <cfargument name="IsPatriarch" type="boolean" default="false"/>
  79.         <cfset var config = getConfig() />
  80.         <cfset var ParentNodeKidsCount =  arguments.ParentNode.getNakedAndBusy( config )  />
  81.         <cfset var RollOfTheDice = 0 />
  82.         <cfset var KidConfig = {} />
  83.         <cfset var SpouseConfig = {} />
  84.         <cfset var ParentBirthday = arguments.ParentNode.getSomeBirthDate() />
  85.         <cfset var KidSurname = arguments.ParentNode.getSurnameForKid() />
  86.         <cfset var Kid = "" />
  87.         <cfset var Spouse = "" />
  88.         <cfset var NewFamilyNode = "" />
  89.         <cfset var i = "" />
  90.         <cfset var thisKid = "" />
  91.  
  92.         <!--- Patriatchs with no kids make for boring family trees... --->
  93.         <cfif arguments.IsPatriarch IS true >
  94.             <cfset ParentNodeKidsCount = variables.config.PossibleChildrenBaseline />
  95.         </cfif>
  96.  
  97.         <cfloop from="1" to="#Min(6, ParentNodeKidsCount)#" index="i">
  98.             <!--- Let's see what fate has brought to these folks --->
  99.             <cfset RollOfTheDice = RandRange( 1, 100 ) />
  100.             <cfset KidConfig = {
  101.                 birthday=DateAdd( "yyyy", RandRange(variables.config.MarriageAgeLow, variables.config.MarriageAgeHigh ), ParentBirthday ),
  102.                 firstName=pickName(RollOfTheDice MOD 2 IS 1),
  103.                 lastName=KidSurname,
  104.                 isMale=RollOfTheDice MOD 2
  105.                 } />   
  106.            
  107.             <!--- No kids born in the future... --->
  108.             <cfif KidConfig.birthday LT now()>
  109.                 <cfset Kid = makePerson( argumentcollection:KidConfig ) />
  110.                 <!--- If fate has made this person attractive enough, we'll let them get married. Else, may they die alone and sad. (With lots of cats) --->
  111.                 <cfif RollOfTheDice GTE variables.config.AttractiveScoreLow AND RollOfTheDice LTE variables.config.AttractiveScoreHigh>
  112.                     <cfset SpouseConfig = {
  113.                         birthday=DateAdd("yyyy", -2.5, KidConfig.birthday),
  114.                         firstName=pickName(RollOfTheDice MOD 2 IS 0),
  115.                         lastName=pickSurname(),
  116.                         isMale=RollOfTheDice MOD 2
  117.                         } />   
  118.                
  119.                     <cfset Spouse = makePerson( argumentcollection:SpouseConfig ) />
  120.                 </cfif>
  121.            
  122.                 <cfset NewFamilyNode = makeNode( Kid, Spouse ) />
  123.                 <cfset ParentNode.onStorkVisit( NewFamilyNode ) />
  124.             </cfif>
  125.         </cfloop>
  126.        
  127.         <cfset makeNextGeneration( ParentNode ) />
  128.     </cffunction>
  129.    
  130.     <cffunction name="makeNextGeneration" output="false" access="private" returntype="void" hint="I make the next generation from a parent node">
  131.         <cfargument name="ParentNode" type="FamilyTreeNode" required="true"/>
  132.         <cfset var KidArray = ParentNode.getKids() />
  133.         <cfset var thisKid = "" />
  134.         <cfloop array="#KidArray#" index="thisKid">
  135.             <cfset makeGeneration( thisKid ) />
  136.         </cfloop>
  137.     </cffunction>
  138.    
  139.     <cffunction name="makeNode" output="false" access="private" returntype="FamilyTreeNode" hint="I make a family node">
  140.         <cfargument name="Man" type="any" required="false"/>
  141.         <cfargument name="Woman" type="any" required="false"/>
  142.         <cfreturn createobject("component", "FamilyTreeNode").init(argumentcollection:arguments)  />
  143.     </cffunction>
  144.      
  145.     <cffunction name="makePerson" output="false" access="private" returntype="Person" hint="I make a person as described">
  146.         <cfargument name="Birthday" type="string" default=""/>
  147.         <cfargument name="FirstName" type="string" default=""/>
  148.         <cfargument name="LastName" type="string" default=""/>
  149.         <cfargument name="MaidenName" type="string" default=""/>
  150.         <cfargument name="Gender" type="string" default=""/>        
  151.         <cfargument name="IsMale" type="string" default=""/>
  152.         <cfargument name="LoadChildren" type="string" default=""/>
  153.         <cfargument name="NumberOfChildren" type="string" default=""/>
  154.         <cfargument name="ParentPerson" type="string" default=""/>  
  155.         <cfreturn createobject("component", "Person").init( argumentcollection:arguments) />   
  156.     </cffunction>
  157.  
  158.    
  159.     <cffunction name="pickName" output="false" access="private" returntype="string" hint="I help pick a gender appropriate name">
  160.         <cfargument name="NeedMale" type="boolean" required="true"/>
  161.         <cfset var newName = pickFemaleName() />
  162.         <cfif arguments.NeedMale IS true>
  163.             <cfset newName = pickMaleName() />
  164.         </cfif>
  165.         <cfreturn newName />       
  166.     </cffunction>
  167.  
  168.     <cffunction name="pickFemaleName" output="false" access="private" returntype="string" hint="I pick a new female name">
  169.         <cfreturn variables.config.FirstNameArrayFemale[ randRange(1, arrayLen( variables.config.FirstNameArrayFemale ) ) ] />
  170.     </cffunction>
  171.     <cffunction name="pickMaleName" output="false" access="private" returntype="string" hint="I pick a new male name">
  172.         <cfreturn variables.config.FirstNameArrayMale[ randRange(1, arrayLen( variables.config.FirstNameArrayMale ) ) ] />
  173.     </cffunction>
  174.     <cffunction name="pickSurname" output="false" access="private" returntype="string" hint="I pick a new surname">
  175.         <cfreturn variables.config.SurnameArray[ randRange(1, arrayLen( variables.config.SurnameArray ) ) ] />
  176.     </cffunction>
  177.    
  178. </cfcomponent>
  179. ===============================END FamilyTree.cfc ======================
  180.  
  181. FamilyTreeNode.cfc
  182. <!----------------------
  183. Description: FamilyTreeNode
  184. Author: Dan Wilson (dan@nodans.com)
  185. Date: 9/23/2011
  186. CHANGE LOG:
  187. ------------------------>
  188. <cfcomponent output="false">
  189.     <cfset variables.family.man = "" />
  190.     <cfset variables.family.woman = "" />
  191.     <cfset variables.family.kids = [] />
  192.  
  193.     <cffunction name="init" access="public" returntype="FamilyTreeNode">
  194.         <cfargument name="Man" type="any" required="true"/>
  195.         <cfargument name="Woman" type="any" required="true"/>
  196.         <cfif isObject( arguments.Man ) IS true>
  197.             <cfset variables.family.man = arguments.man />
  198.         </cfif>
  199.         <cfif isObject( arguments.Woman ) IS true>
  200.             <cfset variables.family.woman = arguments.woman />
  201.         </cfif>
  202.         <cfreturn this />
  203.     </cffunction>
  204.    
  205.     <cffunction name="loadNameDetails" output="false" access="public" returntype="any" hint="I make the details about this node">
  206.         <cfset var details = "" />
  207.         <cfset var ManName = "" />
  208.         <cfset var WomanName = "" />
  209.         <cfif hasMan() IS true>
  210.             <cfset ManName =  variables.family.man.getFirstName() />
  211.         </cfif>
  212.         <cfif hasWoman() IS true>
  213.             <cfset WomanName =  variables.family.woman.getFirstName() />
  214.         </cfif>
  215.        
  216.         <cfif isMarried() IS true>
  217.             <cfset details = "#ManName# married #WomanName#" />
  218.         <cfelse>
  219.             <cfset details = "#ManName# #WomanName# lives alone" />
  220.         </cfif>    
  221.         <cfreturn details />
  222.     </cffunction>
  223.    
  224.     <cffunction name="getKids" output="false" access="public" returntype="any" hint="I return the kids array">
  225.         <cfset var kids = [] />
  226.         <cfif arrayLen( variables.family.kids ) GT 0 >
  227.             <cfset kids = variables.family.kids />
  228.         </cfif>
  229.         <cfreturn kids />      
  230.     </cffunction>
  231.    
  232.     <cffunction name="getMan" access="public" output="false" returntype="any">
  233.         <cfreturn variables.family.Man/>
  234.     </cffunction>
  235.    
  236.     <cffunction name="getNakedAndBusy" output="false" access="public" returntype="numeric" hint="You know what this does, right?">
  237.         <cfargument name="config" type="struct" required="true"/>
  238.         <cfset var ReturnKidCount = 0 />
  239.         <cfset var RollOfTheDice = randRange( 1, 100) />
  240.         <!--- Having kids take a bit of effort and a bit of luck, will their luck pay off this time? --->
  241.         <cfif isMarried() IS true AND RollOfTheDice GTE arguments.config.FertilityLow AND RollOfTheDice LTE arguments.config.FertilityHigh >
  242.             <cfset ReturnKidCount = Fix( RollOfTheDice/5 ) />
  243.         </cfif>
  244.  
  245.         <cfreturn ReturnKidCount />
  246.     </cffunction>
  247.  
  248.     <cffunction name="getSomeBirthDate" output="false" access="public" returntype="string" hint="I get a birthday by any means necessary">
  249.         <cfset var returnDate= now() />
  250.         <cfif hasWoman() IS true>
  251.             <cfset returnDate = getWoman().getBirthday() />
  252.         <cfelseif hasMan() IS true>
  253.             <cfset returnDate = getMan().getBirthday() />    
  254.         </cfif>
  255.         <cfreturn returnDate />
  256.     </cffunction>
  257.    
  258.     <cffunction name="getSurnameForKid" access="public" output="false" returntype="string">
  259.         <cfset var newSurname = "" />
  260.         <cfif isMarried() IS true>
  261.             <cfset newSurname = "#listFirst( getMan().getLastName(), "-" )#-#listFirst( getWoman().getLastName(), "-" )#" />
  262.         </cfif>
  263.         <cfreturn newSurname  />
  264.     </cffunction>
  265.    
  266.     <cffunction name="getWoman" access="public" output="false" returntype="any">
  267.         <cfreturn variables.family.Woman/>
  268.     </cffunction>    
  269.    
  270.     <cffunction name="hasKids" output="false" access="public" returntype="boolean" hint="I figure out whether there are kids">
  271.         <cfreturn arrayLen( variables.family.kids ) GT 0 />    
  272.     </cffunction>
  273.    
  274.     <cffunction name="hasMan" output="false" access="public" returntype="any" hint="I check to see if there is a male member of this node">
  275.         <cfreturn isObject( variables.family.man ) IS true/>
  276.     </cffunction>
  277.    
  278.     <cffunction name="hasWoman" output="false" access="public" returntype="any" hint="I check to see if there is a female member of this node">
  279.         <cfreturn isObject( variables.family.woman ) IS true />
  280.     </cffunction>
  281.        
  282.     <cffunction name="isMarried" output="false" access="public" returntype="boolean" hint="I figure out whether this node is married">
  283.         <cfreturn hasMan() IS true and hasWoman() IS true />       
  284.     </cffunction>
  285.  
  286.     <cffunction name="makeSnapshot" output="false" access="public" returntype="any" hint="I make a snapshot">
  287.         <cfargument name="OurFamilyTree" type="any" default="#structNew()#"/>
  288.         <cfset var thisKid = "" />
  289.         <cfset arguments.OurFamilyTree["1DisplayName"] = "#loadNameDetails()#" />
  290.         <cfset arguments.OurFamilyTree["4Kids"] = "No Kids" />
  291.         <cfset arguments.OurFamilyTree["5KidsArray"] = [] />
  292.         <cfloop array="#getKids()#" index="thisKid">
  293.             <cfset arguments.OurFamilyTree["4Kids"] = arrayLen( getKids() ) />
  294.             <cfset arrayAppend( arguments.OurFamilyTree["5KidsArray"], thisKid.makeSnapshot() ) />
  295.         </cfloop>
  296.         <cfif hasMan() IS true>
  297.             <cfset arguments.OurFamilyTree["2Man"] = getMan().makeSnapshot() />
  298.         </cfif>
  299.         <cfif hasWoman() IS true>
  300.             <cfset arguments.OurFamilyTree["3Woman"] = getWoman().makeSnapshot() />
  301.         </cfif>
  302.         <cfreturn arguments />
  303.     </cffunction>
  304.    
  305.     <cffunction name="onStorkVisit" output="false" access="public" returntype="void" hint="I handle a visit from the stork">
  306.         <cfargument name="bundleOfJoy" type="any" required="true"/>
  307.         <cfset arrayAppend( variables.family.kids, arguments.bundleOfJoy ) />  
  308.     </cffunction>
  309.        
  310. </cfcomponent>
  311.  
  312. ===============================END FamilyTreeNode.cfc ======================
  313. Person.cfc
  314. <!----------------------
  315. Description: Person
  316. Author: Dan Wilson (dan@nodans.com)
  317. Date: 9/23/2011
  318. CHANGE LOG:
  319.  
  320. BirthDay
  321. FirstName
  322. LastName
  323. Gender
  324. IsMale
  325. LoadChildren
  326. NumberOfChildren
  327. ParentPerson
  328. SpousePerson
  329. ------------------------>
  330.  
  331. <cfcomponent output="false">
  332.     <cffunction name="init" access="public" returntype="Person">
  333.         <cfargument name="Birthday" type="string" default=""/>
  334.         <cfargument name="FirstName" type="string" default=""/>
  335.         <cfargument name="LastName" type="string" default=""/>
  336.         <cfargument name="Gender" type="string" default=""/>        
  337.         <cfargument name="IsMale" type="string" default=""/>
  338.         <cfargument name="LoadChildren" type="string" default=""/>
  339.         <cfargument name="ParentPerson" type="string" default=""/>
  340.        
  341.         <cfset setBirthday( arguments.Birthday ) />
  342.         <cfset setFirstName( arguments.FirstName ) />
  343.         <cfset setLastName( arguments.LastName ) />
  344.         <cfset setGender( arguments.Gender ) />
  345.         <cfset setIsMale( arguments.IsMale ) />
  346.         <cfset setLoadChildren( arguments.LoadChildren ) />
  347.         <cfset setParentPerson( arguments.ParentPerson ) />
  348.        
  349.         <cfreturn this />
  350.     </cffunction>
  351.    
  352.     <cffunction name="getBirthday" access="public" output="false" returntype="any">
  353.         <cfreturn variables.instance.Birthday />
  354.     </cffunction>
  355.     <cffunction name="setBirthday" access="public" output="false" returntype="void">
  356.         <cfargument name="Birthday" type="any" required="true" />
  357.         <cfset variables.instance.Birthday = arguments.Birthday />
  358.     </cffunction>
  359.    
  360.     <cffunction name="getFirstName" access="public" output="false" returntype="any">
  361.         <cfreturn variables.instance.FirstName />
  362.     </cffunction>
  363.     <cffunction name="setFirstName" access="public" output="false" returntype="void">
  364.         <cfargument name="FirstName" type="any" required="true" />
  365.         <cfset variables.instance.FirstName = arguments.FirstName />
  366.     </cffunction>
  367.    
  368.     <cffunction name="getGender" access="public" output="false" returntype="any">
  369.         <cfreturn variables.instance.Gender />
  370.     </cffunction>
  371.     <cffunction name="setGender" access="public" output="false" returntype="void">
  372.         <cfargument name="Gender" type="any" required="true" />
  373.         <cfset variables.instance.Gender = arguments.Gender />
  374.     </cffunction>
  375.    
  376.     <cffunction name="getIsMale" access="public" output="false" returntype="any">
  377.         <cfreturn variables.instance.IsMale />
  378.     </cffunction>
  379.     <cffunction name="setIsMale" access="public" output="false" returntype="void">
  380.         <cfargument name="IsMale" type="any" required="true" />
  381.         <cfset variables.instance.IsMale = arguments.IsMale />
  382.     </cffunction>
  383.    
  384.     <cffunction name="getLastName" access="public" output="false" returntype="any">
  385.         <cfreturn variables.instance.LastName />
  386.     </cffunction>
  387.     <cffunction name="setLastName" access="public" output="false" returntype="void">
  388.         <cfargument name="LastName" type="any" required="true" />
  389.         <cfset variables.instance.LastName = arguments.LastName />
  390.     </cffunction>
  391.    
  392.     <cffunction name="getLoadChildren" access="public" output="false" returntype="any">
  393.         <cfreturn variables.instance.LoadChildren />
  394.     </cffunction>
  395.     <cffunction name="setLoadChildren" access="public" output="false" returntype="void">
  396.         <cfargument name="LoadChildren" type="any" required="true" />
  397.         <cfset variables.instance.LoadChildren = arguments.LoadChildren />
  398.     </cffunction>
  399.  
  400.     <cffunction name="getParentPerson" access="public" output="false" returntype="any">
  401.         <cfreturn variables.instance.ParentPerson />
  402.     </cffunction>
  403.     <cffunction name="setParentPerson" access="public" output="false" returntype="void">
  404.         <cfargument name="ParentPerson" type="any" required="true" />
  405.         <cfset variables.instance.ParentPerson = arguments.ParentPerson />
  406.     </cffunction>
  407.  
  408.     <cffunction name="makeSnapshot" output="false" access="public" returntype="any" hint="I make a snapshot">
  409.         <cfset var snapshot = {} />
  410.         <cfset snapshot["DisplayName"] = "#getFirstName()# #getLastName()#" />
  411.         <cfset snapshot["Birthday"] = dateFormat( getBirthday(), "long") />
  412.         <cfset snapshot["Gender"] = "Male" />
  413.         <cfif getIsMale() IS 0>
  414.             <cfset snapshot["Gender"] = "Female" />
  415.         </cfif>
  416.         <cfreturn snapshot />
  417.     </cffunction>
  418.  
  419. </cfcomponent>
  420.  
  421. ===============================END Person.cfc ======================
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement