feat: adding ruff linting support

This commit is contained in:
lucas.oskorep
2023-07-09 14:21:29 -04:00
parent 367e646be2
commit 914a698475
6 changed files with 19 additions and 21 deletions

4
.gitignore vendored
View File

@@ -122,4 +122,6 @@ venv.bak/
# mypy
.mypy_cache/
.dmypy.json
dmypy.jsons
dmypy.jsons
.ruff_cache

View File

@@ -1,3 +0,0 @@
from .mta import *
from .train import *
from .stop import *

View File

@@ -52,10 +52,10 @@ class MTA(object):
feed = gtfs_realtime_pb2.FeedMessage()
feed.ParseFromString(r.content)
subway_feed = protobuf_to_dict(feed)['entity']
trains.extend([train for train in [Train.get_train_from_dict(train_dict) for train_dict in subway_feed] if train is not None])
trains.extend([train for train in [Train.get_train_from_dict(train_dict) for train_dict in subway_feed] if
train is not None])
return trains
@staticmethod
def get_trains_for_routes(routes, trains):
return [train for train in trains if train.route in routes]
@@ -64,11 +64,8 @@ class MTA(object):
def get_trains_for_route(route, trains):
return MTA.get_trains_for_routes([route], trains)
async def get_train_information(self):
# Might need to not filter these trains.
valid_trains = [train for train in await self.get_data() if True]
# MTA.trains_arriving_at_stations(self.train_lines, self.station_ids, train, self.max_arrival_time)]
return valid_trains
async def _get_updates(self):
@@ -109,7 +106,8 @@ class MTA(object):
for station_id in self.station_ids:
line_first = {}
for route in self.routes:
valid_trains = [train.get_arrival_at(station_id) for train in MTA.get_trains_for_route(route, trains) if train.arriving_at_station_in_time(station_id, self.max_arrival_time)]
valid_trains = [train.get_arrival_at(station_id) for train in MTA.get_trains_for_route(route, trains) if
train.arriving_at_station_in_time(station_id, self.max_arrival_time)]
if valid_trains:
line_first[route] = valid_trains
if line_first:

View File

@@ -1,10 +1,7 @@
from datetime import datetime
from math import trunc
class Stop(object):
def __init__(self, id, arrival_time, departure_time, ):
self.id = id

View File

@@ -2,7 +2,7 @@ import os
from dotenv import load_dotenv
from mta_manager import MTA
import threading
import time
from time import sleep
from pprint import pprint
@@ -15,13 +15,15 @@ mtaController = MTA(
["127S", "127N", "A27N", "A27S"]
)
async def mta_callback(trains):
print("We are inside of the call back now")
print(len(trains))
pprint([str(route) for route in trains])
pprint(mtaController.get_time_arriving_at_stations(trains))
class threadWrapper(threading.Thread):
class Threadwrapper(threading.Thread):
def __init__(self, run):
threading.Thread.__init__(self)
self.run = run
@@ -29,21 +31,23 @@ class threadWrapper(threading.Thread):
def run(self):
self.run()
def start_mta():
mtaController.add_callback(mta_callback)
mtaController.start_updates()
def stop_mta():
sleep(10)
mtaController.stop_updates()
threadLock = threading.Lock()
threads = []
# Create new threads
thread1 = threadWrapper(start_mta)
thread2 = threadWrapper(stop_mta)
thread1 = Threadwrapper(start_mta)
thread2 = Threadwrapper(stop_mta)
thread1.start()
thread2.start()
@@ -54,5 +58,5 @@ threads.append(thread2)
# Wait for all threads to complete
for t in threads:
t.join()
print ("Exiting Main Thread")
t.join()
print("Exiting Main Thread")

View File

@@ -73,7 +73,7 @@ def get_routes():
@app.route("/get_stop_id", methods=["POST"])
def get_stop_id():
stop_name = request.json["stop_name"]
rows = stops.loc[stops["stop_name"] == stop_name]
stops.loc[stops["stop_name"] == stop_name]
return jsonify({"station_changed": True})