Page 1 of 1

and I own this computer.

Posted: 25 May 2019 19:20
by Ron Melby
I have:

local chil = 0
ptrCHIL = fhGetItemPtr(thisPTR, '~.~CHIL>')
if ptrCHIL:IsNotNull() then
chil = rtvElemCount(ptrCHIL)
end
return chil

Mike Has:
for intChild = 1, 99 do -- Loop through each Child instance
local ptrChild = fhGetItemPtr(ptrIndi,"~.~CHIL["..intChild.."]>")

slightly different he is doing CHIL[1] ... CHIL[99]
and I understand why he doesnt run over the INDI.

I understand why I run over the INDI but am trying to get a child count without going thru FAMS

I can do it thru FAMS, and have working code:

Code: Select all

function rtvCHILCount(eptr)   
  local thisPTR = eptr:Clone()
  local ptrFAMS = fhNewItemPtr()
  local ptrFAM  = fhNewItemPtr()
  local ptrCHIL = fhNewItemPtr()

  local fam     = 0
  local chil    = 0

  ptrFAMS = fhGetItemPtr(thisPTR,'~.FAMS')
  while ptrFAMS:IsNotNull() do
    fam     = fam + 1
    ptrFAM  = fhGetValueAsLink(ptrFAMS)
    ptrCHIL:MoveTo(ptrFAM, '~.CHIL')
    while ptrCHIL:IsNotNull() do
      chil = chil + 1
      ptrCHIL:MoveNext('SAME_TAG')
    end
    ptrFAMS:MoveNext('SAME_TAG')
  end

  return chil, fam
end -- fn rtvElemCount
but am trying to speed up a program.
That is, the rtvAncestors (recursive with decorations)
is immediate return

the rtvDescendants(recursive with decorations)
blinks for quite a bit-- not overlong but long for 3000 records probably 30 seconds on 64 bit early I3, as I go bigger it will be log something and I am trying to shave code times.

**NB, decorations are such things as relationship, sex, age, birth and death etc.
is there a speedier shortcut ?

Re: and I own this computer.

Posted: 26 May 2019 09:05
by DavidNewton
Just in regard to the child count doesn't the built-in function do the job, or does that slow everything down?

Code: Select all

fhCallBuiltInFunction('ChildCount',ptr)
David

Re: and I own this computer.

Posted: 26 May 2019 09:24
by tatewise
If that is too slow, then it could be taken 'offline'.
i.e. Have a dedicated Plugin that loops through every Individual record to invoke fhCallBuiltInFunction('ChildCount',ptrIndi) and update the Child Count Attribute with that number.
That only need be run occasionally after new children have been added to the tree.

Then your Ancestors/Descendants Plugin can simply lookup the Child Count Attribute without needing to loop through FAMS and CHIL links.

Re: and I own this computer.

Posted: 28 May 2019 15:04
by Ron Melby
it sort of seems simple enough, but truthfully all the monkeying around I been doing I have never wrote or updated a tag, not sure how to do that, I have only read them.

the program its pretty easy, codewise (except for exceptions)

INDI, count children for ALL FAMS (I have that routine)
if tag is there (update?) with new count
else
(write?) tag and count

I guess in the FAM that count is easy
same as INDI except this fam only

exceptions are step and foster and? or what is your take?

Re: and I own this computer.

Posted: 28 May 2019 16:05
by DavidNewton
Ron
This is the plugin I use to update the families child count.It does not take account of the relationship status of the children. I don't calculate for individuals but a simple replacement of 'FAM' by 'INDI' should do the job. Then you can read the count from the NCHI tag

Code: Select all

pf=fhNewItemPtr()
pfc=fhNewItemPtr()
pf:MoveToFirstRecord('FAM')
while pf:IsNotNull() do
	pfc:MoveTo(pf,'~.NCHI')
	if pfc:IsNull() then pfc=fhCreateItem('NCHI',pf) end
	fhSetValueAsText(pfc,fhCallBuiltInFunction('ChildCount',pf))
pf:MoveNext()
end
David

Re: and I own this computer.

Posted: 28 May 2019 17:01
by Ron Melby
Thanks Dave,

good starting point for me, I will give it a shot.

Re: and I own this computer.

Posted: 29 May 2019 00:32
by Ron Melby
There it is:

Code: Select all

ptrRCD  = fhNewItemPtr()
ptrNCHI = fhNewItemPtr()

for _, VAL in ipairs ( { 'INDI'; 'FAM'; } ) do
  ptrRCD:MoveToFirstRecord(VAL)
  while ptrRCD:IsNotNull() do
    ptrNCHI:MoveTo(ptrRCD,'~.NCHI')
    if ptrNCHI:IsNull() then
      ptrNCHI  =fhCreateItem('NCHI', ptrRCD)
    end
    fhSetValueAsText(ptrNCHI, fhCallBuiltInFunction('ChildCount', ptrRCD))
    ptrRCD:MoveNext() 
 end
  ptrRCD:MoveNextSpecial()           
end
a couple of comments it does not regard PEDI so a foster child is a child count. dont know about more, yet.

Secondly, I thought, yanno thats a good idea to have a run once in a while program to make all mine faster.
Well-- let me do the same for MarriageCount.

Uh oh.