69 lines
2.1 KiB
Python
69 lines
2.1 KiB
Python
import workers.val
|
|
|
|
class Train:
|
|
def __init__(self, name, tid, dest, xcoord, ycoord, prodclass):
|
|
self.name = name
|
|
self.tid = tid
|
|
self.dest = dest
|
|
self.xcoord = float(xcoord)/1000000
|
|
self.ycoord = float(ycoord)/1000000
|
|
self.prodclass = prodclass
|
|
|
|
def lat(self):
|
|
return self.ycoord
|
|
|
|
def lon(self):
|
|
return self.xcoord
|
|
|
|
def destStation(self):
|
|
return list(workers.val.validateName(self.name))[0]
|
|
|
|
def json(self, indent = 0, name = True, tid = True, dest = True, coords = True, prodclass = False, stationkwargs = {}):
|
|
out = " " * indent + "{\n"
|
|
|
|
out += (" " * indent + " \"name\": \"%s\",\n" % self.name) if name else ""
|
|
out += (" " * indent + " \"id\": \"%s\",\n" % self.tid) if tid else ""
|
|
|
|
if dest:
|
|
# out += " " * indent + " \"destination\":\n"
|
|
# out += self.dest.json(indent + 2, **stationkwargs) + "\n"
|
|
out += " " * indent + " \"destination\": \"%s\",\n" % self.dest
|
|
|
|
if coords:
|
|
out += " " * indent + " \"coords\": {\n"
|
|
out += " " * indent + " \"lon\": %f,\n" % self.xcoord
|
|
out += " " * indent + " \"lat\": %f\n" % self.ycoord
|
|
out += " " * indent + " },\n"
|
|
|
|
out += (" " * indent + " \"prodclass\": \"%s\",\n" % self.prodclass) if prodclass else ""
|
|
|
|
out = "".join(out.rsplit(",", 1))
|
|
|
|
out += " " * indent + "}"
|
|
|
|
return out
|
|
|
|
def xml(self, indent = 0, name = True, tid = True, dest = True, coords = True, prodclass = False, stationkwargs = {}):
|
|
out = " " * indent + "<train>\n"
|
|
|
|
out += (" " * indent + " <name>%s</name>\n" % self.name) if name else ""
|
|
out += (" " * indent + " <id>%s</id>\n" % self.tid) if tid else ""
|
|
|
|
if dest:
|
|
# out += " " * indent + " <destination>\n"
|
|
# out += self.dest.xml(indent + 2, **stationkwargs) + "\n"
|
|
# out += " " * indent + " </destination>\n"
|
|
out += " " * indent + " <destination>%s</destination>\n" % self.dest
|
|
|
|
if coords:
|
|
out += " " * indent + " <coords>\n"
|
|
out += " " * indent + " <lon>%f</lon>\n" % self.xcoord
|
|
out += " " * indent + " <lat>%f</lat>\n" % self.ycoord
|
|
out += " " * indent + " </coords>\n"
|
|
|
|
out += (" " * indent + " <prodclass>%s</prodclass>\n" % self.prodclass) if prodclass else ""
|
|
|
|
out += " " * indent + "</train>"
|
|
|
|
return out
|
|
|