diff --git a/project/api/management/commands/actualiza_GTFS.sql b/project/api/management/commands/actualiza_GTFS.sql index 2121d0d..97ea2f9 100644 --- a/project/api/management/commands/actualiza_GTFS.sql +++ b/project/api/management/commands/actualiza_GTFS.sql @@ -283,7 +283,7 @@ if v_error = '' THEN ----- insert into gtfs_shape - select shape_id::numeric,shape_pt_lat::float8,shape_pt_lon::float8, + select shape_id,shape_pt_lat::float8,shape_pt_lon::float8, shape_pt_sequence::numeric,shape_dist_traveled::float8 from z_shapes zs; @@ -305,7 +305,7 @@ if v_error = '' THEN select trip_id, trim(route_id)||'-'||trim(direction_id::varchar) as route_id, - shape_id::numeric ,null as regreso, trip_headsign,trip_short_name,direction_id::numeric,service_id::varchar,block_id + shape_id ,null as regreso, trip_headsign,trip_short_name,direction_id::numeric,service_id::varchar,block_id from z_trips zt; ----- diff --git a/project/api/models.py b/project/api/models.py index 8f9dabc..4111dd5 100755 --- a/project/api/models.py +++ b/project/api/models.py @@ -98,7 +98,7 @@ class GtfsRouteType(models.Model): class GtfsShape(models.Model): - id_shape = models.DecimalField(max_digits=18, decimal_places=0) + id_shape = models.CharField(max_length=150) shape_pt_lat = models.FloatField(blank=True, null=True) shape_pt_lon = models.FloatField(blank=True, null=True) shape_pt_sequence = models.IntegerField(blank=True, null=True) @@ -132,7 +132,7 @@ class GtfsStopTimes(models.Model): class GtfsTrips(models.Model): id_trip = models.CharField(primary_key=True, max_length=150) id_linea = models.CharField(max_length=150, blank=True, null=True) - id_shape = models.IntegerField(blank=True, null=True) + id_shape = models.CharField(max_length=150,blank=True, null=True) id_trip_regreso = models.ForeignKey('self', models.DO_NOTHING, db_column='id_trip_regreso', blank=True, null=True) trip_headsign = models.CharField(max_length=100, blank=True, null=True) trip_short_name = models.CharField(max_length=100, blank=True, null=True) diff --git a/project/api/views/linea.py b/project/api/views/linea.py index 5e3f1b8..710f2f4 100755 --- a/project/api/views/linea.py +++ b/project/api/views/linea.py @@ -239,7 +239,7 @@ class LineaViewSet(viewsets.ModelViewSet): @action(detail=False, methods=['get']) - def count_buses_recorridos(self, request, pk=None): + def count_buses_recorridos_old(self, request, pk=None): query = "select count(distinct vehicle_license_plate) from gtfs_posiciones" with connection.cursor() as cursor: @@ -247,4 +247,19 @@ class LineaViewSet(viewsets.ModelViewSet): result = cursor.fetchone() return JsonResponse({ 'count': result[0] }) + + @action(detail=False, methods=['get']) + def count_buses_recorridos(self, request, pk=None): + + db_host = getenv('DB_REDIS_HOST') + db_port = getenv('DB_REDIS_PORT') + r = redis.Redis(host=db_host, port=db_port, decode_responses=True) + key = f'stop_id:none' + data = r.get(key) + data = json.loads(data) + unique_vehicle_plates = set(item["vehicle_license_plate"] for item in data) + count_unique_vehicle_plates = len(unique_vehicle_plates) + return JsonResponse({ 'count': count_unique_vehicle_plates }) + + \ No newline at end of file