gblazex commited on
Commit
3613d40
1 Parent(s): b72ecf6

Update src/leaderboard/read_evals.py

Browse files
Files changed (1) hide show
  1. src/leaderboard/read_evals.py +19 -0
src/leaderboard/read_evals.py CHANGED
@@ -111,6 +111,8 @@ from dateutil import parser
111
 
112
  def parse_datetime(iso_datetime):
113
  """Parse an ISO datetime string to a datetime object."""
 
 
114
  try:
115
  tz_unaware = iso_datetime.split('Z')[0].split('+')[0]
116
  return datetime.fromisoformat(tz_unaware)
@@ -124,6 +126,20 @@ def is_recent(iso_datetime, days=7):
124
  parsed_time = parse_datetime(iso_datetime)
125
  return datetime.utcnow() - parsed_time <= timedelta(days=days)
126
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
127
 
128
  # blz end -------------
129
 
@@ -143,6 +159,7 @@ class EvalResult:
143
  license: str = "?"
144
  likes: int = 0
145
  downloads: int = 0
 
146
  likability: float = 0
147
  num_params: int = 0
148
  date: str = "" # submission date of request file
@@ -253,6 +270,7 @@ class EvalResult:
253
  self.likes = popularity.get("likes", request.get("likes", 0))
254
  self.downloads = popularity.get("downloads", 0)
255
  self.likability = calculate_likability(self.likes, self.downloads)
 
256
 
257
  # print(self.full_model, self.likes)
258
  # self.likes = request.get("likes", 0) blz
@@ -288,6 +306,7 @@ class EvalResult:
288
  AutoEvalColumn.license.name: self.license,
289
  AutoEvalColumn.likes.name: self.likes,
290
  AutoEvalColumn.downloads.name: self.downloads, # blz
 
291
  AutoEvalColumn.likability.name: self.likability, # blz
292
  AutoEvalColumn.params.name: self.num_params,
293
  AutoEvalColumn.still_on_hub.name: self.still_on_hub,
 
111
 
112
  def parse_datetime(iso_datetime):
113
  """Parse an ISO datetime string to a datetime object."""
114
+ if isinstance(iso_datetime, datetime):
115
+ return iso_datetime
116
  try:
117
  tz_unaware = iso_datetime.split('Z')[0].split('+')[0]
118
  return datetime.fromisoformat(tz_unaware)
 
126
  parsed_time = parse_datetime(iso_datetime)
127
  return datetime.utcnow() - parsed_time <= timedelta(days=days)
128
 
129
+ def days_difference(d1, d2):
130
+ """Check if the given ISO datetime string is within the past 'days' days."""
131
+ if not iso_datetime:
132
+ return False
133
+ parsed_time = parse_datetime(iso_datetime)
134
+ return datetime.utcnow() - parsed_time <= timedelta(days=days)
135
+
136
+ def days_difference(a, b=datetime.now()):
137
+ date1 = parse_datetime(a)
138
+ date2 = parse_datetime(b)
139
+ difference = abs((date1 - date2).days)
140
+ return difference
141
+
142
+
143
 
144
  # blz end -------------
145
 
 
159
  license: str = "?"
160
  likes: int = 0
161
  downloads: int = 0
162
+ likes_per_day: float = 0
163
  likability: float = 0
164
  num_params: int = 0
165
  date: str = "" # submission date of request file
 
270
  self.likes = popularity.get("likes", request.get("likes", 0))
271
  self.downloads = popularity.get("downloads", 0)
272
  self.likability = calculate_likability(self.likes, self.downloads)
273
+ self.likes_per_day = self.likes / days_difference(popularity.get("created_at"))
274
 
275
  # print(self.full_model, self.likes)
276
  # self.likes = request.get("likes", 0) blz
 
306
  AutoEvalColumn.license.name: self.license,
307
  AutoEvalColumn.likes.name: self.likes,
308
  AutoEvalColumn.downloads.name: self.downloads, # blz
309
+ AutoEvalColumn.likes_per_day.name: self.likes_per_day, # blz
310
  AutoEvalColumn.likability.name: self.likability, # blz
311
  AutoEvalColumn.params.name: self.num_params,
312
  AutoEvalColumn.still_on_hub.name: self.still_on_hub,