VEuPathDB / EdaUserService

An EDA service that tracks user state
Apache License 2.0
0 stars 0 forks source link

Derived Variables #30

Closed Foxcapades closed 1 year ago

Foxcapades commented 1 year ago
ryanrdoherty commented 1 year ago

@Foxcapades Per conversation about copies and provenance, see the following pseudocode to implement during analysis copy/import:


Better devine provenance type; instead of any, use:
{
  copyDate: string (ISO timestamp)
  copiedFrom: string (derived variable ID)
}

On analysis import/copy:

analysisCopy = make a copy of the analysis and assign new analysis ID

if (different user) {
  // assign new owner's ID to copy
}

if (no derived vars in copy) {
  // save off analysisCopy; done!
  return
}

// get all newOwner's existing DVs from derived_variable table

var newDerivedVarRefs = new ArrayList // DV refs to assign to analysisCopy

for (derivedVarRef in analysisCopy) {

  if (any existing DV has provenance that matches derivedVarRef) {
    // don't need a second copy; use the ID of the existing copy
    // note: displayName and description will NOT update; don't want to overwrite any changes the newOwner made
    newDerivedVarRefs.add(existing DV's ID)
  }
  else {
    // need to make a copy of this DV
    oldDv = lookUpDvToBeCopied(derivedVarRef)
    newDv = copyWithNewID(oldDv)
    newDerivedVarRefs.add(newDv.id)

    // handle provenance chain
    if (oldDv.hasProvenance) {
      newDv.provenance = {
        copyDate: new Date().isoFormat,
        copiedFrom: oldDv.provenance.copiedFrom // reference the original DV
      }
    }
    else {
      newDv.provenance = {
        copyDate: new Date().isoFormat,
        copiedFrom: oldDv.id
      }
    }
  }
}

analysisCopy.derivedVars = newDerivedVarRefs
// save off analysisCopy