def createTripCreationGraph(self, userName, userEmail, tripId, tripLegIds, startTime, endTime): """Creates and stores the provenacne graph depecting the action of creating the trip""" #startTime = datetime.datetime.strptime(startTime, "%a, %d %b %Y %H:%M:%S %Z") #endTime = datetime.datetime.strptime(endTime, "%a, %d %b %Y %H:%M:%S %Z") #the namespace of the project cf = Namespace('cf', 'http://users.ecs.soton.ac.uk/pp6g11/ontology/carbonFooprints/') # create a provenance _container g = ProvBundle() g.add_namespace("foaf", "http://xmlns.com/foaf/0.1/") #create activity g.activity(cf['tripCreation'], startTime, endTime) #create entities. g.entity(cf['trip-' + tripId]) #create trip leg entities for tripLegId in tripLegIds: tripLegId = str(tripLegId) g.entity(cf['tripLeg-' + tripLegId]) g.wasGeneratedBy('cf:tripLeg-' + tripLegId, 'cf:tripCreation') g.wasDerivedFrom('cf:trip-' + tripId, 'cf:tripLeg-' + tripLegId) #add relations g.wasGeneratedBy('cf:trip-' + tripId, 'cf:tripCreation') #create agent g.agent('cf:' + userName, {'prov:type': 'prov:Person', 'foaf:mbox': '<mailto:' + userEmail + '>'}) g.wasAssociatedWith('cf:tripCreation', 'cf:' + userName) g.wasAttributedTo('cf:trip-' + tripId, 'cf:' + userName) #save the graph pdBundle = save_bundle(g) #visualize the graph path = tempfile.mkdtemp() filepath = os.path.join(path, 'dot-test.png') # Convert it to DOT dot = graph.prov_to_dot(g) dot.set_dpi(120) # Write it to a temporary PNG file #dot.write_png(filepath) # Display it using matplotlib #img = mpimg.imread(filepath) ##imgplot = plt.imshow(img) #plt.show() #os.remove(filepath) return pdBundle
def createTempProvGraphImage(self, bundleId): """ creates a temporary png image illustrating a provenance graph """ pdBundle = TripLegCarbonEmission.objects.get(provBundle = bundleId).provBundle g = pdBundle.get_prov_bundle() #visualize the graph path = "C:\\Users\\Boliev\\My Documents\\Aptana Studio 3 Workspace\\Thesis\\CarbonEmissions\\static\\images\\provGraphs\\" self.__class__.filepath = os.path.join(path, 'dot-test.png') # Convert it to DOT dot = graph.prov_to_dot(g) dot.set_dpi(120) # Write it to a temporary PNG file dot.write_png(self.__class__.filepath)
def bundle_svg(request, bundle_id): pdBundle = get_object_or_404(PDBundle, pk=bundle_id) prov_g = pdBundle.get_prov_bundle() dot = prov_to_dot(prov_g) svg_content = dot.create(format='svg') return HttpResponse(content=svg_content, mimetype='image/svg+xml')
def bundle_svg(request, container_id): container = get_object_or_404(Container, pk=container_id) prov_g = container.content.get_prov_bundle() dot = prov_to_dot(prov_g) svg_content = dot.create(format='svg') return HttpResponse(content=svg_content, mimetype='image/svg+xml')