本文整理汇总了Python中prov.model.ProvDocument.wasInvalidatedBy方法的典型用法代码示例。如果您正苦于以下问题:Python ProvDocument.wasInvalidatedBy方法的具体用法?Python ProvDocument.wasInvalidatedBy怎么用?Python ProvDocument.wasInvalidatedBy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类prov.model.ProvDocument
的用法示例。
在下文中一共展示了ProvDocument.wasInvalidatedBy方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: write_targets_prov
# 需要导入模块: from prov.model import ProvDocument [as 别名]
# 或者: from prov.model.ProvDocument import wasInvalidatedBy [as 别名]
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)