from streamsx.topology.topology import Topology
from streamsx.topology import context
from my_module import Counter, negative_one

"""
Explanation: Creating a Simple Application
The Streams Python API allows a user to create a streams application using only python. The Python API allows for the definition of data sources, transformations, and sinks by performing operations on Stream and Topology objects.
First, it is necessary to import the Topology class from the streamsx.topology package. This will be used to begin create your application. In addition, the context module must be imported, allowing your application to be submitted.
Lastly, import the classes of the operators you wish to use. Here we use Counter, a source operator which counts from 0 to infinity, and negative_one, an operator which returns the negative of every number it is given
End of explanation
"""


top = Topology("myTop")

"""
Explanation: The Topology Object
A Topology object is a container for the structure of your application. Give it a unique name, otherwise it may overwrite other compiled streams applications.
End of explanation
"""


# Define source
my_counter = Counter()
stream_1 = top.source(my_counter)

"""
Explanation: Define and Create Your Data Source
By creating an instance of the Counter operator, we can use it as a data source by invoking the source method on your Topology object and passing it the my_counter object. The output of a source is a Stream which represents the flow of data in your applications. A streams consists of a potentially infinite sequence of Python object upon which you can perform subsequent operations (such as multiplying by negative one)
End of explanation
"""


# multiple by negative one
neg_one = negative_one()
stream_2 = stream_1.map(neg_one)

# Print stream
stream_2.print()

"""
Explanation: Performing Operations On Your Data Stream
A user might want to perform a number of operations on a stream of live data; for example, extracting sentiment from tweets, keeping track of a GPS device, or monitoring live traffic data. All of these operations take data items of one type and modify them or produce data of another type. With the Python API, this can be achieved by calling map on a Stream and passing it an operator.
As mentioned before, negative_one is a callable class which takes a number, and returns its negative.
End of explanation
"""


out = context.submit("STANDALONE", top.graph)

"""
Explanation: Submission
Submit the application to be run locally in a single process. The output will be sent to standard output and printed to the screen.
End of explanation
"""


