traingraph

module
v0.0.0-...-a4249fa Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 11, 2022 License: MIT

README

Traingraph generation in go

What is this? See https://de.wikipedia.org/wiki/Bildfahrplan

Usage

infrastructure := []model.InfrastructureObject{
		{
			Name:     "A",
			Distance: 0,
			Location: 123.45,
			Type:     "station",
			Id: model.ObjectID{
				Db640: "Aa",
				Ifopt: util.NewIfOpt("at:44:1234:0:1"),
			},
		},
		{
			Name:     "A Ort",
			Distance: 0.5,
			Location: 123.7,
			Type:     "stop",
			Id: model.ObjectID{
				Db640: "Aa H1",
				Ifopt: util.NewIfOpt("at:44:1235"),
			},
		},
		{
			Name:     "B",
			Distance: 1,
			Location: 124.45,
			Type:     "station",
			Id: model.ObjectID{
				Db640: "Bb",
				Ifopt: util.NewIfOpt("at:44:5678:0:2"),
			},
		},
		{
			Name:     "C",
			Distance: 1,
			Location: 125.0,
			Type:     "station",
			Id: model.ObjectID{
				Db640: "Cc",
				Ifopt: util.NewIfOpt("at:44:9876:0:2"),
			},
		},
	}

	timetable := []model.Journey{
		{
			ID:   "1234",
			Name: "REX 1234",
			Stops: []model.StopTime{
				{
					Id: model.ObjectID{
						Ifopt: util.NewIfOpt("at:44:1234:0:1"),
					},
					Departure: "09:00",
				},
				{
					Id: model.ObjectID{
						Ifopt: util.NewIfOpt("at:44:1235"),
					},
					Arrival:   "09:05",
					Departure: "09:06",
				},
				{
					Id: model.ObjectID{
						Ifopt: util.NewIfOpt("at:44:5678:0:2"),
					},
					Arrival:   "09:15",
					Departure: "09:17",
				},
				{
					Id: model.ObjectID{
						Ifopt: util.NewIfOpt("at:44:9876:0:2"),
					},
					Arrival: "09:30",
				},
			},
		},
	}

	renderer := oebb.NewOebbStyleRenderer(
		"A - B",
		"Blatt 1234",
		time.Now(),
		time.Now().AddDate(0, 0, 1),
	)

	traingraph := traingraph.NewTrainGraph(
		infrastructure,
		timetable,
		&renderer,
	)
	traingraph.GeneratePDF("out.pdf")

Example

see the examples folder

traingraph

import "github.com/joushx/traingraph/pkg/traingraph"

Index

type TrainGraph

type TrainGraph struct {
    // contains filtered or unexported fields
}
func NewTrainGraph
func NewTrainGraph(infrastructure []model.InfrastructureObject, journeys []model.Journey, renderer render.Renderer) TrainGraph
func (TrainGraph) GeneratePDF
func (t TrainGraph) GeneratePDF(filename string)

model

import "github.com/joushx/traingraph/pkg/model"

Index

type Ifopt

type Ifopt struct {
    Country  string
    State    string
    Stop     string
    Area     string
    Platform string
}

type InfrastructureObject

type InfrastructureObject struct {
    Name     string   `yaml:"name"`
    Location float32  `yaml:"location"`
    Distance float32  `yaml:"distance"`
    Type     string   `yaml:"type"`
    Id       ObjectID `yaml:"id"`
}

type Journey

type Journey struct {
    ID    string     `yaml:"id"`
    Name  string     `yaml:"name"`
    Stops []StopTime `yaml:"stops"`
}

type ObjectID

type ObjectID struct {
    Db640 string `yaml:"db640,omitempty"`
    ExtId string `yaml:"extId,omitempty"`
    Ifopt Ifopt  `yaml:"ifopt,omitempty"`
}

type StopTime

type StopTime struct {
    Id        ObjectID `yaml:"id"`
    Arrival   string   `yaml:"arrival,omitempty"`
    Departure string   `yaml:"departure,omitempty"`
}

util

import "github.com/joushx/traingraph/pkg/util"

Index

func NewIfOpt

func NewIfOpt(value string) model.Ifopt

Generated by gomarkdoc

Directories

Path Synopsis
internal
pkg

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL