2023,江端さんの技術メモ

PostgreSQLで、新規のデータならinsert, 書き換えならupdate をしようと思ったのですが、なんか面倒くさいので、初期テーブルを沢山作っておくことで対応することしました。

というか、そういうメソッドを準備しておいて欲しい→あるみたいですが、上手く動かせませんでした。

package main

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

	_ "github.com/lib/pq" // ←これを追記
)

func main() {
	// user_log, bike_logへのアクセス
	dbAgent, err := sql.Open("postgres", "user=postgres password=password host=192.168.0.23 port=15432 dbname=agent_db sslmode=disable")
	if err != nil {
		log.Fatal("dbAgent OpenError: ", err)
	}
	defer dbAgent.Close()
	err = dbAgent.Ping()
	if err != nil {
		log.Fatal(err, "\nHint: dbAgent Database may not have started")
	}
	// user_logテーブルの内容の全削除
	dbAgent.Query("delete from bike_log;")

	// insertのテスト
	for i := 0; i < 10; i++ {
		str := fmt.Sprintf("insert into bike_log (stationid, num_bikes) values(%d, -1)", i)
		fmt.Println(str)
		dbAgent.Query(str)
	}

	// updateのテスト
	for i := 0; i < 10; i = i + 2 {
		str := fmt.Sprintf("update bike_log set num_bikes = %d where stationid = %d", i*2, i)
		fmt.Println(str)
		dbAgent.Query(str)
	}
}

出力結果

C:\Users\ebata\yamaguchi\src_try1\others> go run main4.go
insert into bike_log (stationid, num_bikes) values(0, -1)
insert into bike_log (stationid, num_bikes) values(1, -1)
insert into bike_log (stationid, num_bikes) values(2, -1)
insert into bike_log (stationid, num_bikes) values(3, -1)
insert into bike_log (stationid, num_bikes) values(4, -1)
insert into bike_log (stationid, num_bikes) values(5, -1)
insert into bike_log (stationid, num_bikes) values(6, -1)
insert into bike_log (stationid, num_bikes) values(7, -1)
insert into bike_log (stationid, num_bikes) values(8, -1)
insert into bike_log (stationid, num_bikes) values(9, -1)
update bike_log set num_bikes = 0 where stationid = 0
update bike_log set num_bikes = 4 where stationid = 2
update bike_log set num_bikes = 8 where stationid = 4
update bike_log set num_bikes = 12 where stationid = 6
update bike_log set num_bikes = 16 where stationid = 8

データベースの中身

agent_db=# select * from bike_log;
stationid | num_bikes
-----------+-----------
1 | -1
3 | -1
5 | -1
7 | -1
9 | -1
0 | 0
2 | 4
4 | 8
6 | 12
8 | 16
(10 rows)

 

2023,江端さんの忘備録

「「お金に愛されないエンジニア」のための新行動論」の最新記事が掲載されました。

The latest article on "New Behavioral Theory for 'Engineers Not Loved by Money'" has been published.

■最新記事

-Latest Articles

「お金がなくてもそこそこ幸せになれるのか」を宗教と幸福感から真剣に解析してみる

A serious analysis of "Can I be happy there without money?" from the perspective of religion and happiness.

今回は、「なぜ、カルトの信者はあんなに幸せそうなのか」という疑問に端を発して、「お金がなくてもそこそこ幸せになれるのか」を宗教と幸福感から真剣に解析してみました。

In this issue, I have seriously analyzed the question "Why do cult members seem so happy?" from the perspective of religion and happiness, starting with the question "Why do they seem so happy even without money?

 

2023,江端さんの技術メモ

最初はエクスポートです。

Microsoft Windows [Version 10.0.19044.2486]
(c) Microsoft Corporation. All rights reserved.
C:\Users\ebata>psql -U postgres -h 192.168.0.23 -p 15432
Password for user postgres:
psql (13.4, server 12.5 (Debian 12.5-1.pgdg100+1))
Type "help" for help.
postgres=# \c agent_db
psql (13.4, server 12.5 (Debian 12.5-1.pgdg100+1))
You are now connected to database "agent_db" as user "postgres".
agent_db=# \copy user_list to 'testtest.csv' WITH CSV DELIMITER ',';
COPY 20
agent_db=#
C:\Users\ebata に、testtest.csv ができています。
カラム名が必要な場合は、こちら(大抵の場合必要)。
agent_db=# \copy user_list to 'testtest.csv' WITH CSV HEADER;
次にインポートです。
以下のcsvファイルをインポートします。ファイル名はkai_20220522holyday18.csvです。
id,age,type,departure_name,departure_number,departure_lat,departure_lng,arrival_name,arrival_number,arrival_lat,arrival_lng
0,43,resident,,,34.173408,131.470684,,,34.155862,131.501246
1,24,resident,,,34.179449,131.482543,,,34.164116,131.471791
2,42,resident,,,34.168739,131.470768,,,34.160989,131.491124
3,21,resident,,,34.169494,131.469934,,,34.173498,131.471351
4,58,resident,,,34.185295,131.47414,,,34.191481,131.49456
5,48,resident,,,34.150778,131.480747,,,34.16536,131.471872
6,56,resident,,,34.16536,131.471872,,,34.174066,131.479312
7,73,resident,,,34.155731,131.500845,,,34.16776,131.472831
8,47,resident,,,34.167237,131.471785,,,34.155775,131.476531
9,21,resident,,,34.154931,131.50468,,,34.156678,131.49581
10,37,resident,,,34.16727,131.472899,,,34.171253,131.471177
11,40,resident,,,34.147241,131.474921,,,34.150675,131.486268
12,67,resident,,,34.173683,131.476347,,,34.173643,131.471027
13,28,resident,,,34.183079,131.484303,,,34.174245,131.474592
14,46,resident,,,34.146154,131.472711,,,34.159611,131.491548
15,25,resident,,,34.162497,131.489283,,,34.147212,131.475984
次に、テーブルをクリアにします。
agent_db=# delete from user_list;
DELETE 36
agent_db=# select * from user_list;
id | age | type | departure_name | departure_number | departure_lat | departure_lng | arrival_name | arrival_number | arrival_lat | arrival_lng
----+-----+------+----------------+------------------+---------------+---------------+--------------+----------------+-------------+-------------
(0 rows)
として、
agent_db=# \copy user_list from 'kai_20220522holyday18.csv' delimiter ',' csv header;
でインポートが完了します。
一応、確認します。
agent_db=# select * from user_list;
id | age | type | departure_name | departure_number | departure_lat | departure_lng | arrival_name | arrival_number | arrival_lat | arrival_lng
----+-----+----------+----------------+------------------+---------------+---------------+--------------+----------------+-------------+-------------
0 | 43 | resident | | | 34.173408 | 131.470684 | | | 34.155862 | 131.501246
1 | 24 | resident | | | 34.179449 | 131.482543 | | | 34.164116 | 131.471791
2 | 42 | resident | | | 34.168739 | 131.470768 | | | 34.160989 | 131.491124
3 | 21 | resident | | | 34.169494 | 131.469934 | | | 34.173498 | 131.471351
4 | 58 | resident | | | 34.185295 | 131.47414 | | | 34.191481 | 131.49456
5 | 48 | resident | | | 34.150778 | 131.480747 | | | 34.16536 | 131.471872
6 | 56 | resident | | | 34.16536 | 131.471872 | | | 34.174066 | 131.479312
7 | 73 | resident | | | 34.155731 | 131.500845 | | | 34.16776 | 131.472831
8 | 47 | resident | | | 34.167237 | 131.471785 | | | 34.155775 | 131.476531
9 | 21 | resident | | | 34.154931 | 131.50468 | | | 34.156678 | 131.49581
10 | 37 | resident | | | 34.16727 | 131.472899 | | | 34.171253 | 131.471177
11 | 40 | resident | | | 34.147241 | 131.474921 | | | 34.150675 | 131.486268
12 | 67 | resident | | | 34.173683 | 131.476347 | | | 34.173643 | 131.471027
13 | 28 | resident | | | 34.183079 | 131.484303 | | | 34.174245 | 131.474592
14 | 46 | resident | | | 34.146154 | 131.472711 | | | 34.159611 | 131.491548
15 | 25 | resident | | | 34.162497 | 131.489283 | | | 34.147212 | 131.475984
(16 rows)

2023,江端さんの忘備録

特許庁に特許明細書を提出(出願)するだけでは、特許権を得ることはできません。

Simply submitting a patent specification to the Patent Office (filing an application) is not enough to obtain a patent right.

出願から3年以内に、特許庁に自分の発明を審査して貰う請求をする必要があります。

You must file a request to have your invention examined by the Patent Office within three years of filing the application.

これを「出願審査請求」と言います。

This is called a "request for application examination".

この請求をすることで、はじめて特許の審査官と出願人(発明者)とのバトルが開始されることになります。

By filing this request, the battle between the patent examiner and the applicant (inventor) will begin for the first time.

請求をしなければ、その発明を、特許発明にバージョンアップさせることはできません(つまり、特許権は得られない)。

If you do not file a claim, you cannot have your invention upgraded to a patented invention (i.e., you cannot obtain a patent right).

ところが「出願審査請求」は値段が高いのです。

However, the "request for application examination" is expensive.

=====

特許出願 14,000円

Patent application 14,000 yen

出願審査請求 138,000円+(請求項の数×4,000円)

Request for application examination: 138,000 yen + (number of claims x 4,000 yen)

=====

ですので、普通の会社においては、出願数に対して、出願審査請求の数を絞ることになります。

So, in an ordinary company, the number of requests for application examination is narrowed down in relation to the number of applications.

-----

さて、この「出願審査請求」を誰が判断するか? ―― 多くの場合、発明者本人です。

Now, who makes the decision on this "request for application examination"? -- in many cases, the inventor himself/herself.

なぜなら、他人の発明を理解することは、もの凄く難しいからです。

This is because it is extremely difficult to understand other people's inventions.

ところが、ここに問題があります。

However, there is a problem here.

企業の発明者の中には、

There are two types of inventors in a company.

(1)凄く優れた発明をしたのに、自己評価レベルが低すぎて、簡単に出願審査請求を諦めてしまう人

(1) Those who have made a very good invention, but their self-evaluation level is too low and they easily give up on their request for application examination.

(2)恐しく凡庸な発明なのに、自己評価レベルが高すぎて、バシバシ出願審査請求をしてしまう人

(2) Those who request application examination too frequently because their self-evaluation level is too high, even though their invention is terribly mediocre.

の2種類がいます。

つまり、

In other words,

―― 優れた発明が出願審査請求されず、どーでもいい凡庸な発明が出願審査請求される

"Excellent inventions are not requested for application examination, while mediocre inventions are requested for application examination."

という事態が発生してしまうのです。

This above situation occurs.

-----

で、私がどういうタイプの人間かというと、当然、上記(2)です。

And what type of person am I, of course, (2) above.

会社(というか社会)においては、『努力をしている奴』よりも、『能力がある奴』よりも、『騒いでいる奴』の方が強い、というのは、ある意味、事実です。

In a sense, it is a true that in a company (or rather, society), "those who make a fuss" are stronger than "those who make an effort" or "those who are capable".

嫌な話だとは思いますが。

I know it is a disgusting story.

2023,江端さんの忘備録

今、壮絶に凹んでいます。

昨日の続きですが、江端家では、凹んだり、鬱(うつ)になると、

As a continuation of yesterday's diary, in the Ebata family, when we feel down or depressed,

―― <北>が核ミサイルを打ち込むなら、「今」やってくれないかな

-- If the is going to launch nuclear missiles, I hope they do it "now".

―― 都心ではではなく、多摩地区に直撃で

-- not in the center of Tokyo, but directly in the Tama area.

という、会話を、(主に長女と二人)でします。

We have conversations (mainly with my eldest daughter) about this.

これって、「死刑になりたくて、人を殺害しようとした」という奴より、悪質と言えるかもしれません。

This could be considered more vicious than the guy who "wanted to be executed and tried to murder people.

-----

『死刑になりたいから事件を起こした』

という訳で、私に言わせれば「死にたいけど、死にきれない」だの、「死刑になりたい」だの言っている奴は、『覚悟が足りない』のです。

―― 殺害対象が『誰でもいい』って、どういうこと? そんでもって『捕まって死刑になりたい』って、どういうこと?

上記のような文を偉そうに書いている奴の正体は、実際は、この程度の豆腐のようなメンタルの持ち主です。

The guy who writes the above diary pretending a great writer, is, in fact, of this level of tofu-like mentality.

笑ってやって下さい。

Please laugh at me.

2023,江端さんの忘備録

先週、時間をかけて、十分に練り上げたつもりの資料で、発表してきましたが、質疑応答で、

I gave a presentation last week with materials that I thought were well thought out, but during the Q&A session

―― よく分からん

"I don't understand"

と言れて、今、壮絶に凹んでいます。

I am now in a spectacularly depressed state after that.

少なくとも、この週末は、何かをしようとする気力が出ずに、ボーっとしていました。

At least, I was in a daze this past weekend, unable to muster the energy to do anything.

体重が1日で1kg落ちました。

My weight dropped 1 kg in one day.

-----

ただ、私、この年齢になって、この「よく分からん」が『よく分かる』のです。

However, I, at my age, 'understand' this "I don't know" very well.

私も、ここ10年くらい、社内で(特に発明のブレスト)で、このフレーズを乱発して、色々な人(特に若手)を凹ましてきたことは間違いありません。

I have no doubt that I have also used this phrase wildly in my company (especially at invention brainstorming sessions) for the past 10 years, and I made many people (especially younger people) depressed.

そういう意味では、私のようなシニアは、時々、こういう辛辣な言葉を言われて凹むことは、結構大切なことなのかもしれません。

In that sense, it is probably quite important for seniors like me to be depressed by such harsh words from time to time.

とは言え、やっぱり、凹むのは辛いです。

But it is still hard to be depressed.

たとえ、それがダイエットになろうとも、です。

Even if it works for a diet.

2023,江端さんの忘備録

私、瀬戸口みづきさんの著書が好きなのですが、その中でも「ローカル女子の遠吠え」は特に好きです。

I like Mizuki Setoguchi's books, especially "Howl of a Local Girl".


第9巻に記載されていた番外編の以下のセリフは、胸を打ちました。

The following lines from the extra edition listed in Volume 9 struck a chord.

======

『海外で貧困の現実を知りました』

"I learned about the reality of poverty overseas"

「それ国内でわかんなかったの? いいね押す代わりに、目玉に親指入れてやろうか」

"You didn't get that in Japan? I'll put my thumb in your eyeball instead of hitting the 'good' button"

======

少なくとも、私のティーンエイジャは、『目玉に親指入れらても文句は言えなかった』と思います。

At least, I think my teenager 'couldn't complain about having his thumb in his eyeball.

そして、"今ごろ"になって、その現実を(資料やデータから)知り、呆然とし、そして、そこから『目を背ける大人』になりました。

Then, "around this time", I learned of the reality (from data and documents), was stunned, and became an adult who "turned away" from the serious problem.

子ども達が、私のような大人にならないよう、また、私の大人を量産しないような教育を ―― (私以外のエラい人に)期待しています。

I hope that my children will be educated -- (by great other than myself) so that they will not become adults like me and not mass produce adults like me.

----

それと、以下のセリフも好きです。

And I also like the following lines.

======

「うーん・・・ 左右とか上下とかじゃなくて、人生ってもっと3Dじゃない?」

"Ummm... isn't life more 3D, not just left to right or up and down?"

======

うん、人生の次元は3Dどころか、もっとあると思います。

Yeah, I agree that there are more dimensions to life than just 3D.

ただ、私の場合は、極端に次元数が少ない気がします ―― 「パソコンの前に座っている/座っていない」の軸があるだけです。

However, I feel that I have an extremely low number of dimensions -- I just have a "sitting/not sitting in front of a computer" axis.

-----

ちなみに、現在、物理学において定説となっている理論(超弦理論)では、宇宙は少なくとも11次元あるそうです。

Incidentally, the currently accepted theory in physics (superstring theory) says that the universe has at least 11 dimensions.

いつか、きちんと勉強して、コラムのネタにしてみたいです。

Someday I would like to study it properly and use it as fodder for a column.

未分類

このコンテンツはパスワードで保護されています。閲覧するには以下にパスワードを入力してください。

2023,江端さんの忘備録

テレビを見ていたら、釜ケ崎越冬闘争のニュースが流れていました。

I was watching TV and saw news about the Kamagasaki wintering struggle.

大学の自治寮に住んでいた時に、何度か先輩からボランティア要員としての誘いを受けていたのですが、帰省などもあって、一度も行くことはありませんでした。

When I lived in the university's self-governing dormitory, I had received several invitations from seniors to be volunteer personnel, but I never went because I had to return home.

今ごろになって『行っておけばよかったな』と思っています。

By now I'm thinking, 'I wish I had gone.

-----

私は、阪神淡路大震災の時に、ボランティアに参加しました。

I volunteered at the time of the Great Hanshin-Awaji Earthquake.

電力が完全に途絶えた漆黒の闇の街と、骨の髄まで凍りつくような夜の辛さを、今も覚えています。

I still remember the jet-black darkness of the city with its power completely cut off and the pain of the night that chilled me to the bone.

-----

最近のウェルビーイングの研究では、ボランティアのような「他利行為」は、自分の幸福度を上げる「自利行為」であることは、常識らしいです。

In recent research on wellbeing, it seems to be common knowledge that "altruistic acts" such as volunteering are "self-interested acts" that increase one's well-being.

―― ボランティアは偽善ではないのか ?

"Isn't volunteering hypocritical? "

などと悩む必要はありません。

You don't have to worry about such things.

それどころか、『ボランティアは、自分の娯楽です』と言い切ってO.K.です。

On the contrary, it is O.K. to say, 'Volunteering is my pastime'

そのようなボランティア活動でも、十分にWin-Winの関係を築くことができるのです。

Even such volunteer work can be a sufficient win-win.

『ボランティア活動参加 = ディズニーランド来園』というレベルまで、意識を軽量化しましょう。

Let's lighten our awareness to the level of "participating in volunteer activities = visiting Disneyland.

ですから、好きな時に始めて、好きな時に止めしまって、全く構いません。

Therefore, you can start whenever you want and stop whenever you want.

「ディズニーランドに来園したら、閉館まで居なければならない」なんてことはないですからね。

"Even if you come to Disneyland, you don't have to stay until the park closes."

-----

誰かが何かを言ってきたら、私が、ガッチリとあなたを弁護します。

If someone says to you something, I will defend you.

2023,江端さんの忘備録

BS1スペシャル「プーチン 知られざるガス戦略 ~徹底検証 20年の攻防」を見ました。

I watched the BS1 special "Putin: The Unknown Gas Strategy - An In-Depth Look at 20 Years of Offensive and Defense".

『なるほど、世界を相手にする戦争とは、こういう風にやるのか』と、非常に感心しました。

I was very impressed, thinking, 'I see, this is how a war against the world is conducted.

これに比べると、同じ大国でも、『米国の戦争は場当たりで節操がないなぁ』と感じました。

Compared to this, even the same superpower, I felt that 'U.S. wars are opportunistic and unrestrained.

日本の太平洋戦争の開戦のおそまつさに至っては、『プーチンの爪の垢を煎じて飲め』と言えるくらいです。

When it comes to Japan's lousy start of the Pacific War, I could say, "Drink from Putin's fingernails.

ちなみに、私は「正義」や「善悪」の話はしていません。

By the way, I am not talking about "justice" or "right and wrong".

純粋に、「戦争のやり方」の話をしています。

I am talking purely about "how to conduct warfare".

まあ、日本は、資源もないし、大国でもありませんので、ロシアも米国も、全く参考にはなりませんが。

Well, Japan has no resources and is not a great power, so neither Russia nor the U.S. can be of any help at all.

-----

ところで、以前、オイルショックで酷い目にあった後の、我が国のエネルギー輸入事情について、書いたことがあります。

By the way, I have written before about our country's energy import situation after the terrible oil shock.

 

 

『今の日本は、「外国の気まぐれ」対策として、バラバラの国から、ちまちまとエネルギー燃料を買い付けています。ざっくりこんな感じです』

"Today, Japan is buying energy fuels from disparate countries in a piecemeal fashion as a countermeasure to 'foreign whims. Here's a rough table of what's going on"

『コスト度外視で、どんなささいなコネでも作っておくという、「全方向」からエネルギー資源を確保するという涙ぐましい戦略が見てとれます』

"The "tearful strategy to secure energy resources from 'all directions' is evident: 'We will make any connections, no matter how trivial, without regard to cost"

―― てなことを書いていました。

-----

現在、ドイツは、ロシアからエネルギーで散々痛めつけられています。

Germany is currently being hurt a lot by Russia with energy.

今後、ドイツは我が国と同様「全方向政策」に変換するのだろうなぁ、と、思いながら、番組を見ていました。

I was watching the program, thinking that Germany will probably convert to an "all-round policy" in the future, just like our country.