コード例 #1
0
ファイル: simulation.py プロジェクト: thiagojv/udacity_kafka
    def __init__(self, sleep_seconds=5, time_step=None, schedule=None):
        """Initializes the time simulation"""
        self.sleep_seconds = sleep_seconds
        self.time_step = time_step
        if self.time_step is None:
            self.time_step = datetime.timedelta(minutes=self.sleep_seconds)

        # Read data from disk
        self.raw_df = pd.read_csv(
            f"{Path(__file__).parents[0]}/data/cta_stations.csv"
        ).sort_values("order")

        # Define the train schedule (same for all trains)
        self.schedule = schedule
        if schedule is None:
            self.schedule = {
                TimeSimulation.weekdays.mon: {0: TimeSimulation.ten_min_frequency},
                TimeSimulation.weekdays.tue: {0: TimeSimulation.ten_min_frequency},
                TimeSimulation.weekdays.wed: {0: TimeSimulation.ten_min_frequency},
                TimeSimulation.weekdays.thu: {0: TimeSimulation.ten_min_frequency},
                TimeSimulation.weekdays.fri: {0: TimeSimulation.ten_min_frequency},
                TimeSimulation.weekdays.sat: {0: TimeSimulation.ten_min_frequency},
                TimeSimulation.weekdays.sun: {0: TimeSimulation.ten_min_frequency},
            }

        self.train_lines = [
            Line(Line.colors.blue, self.raw_df[self.raw_df["blue"]]),
            Line(Line.colors.red, self.raw_df[self.raw_df["red"]]),
            Line(Line.colors.green, self.raw_df[self.raw_df["green"]]),
        ]
コード例 #2
0
ファイル: test_models.py プロジェクト: blancheta/connectz
    def setUp(self):

        self.cell1 = Cell(1, 1, 0)
        self.cell2 = Cell(1, 1, 1)

        self.line = Line([
            self.cell1,
            self.cell2
        ], 1)
コード例 #3
0
ファイル: views.py プロジェクト: zdvitas/karaoke
def add_order(request, id):
    context = {}
    song = Song.objects.get(number=id)
    user = int(request.user.username)
    line = Line(song=song, table=user, date=datetime.datetime.now())
    line.save()
    context["ordered"] = "true"
    # Перекидывать на страницу с очередями
    return redirect("/pull_list")
コード例 #4
0
ファイル: pep8.py プロジェクト: Bryukh/spygit
def parse_pep8(run, git_path, output):
    """Parse the pep8 output, store the results"""

    errfiles_set = set()
    errortype_set = set()
    lineno_set = set()

    # Add all files in the project to the db
    allfiles = set()
    os.path.walk(git_path, add_file_to_set, allfiles)
    for filename in allfiles:
        filename = filename.replace(git_path + '/', '', 1)
        runfile = File(filename=filename, run=run)
        runfile.save()

    # Generate a set of error types, error files, and lines
    for line in output.readlines():
        filename, lineno, errnum, errtext = string.split(line, ':', 3)
        lineno = int(lineno)
        filename = filename.replace(git_path + '/', '', 1)

        # Create sets to remove duplicates
        errfiles_set.add(filename)

        # Add new err types to the db
        if (errnum, errtext) not in errortype_set:
            errortype_set.add((errnum, errtext))
            if not Error.objects.filter(error_type=errnum):
                err = Error(error_type=errnum, short_descr=errtext)
                err.save()

        # Create a set of line numbers for each file
        for ln in range(max(1, lineno - 3), lineno + 4):
            lineno_set.add((filename, ln))

        # Add err instances to the db
        runfile = File.objects.get(run=run, filename=filename)
        errtype = Error.objects.get(error_type=errnum)
        runerr = RunError(error=errtype, file=runfile, line_number=lineno,
                          error_descr=errtext)
        runerr.save()

    # Add lines to the db
    for filename in errfiles_set:
        runfile = File.objects.get(run=run, filename=filename)

        f = open(git_path + '/' + filename, 'r')
        lineno = 1
        for line in f:
            if (filename, lineno) in lineno_set:
                linetext = Line(file=runfile, line_number=lineno, text=line)
                linetext.save()
            lineno = lineno + 1
        f.close()
コード例 #5
0
ファイル: server.py プロジェクト: popdevelop/resources
    def handle_result(self, tree):
        lines = []
        ns = "http://www.etis.fskab.se/v1.0/ETISws"
        for line in tree.findall('.//{%s}Lines//{%s}Line' % (ns, ns)):
            l = Line()
            l.name = line.find('.//{%s}Name' % ns).text
            l.time = line.find('.//{%s}JourneyDateTime' % ns).text
            l.type = line.find('.//{%s}LineTypeName' % ns).text
            l.towards = line.find('.//{%s}Towards' % ns).text
            lines.append(l)

        return [model_to_dict(l) for l in lines]
コード例 #6
0
    def __init__(self, sleep_seconds=5, time_step=None, schedule=None):
        '''
        Initializes the time simulation
        '''

        self.sleep_seconds = sleep_seconds
        self.time_step = time_step
        if self.time_step is None:
            self.time_step = datetime.timedelta(minutes=self.sleep_seconds)

        # Read data from disk
        data = utils.get_data_path('cta_stations.csv')
        self.raw_df = pd.read_csv(data).sort_values('order')

        # Define the train schedule (same for all trains)
        self.schedule = schedule
        if schedule is None:
            self.schedule = {
                TimeSimulation.weekdays.mon: {
                    0: TimeSimulation.ten_min_frequency
                },
                TimeSimulation.weekdays.tue: {
                    0: TimeSimulation.ten_min_frequency
                },
                TimeSimulation.weekdays.wed: {
                    0: TimeSimulation.ten_min_frequency
                },
                TimeSimulation.weekdays.thu: {
                    0: TimeSimulation.ten_min_frequency
                },
                TimeSimulation.weekdays.fri: {
                    0: TimeSimulation.ten_min_frequency
                },
                TimeSimulation.weekdays.sat: {
                    0: TimeSimulation.ten_min_frequency
                },
                TimeSimulation.weekdays.sun: {
                    0: TimeSimulation.ten_min_frequency
                },
            }

        self.train_lines = [
            Line(Line.colors.blue, self.raw_df[self.raw_df['blue']]),
            Line(Line.colors.red, self.raw_df[self.raw_df['red']]),
            Line(Line.colors.green, self.raw_df[self.raw_df['green']]),
        ]
コード例 #7
0
ファイル: test_models.py プロジェクト: blancheta/connectz
    def test_cannot_create_invalid_line(self):

        """
        Test cannot create an invalid line
        with an empty cell list and invalid player
        """

        with self.assertRaises(ValueError):
            self.line_no_cells = Line([], 3)
コード例 #8
0
    def dowlnoad_index(self, download_index):
        log = logging.getLogger('DOWNLOAD')

        def cb(x, y):
            GLib.idle_add(self.parent.bar1, y / x)

        to_download = self.remote_index.exclude('/Cache.Windows/')
        GLib.idle_add(self.parent.bar2,
                      1 - download_index.size / to_download.size)

        for file in sorted(download_index, key=lambda x: x.size):
            local = Line(str(file))
            local.prefix = self.local_index.prefix

            if self.kill_event.is_set():
                return

            GLib.idle_add(self.parent.status_label, 'Download: ' + file.path)

            file_dir = os.path.dirname(local.full_path)
            if not os.path.exists(file_dir):
                os.makedirs(file_dir)

            try:
                data = file.download(self.kill_event, cb)
            except Exception as e:
                log.error(f'Download error: {e}')
                continue
            if data:
                with open(local.full_path, 'wb+') as f:
                    f.write(data)

            if file not in self.local_index:
                self.local_index.add(file)
                self.local_index.to_file(index_local)

            download_index.remove(file)
            GLib.idle_add(self.parent.bar2,
                          1 - download_index.size / to_download.size)

        log.info('Download ended')
コード例 #9
0
ファイル: test_models.py プロジェクト: blancheta/connectz
    def test_can_return_matching_lines_for_cell(self):

        """
        Test can return a matching line for a cell
        """

        line = Line([
            self.cell1,
        ], 1)

        line2 = Line([
            self.cell3
        ], 1)

        self.game.lines = [line, line2]

        cell = Cell(1, 2, 1)

        matches = self.game.get_matching_lines_for_cell(cell)

        self.assertEqual(len(matches), 2)
コード例 #10
0
class Lines:
    """Contains all train lines"""
    def __init__(self):
        """Creates the Lines object"""
        self.red_line = Line("red")
        self.green_line = Line("green")
        self.blue_line = Line("blue")

    def process_message(self, message):
        """Processes a station message"""
        logger.info(
            f"processing message {message.topic()} with {message.value()}")

        #        if "org.chicago.cta.station" in message.topic():
        if "com.transitchicago.station" in message.topic():
            value = message.value()
            #            if message.topic() == "org.chicago.cta.stations.table.v1":
            if message.topic() == "com.transitchicago.stations.table":
                value = json.loads(value)
            if value["line"] == "green":
                self.green_line.process_message(message)
            elif value["line"] == "red":
                self.red_line.process_message(message)
            elif value["line"] == "blue":
                self.blue_line.process_message(message)
            else:
                logger.debug("discarding unknown line msg %s", value["line"])
コード例 #11
0
class Lines:
    """Contains all train lines"""
    def __init__(self):
        """Creates the Lines object"""
        self.red_line = Line("red")
        self.green_line = Line("green")
        self.blue_line = Line("blue")

    def process_message(self, message):
        """Processes a station message"""

        value = message.value()
        # Content might be JSON (as byte string) or AVRO (as dict)
        if isinstance(value, bytes):
            value = json.loads(message.value())

        # KSQL likes to uppercase things
        if "LINE" in value.keys():
            value["line"] = value.get("LINE")

        if value.get("line") == "green":
            self.green_line.process_message(message)
        elif value.get("line") == "red":
            self.red_line.process_message(message)
        elif value.get("line") == "blue":
            self.blue_line.process_message(message)
        else:
            raise Exception(f"unknown line msg {value}")
コード例 #12
0
    def __init__(self):
        '''
        Creates the Lines object
        '''

        self.red_line = Line('red')
        self.green_line = Line('green')
        self.blue_line = Line('blue')
コード例 #13
0
ファイル: pickett_io.py プロジェクト: kiraboris/holgersimple
    def str2line(str_line, int_fmt):
        """str to Line object"""

        obj_line = Line()
        obj_line.freq = float(str_line[36:51])
        obj_line.freq_err = float(str_line[51:60])

        obj_line.str_lin_text = str_line[60:-1]

        str_q = str_line[0:36]
        dict_qu, dict_ql = LinConverter.__read_quanta(str_q, int_fmt)

        obj_line.int_fmt = int_fmt
        obj_line.q_upper = dict_qu
        obj_line.q_lower = dict_ql

        return obj_line
コード例 #14
0
ファイル: test_models.py プロジェクト: blancheta/connectz
    def test_can_create_a_new_line_for_cells_matching(self):

        line = Line([
            self.cell1,
        ], 1)

        self.game.lines.append(line)

        lines_count = len(self.game.lines)

        self.game.col_counters = {
            3: 1
        }

        self.game.add_move_to_the_board(3)

        self.assertEqual(lines_count + 2, len(self.game.lines))
コード例 #15
0
class Lines:
    def __init__(self):
        self.red_line = Line("red")
        self.green_line = Line("green")
        self.blue_line = Line("blue")

    def process_message(self, message):
        if "org.chicago.cta.station" in message.topic():
            value = message.value()
            if message.topic() == "org.chicago.cta.stations.table.v1":
                value = json.loads(value)
            if value["line"] == "green":
                self.green_line.process_message(message)
            elif value["line"] == "red":
                self.red_line.process_message(message)
            elif value["line"] == "blue":
                self.blue_line.process_message(message)
            else:
                logger.debug("discarding unknown line msg %s", value["line"])
        elif "TURNSTILE_SUMMARY" == message.topic():
            self.green_line.process_message(message)
            self.red_line.process_message(message)
            self.blue_line.process_message(message)
        else:
            logger.info("ignoring non-lines message %s", message.topic())
コード例 #16
0
 def __init__(self):
     self.red_line = Line("red")
     self.green_line = Line("green")
     self.blue_line = Line("blue")
コード例 #17
0
ファイル: lines.py プロジェクト: sheu/udacity
class Lines:
    """Contains all train lines"""
    def __init__(self, name="Default"):
        """Creates the Lines object"""
        self.red_line = Line("red")
        self.green_line = Line("green")
        self.blue_line = Line("blue")
        self.name = name

    def process_message(self, message):
        # print(f"Processing message from topic: {self.name}")

        if "org.chicago.cta.station" in message.topic():
            value = message.value()
            if message.topic() == "org.chicago.cta.stations.table.v1":
                value = json.loads(value)
            if value["line"] == "green":
                self.green_line.process_message(message)
            elif value["line"] == "red":
                self.red_line.process_message(message)
            elif value["line"] == "blue":
                self.blue_line.process_message(message)
            else:
                logger.debug("discarding unknown line msg %s", value["line"])
        elif message.topic() == "TURNSTILE_SUMMARY_STREAM":
            self.green_line.process_message(message)
            self.red_line.process_message(message)
            self.blue_line.process_message(message)
        else:
            print(f"ignoring non-lines message {message.topic()}")
コード例 #18
0
 def __init__(self):
     """Creates the Lines object"""
     self._lines = [Line('red'), Line('green'), Line('blue')]
コード例 #19
0
from models import Track, Line, Point
from dateutil import parser

example_track = Track(
    start_date=parser.parse("2010-01-01"), end_date=parser.parse("2020-01-01")
)
example_track.lines.append(Line(point_a=Point(x=-10, y=20), point_b=Point(x=50, y=25)))
コード例 #20
0
class Lines:
    """Contains all train lines"""
    def __init__(self):
        """Creates the Lines object"""
        self.red_line = Line("red")
        self.green_line = Line("green")
        self.blue_line = Line("blue")

    def process_message(self, message):
        """Processes a station message"""
        if "cta.trains.monitor.stations" in message.topic():
            value = message.value()
            if message.topic() == "cta.trains.monitor.stations.transformed":
                value = json.loads(value)
            if value["line"] == "green":
                self.green_line.process_message(message)
            elif value["line"] == "red":
                self.red_line.process_message(message)
            elif value["line"] == "blue":
                self.blue_line.process_message(message)
            else:
                logger.debug("discarding unknown line msg %s", value["line"])
        elif "cta.trains.monitor.turnstile.summarized" == message.topic():
            self.green_line.process_message(message)
            self.red_line.process_message(message)
            self.blue_line.process_message(message)
        else:
            logger.info("ignoring non-lines message %s", message.topic())
コード例 #21
0
class Lines:
    """Contains all train lines"""
    def __init__(self):
        """Creates the Lines object"""
        self.red_line = Line("red")
        self.green_line = Line("green")
        self.blue_line = Line("blue")

    def process_message(self, message):
        """Processes a station message"""
        #logger.info("processing lines logger")
        print("processing lines", message.topic())
        if "org.chicago.cta.station" in message.topic():
            value = message.value()
            if message.topic() == "org.chicago.cta.stations.table.v1":
                value = json.loads(value)
            if value["line"] == "green":
                self.green_line.process_message(message)
            elif value["line"] == "red":
                self.red_line.process_message(message)
            elif value["line"] == "blue":
                self.blue_line.process_message(message)
            else:
                logger.debug("discarding unknown line msg %s", value["line"])
        elif "TURNSTILE_SUMMARY" == message.topic():
            self.green_line.process_message(message)
            self.red_line.process_message(message)
            self.blue_line.process_message(message)
        else:
            logger.info("ignoring non-lines message %s", message.topic())
コード例 #22
0
ファイル: lines.py プロジェクト: mluc/udacity-data-streaming
class Lines:
    """Contains all train lines"""

    def __init__(self):
        """Creates the Lines object"""
        self.red_line = Line("red")
        self.green_line = Line("green")
        self.blue_line = Line("blue")

    def process_message(self, message):
        """Processes a station message"""
        logger.info("consumer lines process_message")
        print("consumer lines process_message")
        if "org.chicago.cta.station" in message.topic():
            value = message.value()
            if message.topic() == constants.STATION_FAUST_TABLE_TOPIC:
                value = json.loads(value)
            if value["line"] == "green":
                self.green_line.process_message(message)
            elif value["line"] == "red":
                self.red_line.process_message(message)
            elif value["line"] == "blue":
                self.blue_line.process_message(message)
            else:
                logger.debug("discarding unknown line msg %s", value["line"])
        elif constants.TURNSTILE_SUMMARY_TOPIC == message.topic():
            self.green_line.process_message(message)
            self.red_line.process_message(message)
            self.blue_line.process_message(message)
        else:
            logger.info("ignoring non-lines message %s", message.topic())
コード例 #23
0
class Lines:
    """Contains all train lines"""
    def __init__(self):
        """Creates the Lines object"""
        self.red_line = Line("red")
        self.green_line = Line("green")
        self.blue_line = Line("blue")

    def process_message(self, message):
        """Processes a station message"""
        topic: str = message.topic()
        if topic.startswith(CtaTopics.ARRIVALS_PREFIX) or topic in [
                CtaTopics.TURNSTILES,
                CtaTopics.STATIONS,
                CtaTopics.STATIONS_LINE,
        ]:
            value = message.value()
            if topic == CtaTopics.STATIONS_LINE:
                value = json.loads(value)
            if value["line"] == "green":
                self.green_line.process_message(message)
            elif value["line"] == "red":
                self.red_line.process_message(message)
            elif value["line"] == "blue":
                self.blue_line.process_message(message)
            else:
                logger.debug("discarding unknown line msg %s", value["line"])
        elif topic == CtaTopics.TURNSTILES_SUMMARY:
            self.green_line.process_message(message)
            self.red_line.process_message(message)
            self.blue_line.process_message(message)
        else:
            logger.info("ignoring non-lines message %s", message.topic())
コード例 #24
0
class Lines:
    """Contains all train lines"""
    def __init__(self):
        """Creates the Lines object"""
        self.red_line = Line("red")
        self.green_line = Line("green")
        self.blue_line = Line("blue")

    def process_message(self, message):
        """Processes a station message"""
        if "station" in message.topic():
            value = message.value()
            if message.topic(
            ) == "nanodegre.kafka.connect.transformed-stations":
                value = json.loads(value)
            if value["line"] == "green":
                self.green_line.process_message(message)
            elif value["line"] == "red":
                self.red_line.process_message(message)
            elif value["line"] == "blue":
                self.blue_line.process_message(message)
            else:
                logger.debug("discarding unknown line msg %s", value["line"])
        elif "TURNSTILE_SUMMARY" == message.topic():
            self.green_line.process_message(message)
            self.red_line.process_message(message)
            self.blue_line.process_message(message)
        else:
            logger.info("ignoring non-lines message %s", message.topic())
コード例 #25
0
 def __init__(self):
     """Creates the Lines object"""
     logger.info(f'in lines init')
     self.red_line = Line("red")
     self.green_line = Line("green")
     self.blue_line = Line("blue")
コード例 #26
0
ファイル: lines.py プロジェクト: entusias/udacity-dsnd-cta
class Lines:
    """Contains all train lines"""
    def __init__(self):
        """Creates the Lines object"""
        self.red_line = Line("red")
        self.green_line = Line("green")
        self.blue_line = Line("blue")

    def process_message(self, message):
        """Processes a station message"""
        if "org.chicago.cta.station" in message.topic():
            value = message.value()
            if message.topic(
            ) == "org.chicago.cta.stations.table.v1":  # message is from faust processed station topic
                value = json.loads(value)
            if value["line"] == "green":
                self.green_line.process_message(message)
            elif value["line"] == "red":
                self.red_line.process_message(message)
            elif value["line"] == "blue":
                self.blue_line.process_message(message)
            else:
                logger.debug(f'Discarding unknown line msg {value["line"]}')
        elif "TURNSTILE_SUMMARY" == message.topic(
        ):  # message is from KSQL topic
            self.green_line.process_message(message)
            self.red_line.process_message(message)
            self.blue_line.process_message(message)
        else:  # message is not from a org.chicago.cta.station topic
            logger.debug(
                f"message topic {message.topic()} not in org.chicago.cta.station. Ignoring message."
            )
コード例 #27
0
ファイル: test_models.py プロジェクト: blancheta/connectz
class TestsLineModel(TestCase):

    """
    Test Line model and its methods
    """

    def setUp(self):

        self.cell1 = Cell(1, 1, 0)
        self.cell2 = Cell(1, 1, 1)

        self.line = Line([
            self.cell1,
            self.cell2
        ], 1)

    def test_can_create_a_valid_line(self):

        """
        Test can create a valid line
        """

        self.assertIsInstance(self.line, Line)

    def test_cannot_create_invalid_line(self):

        """
        Test cannot create an invalid line
        with an empty cell list and invalid player
        """

        with self.assertRaises(ValueError):
            self.line_no_cells = Line([], 3)

    def test_can_add_a_cell_to_a_line(self):

        """
        Test can add a cell to a line and increment count for line cells
        """

        cells_count = len(self.line.cells)

        self.line.add(Cell(1, 1, 2))

        self.assertEqual(cells_count + 1, len(self.line.cells))
        self.assertEqual(self.line.cells_count, len(self.line.cells))

    def test_can_check_if_cell_is_in_line(self):

        """
        Test can return True if cell in current line else False
        """

        self.assertTrue(
            self.line.contains_cell(self.cell1)
        )

    def test_can_increment_cells_count(self):

        """
        Test can increment the cell count for the line
        """

        initial_cells_count = self.line.cells_count

        self.line.increment_counter()
        self.assertEqual(initial_cells_count + 1, self.line.cells_count)

    def test_can_return_a_formatted_repr_for_object(self):
        self.assertEqual(self.line.__repr__(), "Line : {}".format(
            self.line.cells
        ))

    def test_can_return_a_formatted_str_for_object(self):
        self.assertEqual(self.line.__str__(), "Line : {}".format(
            self.line.cells
        ))
コード例 #28
0
ファイル: pickett_io.py プロジェクト: kiraboris/holgersimple
    def str2line(str_line):
        """str to Line object"""

        obj_line = Line()

        obj_line.freq = float(str_line[0:13])
        obj_line.freq_err = float(str_line[13:21])

        obj_line.log_I = float(str_line[21:29])
        obj_line.int_deg_freedom = int(str_line[29:31])

        obj_line.E = float(str_line[31:41])
        obj_line.g = int(CatConverter.__decode_quant(str_line[41:44]))

        obj_line.int_cat_tag = int(str_line[44:51])

        str_q = str_line[55:79]
        int_fmt = int(str_line[51:55])
        dict_qu, dict_ql = CatConverter.__read_quanta(str_q, int_fmt)

        obj_line.q_upper = dict_qu
        obj_line.q_lower = dict_ql
        obj_line.int_fmt = int_fmt

        return obj_line
コード例 #29
0
from models import Point, Line, LineType
import settings

starting_lines = [
    Line(
        point_a=Point(x=-5, y=settings.STARTING_AREA_Y),
        point_b=Point(x=settings.STARTING_AREA_X, y=settings.STARTING_AREA_Y),
        type=LineType.ACCELERATION,
    )
]
コード例 #30
0
 def __init__(self):
     """Creates the Lines object"""
     self.red_line = Line("red")
     self.green_line = Line("green")
     self.blue_line = Line("blue")
コード例 #31
0
class Lines:
    """Contains all train lines"""

    def __init__(self):
        """Creates the Lines object"""
        self.red_line = Line("red")
        self.green_line = Line("green")
        self.blue_line = Line("blue")

    def process_message(self, message):
        """Processes a station message"""
        
        if "station_topic" in message.topic():
            value = message.value()
            if message.topic() == "SQL_stations_transformed":
                value = json.loads(value)
                logger.info(f"{message.topic()} processed in lines for color {value['line']}")
            if value["line"] == "green":
                self.green_line.process_message(message)
                logger.info(f"{message.topic()} processed in lines for color {value['line']}")
            elif value["line"] == "red":
                self.red_line.process_message(message)
                logger.info(f"{message.topic()} processed in lines for color {value['line']}")
            elif value["line"] == "blue":
                self.blue_line.process_message(message)
                logger.info(f"{message.topic()} processed in lines for color {value['line']}")
            else:
                logger.debug("discarding unknown line msg %s", value["line"])
        elif "TURNSTILE_SUMMARY" == message.topic():
            self.green_line.process_message(message)
            logger.info(f"{message.topic()} processed in lines for color green")
            self.red_line.process_message(message)
            logger.info(f"{message.topic()} processed in lines for color red")
            self.blue_line.process_message(message)
            logger.info(f"{message.topic()} processed in lines for color blue")
        else:
            logger.info("ignoring non-lines message %s", message.topic())
コード例 #32
0
    def create(line_id, site_id, line_name):
        line = Line(line_id=line_id, site_id=site_id, line_name=line_name)

        return line.save()
コード例 #33
0
#!/usr/bin/env python3
from models import Station, Stop, Line, coordinates_to_geography
from datetime import datetime
from shapely import wkt
from shapely.geometry import LineString

import pytz

stations_instances = Station.get_stations()
stations_dict = Station.all_stations
line_instances = Line.get_lines()
lines_dict = Line.all_lines

TIMEZONE = pytz.timezone("Europe/Berlin")

#for line in line_instances:
#    if not line.name.startswith('U'):
#        continue
#    intersecting_lines = line.intersecting_lines()
#    print(f'** Line: {line.name}**')
#    print(f'All stations: {[x.name for x in line.stations_set]}')
#    print('Intersecting:')
#    for line_id in intersecting_lines:
#        line = lines_dict[line_id]
#        print(f' -- {line.name}:')
#        for station in intersecting_lines[line_id]:
#            print(f' -- -- {station.name}')

BERLIN_CENTER = coordinates_to_geography(
    wkt.loads(
        'POLYGON((13.397554705226526 52.55577511250286,13.34399635561715 52.53990827773609,13.277735064113244 52.53092844861436,13.274988482081994 52.49749899889902,13.312753985011682 52.476174448880776,13.427258835295106 52.457571347161775,13.475324020841981 52.47116746155413,13.487059832063096 52.509231759524376,13.480193376984971 52.53555255182724,13.436248064484971 52.55559590471181,13.397554705226526 52.55577511250286))'