Spaces:
Sleeping
Sleeping
rmm
commited on
Commit
·
c45e52f
1
Parent(s):
52b2a06
fix: removed time from InputObservation, renamed date for clarity
Browse files- still some ambiguity with the names "date_option" and "time_option"
but the present change is more involved, while renaming those two
can happen after if valid
- src/input/input_observation.py +27 -23
src/input/input_observation.py
CHANGED
|
@@ -1,6 +1,11 @@
|
|
| 1 |
import hashlib
|
| 2 |
from input.input_validator import generate_random_md5
|
| 3 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
# autogenerated class to hold the input data
|
| 5 |
class InputObservation:
|
| 6 |
"""
|
|
@@ -15,10 +20,8 @@ class InputObservation:
|
|
| 15 |
The longitude where the observation was made.
|
| 16 |
author_email (str):
|
| 17 |
The email of the author of the observation.
|
| 18 |
-
|
| 19 |
-
The
|
| 20 |
-
time (Any): # FIXME: specify the type
|
| 21 |
-
The time when the observation was made.
|
| 22 |
date_option (datetime.date):
|
| 23 |
Additional date option for the observation.
|
| 24 |
time_option (datetime.time):
|
|
@@ -51,7 +54,9 @@ class InputObservation:
|
|
| 51 |
|
| 52 |
def __init__(
|
| 53 |
self, image:ndarray=None, latitude:float=None, longitude:float=None,
|
| 54 |
-
author_email:str=None,
|
|
|
|
|
|
|
| 55 |
time_option:datetime.time=None,
|
| 56 |
uploaded_file:UploadedFile=None, image_md5:str=None):
|
| 57 |
|
|
@@ -59,8 +64,8 @@ class InputObservation:
|
|
| 59 |
self.latitude = latitude
|
| 60 |
self.longitude = longitude
|
| 61 |
self.author_email = author_email
|
| 62 |
-
self.
|
| 63 |
-
self.time = time
|
| 64 |
self.date_option = date_option
|
| 65 |
self.time_option = time_option
|
| 66 |
self.uploaded_file = uploaded_file
|
|
@@ -70,7 +75,10 @@ class InputObservation:
|
|
| 70 |
InputObservation._inst_count += 1
|
| 71 |
self._inst_id = InputObservation._inst_count
|
| 72 |
|
| 73 |
-
|
|
|
|
|
|
|
|
|
|
| 74 |
|
| 75 |
|
| 76 |
def set_top_predictions(self, top_predictions:list):
|
|
@@ -98,7 +106,7 @@ class InputObservation:
|
|
| 98 |
_im_str = "None" if self.image is None else f"image dims: {self.image.shape}"
|
| 99 |
return (
|
| 100 |
f"Observation: {_im_str}, {self.latitude}, {self.longitude}, "
|
| 101 |
-
f"{self.author_email}, {self.
|
| 102 |
f"{self.time_option}, {self.uploaded_file}, {self.image_md5}"
|
| 103 |
)
|
| 104 |
|
|
@@ -110,8 +118,8 @@ class InputObservation:
|
|
| 110 |
f"Latitude: {self.latitude}, "
|
| 111 |
f"Longitude: {self.longitude}, "
|
| 112 |
f"Author Email: {self.author_email}, "
|
| 113 |
-
f"
|
| 114 |
-
f"Time: {self.time}, "
|
| 115 |
f"Date Option: {self.date_option}, "
|
| 116 |
f"Time Option: {self.time_option}, "
|
| 117 |
f"Uploaded Filename: {self.uploaded_file}"
|
|
@@ -133,7 +141,8 @@ class InputObservation:
|
|
| 133 |
self.latitude == other.latitude and
|
| 134 |
self.longitude == other.longitude and
|
| 135 |
self.author_email == other.author_email and
|
| 136 |
-
self.
|
|
|
|
| 137 |
self.date_option == other.date_option and
|
| 138 |
# temporarily skip time_option, it is followed by the clock and that is always differnt
|
| 139 |
#self.time_option == other.time_option and
|
|
@@ -162,10 +171,8 @@ class InputObservation:
|
|
| 162 |
differences.append(f" Longitude is different. (self: {self.longitude}, other: {other.longitude})")
|
| 163 |
if self.author_email != other.author_email:
|
| 164 |
differences.append(f" Author email is different. (self: {self.author_email}, other: {other.author_email})")
|
| 165 |
-
if self.
|
| 166 |
-
differences.append(f" Date is different. (self: {self.
|
| 167 |
-
if self.time != other.time:
|
| 168 |
-
differences.append(f" Time is different. (self: {self.time}, other: {other.time})")
|
| 169 |
if self.date_option != other.date_option:
|
| 170 |
differences.append(f" Date option is different. (self: {self.date_option}, other: {other.date_option})")
|
| 171 |
if self.time_option != other.time_option:
|
|
@@ -194,11 +201,10 @@ class InputObservation:
|
|
| 194 |
"latitude": self.latitude,
|
| 195 |
"longitude": self.longitude,
|
| 196 |
"author_email": self.author_email,
|
| 197 |
-
"
|
| 198 |
-
"time": self.time,
|
| 199 |
"date_option": str(self.date_option),
|
| 200 |
"time_option": str(self.time_option),
|
| 201 |
-
"uploaded_file": self.uploaded_file
|
| 202 |
}
|
| 203 |
|
| 204 |
@classmethod
|
|
@@ -208,8 +214,7 @@ class InputObservation:
|
|
| 208 |
latitude=data.get("latitude"),
|
| 209 |
longitude=data.get("longitude"),
|
| 210 |
author_email=data.get("author_email"),
|
| 211 |
-
|
| 212 |
-
time=data.get("time"),
|
| 213 |
date_option=data.get("date_option"),
|
| 214 |
time_option=data.get("time_option"),
|
| 215 |
uploaded_file=data.get("uploaded_file"),
|
|
@@ -223,8 +228,7 @@ class InputObservation:
|
|
| 223 |
latitude=input.latitude,
|
| 224 |
longitude=input.longitude,
|
| 225 |
author_email=input.author_email,
|
| 226 |
-
|
| 227 |
-
time=input.time,
|
| 228 |
date_option=input.date_option,
|
| 229 |
time_option=input.time_option,
|
| 230 |
uploaded_file=input.uploaded_file,
|
|
|
|
| 1 |
import hashlib
|
| 2 |
from input.input_validator import generate_random_md5
|
| 3 |
|
| 4 |
+
from numpy import ndarray
|
| 5 |
+
from streamlit.runtime.uploaded_file_manager import UploadedFile
|
| 6 |
+
import datetime
|
| 7 |
+
|
| 8 |
+
|
| 9 |
# autogenerated class to hold the input data
|
| 10 |
class InputObservation:
|
| 11 |
"""
|
|
|
|
| 20 |
The longitude where the observation was made.
|
| 21 |
author_email (str):
|
| 22 |
The email of the author of the observation.
|
| 23 |
+
image_datetime_raw (str):
|
| 24 |
+
The datetime extracted from the observation file
|
|
|
|
|
|
|
| 25 |
date_option (datetime.date):
|
| 26 |
Additional date option for the observation.
|
| 27 |
time_option (datetime.time):
|
|
|
|
| 54 |
|
| 55 |
def __init__(
|
| 56 |
self, image:ndarray=None, latitude:float=None, longitude:float=None,
|
| 57 |
+
author_email:str=None, image_datetime_raw:str=None,
|
| 58 |
+
#time=None,
|
| 59 |
+
date_option:datetime.date=None,
|
| 60 |
time_option:datetime.time=None,
|
| 61 |
uploaded_file:UploadedFile=None, image_md5:str=None):
|
| 62 |
|
|
|
|
| 64 |
self.latitude = latitude
|
| 65 |
self.longitude = longitude
|
| 66 |
self.author_email = author_email
|
| 67 |
+
self.image_datetime_raw = image_datetime_raw
|
| 68 |
+
#self.time = time
|
| 69 |
self.date_option = date_option
|
| 70 |
self.time_option = time_option
|
| 71 |
self.uploaded_file = uploaded_file
|
|
|
|
| 75 |
InputObservation._inst_count += 1
|
| 76 |
self._inst_id = InputObservation._inst_count
|
| 77 |
|
| 78 |
+
|
| 79 |
+
#dbg - temporarily give up if hash is not provided
|
| 80 |
+
if self.image_md5 is None:
|
| 81 |
+
raise ValueError(f"Image MD5 hash is required - {self._inst_id:3}.")
|
| 82 |
|
| 83 |
|
| 84 |
def set_top_predictions(self, top_predictions:list):
|
|
|
|
| 106 |
_im_str = "None" if self.image is None else f"image dims: {self.image.shape}"
|
| 107 |
return (
|
| 108 |
f"Observation: {_im_str}, {self.latitude}, {self.longitude}, "
|
| 109 |
+
f"{self.author_email}, {self.image_datetime_raw}, {self.date_option}, "
|
| 110 |
f"{self.time_option}, {self.uploaded_file}, {self.image_md5}"
|
| 111 |
)
|
| 112 |
|
|
|
|
| 118 |
f"Latitude: {self.latitude}, "
|
| 119 |
f"Longitude: {self.longitude}, "
|
| 120 |
f"Author Email: {self.author_email}, "
|
| 121 |
+
f"raw timestamp: {self.image_datetime_raw}, "
|
| 122 |
+
#f"Time: {self.time}, "
|
| 123 |
f"Date Option: {self.date_option}, "
|
| 124 |
f"Time Option: {self.time_option}, "
|
| 125 |
f"Uploaded Filename: {self.uploaded_file}"
|
|
|
|
| 141 |
self.latitude == other.latitude and
|
| 142 |
self.longitude == other.longitude and
|
| 143 |
self.author_email == other.author_email and
|
| 144 |
+
self.image_datetime_raw == other.image_datetime_raw and
|
| 145 |
+
#self.time == other.time and
|
| 146 |
self.date_option == other.date_option and
|
| 147 |
# temporarily skip time_option, it is followed by the clock and that is always differnt
|
| 148 |
#self.time_option == other.time_option and
|
|
|
|
| 171 |
differences.append(f" Longitude is different. (self: {self.longitude}, other: {other.longitude})")
|
| 172 |
if self.author_email != other.author_email:
|
| 173 |
differences.append(f" Author email is different. (self: {self.author_email}, other: {other.author_email})")
|
| 174 |
+
if self.image_datetime_raw != other.image_datetime_raw:
|
| 175 |
+
differences.append(f" Date is different. (self: {self.image_datetime_raw}, other: {other.image_datetime_raw})")
|
|
|
|
|
|
|
| 176 |
if self.date_option != other.date_option:
|
| 177 |
differences.append(f" Date option is different. (self: {self.date_option}, other: {other.date_option})")
|
| 178 |
if self.time_option != other.time_option:
|
|
|
|
| 201 |
"latitude": self.latitude,
|
| 202 |
"longitude": self.longitude,
|
| 203 |
"author_email": self.author_email,
|
| 204 |
+
"image_datetime_raw": self.image_datetime_raw,
|
|
|
|
| 205 |
"date_option": str(self.date_option),
|
| 206 |
"time_option": str(self.time_option),
|
| 207 |
+
#"uploaded_file": self.uploaded_file # can't serialize this in json, not needed anyway.
|
| 208 |
}
|
| 209 |
|
| 210 |
@classmethod
|
|
|
|
| 214 |
latitude=data.get("latitude"),
|
| 215 |
longitude=data.get("longitude"),
|
| 216 |
author_email=data.get("author_email"),
|
| 217 |
+
image_datetime_raw=data.get("image_datetime_raw"),
|
|
|
|
| 218 |
date_option=data.get("date_option"),
|
| 219 |
time_option=data.get("time_option"),
|
| 220 |
uploaded_file=data.get("uploaded_file"),
|
|
|
|
| 228 |
latitude=input.latitude,
|
| 229 |
longitude=input.longitude,
|
| 230 |
author_email=input.author_email,
|
| 231 |
+
image_datetime_raw=input.image_datetime_raw,
|
|
|
|
| 232 |
date_option=input.date_option,
|
| 233 |
time_option=input.time_option,
|
| 234 |
uploaded_file=input.uploaded_file,
|