2022/07,江端さんの技術メモ

// go get github.com/lib/pq を忘れずに
// go run main12.go

/*
	Channelによるブロックを回避する方法として、Goのタイマー time.Timerで、定期的にブロックを破れるかのテストプログラム
*/

package main

import (
	"fmt"
	"time"

	_ "github.com/lib/pq"
)

var Ch1 chan interface{}

func channel_maker() {
	for {
		time.Sleep(2 * time.Second) // 2秒待つ ()
		Ch1 <- "Ebata is great"
	}
}

func main() {
	Ch1 = make(chan interface{}) // チャネルの初期化
	go channel_maker()

	ping := time.NewTimer(5 * time.Second) // イベントが何もなくても5秒後に発火するようにする
	defer ping.Stop()                      // main()を抜ける前に無効にしておく(なくてもいいかも)

	for {
		select {
		case a := <-Ch1:
			fmt.Println(a)
		case <-ping.C:
			fmt.Println("A ping is coming")
			ping = time.NewTimer(5 * time.Second) // イベントが何もなくても5秒後に発火するようにする
		}
	}
}

うむ・・・ちゃんと動く。困った。

2022/07,江端さんの忘備録

飲み物を取りにリビングに降りていくと、嫁さんと娘がテレビドラマを見ていました。

When I went down to the living room to get a drink, my wife and daughter watch the TV drama.

『ITで、全ての子どもに平等に学べる場所を作りたい』

"I will make a place where all children can study equally by IT"

てなセリフを語っている主人公と思われる役者を見ました。

In the drama, an actress, who seemed to play a main character, was speaking such a line.

-----

シニカルな笑顔を浮べて、私が「何か」を言い出そうとした時、

When I am about to say my comment with scornful smile,

―― 何も言わずに、とっとと自分の部屋に戻れ

"Say nothing and go back to your room soon"

という、圧を感じましたので、そのまま、飲み物を片手に、部屋に戻り戻りました。

I felt the pressure like that form them, so I went back to my room with a cup.

2022/03,江端さんの技術メモ

同じ現象が出て、青冷めていたら、自分の記事がヒットしました。

index.html

http://{s}.tile.osm.org/{z}/{x}/{y}.png → https://{s}.tile.osm.org/{z}/{x}/{y}.png
にしたら、直った

L.tileLayer('https://{s}.tile.osm.org/{z}/{x}/{y}.png', {
detectRetina: true,
maxNativeZoom: 18
}).addTo(map);

すぐに直って、本当によかった。

とは言え、そろそろ地図をローカルに取り込んでおく必要もあるかな・・・

キーワード
tile.osm.org  OSM 表示されない tile

 

2022/07,江端さんの忘備録

BS世界のドキュメンタリー 「インポッシブル・プロジェクト インスタントフィルムを復活させた男」

"BS World Documentary "The Impossible Project: The Man Who Revived Instant Film"

を見ました。

I watched the program.

「楽しかった」―― というか「嬉しかった」。

I enjoyed it, rather I feel happy.

-----

私は、自分の半生を、デジタル技術の先端分野で過してきた、という自覚があります。

I am self-conscious that I have spent half my life on the cutting edge of digital tech.

(ちょっと言い過ぎかもしれませんが、世間一般的には、間違っていないと思う)

(It is a bit of exaggeration, but in general, I don't think it's wrong)

だからこそ、「全てにおいて、デジタルがアナログより良い」と言い切れないことも、良く知っています

Therefore, I know that we should not say that "digital is superiors to analog at any case"

それはさておき。

That's aside.

-----

最近、さまざまな企業で、「創造性を高める為」の『共創空間』なるものが流行っているようです。

Recently many companies are trying t make "co-creation space" to "enhance creativity".

このような空間で、「創造性が高まった」という、客観的な(数値等を使った)報告書は見つけられていませんが、このような『おしゃれ』な空間で仕事をする人が好きな人は、多いのかもしれません。

I could not find the reports that show the effectiveness of "creativity" from objective viewpoint using numbers, however, some people seem to like to work in these fashionable space.

一方、私といえば ―― 「ビビッドな色彩の壁」「奇妙な形の(不安定な)椅子」「多くの仲間」「コーヒーの香り」の中で、特許ネタを捻り出せたことがありません ―― というか、

On the other hand, speaking of me, I have never been able to think of a patent story among the "vividly colored walls," "oddly shaped (unstable) chairs," "many friends," and "the smell of coffee.

むしろ「創作の邪魔」と言い切れるレベルです。

Rather, they are always "obstacles" for my patent work.

私の場合、「暗い」「寒い」「狭い」部屋で、たった一人でホワイトボードと対峙している時に、創造力は最高潮に達します。

In my case, my creativities go to the peak when I am alone in the "dark", "cold", "small" room, facing a whiteboard.

企業研究員で、特許出願100件(分割出願やパリ条約の優先権出願を含む)越えをしている人間(例えば、私(江端))が、それほど多いとは思えません。

I don't think that there are many people who have applied more than 100 patent applications( including "divided" or "priority by Paris treaty") to the patent office, like me.

それ故に、『共創空間』の効果は、個人差が大きいのかもしれませんし、または、私が例外的に「変な奴」なのかもしれません。

Therefore, the effectiveness of the "Co-Creation Space" may vary greatly from person to person, or I may be an exceptionally "weird guy".

まあ、「暗く寒く狭いセピア色の実験室」を、『共創空間』と言い張ったら、企業イメージは悪くなるとも思いますので、そこは、大人の事情として汲み取る必要はあると思っています。

Well, if a company insist that "dark, cold, small, sepia-colored laboratory" is a "co-creation space", the company's image will be in ruin. So I think that I have to understand the background of the company.

-----

最近、私、ホワイトボードの自作に関して、色々公開しています。

Recently, I have opened about a DIY whiteboard.

自作ホワイトボード ―― 完結編

私の研究員人生における創作活動で、もっとも役に立ったものは、「ホワイトボード」です。

The most useful item in my research engineer's life, has been "whiteboard"

PCでもスマホでもプリンタでもスキャナでもなく、そして、多くの有能の同僚ですらも「ホワイトボード」には、敵いません。

It is not PC, smartphone, printer, and scanner. Moreover, even my competent colleagues cannot exceed "whiteboard"

「ホワイトボード」といえば、ブレストでの知識の共有ツールとしての利用が定番ですが、私の場合「自分との対峙」の為のツールです。

"Whiteboard" is a common tool to share knowledges in brain storming, however in my case, it is a tool to "fight me".

つまり、ある種類のアナログは、今もまだ、私にとっての最強ツールなのです。

In short, some of analog are the strongest tools for me still now.

2022/07,江端さんの技術メモ

// go run main3.go

/*
	(1)固定長配列を試してみる
*/

package main

import "fmt"

type LocInfo struct {
	Lon float64
	Lat float64
}

func main() {

	var Li [60]LocInfo // 要素0で初期化されている

	for i := 0; i < 60; i++ {
		Li[i].Lon = float64(i)
		Li[i].Lat = float64(i)
	}

	fmt.Println(Li)

	Li[32].Lon = 0.001
	Li[32].Lat = 0.001

	fmt.Println(Li)

}

未分類

// go get github.com/lib/pq を忘れずに
// go run main5.go

/*
	(1)適当な座標情報を入力して、近くのOpenStreetMapのnodeに強制的に寄せて、ダイクストラ計算を強行する方法
	(ここでは300メートル以内で、もっとも近いノードを見つける、という処理をやっている)
*/
package main

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

	_ "github.com/lib/pq"
)

func main() {
	db, err := sql.Open("postgres",
		"user=postgres password=password host=localhost port=15432 dbname=utsu_db sslmode=disable")
	if err != nil {
		log.Fatal("OpenError: ", err)
	}
	defer db.Close()

	rows, err := db.Query("SELECT source, 
	x1 as longitude, y1 as latitude, ST_Distance('SRID=4326;POINT(139.9182893339256 36.573831584767085)'::GEOGRAPHY, the_geom) as dist FROM ways WHERE ST_DWithin(the_geom, ST_GeographyFromText('SRID=4326;POINT(139.9182893339256 36.573831584767085)'), 300.0) ORDER BY dist")
	if err != nil {
		log.Fatal(err)
	}
	defer rows.Close()

	for rows.Next() {
		var source int
		var longitude float64
		var latitude float64
		var dist float64

		if err := rows.Scan(&source, &longitude, &latitude, &dist); err != nil {
			fmt.Println(err)
		}
		fmt.Println(source, longitude, latitude, dist)
	}

	if err := db.Ping(); err != nil { //データベースが繋っているかの確認(らしい)
		log.Fatal("PingError: ", err)
	}
}

2022/07,江端さんの技術メモ

// go get github.com/lib/pq を忘れずに
// go run main9.go

/*
	(1)GolangでOpenStreetMap上にマップマッピングするプリミティブな江端式定番マッピング方法
	(http://kobore.net/over90.jpg参照)
*/

package main

import (
	"database/sql"
	"fmt"
	"log"
	"math"

	_ "github.com/lib/pq"
)

var source int
var longitude float64
var latitude float64
var dist float64

func rad2deg(a float64) float64 {
	return a / math.Pi * 180.0
}

func deg2rad(a float64) float64 {
	return a / 180.0 * math.Pi
}

func distance_km(a_longitude, a_latitude, b_longitude, b_latitude float64) (float64, float64) {
	earth_r := 6378.137

	loRe := deg2rad(b_longitude - a_longitude) // 東西  経度は135度
	laRe := deg2rad(b_latitude - a_latitude)   // 南北  緯度は34度39分

	EWD := math.Cos(deg2rad(a_latitude)) * earth_r * loRe // 東西距離
	NSD := earth_r * laRe                                 //南北距離

	distance_km := math.Sqrt(math.Pow(NSD, 2) + math.Pow(EWD, 2))
	rad_up := math.Atan2(NSD, EWD)

	return distance_km, rad_up
}

func diff_longitude(diff_p_x, latitude float64) float64 {

	earth_r := 6378.137
	// ↓ これが正解だけど、
	loRe := diff_p_x / earth_r / math.Cos(deg2rad(latitude)) // 東西
	// 面倒なので、これで統一しよう(あまり差が出ないしね)
	//loRe := diff_p_x / earth_r / math.Cos(deg2rad(35.700759)) // 東西
	diff_lo := rad2deg(loRe) // 東西

	return diff_lo // 東西
}

func diff_latitude(diff_p_y float64) float64 {
	earth_r := 6378.137
	laRe := diff_p_y / earth_r // 南北
	diff_la := rad2deg(laRe)   // 南北

	return diff_la // 南北
}

func main() {
	db, err := sql.Open("postgres", "user=postgres password=password host=localhost port=15432 dbname=utsu_rail_db sslmode=disable")
	if err != nil {
		log.Fatal("OpenError: ", err)
	}
	defer db.Close()

	rows, err := db.Query("SELECT seq,x1,y1 from lrt")
	if err != nil {
		log.Fatal(err)
	}
	defer rows.Close()

	x1, y1 := -1.0, -1.0
	_x1, _y1, _x2, _y2 := -1.0, -1.0, -1.0, -1.0
	px, py := -1.0, -1.0
	flag := 0
	f_flag := 0
	seq := -1

	for rows.Next() {

		if f_flag == 0 { // 初回だけ2二回入力
			if err := rows.Scan(&seq, &x1, &y1); err != nil {
				fmt.Println(err)
			}
			_x1, _y1 = x1, y1
			//fmt.Println(x1, y1)
			f_flag = 1
			continue
		}

		if err := rows.Scan(&seq, &x1, &y1); err != nil {
			fmt.Println(err)
		}
		//fmt.Println(seq, ",", x1, ",", y1)

		_x2, _y2 = x1, y1

		_, rad_up := distance_km(_x1, _y1, _x2, _y2)

		px, py = _x1, _y1

		for {
			// 5.56m/s → 時速20

			px += diff_longitude(0.00556*2*math.Cos(rad_up), py)
			py += diff_latitude(0.00556 * 2 * math.Sin(rad_up))

			//double rad0 = atan2((end_y - start_y),(end_x - start_x));
			//double rad1 = atan2((end_y - test_person.p_y),(end_x - test_person.p_x));

			rad0 := math.Atan2((_y2 - _y1), (_x2 - _x1))
			rad1 := math.Atan2((_y2 - py), (_x2 - px))
			// ここは、http://kobore.net/over90.jpg で解説してある

			if math.Abs(rad0-rad1) >= math.Pi*0.5 {
				// 終点越えの場合、終点に座標を矯正する
				px, py = _x2, _y2
				flag = 1 // フラグを上げろ
			}

			fmt.Println(px, ",", py)

			if flag == 1 {
				flag = 0
				_x1, _y1 = _x2, _y2
				break
			}
		}

	}

	if err := db.Ping(); err != nil {
		log.Fatal("PingError: ", err)
	}

}

未分類

// go get github.com/lib/pq を忘れずに
// go run main10.go

/*
	(1)golangの中でSQL文を作る時に、てっとり早く数値の部分を文字列にする方法
	(2)golangの可変長配列の作り方と、面倒くさい場所の値をひっぱり出す方法
*/

package main

import (
	"database/sql"
	"fmt"
	"log"
	"math/rand"

	_ "github.com/lib/pq"
)

func transfer_point(origin, destination int) (int, int) {
	// utsu_tram_db3をオープン
	db, err := sql.Open("postgres", "user=postgres password=password host=localhost port=15432 dbname=utsu_tram_db3 sslmode=disable")
	if err != nil {
		log.Fatal("OpenError: ", err)
	}
	defer db.Close()

	// node番号 1200 から 12000 までのダイクストラ計算を行う
	str := "SELECT seq, node, edge FROM pgr_dijkstra('SELECT gid as id, source, target, cost FROM ways'," + fmt.Sprint(origin) + "," + fmt.Sprint(destination) + ", directed:=false)"
	rows, err := db.Query(str)
	if err != nil {
		log.Fatal(err)
	}
	defer rows.Close()

	var seq, node, edge int
	var add_node_num = []int{} // 可変長配列

	for rows.Next() {
		if err := rows.Scan(&seq, &node, &edge); err != nil {
			fmt.Println(err)
		}

		// ルート分離は、0<x<70の値が出てきたら、駅のノードである、とする。
		// 何しろ、私が地図を改ざんしたのだから間違いない
		// で、その値を全部格納する

		if node > 0 && node < 70 {
			add_node_num = append(add_node_num, node)
		}
	}

	if len(add_node_num) >= 4 { // 見つけることができたら最初から2番目と、最後から2番目の番号(0 < X < 70)を取り出す
		first_node := add_node_num[1]
		last_node := add_node_num[len(add_node_num)-2]

		if (first_node > 0 && first_node < 70) || (last_node > 0 && last_node < 70) {
			return first_node, last_node
		} else {
			log.Fatal("wrong node:", err)
		}
		//fmt.Println("first_node:", first_node, "last_node:", last_node)

	} else { // 見つけることができなかったら
		return -1, -1
		//fmt.Println("No node")
	}

	return 0, 0 // ダミー用のリターン(ここには来ないはず)
}

func main() {
	fmt.Println(transfer_point(21509, 11215))

	for i := 0; i < 100; i++ {
		a := rand.Intn(30000)
		b := rand.Intn(30000)

		//fmt.Println(sub_main(2200, 2400))
		fmt.Println(a, b)
		fmt.Println(transfer_point(rand.Intn(a), rand.Intn(b)))
	}
}

2022/07,江端さんの技術メモ

// go get github.com/lib/pq を忘れずに

package main

import (
	"fmt"

	_ "github.com/lib/pq"
)

// GetLoc GetLoc
type GetLoc struct {
	ID    int     `json:"id"`
	Lat   float64 `json:"lat"`
	Lng   float64 `json:"lng"`
	TYPE  string  `json:"type"` // "USER","BUS","CONTROL
	POPUP int     `json:"popup"`
	//Address string  `json:"address"`
}

func person(gl2, gl3 *GetLoc) {

	if gl2.Lng > 0.0 {
		fmt.Println("pass1", gl2)
	} else {
		fmt.Println("pass2", gl2)
	}
}

func person_real() {
	var gl2, gl3 GetLoc

	gl2.Lng = 139.00

	person(&gl2, &gl3)

}

func main() {

	var gl2, gl3 GetLoc

	person(&gl2, &gl3)

	person_real()

}

2022/07,江端さんの忘備録

(私は投票を済ませてきましたが、)明日7/10日は、参議院議員選挙の投票日です。

(Though I have already voted before), tomorrow July 10 is the day to vote for the House of Councillors.

投票所に行く前に、思い出して頂きたいことがあります。

I would like you to remained you of the following incidents, before you go to vote.

■コロナ禍での政府自粛要請の渦中に、宴会やらかしていた政治家一覧(江端が拾ったものだけ)

- List of politicians who were having banquets during the government's restrict request in the corona disaster (only those picked up by Ebata).

『腹掻き切って、国民に詫びて見せろ』―― てな、時代錯誤的なバカげたことを書いてみてもよかったかな、とか、今なら思っています。

■政治資金収支報告書のオンラインシステムの使用した/使用していない団体の政治家一覧

- List of politicians from organizations that used/not used the online system for political fund balance reports

国会議員関係政治団体を政治家名で紐付けして、オンライン提出を無視している比率(オンライン提出無視率)を算出しました。

これは、政治家ではありませんが、厚生労働省の職員が、23人が東京・銀座の飲食店で会食していた事件もありましたね。

The following is not about politician, but there was also incident in which 23 employees of the Ministry of Health, Labor and Welfare had dinner together at a restaurant in Ginza, Tokyo.

官僚や政治家の組織は知りませんが、民間の企業では、この対応が普通です。

-----

先日、英国の首相が「政府自粛要請の渦中でのパーティ」の件で、ようやく辞任に追い込まれました。

The other day, the British Prime Minister was finally forced to resign during the party in the government restraint.

我が国の外交と内政、どちらも両方大切ですが、私たち有権者は『あの怒り』を思い出すことも大切な仕事です。

Both our country's foreign and domestic policy are important for us , but we also have to remained the anger at that time.

あなたが投票する候補者の「資質」や「ふるまい」を、事前に確認されることをお勧めします。

I strongly recommend to check the qualifications and behaviors of candidate you will vote beforehand.

『私たちを怒らせると、怖いぞ』ということを、これから政治家になる人には、覚えておいて貰わなければ困ります。

We have to teach the candidates who will the election that "if you make us angry we become furious enemies against you".