from datetime import datetime
from pyproms import *

# example Agents, could be people or Organisations
ag = ProvAgent('Agent Orange')
agx = ProvAgent('Agent X', actedOnBehalfOf=ag)

# a ReportingSystem (Agent subclass)
# This is the system that actually generates the Reports
rs = PromsReportingSystem('Workflow System Z', actedOnBehalfOf=agx)

# input Entities
entity_used_01 = ProvEntity('Dataset 12', uri='http://pid.geoscience.gov.au/dataset/12')
entity_used_02 = ProvEntity('Input 2',
                            comment='The Entity, 02',
                            wasAttributedTo=ag)
entity_used_03 = ProvEntity('Input 3', uri='http://example.org.au/id/thing/dataset/3')
entity_used_04 = ProvEntity('Band Selector', value='Band_3,Band_4,Band_7')

# two output Entities
entity_generated_01 = ProvEntity('Output Data',
                                 uri='http://web3-wron:8080/water/thredds/somefile.nc',
                                 comment='The Entity, 03',
                                 wasAttributedTo=ag)

entity_generated_02 = ProvEntity('Output Number', value=42)

# the three Activities, as Internal Reports must have at least 2
startedAtTime1 = datetime.strptime('2014-06-25T12:13:14', '%Y-%m-%dT%H:%M:%S')
endedAtTime1 = datetime.strptime('2014-06-25T12:13:24', '%Y-%m-%dT%H:%M:%S')
a1 = ProvActivity('Activity 1',
                  startedAtTime1,
                  endedAtTime1,
                  wasAssociatedWith=agx,
                  comment='A test Activity',
                  used_entities=[entity_used_01, entity_used_02, entity_used_03])

# an entity, generated by a1, used by a2
entity_hanover_01 = ProvEntity('Thing 1', wasAttributedTo=agx)

endedAtTime2 = datetime.strptime('2014-06-25T13:00:00', '%Y-%m-%dT%H:%M:%S')
a2 = ProvActivity('Activity 2',
                  endedAtTime1,
                  endedAtTime2,
                  wasAssociatedWith=agx,
                  comment='A test Activity',
                  used_entities=[entity_hanover_01, entity_used_04],
                  generated_entities=[entity_generated_01])

# an entity, generated by a2, used by a3
entity_hanover_02 = ProvEntity('Thing 2')

startedAtTime3 = datetime.strptime('2014-06-25T13:00:01', '%Y-%m-%dT%H:%M:%S')
endedAtTime3 = datetime.strptime('2014-06-25T13:05:00', '%Y-%m-%dT%H:%M:%S')
a3 = ProvActivity('Activity 3',
                  startedAtTime3,
                  endedAtTime3,
                  wasAssociatedWith=agx,
                  comment='A test Activity',
                  used_entities=[entity_hanover_02],
                  generated_entities=[entity_generated_02])

# make the Report
r = PromsInternalReport('Test Internal Report PyPROMS',
                        rs,  # this is the Reporting System
                        'report-71',  # this could be anything that the Reporting System uses to keep track of Reports
                        a1,
                        a3,
                        [a1, a2, a3],
                        datetime.strptime('2014-06-25T12:13:34', '%Y-%m-%dT%H:%M:%S'),
                        comment='This is an example Internal Report')

# save the report
report_file = 'example_report_internal.ttl'
with open(report_file, 'w') as f:
    f.write((r.get_graph().serialize(format='n3')).decode('UTF-8'))

# print the report, just for testing
print(open(report_file).read())

# send (POST) the Report to a PROMS Server instance
# pr = ReportSender().post('http://pid.geoscience.gov.au/service/proms-dev/id/report/', r)
# print pr.status_code
# print pr.content

from datetime import datetime
from pyproms import *

# example Agents, could be people or Organisations
ag = ProvAgent('Agent Orange')
agx = ProvAgent('Agent X', actedOnBehalfOf=ag)

# a ReportingSystem (Agent subclass)
# This is the system that actually generates the Reports
rs = PromsReportingSystem('Workflow System Z', actedOnBehalfOf=agx)

# input Entities
entity_used_01 = ProvEntity('Dataset 12', uri='http://pid.geoscience.gov.au/dataset/12')
entity_used_02 = ProvEntity('Input 2',
                            comment='The Entity, 02',
                            wasAttributedTo=ag)
entity_used_03 = ProvEntity('Input 3', uri='http://example.org.au/id/thing/dataset/3')
entity_used_04 = ProvEntity('Band Selector', value='Band_3,Band_4,Band_7')

# two output Entities
entity_generated_01 = ProvEntity('Output Data',
                                 uri='http://web3-wron:8080/water/thredds/somefile.nc',
                                 comment='The Entity, 03',
                                 wasAttributedTo=ag)

entity_generated_02 = ProvEntity('Output Number', value=42)

# the three Activities, as Internal Reports must have at least 2
startedAtTime1 = datetime.strptime('2014-06-25T12:13:14', '%Y-%m-%dT%H:%M:%S')
endedAtTime1 = datetime.strptime('2014-06-25T12:13:24', '%Y-%m-%dT%H:%M:%S')
a1 = ProvActivity('Activity 1',
                  startedAtTime1,
                  endedAtTime1,
                  wasAssociatedWith=agx,
                  comment='A test Activity',
                  used_entities=[entity_used_01, entity_used_02, entity_used_03])

# an entity, generated by a1, used by a2
entity_hanover_01 = ProvEntity('Thing 1', wasAttributedTo=agx)

endedAtTime2 = datetime.strptime('2014-06-25T13:00:00', '%Y-%m-%dT%H:%M:%S')
a2 = ProvActivity('Activity 2',
                  endedAtTime1,
                  endedAtTime2,
                  wasAssociatedWith=agx,
                  comment='A test Activity',
                  used_entities=[entity_hanover_01, entity_used_04],
                  generated_entities=[entity_generated_01])

# an entity, generated by a2, used by a3
entity_hanover_02 = ProvEntity('Thing 2')

startedAtTime3 = datetime.strptime('2014-06-25T13:00:01', '%Y-%m-%dT%H:%M:%S')
endedAtTime3 = datetime.strptime('2014-06-25T13:05:00', '%Y-%m-%dT%H:%M:%S')
a3 = ProvActivity('Activity 3',
                  startedAtTime3,
                  endedAtTime3,
                  wasAssociatedWith=agx,
                  comment='A test Activity',
                  used_entities=[entity_hanover_02],
                  generated_entities=[entity_generated_02])

# make the Report
r = PromsInternalReport('Test Internal Report PyPROMS',
                        rs,  # this is the Reporting System
                        'report-71',  # this could be anything that the Reporting System uses to keep track of Reports
                        a1,
                        a3,
                        [a1, a2, a3],
                        datetime.strptime('2014-06-25T12:13:34', '%Y-%m-%dT%H:%M:%S'),
                        comment='This is an example Internal Report')

# save the report
report_file = 'example_report_internal.ttl'
with open(report_file, 'w') as f:
    f.write((r.get_graph().serialize(format='n3')).decode('UTF-8'))

# print the report, just for testing
print(open(report_file).read())

# send (POST) the Report to a PROMS Server instance
# pr = ReportSender().post('http://pid.geoscience.gov.au/service/proms-dev/id/report/', r)
# print pr.status_code
# print pr.content

# example Agents, could be people or Organisations # a ReportingSystem (Agent subclass) # This is the system that actually generates the Reports # input Entities # two output Entities # the three Activities, as Internal Reports must have at least 2 # an entity, generated by a1, used by a2 # an entity, generated by a2, used by a3 # make the Report # this is the Reporting System # this could be anything that the Reporting System uses to keep track of Reports # save the report # print the report, just for testing # send (POST) the Report to a PROMS Server instance # pr = ReportSender().post('http://pid.geoscience.gov.au/service/proms-dev/id/report/', r) # print pr.status_code # print pr.content