nightr/server/nightr/util.py
Casper V. Kristensen 319c03067f
Reasons and battery.
2019-04-06 23:00:08 +02:00

34 lines
919 B
Python

import base64
from dataclasses import dataclass, field
from pathlib import Path
from typing import List, Dict
import cv2
import numpy as np
@dataclass
class Context:
battery: int = 55
position: Dict[str, float] = field(default_factory=lambda: {'latitude': 53.0, 'longitude': 9.0}) # Denmark somewhere
image: np.ndarray = None
# App settings
in_australia: bool = False
flat_earth: bool = False
def __post_init__(self):
if self.image is None: # no image given
self.image = cv2.imread(str(Path(__file__).parent.joinpath("gray.png")))
else:
img_original = base64.b64decode(self.image)
img_as_np = np.frombuffer(img_original, dtype=np.uint8)
self.image = cv2.imdecode(img_as_np, flags=1)
@dataclass
class Prediction:
probability: float = 0.5
weight: float = 1.0
reasons: List[str] = field(default_factory=list)