def diff(diff: DiffModel, document: provo.ProvDocument): print_msg(" Exporting module dependency comparison") added, removed, replaced = diff.modules for module in added: # type: Module _create_module_dep(module, document, suffix="_a") document.wasGeneratedBy("module{}_a".format(module.id), "trial{}Execution".format(diff.trial2.id), None, "module{}AddDep".format(module.id), [(provo.PROV_ROLE, "dependencyAddition")]) for module in removed: # type: Module _create_module_dep(module, document, suffix="_r") document.wasInvalidatedBy("module{}_r".format(module.id), "trial{}Execution".format(diff.trial2.id), None, "module{}RemoveDep".format(module.id), [(provo.PROV_ROLE, "dependencyRemoval")]) for (mod_removed, mod_added) in replaced: # type: Module _create_module_dep(mod_added, document, suffix="_a") document.wasGeneratedBy("module{}_a".format(mod_added.id), "trial{}Execution".format(diff.trial2.id), None, "module{}AddDep".format(mod_added.id), [(provo.PROV_ROLE, "dependencyAddition")]) _create_module_dep(mod_removed, document, suffix="_r") document.wasInvalidatedBy("module{}_r".format(mod_removed.id), "trial{}Execution".format(diff.trial2.id), None, "module{}RemoveDep".format(mod_removed.id), [(provo.PROV_ROLE, "dependencyRemoval")]) document.wasRevisionOf("module{}_a".format(mod_added.id), "module{}_r".format(mod_removed.id), "trial{}Execution".format(diff.trial2.id), None, None, None, [(provo.PROV_TYPE, "dependencyReplacement")])
def deletion(graph: ProvDocument, package: CommitModelPackage, action: Deletion) -> ProvDocument: """Add model for a deleted file.""" file, file_version = action commit = package.commit graph.entity(*file) graph.entity(*file_version) graph.specializationOf(file_version.id, file.id) graph.wasInvalidatedBy(file_version.id, commit.id) return graph
def diff(diff: DiffModel, document: provo.ProvDocument): print_msg(" Exporting environment conditions comparison") added, removed, replaced = diff.environment for env_attr in added: # type: EnvironmentAttr _create_env_attr(document, env_attr, suffix="_a") document.wasGeneratedBy( "environmentAttribute{}_a".format(env_attr.id), "trial{}Execution".format(diff.trial2.id), None, "environmentAttribute{}AddAttr".format(env_attr.id), [(provo.PROV_ROLE, "environmentAttributeAddition")]) for env_attr in removed: # type: EnvironmentAttr _create_env_attr(document, env_attr, suffix="_r") document.wasInvalidatedBy( "environmentAttribute{}_r".format(env_attr.id), "trial{}Execution".format(diff.trial2.id), None, "environmentAttribute{}RemoveAttr".format(env_attr.id), [(provo.PROV_ROLE, "environmentAttributeRemoval")]) for (attr_removed, attr_added) in replaced: # type: EnvironmentAttr _create_env_attr(document, attr_added, suffix="_a") document.wasGeneratedBy( "environmentAttribute{}_a".format(attr_added.id), "trial{}Execution".format(diff.trial2.id), None, "environmentAttribute{}AddAttr".format(attr_added.id), [(provo.PROV_ROLE, "environmentAttributeAddition")]) _create_env_attr(document, attr_removed, suffix="_r") document.wasInvalidatedBy( "environmentAttribute{}_r".format(attr_removed.id), "trial{}Execution".format(diff.trial2.id), None, "environmentAttribute{}RemoveAttr".format(attr_removed.id), [(provo.PROV_ROLE, "environmentAttributeRemoval")]) document.wasRevisionOf( "environmentAttribute{}_a".format(attr_added.id), "environmentAttribute{}_r".format(attr_removed.id), "trial{}Execution".format(diff.trial2.id), None, None, None, [(provo.PROV_TYPE, "environmentAttributeReplacement")])
}) rem.entity("File", other_attributes={ "prov:type": "file", "path_at_addition": "" }) rem.entity("File Version", other_attributes={ "prov:type": "file_version", "new_path": "", "old_path": "" }) rem.wasInformedBy("Commit", "Parent Commit") rem.wasAssociatedWith("Commit", "Committer") rem.wasAssociatedWith("Commit", "Author") rem.wasInvalidatedBy("File Version", "Commit") rem.specializationOf("File Version", "File") com = ProvDocument() com.set_default_namespace("gitlab2prov:") com.agent("Creator", other_attributes={ "prov:type": "user", "prov:role": "creator", "name": "" }) com.agent("Annotator", other_attributes={ "prov:type": "user", "prov:role": "initiator", "name": ""
def write_targets_prov(self, tlist, C, bundle_id): #Initialisation # cs = b.agent('CrowdScanner') if self.document_id == -1: d = ProvDocument() d.add_namespace(AO) d.set_default_namespace(self.defaultns % self.game_id) if uploadprov: provstore_document = self.api.document.create(d, name="Operation%s CrowdScanner" % self.game_id, public=True) document_uri = provstore_document.url logging.info("prov doc URI: " + str(document_uri)) self.provfilelist.append(provstore_document.id) self.savelocalrecord() self.document_id = provstore_document.id b = ProvDocument() # Create a new document for this update b.add_namespace(AO) b.set_default_namespace(self.defaultns % self.game_id) # cs to be used with all targets cs = b.agent('agent/CrowdScanner', (('prov:type', AO['IBCCAlgo']), ('prov:type', PROV['SoftwareAgent']))) timestamp = time.time() # Record the timestamp at each update to generate unique identifiers startTime = datetime.datetime.fromtimestamp(timestamp) endTime = startTime activity = b.activity('activity/cs/update_report_%s' % timestamp, startTime, endTime) activity.wasAssociatedWith(cs) #Add target and report entities for i, tdata in enumerate(tlist): if self.changedtargets[i]==0: continue #Target entity for target i tid = int(tdata[0]) x = tdata[1] y = tdata[2] # targettype = tdata[3] #don't record here, it will be revealed and recorded by UAVs v = int(tdata[4]) agentids = tdata[7] targetattributes = {'ao:longitude': x, 'ao:latitude': y, } #'ao:asset_type':str(targettype)} target_v0 = b.entity('cs/target/'+str(tid)+'.'+str(v), targetattributes) #Post the root report if this is the first version if v==0: self.targets[tid] = b.entity('cs/target/'+str(tid)) else: try: target_v0.wasDerivedFrom(self.targetversions[tid]) except KeyError: logging.error("Got a key error for key " + str(tid) + ', which is supposed to be version' + str(v)) self.targetversions[tid] = target_v0 target_v0.specializationOf(self.targets[tid]) target_v0.wasAttributedTo(cs) #Report entities for origins of target i for j, r in enumerate(self.target_rep_ids[i]): if r not in self.postedreports: Crow = C[r,:] x = Crow[1] y = Crow[2] reptext = tdata[5][j].decode('utf8') # Try to replace unusual characters reptext = reptext.encode('ascii', 'replace') agentid = agentids[j] reporter_name = 'agent/crowdreporter%s' % agentid b.agent(reporter_name, (('prov:type', AO['CrowdReporter']), ('prov:type', PROV['Person']))) reportattributes = {'ao:longitude': x, 'ao:latitude': y, 'ao:report': reptext} self.postedreports[r] = b.entity('cs/report/'+str(r), reportattributes) self.postedreports[r].wasAttributedTo(reporter_name) activity.used(self.postedreports[r]) target_v0.wasDerivedFrom(self.postedreports[r]) if uploadprov: #Invalidate old targets no longer in use for i,tid in enumerate(self.targets_to_invalidate): target_v = self.targetversions[tid] b.wasInvalidatedBy(target_v, activity) #Post the document to the server #bundle = b.bundle('crowd_scanner') bundle_id = 'bundle/csupdate/%s' % timestamp self.api.add_bundle(self.document_id, b.serialize(), bundle_id)