Skip to content

Commit

Permalink
Aborted changes
Browse files Browse the repository at this point in the history
  • Loading branch information
bsekachev committed May 1, 2024
1 parent a3fbec4 commit 6607534
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#
# SPDX-License-Identifier: MIT

from copy import deepcopy
from datetime import datetime

from dateutil import parser
Expand Down Expand Up @@ -30,7 +31,7 @@ def __init__(
):
super().__init__(start_datetime, end_datetime, job_id, task_ids)

SELECT = ["job_id", "sum(JSONExtractUInt(payload, 'working_time')) as wt"]
SELECT = ["job_id", "JSONExtractUInt(payload, 'working_time') as wt, timestamp"]
WHERE = []

if task_ids is not None:
Expand All @@ -39,11 +40,15 @@ def __init__(
WHERE.append("job_id={job_id:UInt64}")

WHERE.extend(
["timestamp >= {start_datetime:DateTime64}", "timestamp < {end_datetime:DateTime64}"]
[
"wt > 0",
"timestamp >= {start_datetime:DateTime64}",
"timestamp < {end_datetime:DateTime64}",
]
)

# bandit false alarm
self._query = f"SELECT {', '.join(SELECT)} FROM events WHERE {'AND '.join(WHERE)} GROUP BY job_id" # nosec B608
self._query = f"SELECT {', '.join(SELECT)} FROM events WHERE {' AND '.join(WHERE)} ORDER BY timestamp" # nosec B608


class JobAnnotationSpeed(PrimaryMetricBase):
Expand Down Expand Up @@ -84,47 +89,40 @@ def get_track_count(annotations):

return count

def get_default():
return {
"data_series": {
"object_count": [],
"working_time": [],
}
}

# Calculate object count
annotations = dm.task.get_job_data(self._db_obj.id)
object_count = 0
object_count += get_tags_count(annotations)
object_count += get_shapes_count(annotations)
object_count += get_track_count(annotations)

timestamp = self._get_utc_now()
start_datetime = self._db_obj.created_date
timestamp = self._db_obj.updated_date
timestamp_str = timestamp.strftime("%Y-%m-%dT%H:%M:%SZ")

report = self._db_obj.analytics_report
if report is None:
statistics = get_default()
else:
report = getattr(self._db_obj, "analytics_report", None)
data_series = self.get_empty()
if report is not None:
statistics = next(
filter(lambda s: s["name"] == "annotation_speed", report.statistics), get_default()
filter(lambda s: s["name"] == "annotation_speed", report.statistics), None
)

data_series = statistics["data_series"]
if statistics is not None:
data_series = deepcopy(statistics["data_series"])

last_entry_count = 0
start_datetime = self._db_obj.created_date
if data_series["object_count"]:
last_entry = data_series["object_count"][-1]
last_entry_timestamp = parser.parse(last_entry["datetime"])

if last_entry_timestamp.date() == timestamp.date():
# remove last entry, it will be re-calculated below, because of the same date
data_series["object_count"] = data_series["object_count"][:-1]
data_series["working_time"] = data_series["working_time"][:-1]

if len(data_series["object_count"]):
last_last_entry = data_series["object_count"][-1]
start_datetime = parser.parse(last_last_entry["datetime"])
last_entry_count = last_last_entry["value"]
current_last_entry = data_series["object_count"][-1]
start_datetime = parser.parse(current_last_entry["datetime"])
last_entry_count = current_last_entry["value"]
else:
last_entry_count = last_entry["value"]
start_datetime = parser.parse(last_entry["datetime"])
Expand All @@ -136,21 +134,21 @@ def get_default():
}
)

# Calculate working time
rows = list(
self._data_extractor.extract_for_job(
self._db_obj.id,
{
"start_datetime": start_datetime,
"end_datetime": self._get_utc_now(),
},
)
)

value = (rows[0][0] if len(rows) else 0) / (1000 * 3600)
working_time = 0
for row in rows:
wt, datetime = row
if start_datetime <= datetime < timestamp:
working_time += wt

data_series["working_time"].append(
{
"value": value,
"value": working_time / (1000 * 3600),
"datetime": timestamp_str,
}
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def __init__(
)

# bandit false alarm
self._query = f"SELECT {', '.join(SELECT)} FROM events WHERE {'AND '.join(WHERE)} ORDER BY timestamp ASC" # nosec B608
self._query = f"SELECT {', '.join(SELECT)} FROM events WHERE {' AND '.join(WHERE)} ORDER BY timestamp ASC" # nosec B608


class JobAnnotationTime(PrimaryMetricBase):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def __init__(
GROUP_BY = ["scope", "day", "job_id"]

# bandit false alarm
self._query = f"SELECT {', '.join(SELECT)} FROM events WHERE {'AND '.join(WHERE)} GROUP BY {', '.join(GROUP_BY)} ORDER BY day ASC" # nosec B608
self._query = f"SELECT {', '.join(SELECT)} FROM events WHERE {' AND '.join(WHERE)} GROUP BY {', '.join(GROUP_BY)} ORDER BY day ASC" # nosec B608


class JobObjects(PrimaryMetricBase):
Expand Down

0 comments on commit 6607534

Please sign in to comment.