-
-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
model models and added simple entity cache
- Loading branch information
Matthew Webster
committed
Sep 8, 2020
1 parent
5b916f8
commit a1f94c7
Showing
10 changed files
with
379 additions
and
134 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
from typing import List, Optional | ||
import datetime | ||
from enum import Enum | ||
|
||
from pydantic import BaseModel, validator | ||
from pydantic.dataclasses import dataclass | ||
|
||
|
||
class Bounds(BaseModel): | ||
north: float | ||
south: float | ||
east: float | ||
west: float | ||
|
||
|
||
class Filter(BaseModel): | ||
startDate: str | ||
endDate: str | ||
ncList: List[int] | ||
requestTypes: List[str] | ||
zoom: Optional[int] = None | ||
bounds: Optional[Bounds] = None | ||
|
||
@validator('startDate', 'endDate') | ||
def parse_date(cls, v): | ||
if isinstance(v, str): | ||
try: | ||
v = datetime.datetime.strptime(v, '%m/%d/%Y') | ||
except ValueError: | ||
try: | ||
v = datetime.datetime.strptime(v, '%Y-%m-%d') | ||
except ValueError: | ||
pass | ||
return v | ||
|
||
|
||
class Pin(BaseModel): | ||
srnumber: str | ||
requesttype: str | ||
latitude: float | ||
longitude: float | ||
|
||
|
||
class Cluster(BaseModel): | ||
count: int | ||
expansion_zoom: Optional[int] | ||
id: int | ||
latitude: float | ||
longitude: float | ||
|
||
|
||
@dataclass | ||
class Set: | ||
district: str | ||
list: List[int] | ||
|
||
@validator('district') | ||
def district_is_valid(cls, v): | ||
assert v in ['cc', 'nc'], 'district must be either "nc" or "cc".' | ||
return v | ||
|
||
def __getitem__(cls, item): | ||
return getattr(cls, item) | ||
|
||
|
||
class Comparison(BaseModel): | ||
startDate: str | ||
endDate: str | ||
requestTypes: List[str] | ||
set1: Set | ||
set2: Set | ||
|
||
|
||
class Feedback(BaseModel): | ||
title: str | ||
body: str | ||
|
||
|
||
class StatusTypes(str, Enum): | ||
api = "api" | ||
database = "db" | ||
system = "sys" | ||
|
||
|
||
Pins = List[Pin] | ||
Clusters = List[Cluster] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,12 @@ | ||
from fastapi import APIRouter | ||
|
||
from .utilities import build_cache | ||
from ..config import cache | ||
|
||
router = APIRouter() | ||
|
||
|
||
@router.get("/") | ||
async def index(): | ||
return {"message": "Hello, new index!"} | ||
await build_cache() | ||
return cache |
Oops, something went wrong.