2017-10-03 11:50:32 +00:00
|
|
|
import workers.val
|
|
|
|
|
|
|
|
|
2022-04-19 13:01:03 +00:00
|
|
|
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
|
2017-10-03 11:50:32 +00:00
|
|
|
|
2022-04-19 13:01:03 +00:00
|
|
|
def lat(self):
|
|
|
|
return self.ycoord
|
2017-10-03 11:50:32 +00:00
|
|
|
|
2022-04-19 13:01:03 +00:00
|
|
|
def lon(self):
|
|
|
|
return self.xcoord
|
2017-10-03 11:50:32 +00:00
|
|
|
|
2022-04-19 13:01:03 +00:00
|
|
|
def destStation(self):
|
|
|
|
return list(workers.val.validateName(self.name))[0]
|
2017-10-03 11:50:32 +00:00
|
|
|
|
2022-04-19 13:01:03 +00:00
|
|
|
def json(self, indent=0, name=True, tid=True, dest=True, coords=True, prodclass=False, stationkwargs={}):
|
|
|
|
out = " " * indent + "{\n"
|
2017-10-03 11:50:32 +00:00
|
|
|
|
2022-04-19 13:01:03 +00:00
|
|
|
out += (" " * indent + " \"name\": \"%s\",\n" %
|
|
|
|
self.name) if name else ""
|
|
|
|
out += (" " * indent + " \"id\": \"%s\",\n" % self.tid) if tid else ""
|
2017-10-03 11:50:32 +00:00
|
|
|
|
2022-04-19 13:01:03 +00:00
|
|
|
if dest:
|
|
|
|
# out += " " * indent + " \"destination\":\n"
|
|
|
|
# out += self.dest.json(indent + 2, **stationkwargs) + "\n"
|
|
|
|
out += " " * indent + " \"destination\": \"%s\",\n" % self.dest
|
2017-10-03 11:50:32 +00:00
|
|
|
|
2022-04-19 13:01:03 +00:00
|
|
|
if coords:
|
|
|
|
out += " " * indent + " \"coords\": {\n"
|
|
|
|
out += " " * indent + " \"lon\": %f,\n" % self.xcoord
|
|
|
|
out += " " * indent + " \"lat\": %f\n" % self.ycoord
|
|
|
|
out += " " * indent + " },\n"
|
2017-10-03 11:50:32 +00:00
|
|
|
|
2022-04-19 13:01:03 +00:00
|
|
|
out += (" " * indent + " \"prodclass\": \"%s\",\n" %
|
|
|
|
self.prodclass) if prodclass else ""
|
2017-10-03 11:50:32 +00:00
|
|
|
|
2022-04-19 13:01:03 +00:00
|
|
|
out = "".join(out.rsplit(",", 1))
|
2017-10-03 11:50:32 +00:00
|
|
|
|
2022-04-19 13:01:03 +00:00
|
|
|
out += " " * indent + "}"
|
2017-10-03 11:50:32 +00:00
|
|
|
|
2022-04-19 13:01:03 +00:00
|
|
|
return out
|
2017-10-03 11:50:32 +00:00
|
|
|
|
2022-04-19 13:01:03 +00:00
|
|
|
def xml(self, indent=0, name=True, tid=True, dest=True, coords=True, prodclass=False, stationkwargs={}):
|
|
|
|
out = " " * indent + "<train>\n"
|
2017-10-03 11:50:32 +00:00
|
|
|
|
2022-04-19 13:01:03 +00:00
|
|
|
out += (" " * indent + " <name>%s</name>\n" %
|
|
|
|
self.name) if name else ""
|
|
|
|
out += (" " * indent + " <id>%s</id>\n" % self.tid) if tid else ""
|
2017-10-03 11:50:32 +00:00
|
|
|
|
2022-04-19 13:01:03 +00:00
|
|
|
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
|
2017-10-03 11:50:32 +00:00
|
|
|
|
2022-04-19 13:01:03 +00:00
|
|
|
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"
|
2017-10-03 11:50:32 +00:00
|
|
|
|
2022-04-19 13:01:03 +00:00
|
|
|
out += (" " * indent + " <prodclass>%s</prodclass>\n" %
|
|
|
|
self.prodclass) if prodclass else ""
|
2017-10-03 11:50:32 +00:00
|
|
|
|
2022-04-19 13:01:03 +00:00
|
|
|
out += " " * indent + "</train>"
|
2017-10-03 11:50:32 +00:00
|
|
|
|
2022-04-19 13:01:03 +00:00
|
|
|
return out
|