|
from json import loads |
|
from peewee import * |
|
|
|
db = SqliteDatabase("data/all_races_1990-2025.db") |
|
|
|
|
|
class Race(Model): |
|
""" |
|
rid: Unique race ID |
|
place_id: Unique ID of racing course |
|
date: Date of race |
|
name: Race name |
|
course: Course type (1: turf, 0: dirt) |
|
course_sit: Course situation (0: θ―, 1: η¨ι, 2: ι, 3: δΈθ―) |
|
weather: Weather (0: ζ΄, 1: ζ, 2: ε°ι¨, 3: ι¨, 4: ε°ιͺ, 5: ιͺ) |
|
distance: Distance (in meters) |
|
horses: Json format, List of horses |
|
list of horse info(in list) |
|
[ |
|
hid, # horse id |
|
ranking, # final result (1: 1st, 2: 2nd, ...) |
|
gate_group, # gate group |
|
gate, # gate number |
|
weight, # addon weight (in kg) |
|
body_weight, # body weight (in kg) |
|
body_weight_diff, # body weight difference (in kg) |
|
time, # time (in seconds) |
|
finalt, # final time(should be last 600m time) (in seconds) |
|
time_factor, # time factor from Netkeiba, just for reference |
|
jockey_id, # jockey id |
|
] |
|
""" |
|
rid = IntegerField(index=True, unique=True) |
|
place_id = CharField() |
|
date = CharField() |
|
name = CharField() |
|
course = BooleanField() |
|
course_sit = IntegerField() |
|
weather = IntegerField() |
|
distance = IntegerField() |
|
horses = CharField(null=True) |
|
|
|
class Meta: |
|
database = db |
|
|
|
def as_dict(self): |
|
return { |
|
"rid": self.rid, |
|
"place_id": self.place_id, |
|
"date": self.date, |
|
"name": self.name, |
|
"course": self.course, |
|
"course_sit": self.course_sit, |
|
"weather": self.weather, |
|
"distance": self.distance, |
|
"horses": loads(self.horses)[0] if self.horses else None |
|
} |
|
|
|
|
|
class Horse(Model): |
|
""" |
|
hid: Unique horse ID |
|
born: Date of birth |
|
name: Horse name |
|
info: Horse info (gender, color, etc.) |
|
races: Json format, List of races |
|
list of race info(in list) |
|
[ |
|
r_id, # race id |
|
r_place_id, # id for racing course |
|
r_time, # date (without years) |
|
weather, # weather (0: ζ΄, 1: ζ, 2: ε°ι¨, 3: ι¨, 4: ε°ιͺ, 5: ιͺ) |
|
c_type, # course type (1: turf, 0: dirt) |
|
dis, # distance (in meters) |
|
c_sit, # course situation (0: θ―, 1: η¨ι, 2: ι, 3: δΈθ―) |
|
all, # total number of horses |
|
gate, # gate number of horses |
|
weight, # addon weight (in kg) |
|
body_weight, # body weight (in kg) |
|
body_weight_diff, # body weight difference (in kg) |
|
ranking, # final result (1: 1st, 2: 2nd, ...) |
|
time, # time (in seconds) |
|
time_diff, # delta time with horse in front of this horse (in seconds) |
|
time_factor, # time factor from Netkeiba, just for reference |
|
finalt, # final time(should be last 600m time) (in seconds) |
|
r_date, # full race date (year mo day) |
|
] |
|
""" |
|
hid = CharField(index=True, unique=True) |
|
born = CharField(null=True) |
|
name = CharField(null=True) |
|
info = CharField(null=True) |
|
races = CharField(null=True) |
|
|
|
class Meta: |
|
database = db |
|
|
|
def as_dict(self): |
|
return { |
|
"hid": self.hid, |
|
"born": self.born, |
|
"name": self.name, |
|
"info": self.info, |
|
"races": loads(self.races)[0] if self.races else None |
|
} |
|
|
|
|
|
def main(): |
|
db.connect() |
|
db.create_tables([Race, Horse]) |
|
|
|
|
|
if __name__ == "__main__": |
|
main() |
|
|