Skip to content

Commit

Permalink
Remove dead code
Browse files Browse the repository at this point in the history
  • Loading branch information
Robert Lucey committed Aug 5, 2023
1 parent d2c8490 commit e85e9b9
Show file tree
Hide file tree
Showing 17 changed files with 5 additions and 468 deletions.
2 changes: 1 addition & 1 deletion src/via/api/main.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from typing import List, Optional, Union
from fastapi import FastAPI, Query
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware

from pydantic import BaseModel
Expand Down
37 changes: 1 addition & 36 deletions src/via/bounding_graph_gdfs_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,38 +6,7 @@
from gridfs import GridFS

from via.utils import get_mongo_interface
from via.settings import (
GRIDFS_BOUNDING_GRAPH_GDFS_GRAPH_FILENAME_PREFIX,
GRIDFS_UTILS_BOUNDING_GRAPH_GDFS_GRAPH_FILENAME_PREFIX,
)


class UtilsBoundingGraphGDFSGraphs:
def __init__(self):
self.mongo_interface = get_mongo_interface()
self.grid = GridFS(self.mongo_interface)

@staticmethod
def get_filename(key):
return f"{GRIDFS_UTILS_BOUNDING_GRAPH_GDFS_GRAPH_FILENAME_PREFIX}_{key}"

@ttl_cache(maxsize=50, ttl=360)
def get_from_gridfs(self, key):
return pickle.loads(
self.grid.find_one({"filename": self.get_filename(key)}).read()
)

def get(self, key: Any):
if self.grid.find_one({"filename": get_filename(key)}):
return self.get_from_gridfs(key)

return None

def set(self, key: Any, value: Any):
if self.get(key):
return

self.grid.put(pickle.dumps(value), filename=self.get_filename(key))
from via.settings import GRIDFS_BOUNDING_GRAPH_GDFS_GRAPH_FILENAME_PREFIX


class BoundingGraphGDFSGraphs:
Expand All @@ -56,8 +25,6 @@ def get_from_gridfs(self, key):
)

def get(self, key: Any):
filename = f"bounding_graph_gdfs_graph_{key}"

if self.grid.find_one({"filename": self.get_filename(key)}):
return self.get_from_gridfs(key)

Expand All @@ -71,5 +38,3 @@ def set(self, key: Any, value: Any):


bounding_graph_gdfs_cache = BoundingGraphGDFSGraphs()

utils_bounding_graph_gdfs_cache = UtilsBoundingGraphGDFSGraphs()
2 changes: 0 additions & 2 deletions src/via/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
else "/tmp/log/via/via.log"
)

POLY_POINT_BUFFER = 0.002

USELESS_GEOJSON_PROPERTIES = {
"oneway",
"length",
Expand Down
33 changes: 0 additions & 33 deletions src/via/geojson/utils.py
Original file line number Diff line number Diff line change
@@ -1,42 +1,9 @@
import datetime
import urllib
from packaging.version import Version
import dateutil.parser

import shapely
from networkx.readwrite import json_graph

from via.constants import USELESS_GEOJSON_PROPERTIES


def parse_start_date(earliest_date: str) -> str:
if earliest_date is None:
raise ValueError("earliest_date cannot be None")

if isinstance(earliest_date, str):
earliest_date = dateutil.parser.parse(earliest_date)
elif isinstance(earliest_date, datetime.date):
earliest_date = datetime.datetime.combine(
earliest_date, datetime.datetime.min.time()
)

return str(earliest_date.date())


def parse_end_date(latest_date: str) -> str:
if latest_date is None:
raise ValueError("latest_date cannot be None")

if isinstance(latest_date, str):
latest_date = dateutil.parser.parse(latest_date)
elif isinstance(latest_date, datetime.date):
latest_date = datetime.datetime.combine(
latest_date, datetime.datetime.min.time()
)

return str(latest_date.date())


def geojson_from_graph(graph, must_include_props: list = None) -> dict:
json_links = json_graph.node_link_data(graph)["links"]

Expand Down
94 changes: 0 additions & 94 deletions src/via/models/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,102 +39,8 @@ def distance_from(self, point: GPSPoint) -> float:
point = point.gps
return self.gps.distance_from(point)

@property
def is_complete(self) -> bool:
"""
Does the frame contain all expected data
"""
return (
isinstance(self.time, float)
and self.gps.is_populated
and self.acceleration != []
)

def serialize(self, **kwargs) -> dict:
data = {"gps": self.gps.serialize(), "acc": self.acceleration}
if kwargs.get("include_time", True):
data["time"] = round(self.time, 2)
return data


class Frames(GenericObjects):
def __init__(self, *args, **kwargs):
kwargs.setdefault("child_class", Frame)
super().__init__(*args, **kwargs)

@property
def most_northern(self) -> float:
return max([frame.gps.lat for frame in self])

@property
def most_southern(self) -> float:
return min([frame.gps.lat for frame in self])

@property
def most_eastern(self) -> float:
return max([frame.gps.lng for frame in self])

@property
def most_western(self) -> float:
return min([frame.gps.lng for frame in self])

@property
def data_quality(self) -> float:
"""
Get the percentage of frames that are good. Should
automatically disregard journeys with low data quality
:rtype: float
:return: The percent between 0 and 1
"""
# Mixed with the deviation between times?
return len([f for f in self if f.is_complete]) / float(len(self))

@property
def origin(self) -> Frame:
"""
The first frame of the journey
:rtype: via.models.Frame
:return: The first frame of the journey
"""
return self[0]

@property
def destination(self) -> Frame:
"""
The last frame of the journey
:rtype: via.models.Frame
:return: The last frame of the journey
"""
return self[-1]

@property
def duration(self) -> float:
"""
Get the time in seconds
Note that much of the start and end may have been removed.
:rtype: float
:return: The number of seconds the journey took
"""
if self.destination.time is None or self.origin.time is None:
return None
return self.destination.time - self.origin.time

@property
def direct_distance(self) -> float:
"""
Get the distance in metres as the crow flies
Note that much of the start and end may have been removed.
:rtype: float
:return: distance from origin to destination in metres
"""
return self[0].distance_from(self[-1])

def serialize(self, include_time: bool = True) -> list:
return [frame.serialize(include_time=include_time) for frame in self]
45 changes: 0 additions & 45 deletions src/via/models/journey.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,14 @@
from dateutil.parser import parse

from cached_property import cached_property
import geopandas as gpd

from shapely.ops import cascaded_union

import networkx as nx
import osmnx as ox

from mappymatch.maps.nx.readers.osm_readers import (
NetworkType,
nx_graph_from_osmnx,
parse_osmnx_graph,
)
from mappymatch import package_root
from mappymatch.constructs.geofence import Geofence
from mappymatch.constructs.trace import Trace
from mappymatch.maps.nx.nx_map import NxMap
from mappymatch.matchers.lcss.lcss import LCSSMatcher
Expand All @@ -34,7 +28,6 @@
from via import logger
from via.utils import window, get_combined_id
from via.constants import (
POLY_POINT_BUFFER,
VALID_JOURNEY_MIN_DISTANCE,
VALID_JOURNEY_MIN_POINTS,
VALID_JOURNEY_MIN_DURATION,
Expand Down Expand Up @@ -476,37 +469,6 @@ def bbox(self) -> dict:
"west": self.most_western,
}

@property
def poly_graph(self):
"""
Get a graph of the journey but excluding nodes far away from the route
:rtype: networkx.classes.multidigraph.MultiDiGraph
"""

if network_cache.get("poly", self) is None:
logger.debug("poly > %s not found in cache, generating...", self.gps_hash)

# TODO: might want to not use polygon for this since we could
# get the benefits of using a parent bbox from the cache

# Maybe use city if possible and then truncate_graph_polygon
points = self.get_multi_points()

buf = points.buffer(POLY_POINT_BUFFER, cap_style=3)
boundary = gpd.GeoSeries(cascaded_union(buf))

network = ox.graph_from_polygon(
boundary.geometry[0], network_type=self.network_type, simplify=True
)

# TODO: might want to merge our edge_quality_data with
# edge data here

network_cache.set("poly", self, network)

return network_cache.get("poly", self)

@property
def graph(self):
"""
Expand Down Expand Up @@ -540,13 +502,6 @@ def version(self):
return self._version
return version.parse(self._version)

@property
def region(self):
"""
Get the region name in which this journey started
"""
return self.origin.gps.reverse_geo["place_2"]

@property
def has_enough_data(self):
"""
Expand Down
9 changes: 0 additions & 9 deletions src/via/models/journeys.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
import statistics
import hashlib
import multiprocessing
from contextlib import closing
from collections import defaultdict
from typing import List

from networkx.classes.multidigraph import MultiDiGraph

from via.models.generic import GenericObjects
from via.models.journey import Journey
from via.utils import flatten
from via.models.journey_mixins import (
SnappedRouteGraphMixin,
GeoJsonMixin,
Expand Down Expand Up @@ -44,12 +41,6 @@ def edge_quality_map(self):
:rtype: dict
"""

# with multiprocessing.Pool(min([multiprocessing.cpu_count() - 1, 4])) as pool:
# journey_edge_quality_maps = pool.map(
# get_journey_edge_quality_map,
# self
# )

journey_edge_quality_maps = [get_journey_edge_quality_map(i) for i in self]

edge_quality_map = defaultdict(list)
Expand Down
Loading

0 comments on commit e85e9b9

Please sign in to comment.