未分類

https://airensoft.gitbook.io/ovenmediaengine/getting-started
のコピペ

オーブンメディアエンジン

 

はじめる

Docker イメージの使用を開始する

OvenMediaEngine は、AirenSoft の Docker Hub (airensoft/ovenmediaengine) リポジトリから Docker イメージを提供します。 Dockerイメージを利用することで簡単にOvenMediaEngineサーバーを利用することができます。詳細については、「Docker 入門」を参照してください。

ソースコードの入門
依存関係のインストール

OvenMediaEngine は、さまざまなオープンソースやライブラリと連携できます。まず、以下で説明するように、これらをクリーンな Linux マシンにインストールします。 OME はほとんどの Linux パッケージをサポートできると考えていますが、使用するテスト済みのプラットフォームは Ubuntu 18 以降、Fedora 28 以降、および CentOS 7 以降です。

curl -LOJ https://github.com/AirenSoft/OvenMediaEngine/archive/v0.16.5.tar.gz && \
tar xvfz OvenMediaEngine-0.16.5.tar.gz && \
OvenMediaEngine-0.16.5/misc/prerequisites.sh

prerequisites.sh スクリプトが失敗した場合は、実行しsudo apt-get updateて再実行してください。これで十分でない場合は、手動インストールに進みます。

構築と実行

次のコマンドを使用して、OvenMediaEngine ソースをビルドできます。

sudo apt-get update
cd OvenMediaEngine-0.16.5/src
make release
sudo make install
systemctl start ovenmediaengine
# If you want automatically start on boot
systemctl enable ovenmediaengine.service 

$ systemctl | grep oven
ovenmediaengine.service loaded active running OvenMediaEngine
と稼働状態を確認できる

Fedora で失敗する場合はsystemctl start ovenmediaengine、SELinux が原因である可能性があります。「トラブルシューティング」の「SELinux の確認」セクションを参照してください。

デフォルトで使用されるポート

デフォルト構成では次のポートが使用されるため、ファイアウォール設定でポートを開く必要があります。

ポート 目的

1935/TCP

RTMP入力

9999/UDP

SRT入力

4000/UDP

MPEG-2 TS入力

9000/TCP

オリジンサーバー (OVT)

3333/TCP 3334/TLS

LLHLS ストリーミング * 非 TLS 経由のストリーミングは、最新のブラウザでは許可されません。

3333/TCP 3334/TLS

WebRTC シグナリング (取り込みとストリーミングの両方)

3478/TCP

WebRTC TCP リレー (TURN サーバー、取り込みとストリーミングの両方)

10000~10009/UDP

WebRTC Ice 候補 (取り込みとストリーミングの両方)

TLS を使用するには、証明書を設定する必要があります。詳細については、「TLS 暗号化」を参照してください。

次の例のようにファイアウォール ポートを開くことができます。

$ sudo firewall-cmd --add-port=3333/tcp
$ sudo firewall-cmd --add-port=3334/tcp
$ sudo firewall-cmd --add-port=1935/tcp
$ sudo firewall-cmd --add-port=9999/udp
$ sudo firewall-cmd --add-port=4000/udp
$ sudo firewall-cmd --add-port=3478/tcp
$ sudo firewall-cmd --add-port=9000/tcp
$ sudo firewall-cmd --add-port=10000-10009/udp

最終更新

 

-----
のコピペ

OvenPlayer

 

Builds

This section describes the development and builds process.

How to write code

OvenPlayer uses npm and webpack when building. If you are using npm for the first time, please refer to Install Node.js, npm. In addition, you need to configure the environment to keep this up-to-date and working.

Environment

If npm works well on your system, run the following command in Terminal to install the packages needed to develop OvenPlayer, such as webpack.

$ npm ci
Production Build

If you want to modify the source code, you need to write it manually.

If you are cloning a project for the first time, you can find already built files in the dist/ directories.

However, you can build your modified source code with the following command. The built source code can be found in the dist/ directory.

npm run build

This command allows you to build the webpack automatically whenever the source code is modified.

Development Build

It is inefficient to build code every time during development and testing. If you use the watch function, webpack detects changes in the source code and automatically builds it quickly. The development built source code can be found in the dev/ directory.

npm run watch

Last updated 

 

未分類

「地球から240億キロ、ボイジャー1号システム復旧に成功 5カ月ぶりに解読可能データ受信」

"24 Billion Kilometers from Earth, Voyager 1 System Recovery Successful, Receives First Decipherable Data in Five Months."

という記事を読んで、感極まる人はそれほど多くないかもしれません。

Not many people may be moved to tears when they read an article called

しかし、私は涙が出そうになりました。

However, I almost cried.

『9日間の忍耐』ができるエンジニア ―― これが、SLIMプロジェクトのエンジニアの皆さんと、私の決定的な差です。

はやぶさの映画

"ボイジャー" ―― この一語だけで、私は、もう、思考停止してしまうのです。

"Voyager" -- this one word is enough to make me stop thinking.

■「さよならジュピター」に使われた「VOYAGER~日付のない墓標」

■"VOYAGER - Tombstone without Date" used in "Farewell Jupiter"

1995年の地上波の「ヤシマ作戦」と「MAGIシステム乗っ取り」で止まっていた私の中で、今、何かが動き始めました。

■「秒速5センチメートル」の「コスモナウト」の主人公の邂逅

■A chance encounter with the protagonist of "Cosmonaut" in "5 Centimeters per Second".

"それは本当に、想像も絶するくらい孤独な旅であるはずだ"

"It really must be an unimaginably lonely journey."

"本当の暗闇の中をただひたむきに、一つの水素原子にさえ、めったに出会う事なく、ただただ深淵にあるはずと信じる世界の秘密に近づきたい一心で"

"Just to go on and on through the real darkness, rarely encountering even a single hydrogen atom, just with the single desire to get closer to the secrets of the world that I believe must lie in the abyss."

-----

ネットワークでのリモートホストを行うための"ping"の応答時間は、長くても1秒以内。

The response time for a "ping" to the remote host on the network is less than one second at most.

比して、ボイジャー1号との応答時間は、45時間(162000秒)です。

In comparison, the response time to Voyager 1 is 45 hours (162,000 seconds).

『このチップを修理する手段がなかったことから、同チームはこのチップに保存されていたコードを同システムのメモリーの別の場所に移すことにした。全てのコードを保存できる区画は見つけることができなかったが、コードをセクションに分割して、それぞれ飛行データシステムの別々の場所に保存することに成功した。』

'Since there was no way to repair this chip, the team moved the stored codes to another location in the system's memory. Although they could not find a compartment to store all the codes, they could break them into sections and store each in a separate location in the flight data system.'

―― マジか!

"Really!?"

これは、240億キロの彼方にいる患者の脳の毛細血管のバイパス手術を、目をつむりながら、その状態の一つ一つを45時間ごとに確かめて行うという、想像を絶するオペレーションです。

This operation is unimaginable to bypass the capillaries of a patient's brain, 24 billion kilometers away, with his eyes closed, checking each one of its conditions every 45 hours.

しかも、多分、数ビット/秒通信という中、誤って通信リンクを切断したら、もう永遠にボイジャー1号とは通信ができない、という、最大級のリスクを背負っての、極限の環境下でのオペレーションです。

Moreover, the operation was in an extreme environment with the highest level of risk. If they mistakenly cut the communication link by a few bits per second, the communication with Voyager 1 would be lost forever.

この"もの凄さ"を、どうやったら説明できるだろうか ―― 私には、到底表現しきれない"偉業"で、そして"奇跡"です。

How can I describe the "greatness" of this "feat" and "miracle" that I cannot even begin to describe?

-----

この技術者たちの『もの凄さ』を言語で表現できないので、私は、他の人間に当たり散らすことにします。

Since I can't express in words the 'awesomeness' of these technicians, I'll hit others.

「UFOの呼び方」とかの本を書いている奴、それを信じている奴、実施している奴。

Who writes books like "How to Call UFOs," who believes in them, and who tries them?

お前たちが何を信じているかは、もちろん、お前たちの自由ではある。

What you believe is, of course, up to you.

しかし、「45億キロメートルの彼方の宇宙空間探査」に「応答時間45時間」で、「メモリ上のコード移動」を成し遂げ、そして「再起動」を成し得たエンジニアたちの、気の遠くなるような努力と、その成果に対して、

But for the mind-boggling efforts and accomplishments of the engineers who managed to 'move the code in memory' and 'reboot it' in '45 hours of response time' to 'space exploration 4.5 billion kilometers away', I would like to say a few words,

『お前たちの口から、何か語れることがあるか?』

"What can you tell them about what you do?"

とは、問いたい。

 

未分類

江端家公認の「暴力装置」の江端です。

I am Ebata, the official "violent device" of the Ebata family.

『江端家における、家長であるこの私(江端)の役割は、この外交 ―― "交渉"と"戦争"である』

暴力装置の実施例としては、

Examples of violent devices include,

(1)学校の校長室に、直談判・・・もとい、話し合いをしにいったことがある

(1) I once went to the principal's office of a school to knock him down, or rather, to discuss the matter with him.

(2)年金センタで、形式不備の書類に対して、役所の責任の所在について争って、不備書類を受理させたことがある

(2) Once, at a pension center, I disputed the responsibility of the government office for an incomplete document and had the incomplete document accepted.

(3)スマホの解約と契約に関して、不誠実な対応に対して、期限を定めて対応を強制完了させたことがある

(3) I have forced a customer to complete the cancellation and contract of a smartphone by setting a time limit for the customer to respond to a dishonest response.

などでしょうか。

-----

いずれも、私以外の家族の問題だったのですが、当事者は、私が窓口で闘っている最中に、スマホや本を読んでいる落ち着きぶりです。

In each case, the problem was a family member other than myself, but the parties involved were restless, reading their phones or books while I was fighting with them at the counter.

私が出張ってくる前に、

Before I joined the problem,

『私の父が、"本気"で動き出したら、あなた"本当"に"終わり"ますよ』

"If my father comes, he will kill you.

と言ったとか。

I heard that she said that.

-----

私の場合、カスハラ(カスタマーハラスメント)とは一線を画してます。

In my case, the following are not customer harassment.

(1)事件の経緯を時系列に並べて、文面に記載する

(1) I list the case process chronologically in the text.

(2)(こちら側も含めて)事件の責任の所在を、きちんと分離する

(2) Properly separate the responsibility for the incident (including our side).

(3)その上で、事件の問題点を双方で確認する。

(3) Then, both parties confirm the issues in the case.

(4)上記(1)~(3)を含めた上で、規則と法律と常識(社会通年)に照らして、どちらにどれだけの不合理と不利益があるかをまとめる

(4) After including (1) through (3) above, summarize which is unreasonable and disadvantageous in light of the rules, the law, and common sense (social common sense).

このように、背景、課題を明確にした上で、

Thus, after clarifying the background and issues,

(5)双方の落とし所を探して、必要な対応を要求し、かつ、こちらが準備している対応(×報復)手段を相手側に、明確に伝える。

(5) Find a compromise point for both sides, demand the necessary response, and inform the other side of the reaction (x retaliation) measures we are prepared to take.

(6)指定した機関内に、相手側が対応を実施しない場合、対応(×報復)を"100%"実行する。

(6) If the other party does not take action within the specified period, the response (x retaliation) is executed "100%".

この辺のアプローチは、(自腹切って通っていた)法学ゼミの勉強が活用できているように思います。

I think I have been able to use my studies at the law seminar (which I attended at my own expense) in this approach.

私は、『この世の中に無駄な勉強などない』などとは言いませんし、『さすがに、それは嘘だろう』と思います。

I would not say, 'There is no such thing as useless study in this world,' I think, 'indeed, that would be a lie.

でも『勉強したことが役に立つことは多い』という気はしています。

But I feel that 'what I have studied is often helpful.

分かりやすい『部内恋愛禁止』の制度趣旨

-----

娘:『パパって、"無理"を通すのが上手いよね』

Daughter: "You're good at making things impossible, aren't you, Dad?

江端:『それは断じて違うぞ。私は"法律"や"ルール"に基づいて主張をしているだけだ。それ以上のことも、それ以下のこともしていない』

Ebata: "That is not true. I am only making a statement based on the "law" and "rules. I am not doing anything more or less than that.

私は、本当にそう信じています。

I genuinely believe that.

-----

多くの人からは、受けいれて貰えないかもしれませんが、私は普段から、

I know many people may not accept this, but I usually think.

―― 『法律の使用方法』って、『数学の証明』や『プログラムのアルゴリズム』に似ているよなぁ

"How to use the law" is like "mathematical proofs" or "program algorithms."

とは、思っています。

―― 法律とは、「数学の証明」あるいは「システムのプログラミング」と同じである

未分類

WindowsのDockerでFlutter for Web(開発環境構築)

https://qiita.com/toshibe/items/e05ebe152e579ad39a58

で、色々問題がでてくるけど、

Flutter

https://qiita.com/tiri/items/5ad8d173df2c3823a265

の記載の内容で対応できました。

動かし方

1. Dockerfileからイメージを作成する

docker-compose build

 2. イメージからコンテナを作成し、起動する

docker-compose up -d

 3. 起動したコンテナに入る

docker exec -it flutter bash

4. フラッターアプリを作成する

cd workspace
flutter create .

5. サーバーを立ち上げる

flutter run -d web-server --web-port=${WEB_SERVER_PORT} --web-hostname 0.0.0.0

さて、これでサンプルは動かせたんだけど、さて、コーディングはどうやるのかな?


docker exec -it flutter bash でシェルに入った後、

root@0c0fd167601e:/usr/local# ls
Android bin etc flutter games include lib man sbin share src workspace
root@0c0fd167601e:/usr/local# cd workspace/
root@0c0fd167601e:/usr/local/workspace# ls
README.md android ios linux pubspec.lock test windows
analysis_options.yaml build lib macos pubspec.yaml web workspace.iml
root@0c0fd167601e:/usr/local/workspace# cd test
root@0c0fd167601e:/usr/local/workspace/test# ls
widget_test.dart ← これがターゲットのソース(だと思う)

root@0c0fd167601e:/usr/local/workspace/test#more widget_test.dart

 

// This is a basic Flutter widget test.
//
// To perform an interaction with a widget in your test, use the WidgetTester
// utility in the flutter_test package. For example, you can send tap and scroll
// gestures. You can also use WidgetTester to find child widgets in the widget
// tree, read text, and verify that the values of widget properties are correct.

import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';

import 'package:workspace/main.dart';

void main() {
  testWidgets('Counter increments smoke test', (WidgetTester tester) async {
    // Build our app and trigger a frame.
    await tester.pumpWidget(const MyApp());

    // Verify that our counter starts at 0.
    expect(find.text('0'), findsOneWidget);
    expect(find.text('1'), findsNothing);

    // Tap the '+' icon and trigger a frame.
    await tester.tap(find.byIcon(Icons.add));
    await tester.pump();

    // Verify that our counter has incremented.
    expect(find.text('0'), findsNothing);
    expect(find.text('1'), findsOneWidget);
  });
}

という記載が見える。
とりあえず、ここを書き換えれば、最初のアプリが作れるのかな、とアタリを付けています。

上記間違いでした。

vscodeで直接dockerコンテナの中を編集できるので、(これについては、どこかで話ます)、ターゲットは、lib/main.dartでした。

で、ちょっと変えて動くかどうか調べてみました。

という変更をして、

flutter run -d web-server --web-port=${WEB_SERVER_PORT} --web-hostname 0.0.0.0

を実施してみました。

で、http://192.168.0.23:8888 (192.168.0.23: DockerコンテナのあるPC)で、ちゃんと変更されているようです。

とりあえず、これで、改造するポイント分かりました。

その後、このlib/main.dart
https://zenn.dev/ryouhei_furugen/articles/583b1003ebcfc1
(Flutterのサンプル カウンターアプリ)にさしかえさせて頂きました。

問題なく動きました。


 

 

https://docs.flutter.dev/get-started/test-drive

ざっくり、翻訳してみておく

Test drive

What you'll learn

#

  1. How to create a new Flutter app from a sample template.
    サンプルテンプレートから新しいFlutterアプリを作成する方法。
  2. How to run the new Flutter app.
    新しいFlutterアプリの実行方法。
  3. How to use "hot reload" after you make changes to the app.
    アプリに変更を加えた後に「ホットリロード」を使用する方法。

Guide depends on your IDE
ガイドはあなたのIDEに依存します。

#

These tasks depend on which integrated development environment (IDE) you use.
これらの作業は、どの統合開発環境(IDE)を使うかによって異なる。

  • Option 1 explains how to code with Visual Studio Code and its Flutter extension.
    オプション1では、Visual Studio CodeとそのFlutter拡張機能を使ってコーディングする方法を説明する。
  • Option 2 explains how to code with Android Studio or IntelliJ IDEA with its Flutter plugin.
    オプション2では、Android StudioまたはIntelliJ IDEAのFlutterプラグインを使ってコーディングする方法を説明する。Flutter supports IntelliJ IDEA Community, Educational, and Ultimate editions.
    FlutterはIntelliJ IDEA Community版、Educational版、Ultimate版をサポートしています。
  • Option 3 explains how to code with an editor of your choice and use the terminal to compile and debug your code.
    オプション3では、好きなエディターを使ってコードを書き、ターミナルを使ってコンパイルとデバッグを行う方法を説明する。

Choose your IDE
IDEを選ぶ

#

Select your preferred IDE for Flutter apps.
Flutterアプリに適したIDEを選択する。

Create your sample Flutter app

#

  1. Open the Command Palette.
    コマンドパレットを開く。Go to View > Command Palette or press Shift + P.
    表示 > コマンドパレットに移動するか、+ Shift + Pを押します。
  2. Type flutter
    fluter
    とタイプする
  3. Select the Flutter: New Project.
    Flutter: New Projectを選択する
  4. When prompted for Which Flutter Project, select Application.
    どのFlutterプロジェクトかを聞かれたら、Applicationを選択する。
  5. Create or select the parent directory for the new project folder.
    新しいプロジェクトフォルダの親ディレクトリを作成または選択します。
  6. When prompted for a Project Name, enter test_drive.
    プロジェクト名の入力を求められたら、test_driveと入力する。
  7. Press Enter.
    Enterを押す。
  8. Wait for project creation to complete.
    プロジェクトの作成が完了するまで待つ。
  9. Open the lib directory, then the main.dart.
    libディレクトリを開き、次にmain.dartを開く。To learn what each code block does, check out the comments in that Dart file.
    各コードブロックが何をするのかを知るには、そのDartファイルのコメントをチェックしてほしい。

The previous commands create a Flutter project directory called test_drive that contains a simple demo app that uses Material Components.
先ほどのコマンドでtest_driveというFlutterプロジェクトディレクトリが作成され、Material Componentsを使ったシンプルなデモアプリが含まれる。

Run your sample Flutter app
サンプルのFlutterアプリを実行する

#

Run your example application on your desktop platform, in the Chrome web browser, in an iOS simulator, or Android emulator.
デスクトップ・プラットフォーム、Chromeウェブ・ブラウザ、iOSシミュレータ、Androidエミュレータでサンプル・アプリケーションを実行してください。

  1. Open the Command Palette.
    コマンドパレットを開く。Go to View > Command Palette or press Shift + P.
  2. Type flutter
    fluterとタイプする
  3. Select the Flutter: Select Device.
    Flutter: New Projectを選択するIf no devices are running, this command prompts you to enable a device.
    実行中のデバイスがない場合、このコマンドはデバイスを有効にするよう促します。
  4. Select a target device from Select Device prompt.
    Select Deviceプロンプトからターゲットデバイスを選択します。
  5. After you select a target, start the app. Go to Run > Start Debugging or press F5.
    ターゲットを選択したら、アプリを起動する。Run > Start Debuggingに進むか、F5を押す。
  6. Wait for the app to launch.
    アプリが起動するのを待つ。You can watch the launch progress in the Debug Console view.
    起動の進行状況は、デバッグコンソールビューで確認できます。

After the app build completes, your device displays your app.
アプリのビルドが完了すると、デバイスにアプリが表示されます。

Starter app on macOS
Starter app
スターターアプリ

Try hot reload
ホットリロードを試す

#

Flutter offers a fast development cycle with Stateful Hot Reload, the ability to reload the code of a live running app without restarting or losing app state.
Flutterは、ステートフルホットリロード(Stateful Hot Reload)、つまりアプリを再起動したりアプリの状態を失ったりすることなく、実行中のアプリのコードをリロードする機能によって、高速な開発サイクルを提供します。

You can change your app source code, run the hot reload command in VS Code, and see the change in your target device.
アプリのソースコードを変更し、VS Codeでホット・リロード・コマンドを実行すれば、ターゲット・デバイスで変更を確認できる。

  1. Open lib/main.dart.
    lib/main.dartを開く。
  2. Change the word pushed to clicked in the following string. It is on line 109 of the main.dart file as of this writing.
    以下の文字列のpushedをclickedに変更する。これを書いている時点では、main.dartファイルの109行目にある。

    Original New
    'You have pushed the button this many times:' , 'You have clicked the button this many times:' ,
  3. Save your changes: invoke Save All, or click Hot Reload lightning bolt .

Your app updates the string as you watch.
変更を保存する:すべて保存を実行するか、ホットリロードをクリックします。

Starter app after hot reload on macOS
Starter app after hot reload

未分類

https://suumo.jp/article/oyakudachi/oyaku/chintai/fr_room/tsuukinjikan_heikin/

https://toyokeizai.net/articles/-/140017?display=b

https://prtimes.jp/main/html/rd/p/000000286.000000624.html

未分類

カート、バスのコストを減らすテスト用に、tomioka_db_c_cost を作成

ebata@DESKTOP-P6KREM0 MINGW64 ~(こっちのシェルを使うこと。パイプを使うため)>createdb -U postgres -h 192.168.0.23 -p 15432 tomioka_db_c_cost
Password:

ebata@DESKTOP-P6KREM0 MINGW64 ~(こっちのシェルを使うこと。パイプを使うため)
$ pg_dump -U postgres -h 192.168.0.23 -p 15432 -Ft tomioka_db_c | pg_restore -U postgres -h 192.168.0.23 -p 15432 -d tomioka_db_c_cost

富岡地区のバス等の平均速度の算出

歩行に対するバスの歩行比 = 0.18

歩行に対するカートの歩行比 = 0.45

は、まだ未設定

 

未分類

 

バスは、平均速度17.9km/hくらい

カートは、平均速度7.2km/hくらい

高低差が富岡地区と程度の1.3kmをテスト歩行 / 24分
歩行は3.25km/hくらい

歩行に対するバスの歩行比 = 0.18

歩行に対するカートの歩行比 = 0.45

 

未分類

-o_lon 139.6295688 -o_lat 35.3660511 -d_lon 139.6270944 -d_lat 35.3636816

IN → IN

-o_lon 35.37104902612216 -o_lat 139.62783634404897 -d_lon 35.36679082984578 -d_lat 139.61990743230746

-o_lon 35.36370323013283 -o_lat 139.62581182970706 -d_lon 35.367220880193656 -d_lat 39.61545727502963

IN → GW → OUT(杉田駅)

-o_lon 35.370129658663075 -o_lat 139.61807940648757 -d_lon 35.38234353115761 -d_lat 139.6169048139053

OUT(金沢文庫) →  GW → IN

-o_lon 35.34242787509463 -o_lat 139.62188682227753 -d_lon 35.36560662891383 -d_lat 139.6284518375501

GWを解さないケースは考えなくてもいいか?

参考用IN座標
35.36806794078537 139.62553044883524
35.368460473893506 139.61904786225577
35.37428653450456 139.62427422430005
35.36540598985192 139.62776680008463
35.369043463845195 139.61565072257753
35.36750734475584 139.62092894663886
35.37074115832766 139.6246677711019
35.36402430298291 139.6278705652247
35.364924425352065 139.61977652223922
35.36501131116549 139.62219084352495
35.36948676753484 139.62847423044224
35.36389080286156 139.62455038923105
35.37062388152758 139.62152611976026
35.369585262158225 139.6169533355986
35.36355717334552 139.62111006291772
35.36659904745299 139.62566195874086
35.37257710543914 139.62647362169034
35.3680835911364 139.6229746670008
35.36975330554079 139.6237745742663
35.361949806922695 139.6228796060347
35.369835300106416 139.61538425327674
35.375224252194165 139.62127037638513
35.3682225046029 139.6248646383888
35.36790771075679 139.61695177096536
35.372372595731235 139.6240863659352

 

未分類

(図面)F:\しゅらばしゅう\有吉先生データ\富岡エリア_座標.pptx
(コード) C:\Users\ebata\tomioka_school\src\trip_school\main.go

Polygon使う時の注意点(赤丸に注意: db.Query()で簡単にエラーにされる

 

// C:\Users\ebata\tomioka3B\src\others\main35.go
/*
	実験用の座標を作る
	修正後 (富岡西5丁目を削除し、富岡6丁目の下1/4を削除)
*/

package main

import (
	"database/sql"
	"fmt"
	"log"
	"regexp"
	"strconv"

	_ "github.com/lib/pq"
)

func main() {
	// 取り扱うDBによってノード番号が代わるので注意すること
	// 例えばtomioka_db_c とtomioka_dbは全く異なる
	db, err := sql.Open("postgres",
		"user=postgres password=password host=192.168.0.23 port=15432 dbname=tomioka_db sslmode=disable")
	if err != nil {
		log.Fatal("OpenError: ", err)
	}
	defer db.Close()

	// 修正後のターゲットの富岡地区 (富岡西5丁目を削除し、富岡6丁目の下1/4を削除)

	query := `
	SELECT st_asText(
		ST_GeneratePoints(
			ST_GeomFromText(
				'POLYGON((
					35.36394967 139.61846500,
					35.36216810 139.61890850,
					35.36170465505306 139.6220415552594,
					35.36163108058289 139.62334070015595,
					35.363117271878345 139.62314221968566,
					35.36335187635167 139.62481739887647,
					35.36310056060587 139.62485183402688,
					35.36376860001917 139.6288186562702,
					35.36420166714637 139.6297897196359,
					35.36754482323006 139.6296024603071,
					35.37126945661188 139.62886244945108,
					35.37375189636854 139.62615207124352,
					35.37464657021711 139.623189740366,
					35.37574882601201 139.6213765671167,
					35.37527643251494 139.6210117866997,
					35.37306314467156 139.6217413475337,
					35.37268696718477 139.62013202216457,
					35.37018828750506 139.61840497406456,
					35.370782160278 139.61705458898427,
					35.36947068533102 139.61641732865053,
					35.370596575495014 139.61476348635583,
					35.37078029225879 139.61403393574466,
					35.36864433631068 139.61438212951467,
					35.36653571408147 139.61453772192408,
					35.36394967 139.61846500
				))'
			),
		25)
	)
	`
	rows, err := db.Query(query) // この25が生成する乱数座標

	if err != nil {
		log.Fatal(err)
	}
	defer rows.Close()

	var msg string

	for rows.Next() {
		if err := rows.Scan(&msg); err != nil {
			fmt.Println(err)
		}

		// まずはMULTIPOINTをバラバラに分解する
		arr1 := regexp.MustCompile("[() ,]").Split(msg, -1) // '('か、')'か、' 'か、","で分割する → "[中身]" という構造でまぎらわしい

		// 2つの値を一度に取得する (最初の値" MULTIPOIN"をスキップする為に、i:=1から始める)
		for i := 1; i < len(arr1); i += 2 {
			// arr1[i]とarr1[i+1]は2つの値を表します
			if i+1 < len(arr1) {
				value1, _ := strconv.ParseFloat(arr1[i], 64)   // 乱数の緯度
				value2, _ := strconv.ParseFloat(arr1[i+1], 64) // 乱数の経度
				fmt.Println(value1, value2)
			}
		}
	}
}