First part of the todo done

This commit is contained in:
christalib 2020-02-04 20:16:42 +01:00
parent 26504b9e91
commit e40cf53702
7 changed files with 42 additions and 14 deletions

11
TODO.md Normal file
View file

@ -0,0 +1,11 @@
# TODO
## Data
[X] Get races and drivers
[] Get results by races linked to drivers
[] Get time by lap by driver by race
[] Get tyre strategy by race by driver
## Analyse
[] who is fatest in which race on which tyres
[] who improves with which tyres

View file

@ -5,33 +5,38 @@ import (
"fmt"
"io/ioutil"
"net/http"
"time"
"framagit.org/pksl/paddockpass/db"
"github.com/jinzhu/gorm"
)
// Driver represents a structure of driver entry in the Eargast API.
type Driver struct {
FirstName string `json:"givenName"`
LastName string `json:"familyName"`
DateOrBirth Date `json:"dateOfBirth"`
Nationality string `json:nationality`
Nationality string `json:"nationality"`
}
// Drivers represents an array of driver in the Eargast API.
type Drivers struct {
Drivers []Driver `json:"Drivers"`
}
// DriverTable reprensts a table of drivers in the Eargast API.
type DriverTable struct {
DriverTable Drivers `json:"DriverTable"`
}
// MRDriverData is the wrapper for the datta in the Eargast API.
type MRDriverData struct {
MRData DriverTable `json:"MRData"`
}
// GetDriversFromErgast gets the driver data from the API.
func GetDriversFromErgast() {
resp, err := http.Get("http://ergast.com/api/f1/drivers.json")
func GetDriversFromErgast(year string) {
resp, err := http.Get("http://ergast.com/api/f1/" + year + "/drivers.json")
if err != nil {
panic(err.Error())
}
@ -54,14 +59,18 @@ func GetDriversFromErgast() {
if err != nil {
fmt.Println(err)
}
defer tx.Close()
for _, driver := range drivers {
fmt.Println(driver)
model := db.Driver{
FirstName: driver.FirstName,
LastName: driver.LastName,
FirstName: driver.FirstName,
LastName: driver.LastName,
Nationality: driver.Nationality,
DoB: (driver.DateOrBirth).Format(time.RFC3339),
}
tx.Assign(model).FirstOrCreate(&model)
tx.Where(Driver{FirstName: driver.FirstName, LastName: driver.LastName}).Assign(model).FirstOrCreate(&model)
}
defer tx.Close()
}
// {

View file

@ -10,6 +10,7 @@ import (
"framagit.org/pksl/paddockpass/db"
"github.com/jinzhu/gorm"
"github.com/sirupsen/logrus"
)
// Location represents the details of a circuit.
@ -89,7 +90,7 @@ func GetSeasonFromErgast(year string) {
var jsonData MRData
err = json.Unmarshal(body, &jsonData)
if err != nil {
panic(err.Error())
logrus.Error(err)
}
races := jsonData.MRData.RaceTable.Races

View file

@ -29,10 +29,10 @@ type Circuit struct {
// Driver describes a driver.
type Driver struct {
gorm.Model
FirstName string
LastName string
Number string
DoB time.Time
FirstName string
LastName string
Nationality string
DoB string
}
// GORM DOC

1
go.mod
View file

@ -5,4 +5,5 @@ go 1.12
require (
github.com/go-sql-driver/mysql v1.4.1
github.com/jinzhu/gorm v1.9.11
github.com/sirupsen/logrus v1.2.0
)

2
go.sum
View file

@ -72,6 +72,7 @@ github.com/prometheus/common v0.2.0/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y8
github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk=
github.com/prometheus/procfs v0.0.0-20190117184657-bf6a532e95b1/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk=
github.com/rcrowley/go-metrics v0.0.0-20181016184325-3113b8401b8a/go.mod h1:bCqnVzQkZxMG4s8nGwiZ5l3QUCyqpo9Y+/ZMZ9VjZe4=
github.com/sirupsen/logrus v1.2.0 h1:juTguoYk5qI21pwyTXY3B3Y5cOTH3ZUyZCg1v/mihuo=
github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
@ -103,6 +104,7 @@ golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5h
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20181122145206-62eef0e2fa9b/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a h1:1BGLXjeY4akVXGgbC9HugT3Jv3hCI0z56oJR5vAMgBU=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=

View file

@ -2,6 +2,8 @@ package main
import (
"fmt"
"strconv"
"time"
"framagit.org/pksl/paddockpass/api"
"framagit.org/pksl/paddockpass/db"
@ -9,7 +11,9 @@ import (
)
func main() {
fmt.Println("Hello there!")
year := time.Now().Year()
fmt.Println("Hello there! It is", year)
db.InitDB()
api.GetSeasonFromErgast("2019")
api.GetSeasonFromErgast(strconv.Itoa(year))
api.GetDriversFromErgast(strconv.Itoa(year))
}