-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add utc timezones to OmenBet timestamps #440
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -6,6 +6,7 @@ | |||||||||||||||||||||||||||||||||||||||||||||
from langfuse.client import TraceWithDetails | ||||||||||||||||||||||||||||||||||||||||||||||
from pydantic import BaseModel | ||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||
from prediction_market_agent_tooling.loggers import logger | ||||||||||||||||||||||||||||||||||||||||||||||
from prediction_market_agent_tooling.markets.data_models import ( | ||||||||||||||||||||||||||||||||||||||||||||||
PlacedTrade, | ||||||||||||||||||||||||||||||||||||||||||||||
ProbabilisticAnswer, | ||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -146,9 +147,21 @@ def get_trace_for_bet( | |||||||||||||||||||||||||||||||||||||||||||||
else: | ||||||||||||||||||||||||||||||||||||||||||||||
# In-case there are multiple traces for the same market, get the closest | ||||||||||||||||||||||||||||||||||||||||||||||
# trace to the bet | ||||||||||||||||||||||||||||||||||||||||||||||
bet_timestamp = add_utc_timezone_validator(bet.created_time) | ||||||||||||||||||||||||||||||||||||||||||||||
closest_trace_index = get_closest_datetime_from_list( | ||||||||||||||||||||||||||||||||||||||||||||||
add_utc_timezone_validator(bet.created_time), | ||||||||||||||||||||||||||||||||||||||||||||||
bet_timestamp, | ||||||||||||||||||||||||||||||||||||||||||||||
[t.timestamp for t in traces_for_bet], | ||||||||||||||||||||||||||||||||||||||||||||||
) | ||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||
# Sanity check: Let's say the upper bound for time between | ||||||||||||||||||||||||||||||||||||||||||||||
# `agent.process_market` being called and the bet being placed is 20 | ||||||||||||||||||||||||||||||||||||||||||||||
# minutes | ||||||||||||||||||||||||||||||||||||||||||||||
candidate_trace = traces_for_bet[closest_trace_index] | ||||||||||||||||||||||||||||||||||||||||||||||
if abs(candidate_trace.timestamp - bet_timestamp).total_seconds() > 1200: | ||||||||||||||||||||||||||||||||||||||||||||||
logger.info( | ||||||||||||||||||||||||||||||||||||||||||||||
f"Closest trace to bet has timestamp {candidate_trace.timestamp}, " | ||||||||||||||||||||||||||||||||||||||||||||||
f"but bet was created at {bet_timestamp}. Not matching" | ||||||||||||||||||||||||||||||||||||||||||||||
) | ||||||||||||||||||||||||||||||||||||||||||||||
return None | ||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+156
to
+166
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Parameterize the time threshold for better maintainability The hard-coded time threshold of Apply this diff to refactor the time threshold: +TIME_THRESHOLD_SECONDS = 1200 # Upper bound for time difference between agent processing and bet placement
candidate_trace = traces_for_bet[closest_trace_index]
-if abs(candidate_trace.timestamp - bet_timestamp).total_seconds() > 1200:
+if abs(candidate_trace.timestamp - bet_timestamp).total_seconds() > TIME_THRESHOLD_SECONDS:
logger.info(
f"Closest trace to bet has timestamp {candidate_trace.timestamp}, "
f"but bet was created at {bet_timestamp}. Not matching"
)
return None 📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||
return traces_for_bet[closest_trace_index] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Codebase verification
candidate_trace.timestamp
is not timezone-awareThe
trace.timestamp
is assigned directly without applyingadd_utc_timezone_validator
, which may lead to timezone-related comparison errors.prediction_market_agent_tooling/tools/langfuse_client_utils.py
🔗 Analysis chain
Ensure
candidate_trace.timestamp
is timezone-aware when comparing datetimesWhile
bet_timestamp
is made timezone-aware usingadd_utc_timezone_validator
, it's important to ensure thatcandidate_trace.timestamp
is also timezone-aware. This prevents potential errors or incorrect time difference calculations when comparing the two datetime objects.Run the following script to verify that
candidate_trace.timestamp
is timezone-aware:🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
Length of output: 1054
Script:
Length of output: 2657