2021/01,江端さんの技術メモ

ca_sim=# select user_id, position_before, position_after from request_log_view;
user_id | position_before | position_after
---------+----------------------------------------------------+----------------------------------------------------
307 | 0101000020E61000003ACC9717607961407CB779E3A4D44140 | 0101000020E61000003EAE0D1563796140B56D1805C1D34140
491 | 0101000020E61000009E5DBEF56179614063EFC517EDD34140 | 0101000020E6100000F7AE415F7A7961406684B70721D44140
57 | 0101000020E61000001A8A3BDE6479614020D1048A58D44140 | 0101000020E610000079909E2287796140FD8348861CD34140
320 | 0101000020E6100000266F80996F79614041F50F2219D44140 | 0101000020E6100000740CC85E6F796140F58079C894D34140
208 | 0101000020E6100000D07B630880796140E84B6F7F2ED44140 | 0101000020E6100000199293895B7961405F5E807D74D44140
60 | 0101000020E6100000751E15FF7779614023A298BC01D44140 | 0101000020E6100000EF75525F96796140EFCA2E185CD34140

見易く、st_astextを使うと、

ca_sim=# select user_id, st_astext(position_before), st_astext(position_after) from request_log_view;
user_id | st_astext | st_astext
---------+-----------------------------+-----------------------------
307 | POINT(139.79298 35.661282) | POINT(139.793345 35.654328)
491 | POINT(139.793208 35.655673) | POINT(139.796188 35.657258)
57 | POINT(139.793563 35.658952) | POINT(139.797746 35.649308)
320 | POINT(139.794873 35.657017) | POINT(139.794845 35.652978)
208 | POINT(139.796879 35.657669) | POINT(139.792424 35.659805)
60 | POINT(139.795898 35.656303) | POINT(139.799606 35.651248)

となる。さて、上記の点が、ある円に属するかどうかを、判定したいんだが ・・・ まだ見つかっていない。

# 絶対にあるはずだ ―― と信じて、今日は寝よう。


起きた。活動開始。

https://myonyomu.hatenablog.com/

PostGIS(地理情報システムを実現するための拡張モジュール)

に、

gisdb=# CREATE INDEX ON t1 USING gist (p1);
CREATE INDEX

gisdb=# SELECT id, ST_AsText(p1) FROM t1 WHERE
  p1 &&
  Box2D(ST_GeomFromText('LINESTRING(139.5 36.5, 139.6 36.6)', 4326));
 id
-----
  11
 323
 503
 663
 669
 683
 804
(7 rows)

を見つけた。

矩形(四角形)に関しては、これでなんとかなりそう。

では、試してみよう。

の、user_idを取り出せるか?

ca_sim=# select user_id, ST_AsText(position_before) from request_log_view WHERE position_before &&  Box2D(ST_GeomFromText('LINESTRING(139.791326 36.663475, 139.795424 35.661496)', 4326));
 user_id |          st_astext
---------+-----------------------------
     149 | POINT(139.792855 35.662321)
     112 | POINT(139.79406 35.662354)
     159 | POINT(139.793198 35.662567)
      12 | POINT(139.792911 35.662442)
     355 | POINT(139.792903 35.662375)
     131 | POINT(139.793011 35.662165)
     490 | POINT(139.793132 35.662414)
     350 | POINT(139.792722 35.662398)
     301 | POINT(139.792798 35.662261)
(9 rows)
ca_sim=#
おお、できた、できた!!
じゃあ今度は、出発地点を"赤"の枠で、到着地点が"青"の枠内のものを探してみよう。

では、

まず、赤の部分と青の部分を指定して・・・

ca_sim=# select user_id, ST_AsText(position_before),ST_AsText(position_after) from request_log_view WHERE (position_before && Box2D(ST_GeomFromText('LINESTRING(139.791326 36.663475, 139.795424 35.661496)', 4326))) && (position_after && Box2D(ST_GeomFromText('LINESTRING(139.780310 35.643812,139.783851 35.641214)', 4326)));
ERROR: operator does not exist: boolean && boolean
LINE 1: ...791326 36.663475, 139.795424 35.661496)', 4326))) && (positi...
^
HINT: No operator matches the given name and argument types. You might need to add explicit type casts.

え、なんで、こうなるの? これで普通いけるよね ..... (ググりながら2~3時間経過)

まさか、&& AND が違うなんてことないよね ―― と思って、試しにやってみたら、

ca_sim=# select user_id, ST_AsText(position_before),ST_AsText(position_after) from request_log_view WHERE (position_before && Box2D(ST_GeomFromText('LINESTRING(139.791326 36.663475, 139.795424 35.661496)', 4326))) AND (position_after && Box2D(ST_GeomFromText('LINESTRING(139.780310 35.643812,139.783851 35.641214)', 4326)));
user_id | st_astext | st_astext
---------+-----------------------------+-----------------------------
149 | POINT(139.792855 35.662321) | POINT(139.782598 35.642426)
(1 row)

―― 通った。

まだ、円形ではないけど、とりあえず当初の目的(に近いとろまで)に達成。

ーーーーー

では、この#149さんの動きを見てみよう。

ca_sim=# select * from user_position_view where id = 149;
date_index | tm | id | x | y | position
------------+---------------------+-----+-----------+-----------+----------------------------------------------------
1 | 2021-01-01 07:57:45 | 149 | 139.79286 | 35.66232 | 0101000020E61000000BEF72115F7961401D3A3DEFC6D44140
1 | 2021-01-01 07:58:00 | 149 | 139.79286 | 35.66232 | 0101000020E61000000BEF72115F7961401D3A3DEFC6D44140
1 | 2021-01-01 07:58:15 | 149 | 139.79286 | 35.66232 | 0101000020E61000000BEF72115F7961401D3A3DEFC6D44140
1 | 2021-01-01 07:58:30 | 149 | 139.79286 | 35.66232 | 0101000020E61000000BEF72115F7961401D3A3DEFC6D44140
1 | 2021-01-01 07:58:45 | 149 | 139.79286 | 35.66232 | 0101000020E61000000BEF72115F7961401D3A3DEFC6D44140
1 | 2021-01-01 07:59:00 | 149 | 139.79286 | 35.66232 | 0101000020E61000000BEF72115F7961401D3A3DEFC6D44140
1 | 2021-01-01 07:59:15 | 149 | 139.79286 | 35.66232 | 0101000020E61000000BEF72115F7961401D3A3DEFC6D44140
1 | 2021-01-01 07:59:30 | 149 | 139.79286 | 35.66232 | 0101000020E61000000BEF72115F7961401D3A3DEFC6D44140
1 | 2021-01-01 07:59:45 | 149 | 139.79286 | 35.66232 | 0101000020E61000000BEF72115F7961401D3A3DEFC6D44140
1 | 2021-01-01 08:00:00 | 149 | 139.79286 | 35.66232 | 0101000020E61000000BEF72115F7961401D3A3DEFC6D44140
1 | 2021-01-01 08:00:15 | 149 | 139.79286 | 35.66232 | 0101000020E61000000BEF72115F7961401D3A3DEFC6D44140
1 | 2021-01-01 08:00:30 | 149 | 139.79286 | 35.66232 | 0101000020E61000000BEF72115F7961401D3A3DEFC6D44140
1 | 2021-01-01 08:00:45 | 149 | 139.79286 | 35.66232 | 0101000020E61000000BEF72115F7961401D3A3DEFC6D44140
1 | 2021-01-01 08:01:00 | 149 | 139.79286 | 35.66232 | 0101000020E61000000BEF72115F7961401D3A3DEFC6D44140
1 | 2021-01-01 08:01:15 | 149 | 139.79286 | 35.66232 | 0101000020E61000000BEF72115F7961401D3A3DEFC6D44140
1 | 2021-01-01 08:01:30 | 149 | 139.79286 | 35.66232 | 0101000020E61000000BEF72115F7961401D3A3DEFC6D44140
1 | 2021-01-01 08:01:45 | 149 | 139.79286 | 35.66232 | 0101000020E61000000BEF72115F7961401D3A3DEFC6D44140
1 | 2021-01-01 08:02:00 | 149 | 139.79286 | 35.66232 | 0101000020E61000000BEF72115F7961401D3A3DEFC6D44140
1 | 2021-01-01 08:02:15 | 149 | 139.79286 | 35.66232 | 0101000020E61000000BEF72115F7961401D3A3DEFC6D44140
1 | 2021-01-01 08:02:30 | 149 | 139.79286 | 35.66232 | 0101000020E61000000BEF72115F7961401D3A3DEFC6D44140
1 | 2021-01-01 08:02:45 | 149 | 139.79298 | 35.66228 | 0101000020E61000000A48FB1F607961408FE1B19FC5D44140
1 | 2021-01-01 08:03:00 | 149 | 139.7931 | 35.66223 | 0101000020E61000008D0C721761796140AE2EA704C4D44140
1 | 2021-01-01 08:03:15 | 149 | 139.79318 | 35.662155 | 0101000020E6100000BC7669C36179614032755776C1D44140
1 | 2021-01-01 08:03:30 | 149 | 139.79326 | 35.66208 | 0101000020E6100000EBE0606F6279614086376BF0BED44140
1 | 2021-01-01 08:03:45 | 149 | 139.7932 | 35.661995 | 0101000020E6100000514D49D661796140F9122A38BCD44140
1 | 2021-01-01 08:04:00 | 149 | 139.7931 | 35.66191 | 0101000020E6100000A54E4013617961409B728577B9D44140
1 | 2021-01-01 08:04:15 | 149 | 139.79301 | 35.661827 | 0101000020E6100000EC2E5052607961400E4E44BFB6D44140
1 | 2021-01-01 08:04:30 | 149 | 139.79291 | 35.66179 | 0101000020E6100000E7FEEA715F79614020ED7F80B5D44140
1 | 2021-01-01 08:04:45 | 149 | 139.79279 | 35.661766 | 0101000020E610000005323B8B5E79614098512CB7B4D44140
1 | 2021-01-01 08:05:00 | 149 | 139.79268 | 35.661743 | 0101000020E61000002F8672A25D796140DF313CF6B3D44140
1 | 2021-01-01 08:05:15 | 149 | 139.79257 | 35.661716 | 0101000020E61000004EB9C2BB5C7961405796E82CB3D44140
1 | 2021-01-01 08:05:30 | 149 | 139.79247 | 35.661694 | 0101000020E6100000780DFAD25B7961409F76F86BB2D44140
1 | 2021-01-01 08:05:45 | 149 | 139.79234 | 35.66167 | 0101000020E610000096404AEC5A796140E75608ABB1D44140
1 | 2021-01-01 08:08:15 | 149 | 139.79189 | 35.660706 | 0101000020E610000009C3802557796140809E060C92D44140
1 | 2021-01-01 08:08:30 | 149 | 139.79202 | 35.659588 | 0101000020E6100000CD76853E58796140217365506DD44140
1 | 2021-01-01 08:08:45 | 149 | 139.79245 | 35.65855 | 0101000020E6100000B3B27DC85B796140F163CC5D4BD44140
1 | 2021-01-01 08:09:00 | 149 | 139.79272 | 35.657696 | 0101000020E6100000DC114E0B5E79614011DF89592FD44140
1 | 2021-01-01 08:09:15 | 149 | 139.79266 | 35.656853 | 0101000020E6100000417E36725D796140C6A354C213D44140
1 | 2021-01-01 08:09:30 | 149 | 139.79323 | 35.655987 | 0101000020E61000006902452C62796140C3482F6AF7D34140
1 | 2021-01-01 08:09:45 | 149 | 139.7939 | 35.65513 | 0101000020E610000060E811A36779614001DD9733DBD34140
1 | 2021-01-01 08:10:00 | 149 | 139.79408 | 35.65424 | 0101000020E6100000F48AA71E6979614075E61E12BED34140
1 | 2021-01-01 08:10:15 | 149 | 139.79427 | 35.65335 | 0101000020E6100000882D3D9A6A796140E9EFA5F0A0D34140
1 | 2021-01-01 08:10:30 | 149 | 139.79384 | 35.652473 | 0101000020E61000005A2BDA1C6779614022C7D63384D34140
1 | 2021-01-01 08:10:45 | 149 | 139.79301 | 35.651573 | 0101000020E61000008D261763607961404276DEC666D34140
1 | 2021-01-01 08:11:00 | 149 | 139.79219 | 35.650677 | 0101000020E6100000B4006DAB5979614093A9825149D34140
1 | 2021-01-01 08:11:15 | 149 | 139.79135 | 35.64979 | 0101000020E610000011363CBD52796140191EFB592CD34140
1 | 2021-01-01 08:11:30 | 149 | 139.7904 | 35.649372 | 0101000020E6100000DAAED0074B796140B56FEEAF1ED34140
1 | 2021-01-01 08:12:00 | 149 | 139.78836 | 35.648926 | 0101000020E61000003C50A73C3A796140454772F90FD34140
1 | 2021-01-01 08:12:15 | 149 | 139.78905 | 35.648067 | 0101000020E6100000E5982CEE3F796140F44E05DCF3D24140
1 | 2021-01-01 08:12:30 | 149 | 139.788 | 35.647343 | 0101000020E610000007EA944737796140E3A9471ADCD24140
1 | 2021-01-01 08:12:45 | 149 | 139.78703 | 35.64754 | 0101000020E6100000D63906642F796140096D3997E2D24140
1 | 2021-01-01 08:13:15 | 149 | 139.7873 | 35.646866 | 0101000020E6100000BDA9488531796140A9F6E978CCD24140
1 | 2021-01-01 08:13:30 | 149 | 139.78622 | 35.64615 | 0101000020E61000005645B8C928796140BB270F0BB5D24140
1 | 2021-01-01 08:13:45 | 149 | 139.78516 | 35.645443 | 0101000020E61000004FE960FD1F79614080BBECD79DD24140
1 | 2021-01-01 08:14:00 | 149 | 139.7842 | 35.645493 | 0101000020E6100000B20FB22C1879614031EA5A7B9FD24140
1 | 2021-01-01 08:14:15 | 149 | 139.78342 | 35.64642 | 0101000020E610000050A73CBA11796140DAC534D3BDD24140
1 | 2021-01-01 08:14:30 | 149 | 139.78328 | 35.64658 | 0101000020E6100000C898BB9610796140849B8C2AC3D24140
1 | 2021-01-01 08:14:45 | 149 | 139.78336 | 35.64649 | 0101000020E610000027874F3A11796140A41CCC26C0D24140
1 | 2021-01-01 08:15:00 | 149 | 139.78343 | 35.646397 | 0101000020E61000007A54FCDF11796140F321A81ABDD24140
1 | 2021-01-01 08:15:15 | 149 | 139.78351 | 35.646305 | 0101000020E6100000CD21A9851279614012A3E716BAD24140
1 | 2021-01-01 08:15:30 | 149 | 139.78358 | 35.64621 | 0101000020E610000020EF552B1379614061A8C30AB7D24140
1 | 2021-01-01 08:15:45 | 149 | 139.78366 | 35.64612 | 0101000020E61000007FDDE9CE1379614080290307B4D24140
1 | 2021-01-01 08:16:00 | 149 | 139.78375 | 35.646027 | 0101000020E6100000D2AA967414796140CF2EDFFAB0D24140
1 | 2021-01-01 08:16:15 | 149 | 139.78383 | 35.64593 | 0101000020E61000002578431A157961401E34BBEEADD24140
1 | 2021-01-01 08:16:30 | 149 | 139.7839 | 35.64584 | 0101000020E61000008466D7BD157961403DB5FAEAAAD24140
1 | 2021-01-01 08:16:45 | 149 | 139.78398 | 35.64575 | 0101000020E6100000D7338463167961408CBAD6DEA7D24140
1 | 2021-01-01 08:17:00 | 149 | 139.78406 | 35.645657 | 0101000020E61000002A01310917796140AC3B16DBA4D24140
1 | 2021-01-01 08:17:15 | 149 | 139.78413 | 35.64556 | 0101000020E610000089EFC4AC17796140FB40F2CEA1D24140
1 | 2021-01-01 08:17:30 | 149 | 139.78423 | 35.64547 | 0101000020E6100000DCBC7152187961401AC231CB9ED24140
1 | 2021-01-01 08:17:45 | 149 | 139.7843 | 35.64538 | 0101000020E61000002F8A1EF81879614069C70DBF9BD24140
1 | 2021-01-01 08:18:00 | 149 | 139.78438 | 35.645287 | 0101000020E61000008257CB9D1979614088484DBB98D24140
1 | 2021-01-01 08:18:15 | 149 | 139.78445 | 35.64519 | 0101000020E6100000E1455F411A796140D74D29AF95D24140
1 | 2021-01-01 08:18:30 | 149 | 139.78453 | 35.6451 | 0101000020E610000034130CE71A796140F6CE68AB92D24140
1 | 2021-01-01 08:18:45 | 149 | 139.78462 | 35.64501 | 0101000020E610000033F9669B1B796140573F36C98FD24140
1 | 2021-01-01 08:19:00 | 149 | 139.78471 | 35.644928 | 0101000020E6100000035B25581C79614059A7CAF78CD24140
1 | 2021-01-01 08:19:15 | 149 | 139.78479 | 35.644833 | 0101000020E61000006249B9FB1C796140A8ACA6EB89D24140
1 | 2021-01-01 08:19:30 | 149 | 139.78487 | 35.64474 | 0101000020E6100000C1374D9F1D796140F7B182DF86D24140
1 | 2021-01-01 08:19:45 | 149 | 139.78494 | 35.64465 | 0101000020E61000002026E1421E79614045B75ED383D24140
1 | 2021-01-01 08:20:00 | 149 | 139.78502 | 35.644554 | 0101000020E61000007F1475E61E79614094BC3AC780D24140
1 | 2021-01-01 08:20:15 | 149 | 139.7851 | 35.644463 | 0101000020E6100000EA23F0871F796140E3C116BB7DD24140
1 | 2021-01-01 08:20:30 | 149 | 139.78517 | 35.644367 | 0101000020E61000004912842B2079614032C7F2AE7AD24140
1 | 2021-01-01 08:20:45 | 149 | 139.78525 | 35.644276 | 0101000020E6100000A80018CF2079614081CCCEA277D24140
1 | 2021-01-01 08:21:00 | 149 | 139.78534 | 35.644184 | 0101000020E610000007EFAB7221796140D0D1AA9674D24140
1 | 2021-01-01 08:21:15 | 149 | 139.78542 | 35.64409 | 0101000020E610000066DD3F16227961401FD7868A71D24140
1 | 2021-01-01 08:21:30 | 149 | 139.78549 | 35.643997 | 0101000020E6100000C5CBD3B9227961406EDC627E6ED24140
1 | 2021-01-01 08:21:45 | 149 | 139.78557 | 35.643906 | 0101000020E610000023BA675D23796140BDE13E726BD24140
1 | 2021-01-01 08:22:00 | 149 | 139.78564 | 35.64381 | 0101000020E61000009AEAC9FC23796140DC627E6E68D24140
1 | 2021-01-01 08:22:15 | 149 | 139.78552 | 35.64375 | 0101000020E610000000E484092379614037E2C96E66D24140
1 | 2021-01-01 08:22:30 | 149 | 139.78542 | 35.643684 | 0101000020E61000003659A31E227961405072874D64D24140
1 | 2021-01-01 08:22:45 | 149 | 139.78531 | 35.64362 | 0101000020E61000006CCEC133217961409886E12362D24140
1 | 2021-01-01 08:23:00 | 149 | 139.78519 | 35.643555 | 0101000020E6100000A243E04820796140B1169F0260D24140
1 | 2021-01-01 08:23:15 | 149 | 139.78508 | 35.64349 | 0101000020E6100000D8B8FE5D1F796140CAA65CE15DD24140
1 | 2021-01-01 08:23:30 | 149 | 139.78497 | 35.643425 | 0101000020E61000000E2E1D731E796140E3361AC05BD24140
1 | 2021-01-01 08:23:45 | 149 | 139.78485 | 35.64336 | 0101000020E610000044A33B881D7961402B4B749659D24140
1 | 2021-01-01 08:24:00 | 149 | 139.78474 | 35.643295 | 0101000020E61000007A185A9D1C79614044DB317557D24140
1 | 2021-01-01 08:24:15 | 149 | 139.78464 | 35.64323 | 0101000020E6100000B08D78B21B7961405D6BEF5355D24140
1 | 2021-01-01 08:24:30 | 149 | 139.78453 | 35.643158 | 0101000020E61000009F3C2CD41A796140C498F4F752D24140
1 | 2021-01-01 08:24:45 | 149 | 139.78442 | 35.64308 | 0101000020E61000005E6743FE19796140E9D66B7A50D24140
1 | 2021-01-01 08:25:00 | 149 | 139.78432 | 35.643013 | 0101000020E61000007079AC1919796140616F62484ED24140
1 | 2021-01-01 08:25:15 | 149 | 139.78418 | 35.64297 | 0101000020E610000059DE550F1879614062A3ACDF4CD24140
1 | 2021-01-01 08:25:30 | 149 | 139.78406 | 35.642925 | 0101000020E61000004E64E60217796140925B936E4BD24140
1 | 2021-01-01 08:25:45 | 149 | 139.78394 | 35.642883 | 0101000020E610000036C98FF815796140C2137AFD49D24140
1 | 2021-01-01 08:26:00 | 149 | 139.7838 | 35.64284 | 0101000020E61000001F2E39EE14796140C347C49448D24140
1 | 2021-01-01 08:26:15 | 149 | 139.78368 | 35.642796 | 0101000020E61000000893E2E313796140F3FFAA2347D24140
1 | 2021-01-01 08:26:30 | 149 | 139.78355 | 35.642754 | 0101000020E6100000FC1873D712796140F433F5BA45D24140
1 | 2021-01-01 08:26:45 | 149 | 139.78342 | 35.642708 | 0101000020E6100000E57D1CCD1179614025ECDB4944D24140
1 | 2021-01-01 08:27:00 | 149 | 139.7833 | 35.642666 | 0101000020E6100000CEE2C5C21079614055A4C2D842D24140
1 | 2021-01-01 08:27:15 | 149 | 139.78317 | 35.642624 | 0101000020E6100000B6476FB80F79614056D80C7041D24140
1 | 2021-01-01 08:27:30 | 149 | 139.78304 | 35.64258 | 0101000020E6100000ABCDFFAB0E7961408690F3FE3FD24140
1 | 2021-01-01 08:27:45 | 149 | 139.78291 | 35.642532 | 0101000020E61000009432A9A10D796140B648DA8D3ED24140
1 | 2021-01-01 08:28:00 | 149 | 139.78279 | 35.64249 | 0101000020E61000007D9752970C796140B77C24253DD24140
1 | 2021-01-01 08:28:15 | 149 | 139.78265 | 35.64245 | 0101000020E610000065FCFB8C0B796140E7340BB43BD24140
(112 rows)

ふむ、移動時間は、約30分というところか。

ゆりかもめを使うとこんな感じ

バスだと、こんな感じ

#149の人をトラッキングしてみました。

QGIS3 →  postGISから「新しいpostGIS接続を作成する」

(その前に、docker psで、DBのポート番号を抑えておくこと 0ba7ddf90bf2 pamtrak06/postgis-pgrouting-osm:latest "docker-entrypoint.s…" 4 hours ago Up 4 hours 0.0.0.0:8911->5432/tcp toyosu_postgres_1)

で、接続に成功したら、メニューの「データベース」から「DBマネージャ」を選択して、以下の順番に入力をしていく。

すると、こんな感じのものが出てくる。

waysを合わせてみるとこんな感じ

さらに、ways_vertices_pgrを重ねると、こんな感じ

#149さんの連続ルートはこれで見える。

select moving_route_log from request_log_view where user_id = 149;

■スマホを見て、走っているのバスに”飛び乗っている”(サービス稼動中の乗車の例)
①待ち時間が0の乗客を抽出する。(到着時刻-出発時刻-所要時間≒0)
到着時刻 request_log_view.time_after
出発時刻 request_log_view.time_before
所要時間 request_log_view.distance_on_foot [meter] と、 request_log_view.distance_by_bus [meter]、バスの速さ 30 km/h、人の速さ 3 km/h から計算する。
②ユーザのidから、移動履歴を取得する。

まず軽く実験 (time_after - time_before < '10 mins'を取り出す)

ca_sim=# select time_after, time_before from request_log_view where time_after - time_before < '10 mins';
time_after | time_before
------------+-------------
10:37:15 | 10:28:00
11:49:30 | 11:41:15
20:36:30 | 20:26:45
22:19:15 | 22:09:45
00:00:00 | 23:48:45
00:00:00 | 23:47:30
00:00:00 | 11:25:45
00:00:00 | 23:48:00
00:00:00 | 23:24:15
00:00:00 | 23:59:15
00:00:00 | 23:39:15
00:00:00 | 23:10:30

時刻と時間を表示させてみる 後半の2つは秒数になっている

ca_sim=# select time_after, time_before, distance_on_foot/0.8333, distance_by_bus/8.333 from request_log_view ;
time_after | time_before | ?column? | ?column?
------------+-------------+--------------------+--------------------
03:37:45 | 03:26:15 | 511.5950243478489 | 84.87666166802921
03:43:30 | 03:22:00 | 494.1959763351471 | 252.84164686899976
03:46:45 | 03:32:00 | 593.0148094595659 | 0
03:52:15 | 03:42:00 | 614.8145339876095 | 0
03:58:45 | 00:27:15 | 1931.1687506562762 | 402.76739975849034

さて、HH:MM:SSを"秒"の表記にする方法は、こうするらしい

ca_sim=# select time_after, time_before, time_after - time_before, (extract(epoch from (time_after - time_before)::time))::numeric from request_log_view;
time_after | time_before | ?column? | date_part
------------+-------------+-----------+-----------
00:28:00 | 00:16:15 | 00:11:45 | 705
00:32:00 | 00:12:15 | 00:19:45 | 1185
00:40:15 | 00:18:45 | 00:21:30 | 1290
00:41:45 | 00:11:45 | 00:30:00 | 1800
00:43:30 | 00:20:45 | 00:22:45 | 1365

では、本命 (到着時間 ー 出発時間 ー 歩行時間 ー 乗車時間 < 60(秒)以内)の乗客をピックアップしろ。

ca_sim=# select user_id,time_after, time_before, time_after - time_before, distance_on_foot, distance_by_bus from request_log_view where extract(epoch from (time_after - time_before)::time)::numeric - distance_on_foot/0.8333 - distance_by_bus/8.333 < 60;
user_id | time_after | time_before | ?column? | distance_on_foot | distance_by_bus
---------+------------+-------------+-----------+------------------+-----------------
234 | 00:28:00 | 00:16:15 | 00:11:45 | 563.23376 | 0
275 | 01:23:30 | 01:12:00 | 00:11:30 | 536.52704 | 0
324 | 03:23:15 | 03:07:45 | 00:15:30 | 731.304 | 0
118 | 03:52:15 | 03:42:00 | 00:10:15 | 512.32495 | 0
57 | 04:16:00 | 03:48:00 | 00:28:00 | 1388.9436 | 0
157 | 07:59:45 | 07:47:15 | 00:12:30 | 618.9883 | 0
458 | 07:59:45 | 07:41:45 | 00:18:00 | 898.75244 | 0
397 | 08:37:00 | 08:09:15 | 00:27:45 | 1363.375 | 0
410 | 08:52:00 | 08:27:30 | 00:24:30 | 1221.9526 | 0
395 | 09:52:15 | 09:41:45 | 00:10:30 | 516.0718 | 0
92 | 09:57:00 | 09:36:30 | 00:20:30 | 1023.69165 | 0
310 | 10:02:15 | 09:50:15 | 00:12:00 | 564.49817 | 0
90 | 10:02:45 | 09:50:45 | 00:12:00 | 596.32117 | 0
155 | 10:28:00 | 10:14:15 | 00:13:45 | 671.9812 | 0
178 | 11:49:30 | 11:41:15 | 00:08:15 | 372.38193 | 0
315 | 12:09:15 | 11:56:15 | 00:13:00 | 643.7695 | 0
481 | 12:11:00 | 11:55:45 | 00:15:15 | 685.71277 | 348.4668
399 | 12:11:45 | 11:49:00 | 00:22:45 | 1123.1423 | 0
127 | 15:00:15 | 14:41:30 | 00:18:45 | 913.04913 | 0
404 | 12:13:30 | 11:41:15 | 00:32:15 | 1562.6414 | 0
198 | 12:15:30 | 11:55:30 | 00:20:00 | 959.8891 | 0
32 | 12:48:15 | 12:27:30 | 00:20:45 | 1014.6684 | 0
116 | 13:06:15 | 12:48:00 | 00:18:15 | 911.0616 | 0
130 | 13:25:00 | 13:05:30 | 00:19:30 | 971.8267 | 0
411 | 15:42:00 | 15:26:00 | 00:16:00 | 788.83246 | 0
229 | 14:07:15 | 13:50:30 | 00:16:45 | 835.96875 | 0
61 | 14:15:45 | 14:01:15 | 00:14:30 | 684.7999 | 0
79 | 14:32:15 | 14:21:45 | 00:10:30 | 494.44864 | 0
317 | 22:20:00 | 22:05:00 | 00:15:00 | 730.14026 | 0
133 | 17:00:30 | 16:31:15 | 00:29:15 | 1454.8848 | 0
97 | 17:18:00 | 17:03:30 | 00:14:30 | 682.81305 | 0
193 | 18:29:30 | 18:05:30 | 00:24:00 | 1199.9945 | 0
80 | 18:55:00 | 18:44:15 | 00:10:45 | 497.08746 | 0
271 | 19:48:45 | 19:36:00 | 00:12:45 | 622.33954 | 0
298 | 19:50:15 | 19:36:00 | 00:14:15 | 694.23785 | 0
13 | 19:55:30 | 19:36:00 | 00:19:30 | 961.26294 | 0
496 | 22:19:15 | 22:09:45 | 00:09:30 | 447.28525 | 0
305 | 21:10:30 | 20:44:45 | 00:25:45 | 1262.3821 | 0
283 | 21:14:00 | 21:00:00 | 00:14:00 | 652.0706 | 0
67 | 21:29:00 | 21:05:45 | 00:23:15 | 1158.776 | 0
124 | 22:43:15 | 22:17:00 | 00:26:15 | 1281.6383 | 0
309 | 23:05:00 | 22:46:15 | 00:18:45 | 921.8486 | 0
338 | 00:00:00 | 23:59:15 | -23:59:15 | 0 | 0
(43 rows)

よし。ラストだ

■歩いて5分のコンビニからの帰宅にも使われている(近距離利用の例)
①出発座標と到着座標の距離が近い、かつ、バスに乗っている ユーザIDを取得する。
出発、到着: request_log_view.position_before、request_log_view.position_after
バスに乗っている: request_log_view.distance_by_bus > 0
②ユーザのidから、移動履歴を取得する。

5分以内は1人もいなかったけど、10分以内に1人だけいた

ca_sim=# select user_id,time_after, time_before, time_after - time_before, distance_on_foot, distance_by_bus from request_log_view where (extract(epoch from (time_after - time_before)::time)::numeric < 600) AND distance_
by_bus/8.333 > 0;
user_id | time_after | time_before | ?column? | distance_on_foot | distance_by_bus
---------+------------+-------------+----------+------------------+-----------------
14 | 10:37:15 | 10:28:00 | 00:09:15 | 92.753555 | 982.5703
(1 row)

 

結局、知り合いの方から教えて貰ったの方法で実現できたみたい (35.65457592, 139.79652749 を中心に300メートル)

ca_sim=# select user_id, ST_AsText(position_before) from request_log_view where st_dwithin(position_before, st_geomfromtext('POINT(139.79652749 35.65457592)', 4326), 0.03233394 / 3600 * 300);
user_id | st_astext
---------+-----------------------------
368 | POINT(139.797258 35.65431)
298 | POINT(139.795197 35.656211)
396 | POINT(139.795056 35.656002)
212 | POINT(139.794265 35.655042)

では、これでファイナル。

ca_sim=# select user_id, ST_AsText(position_before), ST_AsText(position_after) from request_log_view where st_dwithin(position_before, st_geomfromtext('POINT(1
39.79652749 35.65457592)', 4326), 0.03233394 / 3600 * 300) AND st_dwithin(position_after, st_geomfromtext('POINT(139.78482207 35.64501561)', 4326), 0.03233394 / 3600 * 300);
user_id | st_astext | st_astext
---------+-----------------------------+-----------------------------
388 | POINT(139.796825 35.653691) | POINT(139.783568 35.645798)
159 | POINT(139.794932 35.65632) | POINT(139.783022 35.645729)
316 | POINT(139.796816 35.656201) | POINT(139.787289 35.644699)
454 | POINT(139.795517 35.655392) | POINT(139.784164 35.646674)
428 | POINT(139.795264 35.655453) | POINT(139.785816 35.64436)
318 | POINT(139.79846 35.653964) | POINT(139.782998 35.643485)
349 | POINT(139.798028 35.654032) | POINT(139.785334 35.643373)
115 | POINT(139.795711 35.6562) | POINT(139.786663 35.645087)
72 | POINT(139.797807 35.656475) | POINT(139.785665 35.643757)
(9 rows)

忘れない内に、メモを色々残しておこう。

ca_sim=# SELECT home FROM user_param where st_dwithin("home", st_geomfromtext('POINT(139.79652749 35.65457592)', 4326), 0.03233394 / 3600 * 300);
home
----------------------------------------------------
0101000020E6100000B058C3456E796140FB1F60ADDAD34140
0101000020E610000040A6B5696C796140E19524CFF5D34140
0101000020E610000021904B1C79796140A2258FA7E5D34140
0101000020E610000081CCCEA277796140390B7BDAE1D34140

 

以上

 

 

2021/01,江端さんの忘備録

若者に「世界は広い」といっても無駄 ―― ということを分っていない大人が、多すぎるように思えます。

It seems that there are too many adults who do not understand that it is useless to tell young people that "It is the wide world".

この言葉は、『自殺したい』と思っている若者に、「もっとも心に響かない言葉 No.1」です。

These words are the "No. 1 most nihilistic words" for young people who want to commit suicide.

-----

そもそも「世界は狭い」のです。

In the first place, the world is a small place.

世界とは、自分の認知できる範囲が、その限界です。

The world is the limit of what we can perceive.

他人の世界がどーであるか ―― そんなこと分かりっこない。

There is no way to know what other people's worlds are like.

自己認知できない他人の世界感について、「狭い」だの「浅い」だの語る奴って ―― 真正の馬鹿、だと思う。

People who talk about other people's sense of the world as "small" or "shallow" when they can't even recognize it for themselves, is I think they are true idiots.

大人は、子どもの世界観を見下したように、この「世界は広い」を濫用しますが、子どもから見れば「失業や失職程度で自殺する大人」の世界観は分かりません。

Adults abuse the phrase "the world is big" in a condescending way to children's worldview. However, from a child's point of view, they do not understand the worldview of "adults who commit suicide because of unemployment or job loss.

それこそ、子どもから「死に気になれば、なんでもできるのに」と、思われているかもしれません。

That's what children may think, "If you're worried about death, you can do anything."

私は、他人に対する「世界は広い」という言葉の使用は、それ自体が、もの凄く失礼なことだと思っています。

I know that the use of the word "the world is wide" to others to be extremely rude in itself.

それは、他人の世界観に対する、無理解と不遜と軽視です。

It is incomprehension, irreverence and disrespect for the worldview of others.

-----

『自殺したい』と思っている若者を、本気で助けたいと思っているなら、やるべきことは、

If you really want to help a young guys who wants to commit suicide, what you have to do is

―― その若者の『自殺したい』原因を、物理的に除去する

"Physically eliminate the cause of the young man's "want to commit suicide""

この一択しかありません。

There is only this choice.

恐しく面倒で、鬱陶しく、おそらく費用も時間もかかると思いますが、これ以外の方法はありません。

It's horribly annoying, and probably expensive and time consuming, but there's no other way.

比して、若者に「世界は広い」と語る奴は ――

In comparison, the one who tells young people that the world is wide,

簡単に、楽して、お金も時間もかけずに、口先だけで「本人の資質」を変えようとしているだけの、

is a cowardly hypocrite who is simply trying to change his "qualities" with just his mouth, without spending money or time easily.

卑怯な偽善者です。

-----

私は、他人の世界観に分け入って、理解しようというエネルギーはありません。

I don't have the energy to break into and understand the world of others.

面倒くさいからです。

Because it is troublesome.

その代わり、誰かに、他人の世界観に分け入って貰って、理解して貰おうとかいう ―― 図々しいことも考えません。

Instead, I don't even think that I'd like someone to share in and understand the world of others

まあ、私なら、

Well, for me

「世界は広くないけど、時間が経過すると、世界の方が勝手に変わっていくこともあるから、それを待つという手もある」

"The world isn't big, but over time, the world can change on its own, so you can wait it out"

「『何も考えずに、ただ生きているだけ』という戦略だけで、何度か凌げたことがある」

"I've been able to surpass that a few times just by using the 'don't think about it, just live it' strategy.

くらいのことを、言うにとどめます。

I will only say that.

2021/01,江端さんの忘備録

本日は、コラムがリリースされた日なので、日記はお休みです。

Today, new my column is released, so I take a day off.

 

踊るバズワード ~Behind the Buzzword(10)ブロックチェーン(4):

反逆の通貨「ビットコイン」を使ってみた

Dancing Buzzword - Behind the Buzzword (10) Blockchain(4)

Trying to use the rebel currency, Bitcoin.

-----

以前、どこかで書いたような気がするのですが、以前、私が、「特許明細書とは、どのように書くのか?」と尋ねられた時、

I think I've written about this somewhere before, but once when I was asked, "How do you write a patent specification? I answered

―― 絵本のように書く

"Write like a picture book"

と応えたことがあります。

-----

『むかし、むかし、あるところに、

"Once upon a time, there were,

オブジェクトの位置情報をリアルタイムで転送する第一の手段と、

the first means of transferring the location information of the object in real time,

当該位置情報を受信する第二の手段と、

the second means of receiving said location information,

当該位置情報を地図上に表示する第三の手段

the third means of displaying said location information on a map.

がありました』

という3つの手段の図が記載された上に、その図を簡潔に説明する一枚の絵本のページ ――

A picture book page with a diagram of the three measures and a brief description of the diagram, inside the facing page.

これこそが、特許明細書の本質である、と。

This is the essence of a patent specification, I said.

-----

私のコラムは、よく「長い」と言われていますが、実際のテキストは、それほどボリュームがある訳ではありません。

My columns are often said to be "long," but the actual text is not that voluminous.

毎回、図表を20枚くらい投入しているから、長文に見えているだけです。

It just looks long because I throw in about 20 charts and tables every time.

ですから、私は、「コラムを執筆している」というよりは、「絵本を描いている」と思っています。

Therefore, I think of myself as "drawing picture books" rather than "writing columns"

----

まあ、仮に「絵本」だとしても「長い」のは確かですし、基本的に「長い」ものは「読みにくい」です。

Well, even if it were a "picture book", it would certainly be "long", and basically "long" things are "hard to read".

でも、それでいいんです。

But that's okay.

なぜなら、私は、「未来の私」に向けて書いているからです。

Because I am writing for the "future me".

未来の私が、自分のコラムを読んで「過去の自分が、何を書いたか分からなくなる」では困るのです。

I don't want the future me to read my column and "lose track of what I wrote in the past.

-----

例えば ――

For example --

出願から2年後くらいにやってくる、特許庁の審査官から拒絶理由通知書を受けて、改めて自分の特許明細書を読み直すと、

When I receive a notice of reasons for rejection from the examiner of the Patent Office, which comes about two years after the filing of the application, I re-read my patent specification and I come to think every time,

―― 私は、一体、何を言いたかったんだ?

"What the hell was I trying to say?"

と、思ってしまうのです ―― 毎回。

-----

未来の私に、私のコラムを届ける為には、私が何を考えていたのかを、一切省略することもなく、完全に書き尽くさなければならないのです。

In order to deliver my column to the future me, I have to write a complete account of what I was thinking, without any omissions.

図や表やイラストも、全て、「未来の私」の為です。

The diagrams, tables, and illustrations are all for the "future me".

まあ、今回のように、バラバラのテーマになってしまった場合には、お上(編集部)に、分割を命・・もとい、「依頼」されることもありますが。

Well, if the theme is disjointed, as it was in this case, the top management (the editorial department) may order, or even "request," a division.

2021/01,江端さんの技術メモ

"dummy.py"というファイルを投稿画面に添付しようとしたらこんな画面が出てきました。

で、昔なんかやったことがあるな、と思い出しながら、「WP Add Mime Types」というプラグインをインストールしたのを思い出しました。

以下のように設定したら、これで上手くいくようです。

以上

 

 

2021/01,江端さんの技術メモ

官能の人工知能 ~深層学習を最も分かりやすく説明するパラダイムOver the AI ―― AIの向こう側に(22)

"Artificial Intelligence in Sensuality -- The paradigm that most clearly explains deep learning
Over the AI -- Beyond AI (22)

で使ったソースコード(cpp)が見つからなかったので、添付しておきます。
I could not find the source code (cpp) used in the following, so I am attaching it.

simple-cnn8x8

simple-cnn 8x8

simple-cnn_8x8-2

ついでに、破壊実験の方も
Code for destructive experiments

口に出せない介護問題の真実 ~「働き方改革」の問題点とは何なのか
The Truth About Unspoken Nursing Care Issues - What is the Problem with "Workplace Reform"?

destructive_simple-cnn_8x8

destructive_simple-cnn_8x8-2

 

 

2021/01,江端さんの忘備録

「マーケットイン」とか、「デザイン思考」とか、まあ、言っていることは分かるんですけどね。

I understand what they are saying about "market-in" and "design thinking".

これらが言いたいことは、詰るところ『技術指向では、ビジネスにならない』ということで、

What they are trying to say is that, in essence, "technology oriented is not a viable business.

この手の話、ずっと昔から、散々言われ続けてきて、もう聞き飽きているんですよ ―― 私。

I've been hearing this kind of thing for a long time, and I'm tired of hearing it.

-----

ただ、私の長年の観測から見れば、「マーケットイン」だの「デザイン思考」だのを、繰り返す人間って、

However, from my observation over the years, people who repeat "market-in" and "design thinking",

―― うわー、あいつ技術力ないわー

"have no technical skills"

とか、

or

―― モノを作り切る力量が見当たらないわー

have no ability to make things fully.

とか、

or

―― あいつが完成させた製品って、知らんわー(パワポの資料しか見たことないわー)

have no completed product (I've only seen their powerpoint documents)

という人間が多い気がするんですが、私の気のせいでしょうか?

I feel like there are a lot of people like that, but am I wrong?

-----

もちろん、私は、ビジネスにおける「マーケットイン」とか「デザイン思考」の重要性を否定しませんが、

Of course, I don't deny the importance of "market-in" or "design thinking" in business, but

私に限っていえば、

As far as I'm concerned,

『一つのモノを完成させたこともない奴の語る「マーケットイン」とか「デザイン思考」という言葉は、信じない』

"I don't believe in the words 'market-in' or 'design thinking' spoken by people who have never completed a single product"

です。

2021/01,江端さんの忘備録

故小松左京先生の「果しなき流れの果に」は、小松文学の最高傑作という評価があります。

The late Sakyo Komatsu's "The End of the Endless Stream" is regarded as one of the best works of Komatsu literature.

私は、この評価を、断固として「支持」します。

I firmly "support" this assessment.

この作品の中に、ルキッフという人物が登場するのですが、学生の頃、私は私のあだ名を「ルキッフ」と読んでくれ、と友人たちに頼んでいました。

In this work, there is a character named Lukif, and when I was a student, I used to ask my friends to call my nickname as "Lukif.

ちなみに、私は、最近の教育現場の「あだ名禁止」に賛成する一人です。不快なあだ名を付けられた当事者だからです。

Incidentally, I am one of those who agree with the recent "ban on nicknames" in education. This is because I am a person who has been given unpleasant nicknames.

本人が申告した「あだ名」については特例として良いかとも思うのですが、こういう特例を作ると、なし崩し的に、ルールが崩壊するので、やめた方がいいでしょう。

I think it would be a good idea to make a special exception for "nicknames" reported by the person their selves, but it would be better not to make such a special exception, as it would collapse the rules in an uncontrollable manner.

ともあれ、私のこの自己申告の「あだ名」、友人の殆んどが使ってくれませんでしたが。

Anyway, my self-declared nickname was not used by most of my friends.

-----

「果しなき流れの果に」のストーリーは、こんな感じです。

The story of "The End of the Endless Stream" goes like this.

『地球が、太陽の異常でいましも終焉を迎えようとしていた時、「審判者」は、超能力を持つ人間を選別し、多くの地球人たちをつれ去っていた』

"When the earth was about to end due to the anomaly of the sun, the "judgment" disguised as an "alien" selected humans with supernatural powers and took away many earthlings.

『だが、これに抵抗する勢力があった。あらゆる変化のベクトル対する抵抗力が形象化された存在"ルキッフ"をリーダーとする、一団である』

"But there was a force to resist this. It is a group led by "Lukif", an entity that embodies the resistance to the vector of every change. "

つまり ――

That means,

■「力のある知性のある集団による、御仕着せの善意」を拒否し、

- Rejecting "the good intentions of the punishment by a powerful and intelligent group"

■「力のない無知性な個人による、誤った自己決定」を選ぶ

- Select "wrong self-determination by a weak and ignorant individual"

この物語の中には、そういった「『間違った生き方』を歩む人間に対する『力強い肯定』」があります。

In this novel, there is such a "strong affirmation" for humans who walk the "wrong way of life."

-----

・・・で、実は、私、この話をきっかけに何かを語ろうとしたんですけど、それを忘れてしまいました。

So, actually, I tried to talk about something in the wake of this story, but I forgot it.

格好悪いオチになってしまいました。

It has become a ugly punch line.

2021/01,江端さんの忘備録

長女:「ぶっちゃけ、パパは、今の在宅勤務の状況、どう思っている?」

Daughter: "To be frank, Dad, what do you think of the current telecommuting situation?"

私:「基本的に、私の仕事の内容は、資料作成とコーディングだから、会社の設備が必須かと言われると、そうでもない」

I: "Basically, my job description is creating documents and coding, so if you're asking me if the company's equipment is essential, it's not."

長女:「ミーティングとかは?」

D: "Any meetings or anything?"

私:「本当に細かい仕様策定などは、F2Fミーテイングでないと、できないこともある ―― まあ、それも工夫しだいかな。ミーティングの回数を増やすとか」

I: "I need some things that can only be done in a F2F meeting, such as really detailed specifications. Well, there's room for innovation in that, too. Maybe we should increase the number of meetings."

長女:「ストレスは?」

D: "Are you stressed?"

私:「『ない』という訳ではないけど、ニュースのインタビューで言われているような『外出ストレス』は、他の人よりは小さいように思う。そもそも、私は『人間嫌い』だそうだし」

I: "I wouldn't say 'no,' but I think I have less 'out-of-town stress' than other people, like they say in the news interviews. I hear I'm a 'misanthrope' to begin with."

長女:「じゃあ、このコロナ禍の状況がずっと続けばいい、と思っている?」

D: "So, do you hope that this corona disaster situation will continue forever?"

私:「それはない。凶悪な殺人ウイルスが存在している世界は、続いて欲しくない。できれば「ワクチン」で決着がついて欲しいと、心底から願っている ―― が・・・」

I: "It won't. I don't want the world to continue with a vicious killer virus. I sincerely hope that a vaccine will be the answer, if possible -- but..."

長女:「?」

D:"?"

私:「本当に「ワクチン」で決着が付くのか、今一つ確信が持てない。新型コロナの亜種、別のウイルスが登場もあるかもしれない」

I: "I'm still not convinced that a 'vaccine' will really settle the issue. There may be a variant of the new corona, another virus."

長女:「それで?」

D: "And?"

私:「これからの、殺人ウイルスとの共存を考えると、少なくとも、これからの世界は、多人数による同じ場所を共有する行動 ―― 『修学旅行』『文化祭』『高校野球、特に甲子園大会』など、廃止とまでは言わないまでも、縮小方向にパラダイムシフトした方が良いと思う。そして『運動会』。うん、これは廃止の一択しかないな」

I: "Considering the future coexistence with the killer virus, at least in the future, the world should make a paradigm shift to reduce, if not abolish, activities where many people share the same place, such as school trips, cultural festivals, and high school baseball games, especially the Koshien tournament. And " Athletic meets". Yeah, there's no choice but to abolish it"

長女:「・・・」

D: "..."

私:「修学旅行は、グループ人数4人以下にして、各グループが予算と期間を決めて、好きなところに行けばいい。もちろん、「一人旅」もありだ。それくらいの自由裁量があってもいい」

I: "For the school trip, the group size should be no more than four people, and each group can decide the budget and duration of the trip, and go wherever they want. Of course, you can also travel alone. It would be nice to have that much discretion"

長女:「・・・」

D: "..."

私:「そして、世界は『飲み会』を諦める ―― アフターコロナでも」

I: "And the world gives up 'drinking' -- even after Corona"

2021/01,江端さんの技術メモ

  1. Makrdown → html の場合
    pandoc -s sample.md -o sample.html
  2. markdown → docx  の場合
    pandoc -s sample.md -o sample.docx
  3. html → markdownの場合
    pandoc -s sample.html -o sample.md
  4. docx → markdownの場合
    pandoc -s sample.docx -o sample.md