* and I own this computer.

For users to report plugin bugs and request plugin enhancements; and for authors to test new/new versions of plugins, and to discuss plugin development (in the Programming Technicalities sub-forum). If you want advice on choosing or using a plugin, please ask in General Usage or an appropriate sub-forum.
Post Reply
User avatar
Ron Melby
Megastar
Posts: 928
Joined: 15 Nov 2016 15:40
Family Historian: V6.2

and I own this computer.

Post 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 ?
FH V.6.2.7 Win 10 64 bit
User avatar
DavidNewton
Superstar
Posts: 464
Joined: 25 Mar 2014 11:46
Family Historian: V7

Re: and I own this computer.

Post 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
User avatar
tatewise
Megastar
Posts: 28414
Joined: 25 May 2010 11:00
Family Historian: V7
Location: Torbay, Devon, UK
Contact:

Re: and I own this computer.

Post 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.
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry
User avatar
Ron Melby
Megastar
Posts: 928
Joined: 15 Nov 2016 15:40
Family Historian: V6.2

Re: and I own this computer.

Post 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?
FH V.6.2.7 Win 10 64 bit
User avatar
DavidNewton
Superstar
Posts: 464
Joined: 25 Mar 2014 11:46
Family Historian: V7

Re: and I own this computer.

Post 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
User avatar
Ron Melby
Megastar
Posts: 928
Joined: 15 Nov 2016 15:40
Family Historian: V6.2

Re: and I own this computer.

Post by Ron Melby »

Thanks Dave,

good starting point for me, I will give it a shot.
FH V.6.2.7 Win 10 64 bit
User avatar
Ron Melby
Megastar
Posts: 928
Joined: 15 Nov 2016 15:40
Family Historian: V6.2

Re: and I own this computer.

Post 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.
FH V.6.2.7 Win 10 64 bit
Post Reply