rmm commited on
Commit
1ba3d0b
·
1 Parent(s): 882be26

fix: InputObservation uses date, time, and raw_image_datetime

Browse files

- no more "options", too ambiguous. The goal of this implementation is
to have one date and one time for the observation, which could have
been corrected manually.

- see beca8fa where I did the first update

src/input/input_handling.py CHANGED
@@ -231,13 +231,13 @@ def metadata_inputs_one_file(file:UploadedFile, image_hash:str, dbg_ix:int=0) ->
231
  time_value = datetime.datetime.now().time() # Default to current time
232
  date_value = datetime.datetime.now().date()
233
 
234
- ## if not, give user the option to enter manually
235
- date_option = viewcontainer.date_input("Date for "+filename, value=date_value, key=f"input_date_{image_hash}")
236
- time_option = viewcontainer.time_input("Time for "+filename, time_value, key=f"input_time_{image_hash}")
237
 
238
  observation = InputObservation(image=image, latitude=latitude, longitude=longitude,
239
  author_email=author_email, image_datetime_raw=image_datetime_raw,
240
- date_option=date_option, time_option=time_option,
241
  uploaded_file=file, image_md5=image_hash
242
  )
243
 
 
231
  time_value = datetime.datetime.now().time() # Default to current time
232
  date_value = datetime.datetime.now().date()
233
 
234
+ ## either way, give user the option to enter manually (or correct, e.g. if camera has no rtc clock)
235
+ date = viewcontainer.date_input("Date for "+filename, value=date_value, key=f"input_date_{image_hash}")
236
+ time = viewcontainer.time_input("Time for "+filename, time_value, key=f"input_time_{image_hash}")
237
 
238
  observation = InputObservation(image=image, latitude=latitude, longitude=longitude,
239
  author_email=author_email, image_datetime_raw=image_datetime_raw,
240
+ date=date, time=time,
241
  uploaded_file=file, image_md5=image_hash
242
  )
243
 
src/input/input_observation.py CHANGED
@@ -22,10 +22,10 @@ class InputObservation:
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):
28
- Additional time option for the observation.
29
  uploaded_file (UploadedFile):
30
  The uploaded file associated with the observation.
31
  image_md5 (str):
@@ -55,9 +55,8 @@ class InputObservation:
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
 
63
  self.image = image
@@ -65,9 +64,8 @@ class InputObservation:
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
72
  self.image_md5 = image_md5
73
  self._top_predictions = []
@@ -106,8 +104,8 @@ class InputObservation:
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
 
113
  def __repr__(self):
@@ -119,9 +117,8 @@ class InputObservation:
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}"
126
  f"Image MD5 hash: {self.image_md5}"
127
  )
@@ -142,10 +139,9 @@ class InputObservation:
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
149
  self.uploaded_file == other.uploaded_file and
150
  self.image_md5 == other.image_md5
151
  )
@@ -173,10 +169,10 @@ class InputObservation:
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:
179
- differences.append(f" Time option is different. (self: {self.time_option}, other: {other.time_option})")
180
  if self.uploaded_file != other.uploaded_file:
181
  differences.append(" Uploaded filename is different.")
182
  if self.image_md5 != other.image_md5:
@@ -202,9 +198,9 @@ class InputObservation:
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
@@ -215,8 +211,8 @@ class InputObservation:
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"),
221
  image_hash=data.get("image_md5")
222
  )
@@ -229,8 +225,8 @@ class InputObservation:
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,
235
  image_hash=input.image_hash
236
  )
 
22
  The email of the author of the observation.
23
  image_datetime_raw (str):
24
  The datetime extracted from the observation file
25
+ date (datetime.date):
26
+ Date of the observation
27
+ time (datetime.time):
28
+ Time of the observation
29
  uploaded_file (UploadedFile):
30
  The uploaded file associated with the observation.
31
  image_md5 (str):
 
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
+ date:datetime.date=None,
59
+ time:datetime.time=None,
 
60
  uploaded_file:UploadedFile=None, image_md5:str=None):
61
 
62
  self.image = image
 
64
  self.longitude = longitude
65
  self.author_email = author_email
66
  self.image_datetime_raw = image_datetime_raw
67
+ self.date = date
68
+ self.time = time
 
69
  self.uploaded_file = uploaded_file
70
  self.image_md5 = image_md5
71
  self._top_predictions = []
 
104
  _im_str = "None" if self.image is None else f"image dims: {self.image.shape}"
105
  return (
106
  f"Observation: {_im_str}, {self.latitude}, {self.longitude}, "
107
+ f"{self.author_email}, {self.image_datetime_raw}, {self.date}, "
108
+ f"{self.time}, {self.uploaded_file}, {self.image_md5}"
109
  )
110
 
111
  def __repr__(self):
 
117
  f"Longitude: {self.longitude}, "
118
  f"Author Email: {self.author_email}, "
119
  f"raw timestamp: {self.image_datetime_raw}, "
120
+ f"Date: {self.date}, "
121
+ f"Time: {self.time}, "
 
122
  f"Uploaded Filename: {self.uploaded_file}"
123
  f"Image MD5 hash: {self.image_md5}"
124
  )
 
139
  self.longitude == other.longitude and
140
  self.author_email == other.author_email and
141
  self.image_datetime_raw == other.image_datetime_raw and
142
+ self.date == other.date and
143
+ # temporarily skip time, it is followed by the clock and that is always differnt
144
  #self.time == other.time and
 
 
 
145
  self.uploaded_file == other.uploaded_file and
146
  self.image_md5 == other.image_md5
147
  )
 
169
  differences.append(f" Author email is different. (self: {self.author_email}, other: {other.author_email})")
170
  if self.image_datetime_raw != other.image_datetime_raw:
171
  differences.append(f" Date is different. (self: {self.image_datetime_raw}, other: {other.image_datetime_raw})")
172
+ if self.date != other.date:
173
+ differences.append(f" Date is different. (self: {self.date}, other: {other.date})")
174
+ if self.time != other.time:
175
+ differences.append(f" Time is different. (self: {self.time}, other: {other.time})")
176
  if self.uploaded_file != other.uploaded_file:
177
  differences.append(" Uploaded filename is different.")
178
  if self.image_md5 != other.image_md5:
 
198
  "longitude": self.longitude,
199
  "author_email": self.author_email,
200
  "image_datetime_raw": self.image_datetime_raw,
201
+ "date": str(self.date),
202
+ "time": str(self.time),
203
+ #"uploaded_file": self.uploaded_file # can't serialize this in json, not sent to dataset anyway.
204
  }
205
 
206
  @classmethod
 
211
  longitude=data.get("longitude"),
212
  author_email=data.get("author_email"),
213
  image_datetime_raw=data.get("image_datetime_raw"),
214
+ date=data.get("date"),
215
+ time=data.get("time"),
216
  uploaded_file=data.get("uploaded_file"),
217
  image_hash=data.get("image_md5")
218
  )
 
225
  longitude=input.longitude,
226
  author_email=input.author_email,
227
  image_datetime_raw=input.image_datetime_raw,
228
+ date=input.date,
229
+ time=input.time,
230
  uploaded_file=input.uploaded_file,
231
  image_hash=input.image_hash
232
  )
src/utils/metadata_handler.py CHANGED
@@ -11,13 +11,10 @@ def metadata2md(image_hash:str) -> str:
11
 
12
  """
13
  markdown_str = "\n"
14
- # FIXME get the right keys
15
- # keys_to_print = ["latitude","longitude","author_email","date","time"]
16
- keys_to_print = ["latitude","longitude","author_email","date_option","time_option"]
17
 
18
  observation = st.session_state.public_observations.get(image_hash, {})
19
 
20
- #for key, value in st.session_state.public_observation.items():
21
  for key, value in observation.items():
22
  if key in keys_to_print:
23
  markdown_str += f"- **{key}**: {value}\n"
 
11
 
12
  """
13
  markdown_str = "\n"
14
+ keys_to_print = ["author_email", "latitude", "longitude", "date", "time"]
 
 
15
 
16
  observation = st.session_state.public_observations.get(image_hash, {})
17
 
 
18
  for key, value in observation.items():
19
  if key in keys_to_print:
20
  markdown_str += f"- **{key}**: {value}\n"