# HG changeset patch # User Teemu Piippo # Date 1596135151 -10800 # Node ID 7378b802ddf88d9ad1686c037e73fb8d47d24faf # Parent f9788970fa46e59341e9f4f016e3b04d2d776bf4 destination processing diff -r f9788970fa46 -r 7378b802ddf8 compute_regions.py --- a/compute_regions.py Wed Jul 29 23:45:53 2020 +0300 +++ b/compute_regions.py Thu Jul 30 21:52:31 2020 +0300 @@ -49,7 +49,7 @@ # Minor shapes contain major shapes, so just use those for shape in (region['minor_shapes'] or region['major_shapes']): for block in blocks_in_shape(blockmap, shape): - set.add(block, region['name']) + set.add(block, region['ref']) return blockmap def get_args(): @@ -74,9 +74,9 @@ def locate_regionally(position, region): if test_shapes(region['major_shapes'], position): - return RegionalLocation(region = region['name'], region_class = 'major') + return RegionalLocation(region = region['ref'], region_class = 'major') elif test_shapes(region['minor_shapes'], position): - return RegionalLocation(region = region['name'], region_class = 'minor') + return RegionalLocation(region = region['ref'], region_class = 'minor') else: return None diff -r f9788970fa46 -r 7378b802ddf8 datamodel.py --- a/datamodel.py Wed Jul 29 23:45:53 2020 +0300 +++ b/datamodel.py Thu Jul 30 21:52:31 2020 +0300 @@ -39,17 +39,47 @@ class GtfsRegion(GtfsBase): # Not a gtfs data set, but the Gtfs prefix added for consistency __tablename__ = 'regions' - region_name = sqlalchemy.Column(sqlalchemy.String, primary_key = True) + ref = sqlalchemy.Column(sqlalchemy.String, primary_key = True) + region_name_fi = sqlalchemy.Column(sqlalchemy.String, nullable = False) region_name_sv = sqlalchemy.Column(sqlalchemy.String) region_name_en = sqlalchemy.Column(sqlalchemy.String) region_name_ja = sqlalchemy.Column(sqlalchemy.String) - region_short_name = sqlalchemy.Column(sqlalchemy.String) + region_short_name_fi = sqlalchemy.Column(sqlalchemy.String) region_short_name_sv = sqlalchemy.Column(sqlalchemy.String) region_short_name_en = sqlalchemy.Column(sqlalchemy.String) region_short_name_ja = sqlalchemy.Column(sqlalchemy.String) - region_internal_name = sqlalchemy.Column(sqlalchemy.String) + region_internal_name_fi = sqlalchemy.Column(sqlalchemy.String) region_internal_name_sv = sqlalchemy.Column(sqlalchemy.String) region_internal_name_en = sqlalchemy.Column(sqlalchemy.String) region_internal_name_ja = sqlalchemy.Column(sqlalchemy.String) municipality = sqlalchemy.Column(sqlalchemy.String, nullable = False) external = sqlalchemy.Column(sqlalchemy.Boolean) + +class GtfsStopTime(GtfsBase): + __tablename__ = 'stop_times' + trip_id = sqlalchemy.Column( + sqlalchemy.String, + sqlalchemy.ForeignKey(GtfsTrip.id), + primary_key = True, + ) + stop_id = sqlalchemy.Column( + sqlalchemy.String, + sqlalchemy.ForeignKey(GtfsStop.stop_id), + nullable = False, + ) + stop_sequence = sqlalchemy.Column( + sqlalchemy.Integer, + primary_key = True, + ) + arrival_time = sqlalchemy.Column(sqlalchemy.Interval, nullable = False) + departure_time = sqlalchemy.Column(sqlalchemy.Interval, nullable = False) + shape_distance_traveled = sqlalchemy.Column(sqlalchemy.Numeric) + destination = sqlalchemy.Column(sqlalchemy.String) + stop = sqlalchemy.orm.relationship( + 'GtfsStop', + foreign_keys = 'GtfsStopTime.stop_id', + ) + trip = sqlalchemy.orm.relationship( + 'GtfsTrip', + foreign_keys = 'GtfsStopTime.trip_id', + ) diff -r f9788970fa46 -r 7378b802ddf8 föli.osm --- a/föli.osm Wed Jul 29 23:45:53 2020 +0300 +++ b/föli.osm Thu Jul 30 21:52:31 2020 +0300 @@ -767,36 +767,11 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + @@ -2954,7 +2929,7 @@ - + @@ -2966,9 +2941,10 @@ - + + @@ -2981,8 +2957,9 @@ - + + @@ -2994,8 +2971,9 @@ - + + @@ -3008,8 +2986,9 @@ - + + @@ -3023,9 +3002,10 @@ - + + @@ -3036,7 +3016,8 @@ - + + @@ -3052,9 +3033,10 @@ - + + @@ -3070,11 +3052,12 @@ - + - + + @@ -3086,7 +3069,8 @@ - + + @@ -3096,11 +3080,12 @@ - + + @@ -3115,10 +3100,11 @@ - + - + + @@ -3140,9 +3126,10 @@ - + + @@ -3152,8 +3139,9 @@ - + + @@ -3167,8 +3155,9 @@ - + + @@ -3180,8 +3169,9 @@ - + + @@ -3196,8 +3186,9 @@ - + + @@ -3207,18 +3198,19 @@ - + - + - + + @@ -3232,9 +3224,10 @@ - + + @@ -3246,8 +3239,9 @@ - + + @@ -3259,8 +3253,9 @@ - + + @@ -3276,9 +3271,10 @@ - + + @@ -3290,8 +3286,9 @@ - + + @@ -3300,9 +3297,9 @@ - - - + + + @@ -3310,10 +3307,10 @@ - - - + + + @@ -3324,11 +3321,12 @@ - + + @@ -3344,8 +3342,9 @@ - + + @@ -3366,8 +3365,9 @@ - + + @@ -3379,9 +3379,10 @@ - - - + + + + @@ -3401,8 +3402,9 @@ - + + @@ -3420,8 +3422,9 @@ - + + @@ -3432,10 +3435,10 @@ - - - + + + @@ -3445,18 +3448,19 @@ - + - + - + + @@ -3479,8 +3483,9 @@ - + + @@ -3492,8 +3497,9 @@ - + + @@ -3510,9 +3516,10 @@ - + - + + @@ -3525,9 +3532,10 @@ - + + @@ -3542,8 +3550,9 @@ - + + @@ -3555,8 +3564,9 @@ - + + @@ -3569,8 +3579,9 @@ - + + @@ -3588,8 +3599,9 @@ - + + @@ -3602,7 +3614,8 @@ - + + @@ -3615,7 +3628,8 @@ - + + @@ -3628,7 +3642,8 @@ - + + @@ -3645,8 +3660,9 @@ - + + @@ -3660,7 +3676,8 @@ - + + @@ -3675,9 +3692,10 @@ - + + @@ -3688,8 +3706,9 @@ - + + @@ -3701,9 +3720,10 @@ - + + @@ -3715,7 +3735,8 @@ - + + @@ -3728,8 +3749,9 @@ - + + @@ -3741,7 +3763,8 @@ - + + @@ -3751,9 +3774,10 @@ - + + @@ -3765,7 +3789,8 @@ - + + @@ -3775,7 +3800,8 @@ - + + @@ -3787,7 +3813,8 @@ - + + @@ -3798,7 +3825,8 @@ - + + @@ -3809,8 +3837,9 @@ - + + @@ -3824,9 +3853,10 @@ - + + @@ -3838,8 +3868,9 @@ - + + @@ -3854,9 +3885,10 @@ - + + @@ -3868,10 +3900,11 @@ - + + @@ -3881,8 +3914,9 @@ - + + @@ -3895,8 +3929,9 @@ - + + @@ -3909,7 +3944,8 @@ - + + @@ -3920,9 +3956,10 @@ - + + @@ -3934,9 +3971,10 @@ - + + @@ -3949,8 +3987,9 @@ - + + @@ -3962,8 +4001,9 @@ - + + @@ -3979,9 +4019,10 @@ - + + @@ -3997,9 +4038,10 @@ - + + @@ -4011,8 +4053,9 @@ - + + @@ -4024,9 +4067,10 @@ - + + @@ -4043,8 +4087,9 @@ - + + @@ -4057,8 +4102,9 @@ - + + @@ -4078,9 +4124,10 @@ - + + @@ -4090,7 +4137,8 @@ - + + @@ -4105,9 +4153,10 @@ - + - + + @@ -4125,9 +4174,10 @@ - + - + + @@ -4144,9 +4194,10 @@ - + - + + @@ -4160,13 +4211,14 @@ - + - + - + + @@ -4179,22 +4231,24 @@ - + - + + - - - - + - + + + + - + - + + @@ -4205,8 +4259,9 @@ - + + @@ -4218,9 +4273,10 @@ - + - + + @@ -4229,9 +4285,10 @@ - + - + + @@ -4239,9 +4296,10 @@ - + - + + @@ -4252,9 +4310,10 @@ - + - + + @@ -4263,9 +4322,10 @@ - + - + + @@ -4282,12 +4342,13 @@ - + - + + @@ -4304,7 +4365,8 @@ - + + @@ -4314,7 +4376,8 @@ - + + @@ -4334,17 +4397,18 @@ - + - + - + + @@ -4355,8 +4419,10 @@ - + + + @@ -4368,7 +4434,8 @@ - + + @@ -4378,7 +4445,8 @@ - + + @@ -4389,7 +4457,8 @@ - + + @@ -4405,7 +4474,8 @@ - + + @@ -4416,7 +4486,8 @@ - + + @@ -4428,7 +4499,8 @@ - + + @@ -4441,7 +4513,8 @@ - + + @@ -4455,7 +4528,8 @@ - + + @@ -4466,7 +4540,8 @@ - + + @@ -4478,7 +4553,8 @@ - + + @@ -4490,7 +4566,8 @@ - + + @@ -4501,7 +4578,8 @@ - + + @@ -4512,7 +4590,8 @@ - + + @@ -4525,7 +4604,8 @@ - + + @@ -4536,7 +4616,8 @@ - + + @@ -4547,7 +4628,8 @@ - + + @@ -4557,7 +4639,8 @@ - + + @@ -4569,7 +4652,8 @@ - + + @@ -4583,8 +4667,9 @@ - + + @@ -4597,7 +4682,8 @@ - + + @@ -4610,7 +4696,8 @@ - + + @@ -4620,7 +4707,8 @@ - + + @@ -4631,7 +4719,8 @@ - + + @@ -4641,7 +4730,8 @@ - + + @@ -4656,7 +4746,8 @@ - + + @@ -4669,7 +4760,8 @@ - + + @@ -4680,7 +4772,8 @@ - + + @@ -4692,7 +4785,8 @@ - + + @@ -4707,7 +4801,8 @@ - + + @@ -4719,18 +4814,8 @@ - - - - - - - - - - - - + + @@ -4742,49 +4827,10 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + @@ -4798,7 +4844,8 @@ - + + @@ -4811,7 +4858,8 @@ - + + @@ -4822,7 +4870,8 @@ - + + @@ -4835,8 +4884,9 @@ - + + @@ -4851,18 +4901,19 @@ - + - + - + + @@ -4877,8 +4928,9 @@ - + + @@ -4889,7 +4941,8 @@ - + + @@ -4901,7 +4954,8 @@ - + + @@ -4911,7 +4965,8 @@ - + + @@ -4921,7 +4976,8 @@ - + + @@ -4933,7 +4989,8 @@ - + + @@ -4944,7 +5001,8 @@ - + + @@ -4961,8 +5019,9 @@ - + + @@ -4975,7 +5034,8 @@ - + + @@ -4987,9 +5047,10 @@ - + + @@ -5007,7 +5068,8 @@ - + + @@ -5018,7 +5080,8 @@ - + + @@ -5029,7 +5092,8 @@ - + + @@ -5040,7 +5104,8 @@ - + + @@ -5051,7 +5116,8 @@ - + + @@ -5065,7 +5131,8 @@ - + + @@ -5077,7 +5144,8 @@ - + + @@ -5090,8 +5158,9 @@ - + + @@ -5106,8 +5175,9 @@ - + + @@ -5119,11 +5189,12 @@ - + - + + @@ -5142,7 +5213,8 @@ - + + @@ -5154,7 +5226,8 @@ - + + @@ -5165,14 +5238,15 @@ - + - + + @@ -5187,8 +5261,9 @@ - + + @@ -5200,8 +5275,9 @@ - + + @@ -5213,8 +5289,9 @@ - + + @@ -5228,8 +5305,9 @@ - + + @@ -5241,7 +5319,8 @@ - + + @@ -5254,9 +5333,10 @@ - + + @@ -5267,8 +5347,9 @@ - + + @@ -5281,10 +5362,11 @@ - + + @@ -5297,7 +5379,8 @@ - + + @@ -5312,9 +5395,10 @@ - + + @@ -5325,7 +5409,8 @@ - + + @@ -5342,8 +5427,9 @@ - + + @@ -5356,8 +5442,9 @@ - + + @@ -5374,7 +5461,8 @@ - + + @@ -5393,8 +5481,9 @@ - + + @@ -5406,10 +5495,11 @@ - + + @@ -5424,13 +5514,13 @@ - - - + + + @@ -5441,8 +5531,9 @@ - + + @@ -5457,9 +5548,10 @@ - + + @@ -5472,7 +5564,8 @@ - + + @@ -5484,8 +5577,9 @@ - + + @@ -5497,8 +5591,9 @@ - + + @@ -5512,16 +5607,16 @@ - - - + + - + + @@ -5531,7 +5626,8 @@ - + + @@ -5544,9 +5640,10 @@ - + + @@ -5558,7 +5655,8 @@ - + + @@ -5569,9 +5667,10 @@ - + + @@ -5593,12 +5692,13 @@ - + - + + @@ -5614,8 +5714,9 @@ - + + @@ -5633,9 +5734,10 @@ - + + @@ -5645,8 +5747,9 @@ - + + @@ -5660,9 +5763,10 @@ - + + @@ -5671,9 +5775,10 @@ - + + @@ -5689,8 +5794,9 @@ - + + @@ -5702,8 +5808,9 @@ - + + @@ -5716,7 +5823,8 @@ - + + @@ -5733,18 +5841,19 @@ - + - + - + + @@ -5760,7 +5869,8 @@ - + + @@ -5769,18 +5879,19 @@ - + - + - + + @@ -5796,7 +5907,8 @@ - + + @@ -5807,8 +5919,9 @@ - - + + + @@ -5820,8 +5933,9 @@ - + + @@ -5832,8 +5946,9 @@ - - + + + @@ -5843,7 +5958,8 @@ - + + @@ -5853,7 +5969,8 @@ - + + @@ -5863,9 +5980,10 @@ - + + @@ -5875,7 +5993,8 @@ - + + @@ -5892,9 +6011,10 @@ - + + @@ -5905,8 +6025,9 @@ - + + @@ -5919,7 +6040,8 @@ - + + @@ -5930,7 +6052,8 @@ - + + @@ -5942,7 +6065,8 @@ - + + @@ -5954,10 +6078,11 @@ - + + @@ -5971,9 +6096,10 @@ - + + @@ -5988,9 +6114,10 @@ - + + @@ -6002,8 +6129,9 @@ - + + @@ -6020,9 +6148,10 @@ - + + @@ -6035,9 +6164,10 @@ - + + @@ -6048,7 +6178,8 @@ - + + @@ -6060,8 +6191,9 @@ - + + @@ -6074,8 +6206,9 @@ - + + @@ -6085,9 +6218,9 @@ - - - + + + @@ -6095,9 +6228,9 @@ - - - + + + @@ -6106,9 +6239,9 @@ - - - + + + @@ -6116,9 +6249,9 @@ - - - + + + @@ -6128,8 +6261,9 @@ - + + @@ -6139,7 +6273,8 @@ - + + @@ -6154,8 +6289,9 @@ - + + @@ -6165,8 +6301,9 @@ - + + @@ -6176,7 +6313,8 @@ - + + @@ -6186,7 +6324,8 @@ - + + @@ -6194,10 +6333,10 @@ - - - + + + @@ -6211,8 +6350,9 @@ - + + @@ -6232,10 +6372,11 @@ - + - + + @@ -6247,8 +6388,9 @@ - + + @@ -6258,7 +6400,8 @@ - + + @@ -6268,7 +6411,8 @@ - + + @@ -6280,8 +6424,9 @@ - + + @@ -6289,13 +6434,13 @@ - - - + + - + + @@ -6305,7 +6450,8 @@ - + + @@ -6315,7 +6461,8 @@ - + + @@ -6326,8 +6473,9 @@ - + + @@ -6338,9 +6486,10 @@ - + + @@ -6350,9 +6499,10 @@ - + - + + @@ -6363,9 +6513,10 @@ - + - + + @@ -6375,7 +6526,8 @@ - + + @@ -6385,7 +6537,8 @@ - + + @@ -6395,7 +6548,8 @@ - + + @@ -6406,7 +6560,8 @@ - + + @@ -6417,9 +6572,10 @@ - + + @@ -6431,8 +6587,9 @@ - + + @@ -6442,8 +6599,9 @@ - + + @@ -6459,9 +6617,10 @@ - + + @@ -6472,7 +6631,8 @@ - + + @@ -6483,7 +6643,8 @@ - + + @@ -6493,7 +6654,8 @@ - + + @@ -6504,7 +6666,8 @@ - + + @@ -6514,7 +6677,8 @@ - + + @@ -6526,7 +6690,8 @@ - + + @@ -6537,8 +6702,9 @@ - + + @@ -6548,8 +6714,9 @@ - + + @@ -6560,8 +6727,9 @@ - + + @@ -6573,20 +6741,22 @@ - + + - - - + - + + + - + + @@ -6598,8 +6768,9 @@ - + + @@ -6613,7 +6784,8 @@ - + + @@ -6623,7 +6795,8 @@ - + + @@ -6631,9 +6804,9 @@ - - - + + + @@ -6646,8 +6819,9 @@ - + + @@ -6661,8 +6835,9 @@ - + + @@ -6672,7 +6847,8 @@ - + + @@ -6683,7 +6859,8 @@ - + + @@ -6695,7 +6872,8 @@ - + + @@ -6706,7 +6884,8 @@ - + + @@ -6721,7 +6900,8 @@ - + + @@ -6732,7 +6912,8 @@ - + + @@ -6742,7 +6923,8 @@ - + + @@ -6752,7 +6934,8 @@ - + + @@ -6765,7 +6948,8 @@ - + + @@ -6775,7 +6959,8 @@ - + + @@ -6786,7 +6971,8 @@ - + + @@ -6796,7 +6982,8 @@ - + + @@ -6808,8 +6995,9 @@ - + + @@ -6820,9 +7008,10 @@ - + + @@ -6832,7 +7021,8 @@ - + + @@ -6842,7 +7032,8 @@ - + + @@ -6853,7 +7044,8 @@ - + + @@ -6865,8 +7057,9 @@ - + + @@ -6876,9 +7069,10 @@ - + + @@ -6893,9 +7087,10 @@ - + + @@ -6906,8 +7101,9 @@ - + + @@ -6917,7 +7113,8 @@ - + + @@ -6927,7 +7124,8 @@ - + + @@ -6937,7 +7135,8 @@ - + + @@ -6947,7 +7146,8 @@ - + + @@ -6957,7 +7157,8 @@ - + + @@ -6968,11 +7169,12 @@ - + + @@ -6983,7 +7185,8 @@ - + + @@ -6994,7 +7197,8 @@ - + + @@ -7005,7 +7209,8 @@ - + + @@ -7018,7 +7223,8 @@ - + + @@ -7029,7 +7235,8 @@ - + + @@ -7040,7 +7247,8 @@ - + + @@ -7051,7 +7259,8 @@ - + + @@ -7062,7 +7271,8 @@ - + + @@ -7072,7 +7282,8 @@ - + + @@ -7082,7 +7293,8 @@ - + + @@ -7092,7 +7304,8 @@ - + + @@ -7102,7 +7315,8 @@ - + + @@ -7112,7 +7326,8 @@ - + + @@ -7122,7 +7337,8 @@ - + + @@ -7132,7 +7348,8 @@ - + + @@ -7142,7 +7359,8 @@ - + + @@ -7155,7 +7373,8 @@ - + + @@ -7165,7 +7384,8 @@ - + + @@ -7175,7 +7395,8 @@ - + + @@ -7198,9 +7419,10 @@ - + + @@ -7211,8 +7433,9 @@ - + + @@ -7229,9 +7452,10 @@ - + + @@ -7242,7 +7466,8 @@ - + + @@ -7252,7 +7477,8 @@ - + + @@ -7262,7 +7488,8 @@ - + + @@ -7276,8 +7503,9 @@ - + + @@ -7287,7 +7515,8 @@ - + + @@ -7297,7 +7526,8 @@ - + + @@ -7307,7 +7537,8 @@ - + + @@ -7318,7 +7549,8 @@ - + + @@ -7329,7 +7561,8 @@ - + + @@ -7341,9 +7574,10 @@ - + + @@ -7351,9 +7585,9 @@ - - - + + + @@ -7363,7 +7597,8 @@ - + + @@ -7374,7 +7609,8 @@ - + + @@ -7384,7 +7620,8 @@ - + + @@ -7394,7 +7631,8 @@ - + + @@ -7405,7 +7643,8 @@ - + + @@ -7415,7 +7654,8 @@ - + + @@ -7426,7 +7666,8 @@ - + + @@ -7437,7 +7678,8 @@ - + + @@ -7448,7 +7690,8 @@ - + + @@ -7459,7 +7702,8 @@ - + + @@ -7469,7 +7713,8 @@ - + + @@ -7479,7 +7724,8 @@ - + + @@ -7490,7 +7736,8 @@ - + + @@ -7500,7 +7747,8 @@ - + + @@ -7510,7 +7758,8 @@ - + + @@ -7520,7 +7769,8 @@ - + + @@ -7530,7 +7780,8 @@ - + + @@ -7541,7 +7792,8 @@ - + + @@ -7551,7 +7803,8 @@ - + + @@ -7561,7 +7814,8 @@ - + + @@ -7571,7 +7825,8 @@ - + + @@ -7583,8 +7838,9 @@ - + + @@ -7596,8 +7852,9 @@ - + + @@ -7607,7 +7864,8 @@ - + + @@ -7617,7 +7875,8 @@ - + + @@ -7627,7 +7886,8 @@ - + + @@ -7637,7 +7897,8 @@ - + + @@ -7647,7 +7908,8 @@ - + + @@ -7657,7 +7919,8 @@ - + + @@ -7667,7 +7930,8 @@ - + + @@ -7677,7 +7941,8 @@ - + + @@ -7687,7 +7952,8 @@ - + + @@ -7698,7 +7964,8 @@ - + + @@ -7708,7 +7975,8 @@ - + + @@ -7719,7 +7987,8 @@ - + + @@ -7729,7 +7998,8 @@ - + + @@ -7739,7 +8009,8 @@ - + + @@ -7749,7 +8020,8 @@ - + + @@ -7759,7 +8031,8 @@ - + + @@ -7769,7 +8042,8 @@ - + + @@ -7779,7 +8053,8 @@ - + + @@ -7789,7 +8064,8 @@ - + + @@ -7799,7 +8075,8 @@ - + + @@ -7809,7 +8086,8 @@ - + + @@ -7819,7 +8097,8 @@ - + + @@ -7829,7 +8108,8 @@ - + + @@ -7842,7 +8122,8 @@ - + + @@ -7852,7 +8133,8 @@ - + + @@ -7862,7 +8144,8 @@ - + + @@ -7872,7 +8155,8 @@ - + + @@ -7882,8 +8166,9 @@ - + + @@ -7893,8 +8178,9 @@ - + + @@ -7902,9 +8188,9 @@ - - - + + + @@ -7918,8 +8204,9 @@ - + + @@ -7930,7 +8217,8 @@ - + + @@ -7942,8 +8230,9 @@ - + + @@ -7951,10 +8240,11 @@ - + - + + @@ -7964,7 +8254,8 @@ - + + @@ -7976,7 +8267,8 @@ - + + @@ -7986,8 +8278,9 @@ - + + @@ -7998,7 +8291,8 @@ - + + @@ -8008,9 +8302,10 @@ - + + @@ -8021,8 +8316,9 @@ - + + @@ -8035,9 +8331,10 @@ - + + @@ -8047,7 +8344,8 @@ - + + @@ -8058,8 +8356,9 @@ - + + @@ -8074,8 +8373,9 @@ - + + @@ -8085,9 +8385,10 @@ - + - + + @@ -8098,8 +8399,9 @@ - + + @@ -8109,8 +8411,9 @@ - + + @@ -8122,7 +8425,8 @@ - + + @@ -8135,7 +8439,8 @@ - + + @@ -8146,7 +8451,8 @@ - + + @@ -8156,10 +8462,11 @@ - + + @@ -8170,7 +8477,8 @@ - + + @@ -8180,7 +8488,8 @@ - + + @@ -8190,7 +8499,8 @@ - + + @@ -8200,7 +8510,8 @@ - + + @@ -8215,8 +8526,9 @@ - + + @@ -8227,8 +8539,9 @@ - + + @@ -8238,7 +8551,8 @@ - + + @@ -8248,7 +8562,8 @@ - + + @@ -8258,7 +8573,8 @@ - + + @@ -8269,8 +8585,9 @@ - + + @@ -8285,7 +8602,8 @@ - + + @@ -8297,8 +8615,9 @@ - + + @@ -8308,8 +8627,9 @@ - + + @@ -8321,8 +8641,9 @@ - + + @@ -8333,8 +8654,9 @@ - + + @@ -8344,7 +8666,8 @@ - + + @@ -8365,7 +8688,8 @@ - + + @@ -8379,7 +8703,8 @@ - + + @@ -8391,7 +8716,8 @@ - + + @@ -8401,7 +8727,8 @@ - + + @@ -8411,7 +8738,8 @@ - + + @@ -8421,7 +8749,8 @@ - + + @@ -8431,7 +8760,8 @@ - + + @@ -8439,9 +8769,9 @@ - - - + + + @@ -8451,8 +8781,9 @@ - + + @@ -8461,10 +8792,10 @@ - - - + + + @@ -8472,10 +8803,10 @@ - - - + + + @@ -8486,8 +8817,9 @@ - + + @@ -8497,7 +8829,8 @@ - + + @@ -8508,10 +8841,11 @@ - + + @@ -8531,8 +8865,9 @@ - + + @@ -8546,7 +8881,7 @@ - + @@ -8558,8 +8893,9 @@ - + + @@ -8578,14 +8914,15 @@ - + - + + @@ -8610,8 +8947,9 @@ - + + @@ -8627,7 +8965,7 @@ - + @@ -8642,7 +8980,7 @@ - + @@ -8655,7 +8993,7 @@ - + @@ -8666,7 +9004,7 @@ - + @@ -8678,7 +9016,7 @@ - + @@ -8689,7 +9027,7 @@ - + @@ -8698,7 +9036,7 @@ - + @@ -8722,8 +9060,9 @@ - + + @@ -8733,7 +9072,7 @@ - + @@ -8742,7 +9081,7 @@ - + @@ -8753,7 +9092,7 @@ - + @@ -8766,7 +9105,7 @@ - + @@ -8778,7 +9117,7 @@ - + @@ -8790,7 +9129,7 @@ - + @@ -8805,7 +9144,7 @@ - + @@ -8820,7 +9159,7 @@ - + @@ -8832,7 +9171,7 @@ - + @@ -8841,7 +9180,7 @@ - + @@ -8852,7 +9191,7 @@ - + @@ -8863,7 +9202,7 @@ - + @@ -8876,7 +9215,7 @@ - + @@ -8890,7 +9229,7 @@ - + @@ -8903,7 +9242,7 @@ - + @@ -8914,7 +9253,7 @@ - + @@ -8939,11 +9278,12 @@ - + + @@ -8958,7 +9298,7 @@ - + @@ -8974,7 +9314,7 @@ - + @@ -8986,7 +9326,7 @@ - + @@ -9000,7 +9340,7 @@ - + @@ -9018,7 +9358,7 @@ - + @@ -9028,7 +9368,7 @@ - + @@ -9040,7 +9380,7 @@ - + @@ -9051,7 +9391,7 @@ - + @@ -9061,7 +9401,7 @@ - + @@ -9075,7 +9415,7 @@ - + @@ -9086,7 +9426,7 @@ - + @@ -9098,7 +9438,7 @@ - + @@ -9107,7 +9447,7 @@ - + @@ -9118,7 +9458,7 @@ - + @@ -9133,7 +9473,7 @@ - + @@ -9149,7 +9489,7 @@ - + @@ -9162,7 +9502,7 @@ - + @@ -9177,7 +9517,7 @@ - + @@ -9190,9 +9530,10 @@ - + + @@ -9208,7 +9549,8 @@ - + + @@ -9226,7 +9568,7 @@ - + @@ -9239,7 +9581,7 @@ - + @@ -9254,7 +9596,7 @@ - + @@ -9270,7 +9612,7 @@ - + @@ -9282,7 +9624,7 @@ - + @@ -9292,7 +9634,7 @@ - + @@ -9304,7 +9646,7 @@ - + @@ -9314,7 +9656,7 @@ - + @@ -9328,7 +9670,7 @@ - + @@ -9339,8 +9681,9 @@ - + + diff -r f9788970fa46 -r 7378b802ddf8 gtfsc.py --- a/gtfsc.py Wed Jul 29 23:45:53 2020 +0300 +++ b/gtfsc.py Thu Jul 30 21:52:31 2020 +0300 @@ -3,6 +3,7 @@ import sys import sqlalchemy import sqlalchemy.orm +import datetime from datamodel import * ROUTE_TYPES = { @@ -92,6 +93,22 @@ stop_longitude = float(row['stop_lon']), ) +def parse_time(timetext): + hour, minute, second = map(int, timetext.split(':')) + return datetime.timedelta(hours = hour, minutes = minute, seconds = second) + +def load_stop_times(gtfs_zip): + with gtfs_zip.open('stop_times.txt') as file: + for row in read_csv(map(bytes.decode, file)): + yield GtfsStopTime( + trip_id = row['trip_id'], + stop_id = row['stop_id'], + arrival_time = parse_time(row['arrival_time']), + departure_time = parse_time(row['departure_time']), + stop_sequence = int(row['stop_sequence']), + shape_distance_traveled = float(row['shape_dist_traveled']), + ) + def gtfs_stop_spatial_testing(session, regions): print('Finding out in which regions bus stops are...') from compute_regions import RegionTester @@ -138,12 +155,22 @@ print('Loading stops...') for stop in load_stops(gtfs_zip): session.add(stop) + session.commit() print('Loading shapes...') for shape in load_shapes(gtfs_zip): session.add(shape) + session.commit() print('Loading trips...') for trip_or_service in load_trips(gtfs_zip): session.add(trip_or_service) + session.commit() + print('Loading stop times...') + for i, stop_time in enumerate(load_stop_times(gtfs_zip)): + if i & 0xffff == 0: + # commit every now and then to keep RAM usage under control + session.commit() + session.add(stop_time) + session.commit() def parse_yesno(value): return value and value != 'no' @@ -154,31 +181,40 @@ names = dict() for prefix, language in product( ['', 'short_', 'internal_'], - ['', ':sv', ':en', ':ja'], + ['fi', 'sv', 'en', 'ja'], ): - key = 'region_' + prefix + 'name' + str.replace(language, ':', '_') - value = dict.get(region, prefix + 'name' + language) + key = 'region_' + prefix + 'name_' + language + value = dict.get(region, prefix + 'name:' + language) names[key] = value yield GtfsRegion( **names, + ref = region['ref'], municipality = dict.get(region, 'municipality'), external = parse_yesno(dict.get(region, 'external')), ) +def get_args(): + import argparse + parser = argparse.ArgumentParser() + parser.add_argument('profile') + parser.add_argument('gtfs') + parser.add_argument('--process-only', action = 'store_true') + return parser.parse_args() + if __name__ == '__main__': - import sys from configparser import ConfigParser from regions import parse_regions + args = get_args() profile = ConfigParser() - profile.read('föli.ini') + profile.read(args.profile) engine = sqlalchemy.create_engine('sqlite:///gtfs.db') GtfsBase.metadata.create_all(engine) session = sqlalchemy.orm.sessionmaker(bind = engine)() regions = parse_regions('föli.osm') - for region in regions_to_db(regions): - session.add(region) + if not args.process_only: + for region in regions_to_db(regions): + session.add(region) + session.commit() + buses = load_gtfs(args.gtfs, profile = profile, session = session) + gtfs_stop_spatial_testing(session = session, regions = regions) session.commit() - buses = load_gtfs('gtfs.zip', profile = profile, session = session) - gtfs_stop_spatial_testing(session = session, regions = regions) - print('Committing to database...') - session.commit() diff -r f9788970fa46 -r 7378b802ddf8 itienary_processing.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/itienary_processing.py Thu Jul 30 21:52:31 2020 +0300 @@ -0,0 +1,50 @@ +#!/usr/bin/env python3 +import sqlalchemy +import sqlalchemy.orm +from regions import parse_regions +from datamodel import * +engine = sqlalchemy.create_engine('sqlite:///gtfs.db') +GtfsBase.metadata.create_all(engine) +session = sqlalchemy.orm.sessionmaker(bind = engine)() +regions = parse_regions('föli.osm') + +def filter_itinerary(raw_itinerary): + encountered = set() + for region in raw_itinerary: + if region and region not in encountered: + yield region + encountered.add(region) + +def get_stoptimes(session): + yield from session \ + .query(GtfsStopTime) \ + .filter(GtfsStopTime.destination == None) \ + .limit(1000) + +def length_left(stoptime): + return stoptime.trip.shape.length - stoptime.shape_distance_traveled + +amount = session.query(GtfsStopTime).filter(GtfsStopTime.destination == None).count() +k = 0 +got_stoptimes = amount != 0 + +while got_stoptimes: + print('%.2f%%' % (k * 100 / amount)) + got_stoptimes = False + for stoptime in get_stoptimes(session): + got_stoptimes = True + k += 1 + itinerary = list(filter_itinerary( + entry.stop.stop_region + for entry in session.query(GtfsStopTime) + .filter(GtfsStopTime.trip_id == stoptime.trip_id) + .filter(GtfsStopTime.stop_sequence > stoptime.stop_sequence) + )) + from busroute import destinations_list + dests = destinations_list( + itinerary = itinerary, + trip_length = float(length_left(stoptime)), + regions = regions, + ) + stoptime.destination = '-'.join(dests) + session.commit() diff -r f9788970fa46 -r 7378b802ddf8 regions.py --- a/regions.py Wed Jul 29 23:45:53 2020 +0300 +++ b/regions.py Thu Jul 30 21:52:31 2020 +0300 @@ -33,11 +33,10 @@ return None # we're not interested in it! if shape[-1] != shape[0]: raise ValueError('polygon is not closed: %r' % result) - if 'boundary' not in result: - raise ValueError('polygon not tagged as a boundary: %r' % result) - shape = [nodes[ref] for ref in shape[:-1]] - choose_shapes(result, result['boundary']).append(Polygon(*shape)) - return result + if 'boundary' in result: + shape = [nodes[ref] for ref in shape[:-1]] + choose_shapes(result, result['boundary']).append(Polygon(*shape)) + return result def parse_boundaries(root, *, nodes): for child in root: @@ -54,22 +53,23 @@ regions = dict() extra_shapes = list() for way in parse_boundaries(root, nodes = nodes): - if 'boundary' in way and way['boundary'] != 'subregion' and 'name' in way: + if 'boundary' in way and 'ref' in way: # defines a region way['via_factor'] = int(way.get('via_factor', 1)) - if way['name'] in regions: + if way['ref'] in regions: raise ValueError(str.format( - 'Region {name} defined twice', - name = repr(way['name']), + 'Region {ref} defined twice', + ref = repr(way['ref']), )) - regions[way['name']] = way + regions[way['ref']] = way del way['boundary'] if 'external' in way: way['boundary'] = 'minor_region' for prefix in ['', 'short_', 'internal_']: - name_key = prefix + 'name' - if name_key in way and way[name_key] and name_key + ':ja' not in way: - way[name_key + ':ja'] = transliterate_katakana(way[name_key]) + name_key = prefix + 'name:fi' + ja_name_key = prefix + 'name:ja' + if name_key in way and way[name_key] and ja_name_key not in way: + way[ja_name_key] = transliterate_katakana(way[name_key]) elif 'boundary' in way and 'is_in' in way: # adds an extra shape to an existing region extra_shapes.append(way)