Skip to content

Commit

Permalink
Basic simulation framework set up, bringing in some legacy code
Browse files Browse the repository at this point in the history
luke-marshall committed Feb 3, 2019
1 parent 9e47f4f commit 1d00a57
Showing 5 changed files with 58 additions and 13 deletions.
11 changes: 9 additions & 2 deletions marketsim/io/clients/hello.py
Original file line number Diff line number Diff line change
@@ -7,6 +7,7 @@
#

import zmq
import json

context = zmq.Context()

@@ -16,9 +17,15 @@
socket.connect("tcp://localhost:5555")

# Do 10 requests, waiting each time for a response
for request in range(100000):
for request in range(10):
print("Sending request %s …" % request)
socket.send(b"Hello")
data = {
'id':'Nyngan',
'bids':[50,50,50,50,50,50,50,50,50,50],
}
data_str = json.dumps(data)
socket.send_string(data_str)
# socket.send(b"Hello")

# Get the reply.
message = socket.recv()
33 changes: 22 additions & 11 deletions marketsim/io/servers/hello.py
Original file line number Diff line number Diff line change
@@ -8,18 +8,29 @@

import time
import zmq
import json

context = zmq.Context()
socket = context.socket(zmq.REP)
socket.bind("tcp://*:5555")
class Server():
def __init__(self):
context = zmq.Context()
self.socket = context.socket(zmq.REP)
self.socket.bind("tcp://*:5555")

def run(self):
while True:
# Wait for next request from client
message = self.socket.recv()
print("Received request: %s" % message)
data = json.loads(message)

while True:
# Wait for next request from client
message = socket.recv()
print("Received request: %s" % message)
# Do some 'work'
time.sleep(1)

# Do some 'work'
# time.sleep(1)
# Send reply back to client
self.socket.send_string("Your Generator ID was %s" % data['id'])

# Send reply back to client
socket.send(b"World")


if __name__ == "__main__":
s = Server()
s.run()
2 changes: 2 additions & 0 deletions marketsim/model/energy_market.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@


class Market():
pass
4 changes: 4 additions & 0 deletions marketsim/model/generator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
class Generator():
def __init__(self, nameplate_MW):
self.nameplate_MW = nameplate_MW

21 changes: 21 additions & 0 deletions marketsim/simulations/simulation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from .model.generator import Generator
from .model.energy_market import Market

class Simulation():
"""
A simulation defines the way in which an electricity market is set up.
This object provides a minimal implementation and example of the simulation api.
This api can then be used as a standalone package, or linked to a server (ie http/ws/zmq)
"""
def __init__():
self.market =

def add_generator(label, type, nameplate_MW):
"""Add a generator to the simulation."""
g = Generator(nameplate_MW)


class SimulationFactory():

def get_scenario(scenario_type):
return Scenario()

0 comments on commit 1d00a57

Please sign in to comment.