Skip to content

Instantly share code, notes, and snippets.

View polettif's full-sized avatar

Flavio Poletti polettif

  • TEAMverkehr.zug
View GitHub Profile
@polettif
polettif / trips_after_midnight_dst_change.R
Last active November 26, 2021 11:19
trips during clock change (dst -> standard time) in Swiss GTFS
library(tidytransit)
library(dplyr)
library(tidytable)
# https://opentransportdata.swiss/de/dataset/timetable-2021-gtfs2020/resource/10ed3c73-231e-49ba-beac-2df54de48c29
g = read_gtfs("gtfs_fp2021_2021-11-24_09-10.zip")
summary(g)
#> tidygtfs object
#> files agency, stops, routes, trips, stop_times, calendar, calendar_dates, transfers, feed_info
#> agencies Schweizerische Bundesbahnen SBB, Sihltal-Zürich-Uetliberg-Bahn, BLS AG (bls) ... 459 more
@polettif
polettif / gtfsrouter_comparison.R
Last active December 15, 2020 15:27
Compare gtfsrouter and tidytransit
from = "Berlin Hauptbahnhof"
start_time = 8 * 3600
gtfsrouter::berlin_gtfs_to_zip()
gtfs_file = paste0(tempdir(), "/vbb.zip")
# 1a) tidytransit #####
suppressMessages({
library(tidytransit)
library(dplyr)
})
@polettif
polettif / election_method_examples.R
Last active August 8, 2020 12:03
Examples for different election system with data from the 2019 Finnish parliamentary election
library(proporz)
# data set
votes_matrix = pivot_to_matrix(finland2019$votes_df)
party_votes = rowSums(votes_matrix)
district_seats = finland2019$district_seats_df$election_mandates
names(district_seats) <- finland2019$district_seats_df$entity_id
# calculate the seat distribution in each district with a given method
# returns the national seat distribution